/* ============================================================
   Marché X3 — Assistant Chat IA (Style ChatGPT)
   ============================================================ */

.chat-page-wrap {
  background: #F4F7F5;
  padding: 18px 0 28px;
}

.chat-app-shell {
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr);
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
  height: calc(100vh - 155px);
  min-height: 610px;
  max-height: 900px;
  position: relative;
}

/* ---------- Sidebar ---------- */
.chat-sidebar {
  background: #0F291A;
  color: #EAF4EE;
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  min-height: 0;
}

.chat-sidebar-head {
  padding: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: grid;
  gap: 10px;
}

.chat-new-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.09);
  color: #FFFFFF;
  font-weight: 800;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.18s ease;
}

.chat-new-btn:hover {
  background: var(--brand-green);
  border-color: var(--brand-green);
  transform: translateY(-1px);
}

.chat-autofill-box {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(250, 204, 21, 0.25);
  border-radius: 12px;
  padding: 10px 12px;
  display: grid;
  gap: 8px;
}

.chat-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.82rem;
  font-weight: 700;
  color: #FFFFFF;
  cursor: pointer;
}

.chat-switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

.chat-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.chat-switch-slider {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  transition: 0.2s;
  cursor: pointer;
}

.chat-switch-slider::before {
  content: "";
  position: absolute;
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background: #FFFFFF;
  border-radius: 50%;
  transition: 0.2s;
}

.chat-switch input:checked + .chat-switch-slider {
  background: #22C55E;
}

.chat-switch input:checked + .chat-switch-slider::before {
  transform: translateX(18px);
}

.chat-mode-select {
  width: 100%;
  background: rgba(0, 0, 0, 0.28);
  color: #FACC15;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 0.78rem;
  font-weight: 700;
  outline: none;
}

.chat-mode-select option {
  background: #0F291A;
  color: #FFFFFF;
}

.chat-history-label {
  padding: 12px 16px 6px;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(255, 255, 255, 0.52);
}

.chat-sessions-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-session-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 10px;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.84);
  font-size: 0.84rem;
  transition: background 0.15s ease;
  border: 1px solid transparent;
}

.chat-session-item:hover {
  background: rgba(255, 255, 255, 0.09);
  color: #FFFFFF;
}

.chat-session-item.active {
  background: rgba(22, 128, 57, 0.45);
  border-color: rgba(34, 197, 94, 0.4);
  color: #FFFFFF;
}

.chat-session-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.chat-session-del {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.45);
  cursor: pointer;
  padding: 2px 5px;
  border-radius: 6px;
  font-size: 0.82rem;
  flex-shrink: 0;
}

.chat-session-del:hover {
  color: #FCA5A5;
  background: rgba(239, 68, 68, 0.2);
}

.chat-sidebar-cart {
  padding: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.22);
  display: grid;
  gap: 8px;
}

.chat-sidebar-cart-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.84rem;
}

.chat-sidebar-cart-total {
  color: var(--brand-yellow);
  font-weight: 900;
  font-size: 1rem;
  font-family: 'Cairo', sans-serif;
}

/* ---------- Main Chat Area ---------- */
.chat-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: #FCFDFC;
}

.chat-topbar {
  padding: 12px 20px;
  background: #FFFFFF;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.chat-topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.chat-mobile-toggle {
  display: none;
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 11px;
  font-weight: 800;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--ink-main);
}

.chat-ai-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, #E9F7EE 0%, #FEF3C7 100%);
  color: var(--brand-green-dark);
  border: 1px solid #BBF7D0;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.chat-topbar-title {
  font-weight: 800;
  font-size: 0.96rem;
  color: var(--ink-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.chat-live-cart-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--brand-red-soft);
  color: var(--brand-red);
  border: 1px solid #FECACA;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.16s ease;
}

.chat-live-cart-pill:hover {
  background: var(--brand-red);
  color: #FFFFFF;
}

/* ---------- Messages Viewport ---------- */
.chat-messages-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  scroll-behavior: smooth;
}

.chat-stream-inner {
  max-width: 820px;
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Welcome Screen */
.chat-welcome {
  max-width: 740px;
  margin: 18px auto 8px;
  text-align: center;
}

.chat-welcome-icon {
  width: 68px;
  height: 68px;
  margin: 0 auto 14px;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--brand-green-dark) 0%, var(--brand-green) 60%, #22C55E 100%);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  box-shadow: 0 12px 28px rgba(22, 128, 57, 0.24);
}

.chat-welcome h1 {
  margin: 0 0 8px;
  font-size: 1.65rem;
  font-weight: 900;
  color: var(--ink-main);
}

.chat-welcome-sub {
  margin: 0 auto 22px;
  max-width: 600px;
  font-size: 0.94rem;
  color: var(--ink-secondary);
  line-height: 1.65;
}

.chat-lang-pills {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 22px;
}

.chat-lang-pills span {
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink-secondary);
}

.chat-starters-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  text-align: left;
}

.chat-starter-card {
  background: #FFFFFF;
  border: 1.5px solid var(--border);
  border-radius: 16px;
  padding: 14px 16px;
  cursor: pointer;
  transition: all 0.18s ease;
  display: flex;
  flex-direction: column;
  gap: 5px;
  box-shadow: var(--shadow-sm);
}

.chat-starter-card:hover {
  border-color: var(--brand-green);
  background: #F4FBF6;
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(15, 102, 43, 0.1);
}

.chat-starter-card.rtl {
  direction: rtl;
  text-align: right;
  font-family: 'Cairo', sans-serif;
}

.chat-starter-tag {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--brand-green-dark);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.chat-starter-q {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--ink-main);
  line-height: 1.45;
}

/* Message Rows */
.chat-msg-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  animation: chatFadeIn 0.22s ease;
}

@keyframes chatFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-msg-row.user {
  justify-content: flex-end;
}

.chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
  font-weight: 900;
}

.chat-avatar.assistant {
  background: linear-gradient(135deg, var(--brand-green-dark), var(--brand-green));
  color: #FFFFFF;
  box-shadow: 0 4px 12px rgba(22, 128, 57, 0.22);
}

.chat-msg-content-wrap {
  max-width: 88%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-msg-row.user .chat-msg-content-wrap {
  max-width: 78%;
  align-items: flex-end;
}

.chat-bubble {
  padding: 13px 17px;
  border-radius: 18px;
  font-size: 0.95rem;
  line-height: 1.7;
  word-wrap: break-word;
}

.chat-bubble.user {
  background: linear-gradient(135deg, var(--brand-green-dark) 0%, var(--brand-green) 100%);
  color: #FFFFFF;
  border-bottom-right-radius: 5px;
  box-shadow: 0 5px 14px rgba(15, 102, 43, 0.18);
  font-weight: 500;
}

.chat-bubble.assistant {
  background: #FFFFFF;
  color: var(--ink-main);
  border: 1px solid var(--border);
  border-top-left-radius: 5px;
  box-shadow: var(--shadow-sm);
}

.chat-bubble.rtl {
  direction: rtl;
  text-align: right;
  font-family: 'Cairo', sans-serif;
  font-size: 0.99rem;
}

.chat-bubble p {
  margin: 0 0 10px;
}

.chat-bubble p:last-child {
  margin-bottom: 0;
}

.chat-bubble ul, .chat-bubble ol {
  margin: 6px 0 10px;
  padding-inline-start: 22px;
}

.chat-bubble li {
  margin-bottom: 4px;
}

.chat-bubble strong {
  color: inherit;
  font-weight: 800;
}

.chat-bubble.assistant strong {
  color: #0F3D1E;
}

.chat-msg-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.73rem;
  color: var(--ink-muted);
  padding-inline: 4px;
}

/* Recommended Basket Card inside Assistant Message */
.chat-basket-card {
  background: linear-gradient(180deg, #FFFFFF 0%, #F7FCF8 100%);
  border: 1.5px solid #B7E4C7;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 6px 18px rgba(15, 102, 43, 0.08);
}

.chat-basket-head {
  background: linear-gradient(90deg, #E9F7EE 0%, #FFFDF4 100%);
  padding: 11px 15px;
  border-bottom: 1px solid #D1FAE5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.chat-basket-title {
  font-weight: 900;
  font-size: 0.9rem;
  color: var(--brand-green-dark);
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-basket-badges {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.chat-pill-filled {
  background: #168039;
  color: #FFFFFF;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 800;
}

.chat-pill-budget {
  background: #FEF3C7;
  color: #92400E;
  border: 1px solid #FDE68A;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 800;
}

.chat-basket-items {
  display: grid;
  gap: 1px;
  background: #EDF4EF;
  max-height: 310px;
  overflow-y: auto;
}

.chat-basket-item {
  background: #FFFFFF;
  padding: 9px 14px;
  display: flex;
  align-items: center;
  gap: 11px;
}

.chat-basket-item img {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #FAFAFA;
  flex-shrink: 0;
}

.chat-basket-item-info {
  flex: 1;
  min-width: 0;
}

.chat-basket-item-name {
  font-weight: 800;
  font-size: 0.86rem;
  color: var(--ink-main);
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-basket-item-name:hover {
  color: var(--brand-red);
}

.chat-basket-item-sub {
  font-size: 0.76rem;
  color: var(--ink-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.chat-basket-promo-tag {
  background: var(--brand-red);
  color: #FFFFFF;
  font-size: 0.67rem;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 999px;
}

.chat-basket-item-price {
  text-align: right;
  flex-shrink: 0;
}

.chat-basket-item-qty {
  display: inline-block;
  background: var(--brand-green-soft);
  color: var(--brand-green-dark);
  font-weight: 800;
  font-size: 0.75rem;
  padding: 1px 7px;
  border-radius: 999px;
  margin-bottom: 2px;
}

.chat-basket-item-line {
  display: block;
  font-weight: 900;
  font-size: 0.88rem;
  color: var(--brand-red);
}

.chat-basket-foot {
  padding: 11px 14px;
  background: #FFFFFF;
  border-top: 1px solid #E2EFE6;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.chat-basket-total-wrap {
  display: flex;
  flex-direction: column;
}

.chat-basket-total-label {
  font-size: 0.74rem;
  color: var(--ink-muted);
  font-weight: 700;
}

.chat-basket-total-val {
  font-family: 'Cairo', sans-serif;
  font-size: 1.15rem;
  font-weight: 900;
  color: var(--brand-red);
  line-height: 1.15;
}

.chat-basket-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

/* Follow-up chips */
.chat-followups {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chat-followup-chip {
  background: #FFFFFF;
  border: 1px solid #CBD9D0;
  color: var(--ink-main);
  padding: 6px 13px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.16s ease;
}

.chat-followup-chip:hover {
  background: var(--brand-green-soft);
  border-color: var(--brand-green);
  color: var(--brand-green-dark);
}

/* Typing indicator */
.chat-typing {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-radius: 16px;
  color: var(--ink-secondary);
  font-size: 0.86rem;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

.chat-dots {
  display: inline-flex;
  gap: 4px;
}

.chat-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--brand-green);
  animation: chatBounce 1.2s infinite ease-in-out;
}

.chat-dots span:nth-child(2) { animation-delay: 0.18s; }
.chat-dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes chatBounce {
  0%, 80%, 100% { transform: scale(0.65); opacity: 0.45; }
  40% { transform: scale(1.1); opacity: 1; }
}

/* ---------- Bottom Composer ---------- */
.chat-composer-area {
  padding: 12px 20px 16px;
  background: #FFFFFF;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-composer-form {
  max-width: 820px;
  margin-inline: auto;
  background: #F7FAF8;
  border: 1.5px solid #D3E2D8;
  border-radius: 18px;
  padding: 8px 10px 8px 16px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.chat-composer-form:focus-within {
  border-color: var(--brand-green);
  background: #FFFFFF;
  box-shadow: 0 0 0 4px rgba(22, 128, 57, 0.1);
}

.chat-composer-input {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  outline: none;
  font-size: 0.96rem;
  line-height: 1.5;
  max-height: 140px;
  min-height: 26px;
  padding: 6px 0;
  color: var(--ink-main);
  font-family: 'Cairo', 'Roboto', sans-serif;
}

.chat-send-btn {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  border: none;
  background: linear-gradient(135deg, var(--brand-red) 0%, #A11016 100%);
  color: #FFFFFF;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.16s ease;
  box-shadow: 0 4px 12px rgba(200, 22, 29, 0.25);
}

.chat-send-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--brand-green-dark) 0%, var(--brand-green) 100%);
  transform: translateY(-1px);
}

.chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-composer-hint {
  max-width: 820px;
  margin: 7px auto 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 0.74rem;
  color: var(--ink-muted);
}

/* ---------- Mobile Responsive ---------- */
.chat-sidebar-backdrop {
  display: none;
}

@media (max-width: 960px) {
  .chat-page-wrap {
    padding: 10px 0 18px;
  }
  .chat-app-shell {
    grid-template-columns: 1fr;
    height: calc(100vh - 135px);
    min-height: 540px;
    border-radius: 16px;
  }
  .chat-mobile-toggle {
    display: inline-flex;
    align-items: center;
    gap: 5px;
  }
  .chat-sidebar {
    position: absolute;
    inset-block: 0;
    left: 0;
    width: 285px;
    max-width: 86%;
    z-index: 40;
    transform: translateX(-105%);
    transition: transform 0.24s ease;
    box-shadow: 12px 0 36px rgba(0, 0, 0, 0.35);
  }
  .chat-sidebar.open {
    transform: translateX(0);
  }
  .chat-sidebar-backdrop.open {
    display: block;
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 30;
  }
  .chat-starters-grid {
    grid-template-columns: 1fr;
  }
  .chat-msg-content-wrap {
    max-width: 95%;
  }
  .chat-topbar {
    padding: 10px 14px;
  }
  .chat-messages-scroll {
    padding: 16px 12px;
  }
  .chat-composer-area {
    padding: 10px 12px 12px;
  }
}
