:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --border: #e6e8eb;
  --text: #1a1d21;
  --text-muted: #6b7280;
  --accent: #1f7a5a;
  --accent-soft: #e7f3ee;
  --user-bubble: #1f7a5a;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

.logo {
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--accent);
  letter-spacing: -0.02em;
}

/* ---------- Login ---------- */

.login-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 10;
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 2.5rem;
  width: 360px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  text-align: center;
}

.login-sub {
  color: var(--text-muted);
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
}

.login-card input,
.chat-form input,
#emailInput {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  font-size: 0.95rem;
  outline: none;
}

.login-card input:focus,
.chat-form input:focus {
  border-color: var(--accent);
}

.login-card button,
.new-chat-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 0.7rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.login-error {
  color: #c0392b;
  font-size: 0.85rem;
  min-height: 1rem;
}

.login-hint {
  color: var(--text-muted);
  font-size: 0.78rem;
}

/* ---------- App layout ---------- */

.app {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  grid-template-rows: 100vh;
  height: 100vh;
  max-width: 100vw;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.new-chat-btn {
  padding: 0.4rem 0.7rem;
  font-size: 0.8rem;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.chat-item {
  display: flex;
  align-items: center;
  border-radius: 8px;
}

.chat-item:hover {
  background: var(--bg);
}

.chat-item.active {
  background: var(--accent-soft);
}

.chat-item-title {
  flex: 1;
  min-width: 0;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 8px 0 0 8px;
  padding: 0.6rem 0.7rem;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item.active .chat-item-title {
  color: var(--accent);
  font-weight: 600;
}

.chat-delete-btn {
  flex: none;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.3rem 0.55rem;
  margin-right: 0.15rem;
  border-radius: 6px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease, color 0.12s ease;
}

.chat-item:hover .chat-delete-btn,
.chat-item.active .chat-delete-btn {
  opacity: 1;
}

.chat-delete-btn:hover {
  background: var(--bg-elev, rgba(0, 0, 0, 0.06));
  color: var(--danger, #d64545);
}

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding: 0.75rem 1rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.logout-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.78rem;
}

/* ---------- Panels ---------- */

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.chat-panel {
  background: var(--bg);
}

.chat-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0;
  padding: 1.5rem;
}

.welcome {
  max-width: 520px;
  margin: 3rem auto;
  text-align: center;
}

.welcome h2 {
  margin-bottom: 0.5rem;
}

.welcome p {
  color: var(--text-muted);
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 1.5rem;
}

.quick-btn,
.chip {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.5rem 0.9rem;
  font-size: 0.82rem;
  cursor: pointer;
  color: var(--text);
}

.quick-btn:hover,
.chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
}

.message {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
  max-width: 100%;
}

.message.user {
  align-items: flex-end;
}

.message-id {
  margin-top: 0.2rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.65rem;
  color: var(--text-muted);
  opacity: 0.7;
  user-select: all;
}
.message-id:empty {
  display: none;
}

.message-bubble {
  max-width: 80%;
  padding: 0.7rem 1rem;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.5;
  background: var(--panel);
  border: 1px solid var(--border);
}

.message.user .message-bubble {
  background: var(--user-bubble);
  color: #fff;
  border-color: var(--user-bubble);
}

.input-area {
  border-top: 1px solid var(--border);
  background: var(--panel);
  padding: 0.75rem 1rem 1rem;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.6rem;
}

.chat-form {
  display: flex;
  gap: 0.5rem;
}

.chat-form input {
  flex: 1;
}

.chat-form button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.chat-form button:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ---------- Product carousel (inline in chat) ---------- */

.product-carousel {
  position: relative;
  margin: 0.25rem 0 0.25rem;
  min-width: 0;
  max-width: 100%;
}

.carousel-track {
  display: flex;
  gap: 0.75rem;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scroll-padding: 0.25rem;
  padding: 0.25rem 0.25rem 0.5rem;
  scrollbar-width: thin;
}

.carousel-track::-webkit-scrollbar {
  height: 8px;
}

.carousel-track::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}

.carousel-arrow {
  position: absolute;
  top: calc(50% - 18px);
  transform: translateY(-50%);
  z-index: 3;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
}

.carousel-arrow:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.carousel-arrow.prev {
  left: -6px;
}

.carousel-arrow.next {
  right: -6px;
}

@media (hover: none) {
  .carousel-arrow {
    display: none;
  }
}

.product-card {
  position: relative;
  flex: 0 0 auto;
  width: 168px;
  scroll-snap-align: start;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
}

.product-link {
  text-decoration: none;
  color: inherit;
  display: block;
}

.product-img-wrap {
  position: relative;
  aspect-ratio: 1;
  background: var(--bg);
}

.product-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.product-badge,
.product-seller-badge {
  position: absolute;
  bottom: 6px;
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
}

.product-badge {
  left: 6px;
}

.product-seller-badge {
  right: 6px;
  background: var(--accent);
}

.fav-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.9);
  color: #c0392b;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.fav-btn.on {
  background: #c0392b;
  color: #fff;
}

.product-details {
  padding: 0.6rem;
}

.product-brand {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.product-title {
  font-size: 0.82rem;
  margin: 0.15rem 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-price {
  font-weight: 700;
  font-size: 0.9rem;
}

.product-meta {
  margin-top: 0.3rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

/* Live, node-driven progress indicator shown while a turn runs. */
.activity {
  color: var(--text-muted);
  font-style: italic;
  display: inline-block;
  animation: activity-pulse 1.2s ease-in-out infinite;
}

@keyframes activity-pulse {
  0%,
  100% {
    opacity: 0.55;
  }
  50% {
    opacity: 1;
  }
}
