/* ── Kavya Brand System ─────────────────────────────────────────────── */
:root {
  --deep-blue:   #1e3a8a;
  --bright-blue: #3b82f6;
  --light-blue:  #60a5fa;
  --accent-cyan: #38bdf8;
  --surface:     #f8faff;
  --surface-2:   #eef2ff;
  --text:        #0f172a;
  --text-muted:  #64748b;
  --border:      #e2e8f0;

  /* Themeable tokens */
  --sidebar-bg:      #1e3a8a;
  --sidebar-text:    rgba(255,255,255,0.8);
  --sidebar-muted:   rgba(255,255,255,0.5);
  --sidebar-border:  rgba(255,255,255,0.1);
  --sidebar-hover:   rgba(255,255,255,0.08);
  --sidebar-active:  rgba(255,255,255,0.15);
  --page-bg:         #f8faff;
  --chat-bg:         #f8faff;
  --header-bg:       white;
  --header-border:   #e2e8f0;
  --input-bar-bg:    white;
  --bubble-ai-bg:    white;
  --bubble-ai-text:  #0f172a;
  --bubble-ai-border:#e2e8f0;
  --bubble-user-bg:  #1e3a8a;
  --bubble-user-text:white;
  --primary:         #3b82f6;
  --primary-hover:   #2563eb;
  --msg-name-color:  #3b82f6;
  --welcome-title:   #1e3a8a;
  --card-bg:         white;
  --card-border:     #e2e8f0;

  --sidebar-w: 260px;
  --radius: 14px;
}

/* ── Theme: Midnight (dark) ─────────────────────────────────────────── */
[data-theme="midnight"] {
  --sidebar-bg:      #0f172a;
  --sidebar-text:    rgba(255,255,255,0.75);
  --sidebar-muted:   rgba(255,255,255,0.4);
  --sidebar-border:  rgba(255,255,255,0.07);
  --sidebar-hover:   rgba(255,255,255,0.06);
  --sidebar-active:  rgba(255,255,255,0.12);
  --page-bg:         #0f172a;
  --chat-bg:         #1e293b;
  --header-bg:       #1e293b;
  --header-border:   rgba(255,255,255,0.08);
  --input-bar-bg:    #1e293b;
  --bubble-ai-bg:    #293548;
  --bubble-ai-text:  #e2e8f0;
  --bubble-ai-border:rgba(255,255,255,0.08);
  --bubble-user-bg:  #3b82f6;
  --bubble-user-text:white;
  --primary:         #60a5fa;
  --primary-hover:   #3b82f6;
  --msg-name-color:  #60a5fa;
  --welcome-title:   #e2e8f0;
  --text:            #e2e8f0;
  --text-muted:      #94a3b8;
  --border:          rgba(255,255,255,0.08);
  --card-bg:         #1e293b;
  --card-border:     rgba(255,255,255,0.08);
  --surface:         #1e293b;
  --surface-2:       #293548;
}

/* ── Theme: Aurora (gradient sidebar) ──────────────────────────────── */
[data-theme="aurora"] {
  --sidebar-bg:      linear-gradient(180deg, #1e3a8a 0%, #1e40af 50%, #2563eb 100%);
  --sidebar-text:    rgba(255,255,255,0.85);
  --sidebar-muted:   rgba(255,255,255,0.5);
  --sidebar-border:  rgba(255,255,255,0.12);
  --sidebar-hover:   rgba(255,255,255,0.1);
  --sidebar-active:  rgba(255,255,255,0.2);
  --page-bg:         #f0f4ff;
  --chat-bg:         #f0f4ff;
  --header-bg:       white;
  --header-border:   #dbeafe;
  --input-bar-bg:    white;
  --bubble-ai-bg:    white;
  --bubble-ai-text:  #0f172a;
  --bubble-ai-border:#dbeafe;
  --bubble-user-bg:  #1e40af;
  --bubble-user-text:white;
  --primary:         #60a5fa;
  --primary-hover:   #3b82f6;
  --msg-name-color:  #2563eb;
  --welcome-title:   #1e3a8a;
  --card-bg:         white;
  --card-border:     #dbeafe;
  --surface:         #f0f4ff;
  --surface-2:       #dbeafe;
}

/* ── Theme: Cyan (sky accent) ───────────────────────────────────────── */
[data-theme="cyan"] {
  --sidebar-bg:      #0c4a6e;
  --sidebar-text:    rgba(255,255,255,0.85);
  --sidebar-muted:   rgba(255,255,255,0.5);
  --sidebar-border:  rgba(255,255,255,0.1);
  --sidebar-hover:   rgba(255,255,255,0.08);
  --sidebar-active:  rgba(255,255,255,0.18);
  --page-bg:         #f0f9ff;
  --chat-bg:         #f0f9ff;
  --header-bg:       white;
  --header-border:   #bae6fd;
  --input-bar-bg:    white;
  --bubble-ai-bg:    white;
  --bubble-ai-text:  #0f172a;
  --bubble-ai-border:#bae6fd;
  --bubble-user-bg:  #0369a1;
  --bubble-user-text:white;
  --primary:         #0ea5e9;
  --primary-hover:   #0284c7;
  --msg-name-color:  #0ea5e9;
  --welcome-title:   #0c4a6e;
  --card-bg:         white;
  --card-border:     #bae6fd;
  --surface:         #f0f9ff;
  --surface-2:       #e0f2fe;
  --deep-blue:       #0c4a6e;
  --bright-blue:     #0ea5e9;
  --accent-cyan:     #38bdf8;
}

/* ── Reset ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text);
  background: var(--page-bg);
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s, color 0.2s;
}
a { cursor: pointer; color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Auth Page ─────────────────────────────────────────────────────── */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--page-bg);
}

.auth-wrapper {
  width: 100%;
  max-width: 420px;
  padding: 24px 16px;
}

.auth-card {
  background: var(--card-bg);
  border-radius: 24px;
  border: 1px solid var(--card-border);
  padding: 40px 36px 36px;
  box-shadow: 0 4px 32px rgba(30,58,138,0.08);
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 6px;
}

.auth-logo-text {
  display: flex;
  flex-direction: column;
}

.auth-logo-name {
  font-family: 'DM Sans', sans-serif;
  font-size: 28px;
  font-weight: 700;
  color: var(--deep-blue);
  letter-spacing: -0.5px;
  line-height: 1;
}

.auth-logo-sub {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 2.5px;
  color: var(--primary);
  margin-top: 3px;
}

.auth-powered {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 28px;
  padding-left: 2px;
}

.auth-powered strong { color: var(--deep-blue); }

.auth-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.auth-hint {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 24px;
  line-height: 1.5;
}

.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  font-family: 'DM Sans', sans-serif;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s;
  outline: none;
}

.form-group input:focus {
  border-color: var(--primary);
  background: var(--card-bg);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}

.auth-btn {
  width: 100%;
  padding: 13px;
  background: var(--deep-blue);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  margin-top: 4px;
}

.auth-btn:hover:not(:disabled) { background: var(--primary-hover); }
.auth-btn:active:not(:disabled) { transform: scale(0.99); }

.auth-error {
  display: none;
  margin-top: 10px;
  font-size: 13px;
  color: #dc2626;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 8px 12px;
}

.resend-row {
  text-align: center;
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-muted);
}

.auth-back {
  text-align: center;
  margin-top: 12px;
  font-size: 13px;
  color: var(--text-muted);
}

/* ── Chat App Layout ─────────────────────────────────────────────────── */
.chat-app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: background 0.2s;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon { flex-shrink: 0; }

.brand-name {
  font-size: 18px;
  font-weight: 700;
  color: white;
  letter-spacing: -0.3px;
}

.new-chat-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--sidebar-hover);
  border: 1px solid var(--sidebar-border);
  color: white;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.new-chat-btn:hover { background: var(--sidebar-active); }

.conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  min-height: 0;
}

.conv-item {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--sidebar-text);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.15s;
}

.conv-item:hover { background: var(--sidebar-hover); color: white; }
.conv-item.active { background: var(--sidebar-active); color: white; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.sidebar-footer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.user-phone {
  font-size: 12px;
  color: var(--sidebar-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-btn {
  background: var(--sidebar-hover);
  border: 1px solid var(--sidebar-border);
  color: var(--sidebar-text);
  font-size: 12px;
  font-family: 'DM Sans', sans-serif;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.logout-btn:hover { background: var(--sidebar-active); color: white; }

/* Theme switcher */
.theme-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--sidebar-muted);
  flex-shrink: 0;
}

.theme-dots {
  display: flex;
  gap: 6px;
  align-items: center;
}

.theme-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.15s, border-color 0.15s;
  flex-shrink: 0;
}

.theme-dot:hover { transform: scale(1.2); }

.theme-dot.active {
  border-color: white;
  transform: scale(1.15);
}

.theme-dot[data-theme="ocean"]    { background: #1e3a8a; }
.theme-dot[data-theme="midnight"] { background: #0f172a; }
.theme-dot[data-theme="aurora"]   { background: linear-gradient(135deg, #1e3a8a, #2563eb); }
.theme-dot[data-theme="cyan"]     { background: #0ea5e9; }

/* ── Chat Main ───────────────────────────────────────────────────────── */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--chat-bg);
  transition: background 0.2s;
  min-width: 0;
}

/* Welcome screen */
.welcome-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
  padding: 40px;
}

.welcome-logo {
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card-bg);
  border-radius: 20px;
  border: 1px solid var(--card-border);
  box-shadow: 0 4px 16px rgba(30,58,138,0.1);
  margin-bottom: 8px;
}

.welcome-title {
  font-family: 'Instrument Serif', serif;
  font-size: 28px;
  font-weight: 400;
  color: var(--welcome-title);
}

.welcome-sub {
  font-size: 15px;
  color: var(--text-muted);
  max-width: 320px;
}

/* Chat view — CRITICAL: must be flex column with constrained height */
#chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;        /* ← fixes flex scroll */
  overflow: hidden;
}

/* Chat header */
.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--header-border);
  flex-shrink: 0;
  transition: background 0.2s;
}

.chat-header-avatar {
  width: 34px;
  height: 34px;
  background: var(--surface-2);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-header-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--welcome-title);
  display: flex;
  align-items: center;
  gap: 6px;
}

.online-dot {
  width: 7px;
  height: 7px;
  background: #22c55e;
  border-radius: 50%;
  display: inline-block;
}

.chat-header-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: 2px;
}

/* Messages — CRITICAL: flex:1 + min-height:0 + overflow-y:auto = scrollable */
.messages {
  flex: 1;
  min-height: 0;        /* ← the real scroll fix */
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Load more button */
.load-more-btn {
  align-self: center;
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  font-family: 'DM Sans', sans-serif;
  padding: 6px 16px;
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
  margin-bottom: 4px;
}

.load-more-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.msg {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  max-width: 75%;
}

.msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--surface-2);
  overflow: hidden;
}

.msg.user .msg-avatar {
  background: var(--primary);
  color: white;
  font-size: 13px;
  font-weight: 600;
}

.msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  transition: background 0.2s;
}

.msg.ai .msg-bubble {
  background: var(--bubble-ai-bg);
  border: 1px solid var(--bubble-ai-border);
  border-top-left-radius: 4px;
  color: var(--bubble-ai-text);
}

.msg.user .msg-bubble {
  background: var(--bubble-user-bg);
  color: var(--bubble-user-text);
  border-top-right-radius: 4px;
}

.msg-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--msg-name-color);
  margin-bottom: 3px;
}

/* Typing indicator */
.typing-indicator {
  display: none;
  padding: 0 20px 12px;
  gap: 4px;
  flex-shrink: 0;
}

.typing-indicator.show {
  display: flex;
  align-items: center;
}

.typing-indicator .dot {
  width: 7px;
  height: 7px;
  background: var(--light-blue);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}

.typing-indicator .dot:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

/* Input bar */
.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 16px;
  background: var(--input-bar-bg);
  border-top: 1px solid var(--header-border);
  flex-shrink: 0;
  transition: background 0.2s;
}

#msg-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  font-size: 14px;
  font-family: 'DM Sans', sans-serif;
  color: var(--text);
  background: var(--surface);
  resize: none;
  outline: none;
  max-height: 140px;
  overflow-y: auto;
  transition: border-color 0.15s, background 0.2s;
  line-height: 1.5;
}

#msg-input:focus {
  border-color: var(--primary);
  background: var(--card-bg);
}

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--deep-blue);
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}

.send-btn:hover { background: var(--primary); }
.send-btn:active { transform: scale(0.96); }

/* Mobile toggle */
.mobile-toggle {
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 100;
  background: var(--deep-blue);
  color: white;
  border: none;
  border-radius: 8px;
  width: 36px;
  height: 36px;
  font-size: 18px;
  cursor: pointer;
}

/* Scrollbar */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

/* ── Mobile ──────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .mobile-toggle { display: flex; align-items: center; justify-content: center; }
  .sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    height: 100%;
    z-index: 50;
    transition: left 0.25s;
    box-shadow: 4px 0 24px rgba(0,0,0,0.2);
  }
  .sidebar.open { left: 0; }
  .msg { max-width: 90%; }
  .auth-card { padding: 32px 24px; }
}
