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

/* ── Design Tokens (Aurora Theme) ── */
:root {
  --bg:           #0f0f1a;
  --surface:      #ffffff06;
  --surface2:     #ffffff0d;
  --surface3:     #ffffff14;
  --border:       #ffffff0d;
  --border2:      #ffffff18;
  --text:         #f1f5f9;
  --text-dim:     #94a3b8;
  --text-faint:   #475569;
  --grad-start:   #7c3aed;
  --grad-end:     #0ea5e9;
  --grad:         linear-gradient(135deg, #7c3aed, #0ea5e9);
  --grad-soft:    linear-gradient(135deg, #7c3aed22, #0ea5e922);
  --grad-border:  linear-gradient(135deg, #7c3aed44, #0ea5e944);
  --glow:         0 0 60px #7c3aed18;
  --radius:       14px;
  --radius-sm:    8px;
  --font-main:    'Space Grotesk', sans-serif;
  --font-mono:    'DM Mono', monospace;
  --sidebar-w:    268px;
  --topbar-h:     56px;
  --modelbar-h:   52px;
  --inputbar-h:   72px;
}

html, body { height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--font-main); }

/* ══════════════════════════════════════
   LAYOUT VISIBILITY — Device Detection
══════════════════════════════════════ */
.layout-desktop { display: flex; height: 100vh; }
.layout-mobile  { display: none; flex-direction: column; height: 100vh; }

/* JS adds .is-mobile to body */
body.is-mobile  .layout-desktop { display: none; }
body.is-mobile  .layout-mobile  { display: flex; }
body.is-desktop .layout-desktop { display: flex; }
body.is-desktop .layout-mobile  { display: none; }

/* ══════════════════════════════════════
   SHARED COMPONENTS
══════════════════════════════════════ */

/* Logo */
.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon {
  width: 32px; height: 32px; border-radius: 9px;
  background: var(--grad);
  display: grid; place-items: center;
  font-size: 15px; font-weight: 800; color: #fff;
  flex-shrink: 0;
}
.logo-icon.sm { width: 26px; height: 26px; font-size: 12px; border-radius: 7px; }
.logo-text { font-size: 16px; font-weight: 700; letter-spacing: -0.02em; }
.logo-small { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 700; }

/* Section label */
.section-label {
  font-size: 9px; font-weight: 700; letter-spacing: .12em;
  color: var(--text-faint); font-family: var(--font-mono);
  margin-bottom: 8px; padding: 0 2px;
}

/* Icon button */
.icon-btn {
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-dim); cursor: pointer;
  display: grid; place-items: center;
  transition: all .15s;
}
.icon-btn:hover { background: var(--surface2); color: var(--text); border-color: var(--border2); }

/* Model card (sidebar) */
.model-list { display: flex; flex-direction: column; gap: 3px; }
.model-card {
  display: flex; align-items: center; gap: 10px;
  background: none; border: 1px solid transparent;
  border-radius: var(--radius-sm); padding: 9px 11px;
  cursor: pointer; color: var(--text-dim);
  transition: all .15s; text-align: left; width: 100%;
}
.model-card:hover { background: var(--surface2); color: var(--text); border-color: var(--border); }
.model-card.active { background: var(--grad-soft); border-color: #7c3aed44; color: var(--text); }
.model-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.model-info { flex: 1; }
.model-name { display: block; font-size: 13px; font-weight: 600; line-height: 1.2; }
.model-sub  { display: block; font-size: 10px; font-family: var(--font-mono); color: var(--text-faint); }
.model-check { font-size: 11px; color: #a78bfa; opacity: 0; transition: opacity .15s; margin-left: auto; }
.model-card.active .model-check { opacity: 1; }

/* Model badge (topbar) */
.model-badge {
  display: flex; align-items: center; gap: 8px;
  background: var(--grad-soft); border: 1px solid #7c3aed33;
  border-radius: 20px; padding: 6px 14px;
  font-size: 12px; font-family: var(--font-mono); color: #a78bfa;
}
.badge-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }

/* History list */
.history-section { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.history-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.history-list::-webkit-scrollbar { width: 3px; }
.history-list::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }
.history-item {
  padding: 8px 10px; border-radius: var(--radius-sm);
  font-size: 12px; color: var(--text-dim); cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: all .15s; border: 1px solid transparent;
  display: flex; align-items: center; gap: 6px;
}
.history-item:hover { background: var(--surface2); color: var(--text); border-color: var(--border); }
.history-item.active-chat { background: var(--grad-soft); border-color: #7c3aed33; color: var(--text); }
.history-item .hi-icon { font-size: 10px; flex-shrink: 0; opacity: .5; }
.history-empty { font-size: 11px; color: var(--text-faint); font-family: var(--font-mono); padding: 4px 2px; }

/* Input box */
.input-box {
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--surface2); border: 1px solid var(--border2);
  border-radius: var(--radius); padding: 10px 12px;
  transition: border-color .15s;
}
.input-box:focus-within { border-color: #7c3aed66; box-shadow: 0 0 0 3px #7c3aed14; }
.input-box textarea {
  flex: 1; background: none; border: none; outline: none;
  font-family: var(--font-main); font-size: 14px; color: var(--text);
  resize: none; max-height: 140px; line-height: 1.6;
}
.input-box textarea::placeholder { color: var(--text-faint); }
.input-box textarea::-webkit-scrollbar { width: 3px; }
.send-btn {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--grad); color: #fff; border: none;
  cursor: pointer; display: grid; place-items: center;
  flex-shrink: 0; transition: all .15s;
}
.send-btn:hover { opacity: .85; transform: scale(1.05); }
.send-btn:active { transform: scale(.95); }
.send-btn:disabled { opacity: .35; cursor: not-allowed; transform: none; }
.input-hint { font-size: 11px; font-family: var(--font-mono); color: var(--text-faint); text-align: center; margin-top: 8px; }

/* Welcome screen */
.welcome-screen {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center;
  padding: 40px 24px; flex: 1; animation: fadeUp .4s ease both;
}
.welcome-orb {
  width: 72px; height: 72px; border-radius: 50%;
  background: var(--grad); opacity: .2;
  filter: blur(20px); margin-bottom: -36px;
}
.welcome-title { font-size: clamp(22px, 4vw, 34px); font-weight: 700; letter-spacing: -.03em; margin-bottom: 8px; }
.welcome-sub { font-size: 13px; color: var(--text-dim); font-family: var(--font-mono); margin-bottom: 32px; }
.starter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; max-width: 500px; width: 100%; }
.starter-grid.mobile { grid-template-columns: 1fr; max-width: 300px; }
.starter-card {
  background: var(--surface); border: 1px solid var(--border2);
  border-radius: var(--radius); padding: 13px 15px;
  color: var(--text-dim); font-family: var(--font-main); font-size: 13px;
  font-weight: 500; cursor: pointer; text-align: left;
  transition: all .15s; line-height: 1.4;
}
.starter-card:hover { background: var(--grad-soft); border-color: #7c3aed44; color: var(--text); }

/* Messages */
.messages-list { display: flex; flex-direction: column; gap: 20px; }
.msg { display: flex; gap: 12px; animation: fadeUp .25s ease both; }
.msg-avatar {
  width: 30px; height: 30px; border-radius: 8px;
  display: grid; place-items: center; font-size: 10px;
  font-weight: 700; flex-shrink: 0; margin-top: 2px;
}
.msg-content { flex: 1; max-width: 720px; }
.msg-meta {
  font-size: 10px; font-family: var(--font-mono); color: var(--text-faint);
  margin-bottom: 5px; display: flex; align-items: center; gap: 7px;
}
.model-tag {
  background: var(--surface2); padding: 2px 7px;
  border-radius: 20px; border: 1px solid var(--border);
}
.msg-text { font-size: 14px; line-height: 1.75; color: var(--text); }
.msg.user .msg-text {
  background: var(--grad-soft); border: 1px solid #7c3aed33;
  border-radius: 4px 14px 14px 14px; padding: 12px 16px; display: inline-block;
}
.msg-text pre {
  background: #0d0d18; border: 1px solid var(--border2); border-radius: 8px;
  padding: 14px 16px; overflow-x: auto; margin: 10px 0;
  font-family: var(--font-mono); font-size: 12px; line-height: 1.6;
}
.msg-text code {
  font-family: var(--font-mono); font-size: 12px;
  background: var(--surface2); padding: 2px 5px; border-radius: 4px; color: #a78bfa;
}
.msg-text pre code { background: none; padding: 0; color: #c8d0e0; }

/* Typing */
.typing-indicator .msg-text {
  display: flex; align-items: center; gap: 5px;
  padding: 12px 16px; background: var(--surface2); border-radius: 14px; width: fit-content;
}
.typing-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--text-faint);
  animation: blink 1.2s infinite;
}
.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }
@keyframes blink {
  0%, 80%, 100% { opacity: .2; transform: scale(.8); }
  40% { opacity: 1; transform: scale(1); }
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ══════════════════════════════════════
   DESKTOP LAYOUT
══════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-w); height: 100vh;
  background: #0c0c16; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0;
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.new-chat-btn {
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  background: var(--grad-soft); border: 1px solid #7c3aed44;
  color: #a78bfa; cursor: pointer; display: grid; place-items: center;
  transition: all .15s;
}
.new-chat-btn:hover { background: var(--grad); color: #fff; border-color: transparent; }
.sidebar-section { padding: 14px 12px; flex-shrink: 0; }
.sidebar-section.history-section { flex: 1; overflow: hidden; display: flex; flex-direction: column; padding-bottom: 16px; }

.chat-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; position: relative; }
/* Aurora background glow */
.chat-main::before {
  content: ''; position: absolute; top: -100px; right: -100px;
  width: 400px; height: 400px;
  background: radial-gradient(circle, #7c3aed18, transparent 70%);
  pointer-events: none; z-index: 0;
}
.chat-main::after {
  content: ''; position: absolute; bottom: -80px; left: 50px;
  width: 300px; height: 300px;
  background: radial-gradient(circle, #0ea5e912, transparent 70%);
  pointer-events: none; z-index: 0;
}

.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; border-bottom: 1px solid var(--border);
  flex-shrink: 0; position: relative; z-index: 1;
}
.messages-wrap {
  flex: 1; overflow-y: auto; padding: 24px;
  display: flex; flex-direction: column;
  position: relative; z-index: 1;
}
.messages-wrap::-webkit-scrollbar { width: 5px; }
.messages-wrap::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
.messages-wrap .welcome-screen { min-height: 100%; }

.input-area { padding: 16px 24px 20px; flex-shrink: 0; position: relative; z-index: 1; }

/* ══════════════════════════════════════
   MOBILE LAYOUT
══════════════════════════════════════ */
.mobile-topbar {
  height: var(--topbar-h); display: flex; align-items: center;
  justify-content: space-between; padding: 0 16px;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
  background: #0c0c16; position: relative; z-index: 10;
}

.mobile-messages-wrap {
  flex: 1; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column;
}
.mobile-messages-wrap::-webkit-scrollbar { width: 3px; }
.mobile-messages-wrap::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }
.mobile-messages-wrap .welcome-screen { min-height: 100%; padding: 20px 16px; }
.mobile-messages-wrap .welcome-title { font-size: 22px; }

.mobile-model-bar {
  height: var(--modelbar-h); flex-shrink: 0;
  border-top: 1px solid var(--border); background: #0c0c16;
  display: flex; align-items: center;
}
.model-pills {
  display: flex; gap: 7px; padding: 0 14px;
  overflow-x: auto; scrollbar-width: none; align-items: center;
}
.model-pills::-webkit-scrollbar { display: none; }
.model-pill {
  padding: 6px 14px; border-radius: 20px; white-space: nowrap;
  font-size: 12px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--border2); color: var(--text-dim);
  background: none; transition: all .15s; flex-shrink: 0;
}
.model-pill.active {
  background: color-mix(in srgb, var(--c) 20%, transparent);
  border-color: color-mix(in srgb, var(--c) 50%, transparent);
  color: var(--c);
}

.mobile-input-area {
  padding: 10px 14px 14px; flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: #0c0c16;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
}

/* Drawer */
.drawer-overlay {
  display: none; position: fixed; inset: 0;
  background: #00000070; z-index: 99; backdrop-filter: blur(2px);
}
.drawer-overlay.show { display: block; }
.mobile-drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: 280px;
  background: #0c0c16; border-right: 1px solid var(--border);
  z-index: 100; display: flex; flex-direction: column;
  transform: translateX(-100%); transition: transform .3s cubic-bezier(.4,0,.2,1);
}
.mobile-drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.drawer-section { padding: 14px 12px; flex-shrink: 0; }
.drawer-section.history-section { flex: 1; overflow: hidden; display: flex; flex-direction: column; padding-bottom: 12px; }
.drawer-new-chat {
  margin: 0 12px 20px; padding: 12px;
  background: var(--grad-soft); border: 1px solid #7c3aed44;
  border-radius: var(--radius); color: #a78bfa;
  font-family: var(--font-main); font-size: 13px; font-weight: 600;
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: all .15s;
}
.drawer-new-chat:hover { background: var(--grad); color: #fff; border-color: transparent; }
