/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-base:       #07070f;
  --bg-surface:    #0f0f1e;
  --bg-elevated:   #161628;
  --bg-hover:      #1e1e35;
  --border:        rgba(255,255,255,0.07);
  --border-accent: rgba(139,92,246,0.4);

  --accent:        #8b5cf6;
  --accent-2:      #06b6d4;
  --accent-glow:   rgba(139,92,246,0.25);

  --text-primary:  #f0f0ff;
  --text-secondary:#9898c0;
  --text-muted:    #5a5a80;

  --user-bubble:   linear-gradient(135deg,#7c3aed,#4f46e5);
  --bot-bubble:    #161628;

  --success:       #22c55e;
  --warning:       #f59e0b;
  --danger:        #ef4444;

  --radius-sm:     8px;
  --radius-md:     14px;
  --radius-lg:     20px;
  --radius-xl:     28px;

  --shadow-sm:     0 2px 8px rgba(0,0,0,0.4);
  --shadow-md:     0 4px 24px rgba(0,0,0,0.5);
  --shadow-glow:   0 0 40px rgba(139,92,246,0.15);

  --transition:    all 0.22s cubic-bezier(0.4,0,0.2,1);

  --header-h:      64px;
  --cart-w:        360px;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
#app-header {
  height: var(--header-h);
  background: rgba(15,15,30,0.85);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
  position: relative;
  z-index: 100;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  font-size: 28px;
  filter: drop-shadow(0 0 12px rgba(139,92,246,0.6));
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%,100% { transform: translateY(0); }
  50%      { transform: translateY(-3px); }
}

.logo-title {
  display: block;
  font-size: 18px;
  font-weight: 700;
  background: linear-gradient(135deg, #c4b5fd, #67e8f9);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.2;
}

.logo-subtitle {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
}

/* Status badge */
.status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 100px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-connecting .status-dot { background: var(--warning); animation: pulse 1.2s infinite; }
.status-ready      .status-dot { background: var(--success); }
.status-error      .status-dot { background: var(--danger); }
.status-connecting { border-color: rgba(245,158,11,0.3); }
.status-ready      { border-color: rgba(34,197,94,0.3); }
.status-error      { border-color: rgba(239,68,68,0.3); }

@keyframes pulse {
  0%,100% { opacity: 1; }
  50%      { opacity: 0.3; }
}

/* Cart toggle */
.cart-toggle-btn {
  position: relative;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 20px;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.cart-toggle-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-accent);
  transform: scale(1.05);
}

.cart-count {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--accent);
  color: white;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 2px solid var(--bg-base);
}

/* ── Main layout ─────────────────────────────────────────────────────────── */
#app-main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Chat Panel ──────────────────────────────────────────────────────────── */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* Welcome screen */
.welcome-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 24px;
  animation: fadeIn 0.5s ease;
}

.welcome-icon {
  font-size: 64px;
  margin-bottom: 20px;
  filter: drop-shadow(0 0 24px rgba(139,92,246,0.5));
  animation: float 3s ease-in-out infinite;
}

.welcome-screen h1 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 12px;
  background: linear-gradient(135deg, #e0d7ff, #bae6fd);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome-screen > p {
  font-size: 15px;
  color: var(--text-secondary);
  max-width: 480px;
  line-height: 1.7;
  margin-bottom: 32px;
}

.welcome-examples {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.examples-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 4px;
}

.example-chip {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 10px 20px;
  border-radius: 100px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
}

.example-chip:hover {
  background: var(--bg-hover);
  border-color: var(--border-accent);
  color: var(--text-primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

/* Messages */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: none;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.messages.active {
  display: flex;
}

.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 4px; }

/* Message bubbles */
.message {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  animation: slideIn 0.3s cubic-bezier(0.4,0,0.2,1);
}

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

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.message.user { flex-direction: row-reverse; }

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.message.bot  .message-avatar { background: var(--bg-elevated); border: 1px solid var(--border); }
.message.user .message-avatar { background: var(--user-bubble); }

.message-bubble {
  max-width: min(70%, 600px);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.65;
}

.message.bot .message-bubble {
  background: var(--bot-bubble);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  color: var(--text-primary);
}

.message.user .message-bubble {
  background: var(--user-bubble);
  border-bottom-right-radius: 4px;
  color: white;
}

/* Chat message inner formatting styling */
.message-bubble p {
  margin-bottom: 10px;
}
.message-bubble p:last-child {
  margin-bottom: 0;
}
.message-bubble h1,
.message-bubble h2,
.message-bubble h3,
.message-bubble h4,
.message-bubble h5,
.message-bubble h6 {
  color: var(--text-primary);
  font-weight: 600;
  margin-top: 16px;
  margin-bottom: 8px;
  line-height: 1.4;
}
.message-bubble h1:first-child,
.message-bubble h2:first-child,
.message-bubble h3:first-child,
.message-bubble h4:first-child,
.message-bubble h5:first-child,
.message-bubble h6:first-child {
  margin-top: 0;
}
.message-bubble h1 { font-size: 1.4em; }
.message-bubble h2 { font-size: 1.25em; }
.message-bubble h3 { font-size: 1.15em; }
.message-bubble h4,
.message-bubble h5,
.message-bubble h6 { font-size: 1.05em; }
.message-bubble ol, .message-bubble ul {
  margin-bottom: 12px;
  padding-left: 20px;
}
.message-bubble ol:last-child, .message-bubble ul:last-child {
  margin-bottom: 0;
}
.message-bubble li {
  margin-bottom: 6px;
}
.message-bubble li:last-child {
  margin-bottom: 0;
}
.message-bubble strong {
  color: #fff;
  font-weight: 600;
}
.message.bot .message-bubble strong {
  color: var(--text-primary);
}
.message-bubble code {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 13px;
  color: var(--accent-2);
  background: rgba(6, 182, 212, 0.1);
  padding: 2px 5px;
  border-radius: 4px;
  border: 1px solid rgba(6, 182, 212, 0.2);
}
.message-bubble pre {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 12px;
  overflow-x: auto;
}
.message-bubble pre:last-child {
  margin-bottom: 0;
}
.message-bubble pre code {
  background: none;
  border: none;
  padding: 0;
  border-radius: 0;
  color: var(--text-primary);
}

/* Sources tag */
.message-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.source-tag {
  font-size: 11px;
  color: var(--accent-2);
  background: rgba(6,182,212,0.1);
  border: 1px solid rgba(6,182,212,0.2);
  padding: 2px 8px;
  border-radius: 100px;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 5px;
  padding: 14px 18px;
}

.typing-dot {
  width: 7px;
  height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typingBounce 1.2s ease-in-out infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingBounce {
  0%,60%,100% { transform: translateY(0); opacity: 0.4; }
  30%         { transform: translateY(-6px); opacity: 1; }
}

/* Phase badge */
.phase-badge {
  align-self: center;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 4px 12px;
  border-radius: 100px;
  margin: 4px 0;
}

/* ── Products Bar ─────────────────────────────────────────────────────────── */
.products-bar {
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
  padding: 14px 20px;
  flex-shrink: 0;
  animation: slideUp 0.3s ease;
}

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

.products-bar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.products-bar-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.close-products-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.close-products-btn:hover { color: var(--text-primary); background: var(--bg-hover); }

.products-list {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.products-list::-webkit-scrollbar { height: 3px; }
.products-list::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 3px; }

/* Product card */
.product-card {
  flex-shrink: 0;
  width: 200px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.product-card:hover {
  border-color: var(--border-accent);
  box-shadow: var(--shadow-glow);
  transform: translateY(-2px);
}

.product-card-category {
  font-size: 10px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.product-card-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

.product-card-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-card-reason {
  font-size: 11px;
  color: var(--accent-2);
  font-style: italic;
}

.product-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
}

.product-card-price {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.add-to-cart-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.add-to-cart-btn:hover { background: #7c3aed; transform: scale(1.04); }
.add-to-cart-btn.added { background: var(--success); }
.add-to-cart-btn:disabled { opacity: 0.5; cursor: default; transform: none; }

/* ── Input area ──────────────────────────────────────────────────────────── */
.chat-input-area {
  padding: 16px 20px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
}

.input-wrapper {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 10px 10px 16px;
  transition: var(--transition);
}

.input-wrapper:focus-within {
  border-color: var(--border-accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

#user-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  max-height: 140px;
  min-height: 22px;
}

#user-input::placeholder { color: var(--text-muted); }
#user-input:disabled { opacity: 0.5; cursor: not-allowed; }

.send-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--accent);
  border: none;
  color: white;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.send-btn:hover:not(:disabled) { background: #7c3aed; transform: scale(1.06); }
.send-btn:disabled { background: var(--bg-hover); color: var(--text-muted); cursor: not-allowed; }

.input-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  padding: 0 4px;
}

.char-count {
  font-size: 11px;
  color: var(--text-muted);
}

.new-chat-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  font-family: inherit;
  padding: 4px 12px;
  border-radius: 100px;
  cursor: pointer;
  transition: var(--transition);
}

.new-chat-btn:hover {
  color: var(--text-primary);
  border-color: var(--border-accent);
  background: var(--bg-elevated);
}

/* ── Cart Panel ──────────────────────────────────────────────────────────── */
.cart-panel {
  width: var(--cart-w);
  border-left: 1px solid var(--border);
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateX(var(--cart-w));
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
  flex-shrink: 0;
}

.cart-panel.open {
  transform: translateX(0);
}

.cart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.cart-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.cart-close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.cart-close-btn:hover { color: var(--text-primary); background: var(--bg-hover); }

/* Cart empty */
.cart-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
}

.cart-empty-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.4; }
.cart-empty p { font-size: 14px; margin-bottom: 6px; }
.cart-empty-sub { font-size: 12px; color: var(--text-muted); }

/* Cart items */
.cart-items {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cart-items::-webkit-scrollbar { width: 3px; }
.cart-items::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 3px; }

.cart-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  animation: slideIn 0.25s ease;
}

.cart-item-info { flex: 1; }

.cart-item-name {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 4px;
}

.cart-item-sku {
  font-size: 10px;
  color: var(--text-muted);
  font-family: monospace;
}

.cart-item-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.qty-btn {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-hover);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.qty-btn:hover { background: var(--accent); border-color: var(--accent); }

.cart-item-qty {
  font-size: 14px;
  font-weight: 600;
  min-width: 20px;
  text-align: center;
}

.cart-item-price {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  flex-shrink: 0;
  text-align: right;
}

.cart-item-unit-price {
  font-size: 10px;
  color: var(--text-muted);
}

.cart-item-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 2px;
  border-radius: 4px;
  transition: var(--transition);
  flex-shrink: 0;
  margin-left: auto;
}

.cart-item-remove:hover { color: var(--danger); }

/* Cart footer */
.cart-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.cart-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
}

.cart-total-price {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
}

.checkout-btn {
  background: linear-gradient(135deg, var(--accent), #4f46e5);
  color: white;
  border: none;
  padding: 13px 20px;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  position: relative;
  overflow: hidden;
}

.checkout-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.1);
  opacity: 0;
  transition: var(--transition);
}

.checkout-btn:hover::before { opacity: 1; }
.checkout-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-glow); }

.checkout-arrow { font-size: 18px; }

.clear-cart-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 9px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
}

.clear-cart-btn:hover { color: var(--danger); border-color: rgba(239,68,68,0.3); background: rgba(239,68,68,0.05); }

/* ── Toast ───────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}

.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  font-size: 13px;
  color: var(--text-primary);
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toastIn 0.3s ease;
  max-width: 320px;
}

.toast.success { border-color: rgba(34,197,94,0.3); }
.toast.error   { border-color: rgba(239,68,68,0.3); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(20px); }
}

/* ── Utility ─────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --cart-w: 100vw; }

  .cart-panel {
    position: fixed;
    top: var(--header-h);
    right: 0;
    bottom: 0;
    z-index: 200;
    transform: translateX(100%);
  }
}
