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

:root {
  --coral:       #D85A30;
  --coral-light: #F0997B;
  --coral-pale:  #FAECE7;
  --coral-dark:  #993C1D;
  --coral-deep:  #4A1B0C;
  --ink:         #1A1410;
  --ink-muted:   #6B5B52;
  --ink-faint:   #B8A89F;
  --surface:     #FFFFFF;
  --surface-2:   #FBF8F6;
  --surface-3:   #F5EFEb;
  --border:      rgba(26,20,16,0.10);
  --border-med:  rgba(26,20,16,0.18);
  --sidebar-w:   260px;
  --radius:      12px;
  --radius-sm:   8px;
  --radius-xs:   6px;
  --font-display: 'DM Serif Display', Georgia, serif;
  --font-body:    'DM Sans', system-ui, sans-serif;
  --shadow-sm:    0 1px 3px rgba(26,20,16,0.08), 0 1px 2px rgba(26,20,16,0.04);
  --shadow-md:    0 4px 12px rgba(26,20,16,0.10), 0 2px 4px rgba(26,20,16,0.06);
}

html, body {
  height: 100%;
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--ink);
  background: var(--surface-2);
  -webkit-font-smoothing: antialiased;
}

/* ─── Screens ─── */
.screen { display: flex; height: 100vh; }
.hidden { display: none !important; }

/* ─── AUTH ─── */
.auth-left {
  flex: 1;
  background: var(--ink);
  padding: 48px 52px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.auth-left::before {
  content: '';
  position: absolute;
  top: -80px; right: -80px;
  width: 320px; height: 320px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(216,90,48,0.25) 0%, transparent 70%);
  pointer-events: none;
}

.auth-left::after {
  content: '';
  position: absolute;
  bottom: -60px; left: 40px;
  width: 200px; height: 200px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(216,90,48,0.12) 0%, transparent 70%);
  pointer-events: none;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 52px;
}

.brand-mark {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--coral);
  color: var(--coral-pale);
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.brand-mark.sm {
  width: 30px; height: 30px;
  border-radius: 7px;
  font-size: 11px;
}

.brand-name {
  font-size: 16px;
  font-weight: 500;
  color: #fff;
  letter-spacing: -0.01em;
}

.auth-headline {
  font-family: var(--font-display);
  font-size: clamp(36px, 4vw, 52px);
  line-height: 1.1;
  color: #fff;
  margin-bottom: 20px;
}

.auth-headline em {
  font-style: italic;
  color: var(--coral-light);
}

.auth-sub {
  font-size: 15px;
  line-height: 1.65;
  color: rgba(255,255,255,0.55);
  max-width: 360px;
  margin-bottom: 32px;
}

.auth-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.5);
  letter-spacing: 0.01em;
}

.auth-right {
  width: 420px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 28px;
  background: var(--surface);
}

.auth-card {
  width: 100%;
  max-width: 360px;
}

.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 28px;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  padding: 10px 0;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-faint);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}

.tab-btn.active {
  color: var(--coral);
  border-bottom-color: var(--coral);
}

.auth-form { display: flex; flex-direction: column; gap: 16px; }

.field { display: flex; flex-direction: column; gap: 6px; }

.field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-muted);
  letter-spacing: 0.01em;
}

input[type="text"],
input[type="email"],
input[type="password"],
textarea {
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-med);
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}

input:focus, textarea:focus {
  border-color: var(--coral);
  box-shadow: 0 0 0 3px rgba(216,90,48,0.12);
}

.btn-primary {
  width: 100%;
  padding: 11px 20px;
  background: var(--coral);
  color: var(--coral-pale);
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  letter-spacing: 0.01em;
}

.btn-primary:hover { background: var(--coral-dark); }
.btn-primary:active { transform: scale(0.99); }

.form-hint {
  text-align: center;
  font-size: 13px;
  color: var(--ink-muted);
}

.form-hint a { color: var(--coral); text-decoration: none; font-weight: 500; }
.form-hint a:hover { text-decoration: underline; }

.form-error {
  font-size: 13px;
  color: #C0392B;
  background: #FEF0EE;
  border: 1px solid #F5C6C0;
  border-radius: var(--radius-xs);
  padding: 8px 12px;
}

/* ─── CHAT LAYOUT ─── */
#chat-screen {
  background: var(--surface-2);
  overflow: hidden;
}

/* Sidebar */
#sidebar {
  width: var(--sidebar-w);
  background: var(--ink);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.25s ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}

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

.sidebar-brand .brand-name {
  font-size: 14px;
}

.icon-btn {
  width: 30px; height: 30px;
  border-radius: var(--radius-xs);
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.5);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.9);
}

.new-chat-btn {
  margin: 12px 12px 8px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.12);
  background: transparent;
  color: rgba(255,255,255,0.7);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s, color 0.15s;
}

.new-chat-btn:hover {
  background: rgba(255,255,255,0.07);
  color: #fff;
}

.history-section { flex: 1; overflow-y: auto; padding: 4px 0; }

.history-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.3);
  padding: 8px 16px 4px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  margin: 1px 8px;
  cursor: pointer;
  transition: background 0.12s;
  color: rgba(255,255,255,0.6);
  font-size: 13px;
}

.history-item:hover { background: rgba(255,255,255,0.07); color: rgba(255,255,255,0.9); }
.history-item.active { background: rgba(216,90,48,0.18); color: rgba(255,255,255,0.95); }

.history-item-icon {
  width: 16px; height: 16px; flex-shrink: 0; opacity: 0.5;
}

.history-item-text {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-delete {
  opacity: 0;
  width: 20px; height: 20px;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.4);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.1s, background 0.1s, color 0.1s;
}

.history-item:hover .history-item-delete { opacity: 1; }
.history-item-delete:hover { background: rgba(255,80,50,0.2); color: #ff8080; }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,0.07);
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-info { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }

.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--coral);
  color: var(--coral-pale);
  font-size: 12px;
  font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.user-details {
  display: flex; flex-direction: column;
  min-width: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 500;
  color: rgba(255,255,255,0.85);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.user-email-display {
  font-size: 11px;
  color: rgba(255,255,255,0.35);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.logout-btn { color: rgba(255,255,255,0.35) !important; }

/* ─── Chat Main ─── */
#chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
}

.chat-topbar {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  background: var(--surface);
  flex-shrink: 0;
}

.mobile-menu-btn { display: none; color: var(--ink-muted) !important; }
.mobile-menu-btn:hover { color: var(--ink) !important; background: var(--surface-2) !important; }

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  flex: 1;
}

.topbar-brand .brand-mark { background: var(--coral); color: var(--coral-pale); }

.topbar-status {
  font-size: 12px;
  color: var(--ink-faint);
  display: flex;
  align-items: center;
  gap: 5px;
}

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

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

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

.welcome-mark {
  width: 60px; height: 60px;
  border-radius: 16px;
  background: var(--coral);
  color: var(--coral-pale);
  font-size: 20px;
  font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}

.welcome-state h2 {
  font-family: var(--font-display);
  font-size: 26px;
  color: var(--ink);
}

.welcome-state h2 em { font-style: italic; color: var(--coral); }

.welcome-state p {
  font-size: 14px;
  color: var(--ink-muted);
  max-width: 340px;
  line-height: 1.65;
}

.starter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 500px;
}

.chip {
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 20px;
  border: 1px solid var(--border-med);
  background: var(--surface);
  color: var(--ink-muted);
  cursor: pointer;
  font-family: var(--font-body);
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.chip:hover {
  background: var(--coral-pale);
  color: var(--coral-dark);
  border-color: var(--coral-light);
}

/* Message rows */
.msg-row {
  display: flex;
  gap: 10px;
  max-width: 720px;
  width: 100%;
}

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

.msg-row.bot { align-self: flex-start; }

.msg-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 2px;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  font-weight: 600;
}

.msg-row.bot .msg-avatar {
  background: var(--coral);
  color: var(--coral-pale);
}

.msg-row.user .msg-avatar {
  background: var(--surface-3);
  color: var(--ink-muted);
}

.msg-bubble {
  padding: 11px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.65;
  max-width: calc(100% - 42px);
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-row.bot .msg-bubble {
  background: var(--surface-2);
  color: var(--ink);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
}

.msg-row.user .msg-bubble {
  background: var(--coral);
  color: var(--coral-pale);
  border-bottom-right-radius: 4px;
}

/* Typing indicator */
.typing-row {
  display: flex;
  gap: 10px;
  align-self: flex-start;
}

.typing-bubble {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  padding: 13px 16px;
  display: flex;
  gap: 5px;
  align-items: center;
}

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

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

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

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

.input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border-med);
  border-radius: 14px;
  padding: 8px 8px 8px 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input-wrap:focus-within {
  border-color: var(--coral-light);
  box-shadow: 0 0 0 3px rgba(216,90,48,0.10);
}

#chat-input {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
  max-height: 120px;
  overflow-y: auto;
  outline: none;
  padding: 3px 0;
  box-shadow: none;
}

#chat-input::placeholder { color: var(--ink-faint); }

.send-btn {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: var(--coral);
  border: none;
  color: #fff;
  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(--coral-dark); }
.send-btn:active { transform: scale(0.96); }
.send-btn:disabled { background: var(--ink-faint); cursor: default; }

.input-hint {
  font-size: 11px;
  color: var(--ink-faint);
  text-align: center;
  margin-top: 8px;
  line-height: 1.5;
}

/* ─── API Key Modal ─── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26,20,16,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  backdrop-filter: blur(2px);
}

.modal-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}

.modal-icon { font-size: 32px; }

.modal-card h2 {
  font-family: var(--font-display);
  font-size: 24px;
  color: var(--ink);
}

.modal-card p {
  font-size: 14px;
  color: var(--ink-muted);
  line-height: 1.65;
}

.modal-card .field { text-align: left; }
.modal-card .btn-primary { margin-top: 4px; }

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-med); border-radius: 10px; }

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .auth-left { display: none; }
  .auth-right { width: 100%; }

  #sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
  }

  #sidebar.open { transform: translateX(0); }

  .mobile-menu-btn { display: flex; }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 49;
  }

  .sidebar-overlay.show { display: block; }
}
