/* ═══════════════════════════════════════════════════════════════
   AETHER — AI Assistant  ·  Rebuilt
   Aesthetic: Editorial dark glass · Instrument Serif + Outfit + JetBrains Mono
   Author: Claude
═══════════════════════════════════════════════════════════════ */

/* ── Custom Properties ── */
:root {
  /* Dark palette */
  --bg:          #080810;
  --bg-1:        #0e0e1a;
  --bg-2:        #14141f;
  --bg-3:        #1c1c2a;
  --bg-4:        #242433;

  --glass:       rgba(255,255,255,0.03);
  --glass-2:     rgba(255,255,255,0.055);
  --glass-3:     rgba(255,255,255,0.08);

  --line:        rgba(255,255,255,0.07);
  --line-2:      rgba(255,255,255,0.11);

  --text:        #eeeaf8;
  --text-2:      #9d9ab8;
  --text-3:      #5a5870;

  --ink:         #c2bfe8;      /* assistant message text */

  --hi:          #a78bfa;      /* primary highlight (violet) */
  --hi-glow:     rgba(167,139,250,0.22);
  --hi-dim:      rgba(167,139,250,0.1);
  --hi-border:   rgba(167,139,250,0.3);
  --hi-hover:    #b8a4fb;

  --teal:        #34d5b7;
  --teal-dim:    rgba(52,213,183,0.12);

  --red:         #f87171;
  --red-dim:     rgba(248,113,113,0.12);

  --amber:       #fbbf24;

  /* Radii */
  --r-xs:  4px;
  --r-sm:  8px;
  --r-md:  14px;
  --r-lg:  20px;
  --r-xl:  28px;
  --r-2xl: 40px;

  /* Shadows */
  --sh-sm:  0 2px 10px rgba(0,0,0,0.5);
  --sh-md:  0 8px 40px rgba(0,0,0,0.55);
  --sh-lg:  0 24px 80px rgba(0,0,0,0.7);
  --sh-hi:  0 0 0 1px var(--hi-border), 0 8px 40px var(--hi-glow);

  /* Easing */
  --spring:    cubic-bezier(0.16, 1, 0.3, 1);
  --ease-out:  cubic-bezier(0.0, 0.0, 0.2, 1);

  /* Layout */
  --sidebar:   272px;
  --header:    56px;
  --max-msg:   780px;
}

/* ── Light theme ── */
[data-theme="light"] {
  --bg:          #f4f3fa;
  --bg-1:        #fafaff;
  --bg-2:        #ffffff;
  --bg-3:        #eeedf8;
  --bg-4:        #e5e4f5;

  --glass:       rgba(0,0,0,0.02);
  --glass-2:     rgba(0,0,0,0.035);
  --glass-3:     rgba(0,0,0,0.055);

  --line:        rgba(0,0,0,0.07);
  --line-2:      rgba(0,0,0,0.11);

  --text:        #1a1826;
  --text-2:      #56527a;
  --text-3:      #9896b8;

  --ink:         #2a2638;

  --sh-sm:  0 2px 10px rgba(0,0,0,0.08);
  --sh-md:  0 8px 40px rgba(0,0,0,0.1);
  --sh-lg:  0 24px 80px rgba(0,0,0,0.15);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: 'Outfit', system-ui, sans-serif;
  font-size: 15px;
  font-weight: 400;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow: hidden;
  transition: background 0.35s var(--spring), color 0.35s var(--spring);
  /* subtle grain overlay */
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E");
}
[data-theme="light"] body { background-image: none; }

::selection { background: var(--hi-dim); color: var(--text); }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

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

/* ═══════════════════════════════════════
   APP SHELL
═══════════════════════════════════════ */
.app-container {
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
}

/* ═══════════════════════════════════════
   SIDEBAR
═══════════════════════════════════════ */
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg-1);
  border-right: 1px solid var(--line);
  height: 100dvh;
  overflow: hidden;
  transition: transform 0.35s var(--spring), background 0.35s;
  z-index: 30;
}

/* Wordmark */
.sidebar-top {
  padding: 20px 16px 14px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 2px;
}

.wordmark-glyph {
  font-size: 20px;
  color: var(--hi);
  filter: drop-shadow(0 0 12px var(--hi-glow));
  line-height: 1;
}

.wordmark-text {
  font-family: 'Instrument Serif', Georgia, serif;
  font-size: 22px;
  letter-spacing: -0.01em;
  color: var(--text);
}

.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  background: var(--glass-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--text-2);
  cursor: pointer;
  font-family: 'Outfit', sans-serif;
  font-size: 13px;
  font-weight: 500;
  width: 100%;
  transition: all 0.2s var(--spring);
}
.new-chat-btn svg { width: 14px; height: 14px; }
.new-chat-btn:hover {
  background: var(--hi-dim);
  border-color: var(--hi-border);
  color: var(--hi);
}

/* Section labels */
.section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--text-3);
  padding: 0 4px 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.section-clear {
  background: none;
  border: none;
  font-family: 'Outfit', sans-serif;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-3);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: var(--r-xs);
  transition: color 0.15s, background 0.15s;
}
.section-clear:hover { color: var(--red); background: var(--red-dim); }

/* Chat list */
.chat-list-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px 6px;
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 0;
}

.chat-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 2px;
}

.chat-list-empty {
  font-size: 12px;
  color: var(--text-3);
  font-style: italic;
  padding: 6px 4px;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 0;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
  group: 1;
}

.chat-item:hover { background: var(--glass-2); }
.chat-item.active { background: var(--hi-dim); }

.chat-item-btn {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  color: var(--text-2);
  font-family: 'Outfit', sans-serif;
  font-size: 13px;
  min-width: 0;
  transition: color 0.15s;
}
.chat-item.active .chat-item-btn { color: var(--text); }
.chat-item:hover .chat-item-btn { color: var(--text); }

.chat-item-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  opacity: 0.5;
}
.chat-item.active .chat-item-icon { opacity: 1; color: var(--hi); }

.chat-item-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
}

.chat-item-del {
  width: 26px;
  height: 26px;
  border-radius: var(--r-xs);
  background: none;
  border: none;
  color: var(--text-3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  flex-shrink: 0;
  margin-right: 6px;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}
.chat-item-del svg { width: 12px; height: 12px; }
.chat-item:hover .chat-item-del { opacity: 1; }
.chat-item-del:hover { color: var(--red); background: var(--red-dim); }

/* Memory panel */
.memory-wrap {
  padding: 12px 12px 8px;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
  max-height: 220px;
  overflow-y: auto;
}

.memory-panel {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 4px;
}

.memory-empty {
  font-size: 12px;
  color: var(--text-3);
  font-style: italic;
  padding: 4px 4px;
}

.memory-tag {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  padding: 7px 10px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  animation: riseIn 0.2s var(--spring);
}

.mem-icon { font-size: 13px; flex-shrink: 0; margin-top: 1px; }

.mem-body { display: flex; flex-direction: column; gap: 1px; }

.mem-kind {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--hi);
  font-family: 'Outfit', sans-serif;
}

.mem-val { font-size: 12px; color: var(--text-2); line-height: 1.4; }

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

.footer-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  background: none;
  border: none;
  border-radius: var(--r-sm);
  color: var(--text-2);
  cursor: pointer;
  font-family: 'Outfit', sans-serif;
  font-size: 13px;
  font-weight: 400;
  transition: background 0.15s, color 0.15s;
  width: 100%;
  text-align: left;
}
.footer-btn svg { width: 14px; height: 14px; flex-shrink: 0; }
.footer-btn:hover { background: var(--glass-2); color: var(--text); }

[data-theme="dark"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }

/* ═══════════════════════════════════════
   CHAT MAIN
═══════════════════════════════════════ */
.chat-main {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--bg);
  transition: background 0.35s;
  overflow: hidden;
  position: relative;
}

/* subtle vignette */
.chat-main::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse 80% 50% at 50% 0%, rgba(167,139,250,0.04) 0%, transparent 70%);
  z-index: 0;
}
[data-theme="light"] .chat-main::before {
  background: radial-gradient(ellipse 80% 50% at 50% 0%, rgba(167,139,250,0.06) 0%, transparent 70%);
}

/* Chat Header */
.chat-header {
  height: var(--header);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(8,8,16,0.7);
  backdrop-filter: blur(20px);
  flex-shrink: 0;
  position: relative;
  z-index: 10;
  transition: background 0.35s;
}
[data-theme="light"] .chat-header { background: rgba(244,243,250,0.8); }

.header-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.header-convo-title {
  font-family: 'Outfit', sans-serif;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 400px;
}

.status-ring {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 8px var(--teal), 0 0 16px rgba(52,213,183,0.3);
  flex-shrink: 0;
  animation: breathe 3s ease infinite;
}
.status-ring.small { width: 7px; height: 7px; }

@keyframes breathe {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(0.8); }
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Speed pill */
.speed-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  background: var(--glass-2);
  border: 1px solid var(--line);
  border-radius: 99px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text-3);
  transition: opacity 0.2s;
}
.speed-pill.hidden-speed { opacity: 0; pointer-events: none; }

input[type="range"] {
  -webkit-appearance: none;
  width: 56px;
  height: 2px;
  background: var(--line-2);
  border-radius: 99px;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 11px; height: 11px;
  border-radius: 50%;
  background: var(--hi);
  cursor: pointer;
  box-shadow: 0 0 6px var(--hi-glow);
}

/* Icon buttons */
.icon-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  color: var(--text-2);
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s;
}
.icon-btn svg { width: 15px; height: 15px; }
.icon-btn:hover { background: var(--glass-2); color: var(--text); border-color: var(--line); }
.icon-btn.active { color: var(--hi); background: var(--hi-dim); border-color: var(--hi-border); }

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

/* ═══════════════════════════════════════
   MESSAGES
═══════════════════════════════════════ */
.messages-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 28px 0 16px;
  position: relative;
  z-index: 1;
}

/* Welcome screen */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100dvh - var(--header) - 112px);
  padding: 40px 24px;
  text-align: center;
  animation: riseIn 0.5s var(--spring);
}

.welcome-orb {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, var(--hi), rgba(167,139,250,0.2));
  box-shadow: 0 0 40px var(--hi-glow), 0 0 80px rgba(167,139,250,0.1);
  margin-bottom: 24px;
  animation: orbFloat 5s ease-in-out infinite;
}

@keyframes orbFloat {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-10px) scale(1.04); }
}

.welcome-heading {
  font-family: 'Instrument Serif', Georgia, serif;
  font-size: 48px;
  font-weight: 400;
  letter-spacing: -0.03em;
  color: var(--text);
  margin-bottom: 10px;
  line-height: 1.1;
}

.welcome-sub {
  font-size: 16px;
  color: var(--text-2);
  margin-bottom: 40px;
}

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

.chip {
  padding: 9px 16px;
  background: var(--glass-2);
  border: 1px solid var(--line);
  border-radius: 99px;
  font-family: 'Outfit', sans-serif;
  font-size: 13px;
  font-weight: 400;
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.2s var(--spring);
}
.chip:hover {
  background: var(--hi-dim);
  border-color: var(--hi-border);
  color: var(--text);
  transform: translateY(-2px);
  box-shadow: 0 4px 20px var(--hi-glow);
}

/* Message rows */
.msg-row {
  display: flex;
  flex-direction: column;
  padding: 4px 24px;
  max-width: var(--max-msg);
  margin: 0 auto;
  width: 100%;
  animation: riseIn 0.3s var(--spring);
}

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

.msg-row.user { align-items: flex-end; }
.msg-row.assistant { align-items: flex-start; }

/* Role label */
.msg-role {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 5px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: 'Outfit', sans-serif;
}

.msg-row.user .msg-role { color: var(--hi); opacity: 0.7; }

/* Bubbles */
.msg-bubble {
  max-width: 78%;
  padding: 13px 17px;
  border-radius: var(--r-lg);
  font-size: 15px;
  line-height: 1.72;
  position: relative;
  word-break: break-word;
}

.msg-row.user .msg-bubble {
  background: var(--hi);
  color: #fff;
  border-bottom-right-radius: var(--r-xs);
  box-shadow: 0 4px 24px rgba(167,139,250,0.35);
  font-family: 'Outfit', sans-serif;
}

.msg-row.assistant .msg-bubble {
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--ink);
  border-bottom-left-radius: var(--r-xs);
  box-shadow: var(--sh-sm);
  font-family: 'Instrument Serif', Georgia, serif;
  font-size: 16px;
  line-height: 1.78;
}
[data-theme="light"] .msg-row.assistant .msg-bubble { background: var(--bg-2); }

/* Streaming cursor */
.stream-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--hi);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.8s step-end infinite;
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Message footer (time + actions) */
.msg-footer {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 5px;
  opacity: 0;
  transition: opacity 0.2s;
}
.msg-row:hover .msg-footer { opacity: 1; }

.msg-time {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--text-3);
}

.msg-action {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: var(--r-xs);
  color: var(--text-3);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.msg-action svg { width: 12px; height: 12px; }
.msg-action:hover { color: var(--text); background: var(--glass-3); }
.msg-action.speak:hover { color: var(--teal); }
.msg-action.copy:hover { color: var(--hi); }
.msg-action.regen:hover { color: var(--amber); }

/* ── Markdown inside assistant bubbles ── */
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 {
  font-family: 'Outfit', sans-serif;
  font-weight: 600;
  color: var(--text);
  margin: 16px 0 6px;
  line-height: 1.3;
}
.msg-bubble h1 { font-size: 20px; }
.msg-bubble h2 { font-size: 17px; }
.msg-bubble h3 { font-size: 15px; }
.msg-bubble h1:first-child,
.msg-bubble h2:first-child,
.msg-bubble h3:first-child { margin-top: 0; }

.msg-bubble p { margin: 6px 0; }
.msg-bubble p:first-child { margin-top: 0; }
.msg-bubble p:last-child { margin-bottom: 0; }

.msg-bubble strong { font-weight: 700; color: var(--text); }
.msg-row.user .msg-bubble strong { color: rgba(255,255,255,0.95); }

.msg-bubble em { font-style: italic; }

.msg-bubble ul, .msg-bubble ol {
  padding-left: 20px;
  margin: 8px 0;
}
.msg-bubble li { margin: 4px 0; }

.msg-bubble blockquote {
  border-left: 3px solid var(--hi-border);
  padding-left: 14px;
  color: var(--text-2);
  font-style: italic;
  margin: 10px 0;
}

.msg-bubble a { color: var(--hi); text-decoration: underline; text-underline-offset: 3px; }
.msg-bubble a:hover { color: var(--hi-hover); }

.msg-bubble hr { border: none; border-top: 1px solid var(--line); margin: 12px 0; }

.msg-bubble table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
  font-family: 'Outfit', sans-serif;
  font-size: 13px;
}
.msg-bubble th, .msg-bubble td {
  padding: 8px 12px;
  border: 1px solid var(--line);
  text-align: left;
}
.msg-bubble th { background: var(--glass-2); font-weight: 600; color: var(--text); }

/* Inline code */
.msg-bubble code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
  padding: 2px 6px;
  background: var(--glass-3);
  border-radius: var(--r-xs);
  color: var(--teal);
  border: 1px solid var(--line);
}
[data-theme="light"] .msg-bubble code { background: rgba(0,0,0,0.06); color: #0d6c59; }

/* Code blocks */
.msg-bubble pre {
  position: relative;
  background: #0d0d14;
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  padding: 0;
  overflow: hidden;
  margin: 12px 0;
}
[data-theme="light"] .msg-bubble pre { background: #1a1a2e; }

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: rgba(255,255,255,0.04);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.code-lang {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 500;
  color: rgba(255,255,255,0.35);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.copy-code-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--r-xs);
  padding: 3px 8px;
  font-family: 'Outfit', sans-serif;
  font-size: 11px;
  color: rgba(255,255,255,0.4);
  cursor: pointer;
  transition: all 0.15s;
}
.copy-code-btn:hover { background: rgba(255,255,255,0.07); color: rgba(255,255,255,0.8); border-color: rgba(255,255,255,0.2); }
.copy-code-btn.copied { color: var(--teal); border-color: rgba(52,213,183,0.4); }
.copy-code-btn svg { width: 10px; height: 10px; }

.msg-bubble pre code {
  background: none;
  border: none;
  padding: 14px 16px;
  display: block;
  font-size: 13px;
  line-height: 1.6;
  overflow-x: auto;
  color: #c9d1d9;
}

/* ── Typing indicator ── */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 14px 18px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  border-bottom-left-radius: var(--r-xs);
  max-width: fit-content;
  animation: riseIn 0.2s var(--spring);
}
.typing-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-3);
  animation: dotBounce 1.4s ease infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotBounce {
  0%, 60%, 100% { transform: translateY(0); background: var(--text-3); }
  30% { transform: translateY(-7px); background: var(--hi); }
}

/* ═══════════════════════════════════════
   INPUT ZONE
═══════════════════════════════════════ */
.input-zone {
  padding: 12px 24px 10px;
  background: rgba(8,8,16,0.7);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--line);
  flex-shrink: 0;
  position: relative;
  z-index: 10;
  transition: background 0.35s;
}
[data-theme="light"] .input-zone { background: rgba(244,243,250,0.85); }

.input-shell {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: var(--r-xl);
  padding: 10px 10px 10px 14px;
  max-width: var(--max-msg);
  margin: 0 auto;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.input-shell:focus-within {
  border-color: var(--hi-border);
  box-shadow: 0 0 0 3px var(--hi-dim);
}
.input-shell.listening {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-dim);
}

.user-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  resize: none;
  font-family: 'Outfit', sans-serif;
  font-size: 15px;
  color: var(--text);
  line-height: 1.6;
  max-height: 180px;
  overflow-y: auto;
  min-height: 24px;
  padding: 2px 0;
}
.user-input::placeholder { color: var(--text-3); }

/* Mic button */
.mic-btn {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: 50%;
  color: var(--text-3);
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  transition: color 0.2s;
}
.mic-btn svg { width: 16px; height: 16px; position: relative; z-index: 1; }
.mic-btn:hover { color: var(--text-2); }
.mic-btn.active { color: var(--teal); }

.mic-ripple {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--teal);
  animation: rippleOut 1.2s ease-out infinite;
}
@keyframes rippleOut {
  0% { transform: scale(0.8); opacity: 0.8; }
  100% { transform: scale(1.8); opacity: 0; }
}

/* Send button */
.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--hi);
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.15s, opacity 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 18px rgba(167,139,250,0.45);
}
.send-btn svg { width: 14px; height: 14px; }
.send-btn:hover { background: var(--hi-hover); transform: scale(1.06); }
.send-btn:active { transform: scale(0.93); }
.send-btn:disabled { opacity: 0.25; cursor: not-allowed; transform: none; box-shadow: none; }
.send-btn.small { width: 30px; height: 30px; }
.send-btn.small svg { width: 12px; height: 12px; }

.input-footnote {
  text-align: center;
  font-size: 11px;
  color: var(--text-3);
  padding: 6px 0 0;
  max-width: var(--max-msg);
  margin: 0 auto;
  font-style: italic;
}

/* ═══════════════════════════════════════
   SETTINGS MODAL
═══════════════════════════════════════ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: var(--r-xl);
  box-shadow: var(--sh-lg);
  width: 500px;
  max-width: calc(100vw - 32px);
  animation: riseIn 0.3s var(--spring);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--line);
}
.modal-header h2 {
  font-family: 'Outfit', sans-serif;
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
}

.modal-body {
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: 60vh;
  overflow-y: auto;
}

.setting-group { display: flex; flex-direction: column; gap: 6px; }
.setting-row { flex-direction: row; align-items: center; justify-content: space-between; }

.setting-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  font-family: 'Outfit', sans-serif;
}
.setting-note { color: var(--text-3); font-weight: 400; }

.setting-input {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 9px 12px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}
.setting-input:focus { border-color: var(--hi-border); box-shadow: 0 0 0 3px var(--hi-dim); }
.setting-textarea { resize: vertical; font-family: 'Outfit', sans-serif; font-size: 13px; }

/* Toggle */
.toggle { position: relative; display: inline-block; width: 42px; height: 24px; cursor: pointer; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--bg-4);
  border: 1px solid var(--line-2);
  border-radius: 99px;
  transition: background 0.2s;
}
.toggle-track::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--text-3);
  transition: transform 0.25s var(--spring), background 0.2s;
}
.toggle input:checked + .toggle-track { background: var(--hi); border-color: var(--hi); }
.toggle input:checked + .toggle-track::after { transform: translateX(18px); background: white; }

.modal-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 16px 24px;
  border-top: 1px solid var(--line);
}

.modal-btn {
  padding: 9px 20px;
  border-radius: var(--r-sm);
  font-family: 'Outfit', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  border: none;
}
.modal-btn.secondary { background: var(--glass-2); color: var(--text-2); border: 1px solid var(--line); }
.modal-btn.secondary:hover { background: var(--glass-3); color: var(--text); }
.modal-btn.primary { background: var(--hi); color: white; box-shadow: 0 4px 16px var(--hi-glow); }
.modal-btn.primary:hover { background: var(--hi-hover); transform: translateY(-1px); }

/* ═══════════════════════════════════════
   TOAST NOTIFICATIONS
═══════════════════════════════════════ */
.toast-shelf {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.toast {
  background: var(--bg-3);
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  padding: 10px 18px;
  font-family: 'Outfit', sans-serif;
  font-size: 13px;
  color: var(--text);
  box-shadow: var(--sh-md);
  pointer-events: all;
  animation: toastIn 0.3s var(--spring);
  max-width: 320px;
  text-align: center;
}
.toast.success { border-color: rgba(52,213,183,0.3); color: var(--teal); }
.toast.error { border-color: rgba(248,113,113,0.3); color: var(--red); }
.toast.out { animation: toastOut 0.25s var(--ease-out) forwards; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-8px); }
}

/* ═══════════════════════════════════════
   WIDGET
═══════════════════════════════════════ */
.widget-wrap {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  pointer-events: none;
}
.widget-wrap * { pointer-events: all; }

.widget-fab {
  width: 54px; height: 54px;
  border-radius: 50%;
  background: var(--hi);
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 30px rgba(167,139,250,0.5);
  transition: transform 0.2s var(--spring), box-shadow 0.2s;
  position: relative;
  z-index: 2;
}
.widget-fab svg { width: 22px; height: 22px; }
.widget-fab:hover { transform: scale(1.08); }
.widget-fab:active { transform: scale(0.94); }

.widget-panel {
  width: 360px;
  height: 480px;
  background: var(--bg-1);
  border: 1px solid var(--line-2);
  border-radius: var(--r-xl);
  box-shadow: var(--sh-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transform: scale(0.85) translateY(16px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.35s var(--spring), opacity 0.25s var(--spring);
}
.widget-panel.open { transform: scale(1) translateY(0); opacity: 1; pointer-events: all; }

.widget-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.widget-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Outfit', sans-serif;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}

.widget-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.w-msg {
  display: flex;
  animation: riseIn 0.25s var(--spring);
}
.w-msg.user { justify-content: flex-end; }

.w-bubble {
  max-width: 82%;
  padding: 9px 13px;
  border-radius: var(--r-md);
  font-size: 13.5px;
  line-height: 1.55;
  font-family: 'Outfit', sans-serif;
}
.w-msg.user .w-bubble { background: var(--hi); color: #fff; border-bottom-right-radius: var(--r-xs); }
.w-msg.assistant .w-bubble { background: var(--bg-3); border: 1px solid var(--line); color: var(--text); border-bottom-left-radius: var(--r-xs); }

.widget-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}
.widget-input-row input {
  flex: 1;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 8px 14px;
  font-family: 'Outfit', sans-serif;
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
.widget-input-row input:focus { border-color: var(--hi-border); }
.widget-input-row input::placeholder { color: var(--text-3); }

/* ═══════════════════════════════════════
   RESPONSIVE
═══════════════════════════════════════ */
@media (max-width: 768px) {
  .app-container { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar);
    transform: translateX(-100%);
    box-shadow: var(--sh-lg);
    z-index: 50;
  }
  .sidebar.open { transform: translateX(0); }

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

  .speed-pill { display: none; }

  .msg-bubble { max-width: 92%; }

  .welcome-heading { font-size: 34px; }

  .widget-panel { width: calc(100vw - 48px); }
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 45;
  backdrop-filter: blur(3px);
}
.sidebar-overlay.visible { display: block; }

/* hljs light theme override */
[data-theme="light"] .hljs-theme-link { display: none; }