:root {
  --bg: #0b1220;
  --panel: #101a2e;
  --panel2: #0f172a;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --line: rgba(255,255,255,.08);
  --chip: rgba(255,255,255,.08);
  --good: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --na: #64748b;
  --accent: #38bdf8;
  --accent-dim: rgba(56,189,248,.12);
  --accent-glow: rgba(56,189,248,.25);
  --accent2: #818cf8;
  --sidebar-w: 300px;
  --sidebar-bg: #090e1a;
  --sidebar-border: rgba(255,255,255,.06);
  --font-ui: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --r-pill: 999px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; min-height: 100%; background: var(--bg); color: var(--text); font-family: var(--font-ui); }
body { overflow: hidden; }
button, input, textarea, select { font: inherit; }
a { color: inherit; text-decoration: none; }
.is-hidden { display: none !important; }

.shell {
  display: flex;
  min-height: 100dvh;
  height: 100dvh;
  overflow: hidden;
}

.mobile-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
  z-index: 39;
}

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--sidebar-border);
  display: flex;
  gap: 10px;
  align-items: center;
}

.logo-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  font-weight: 800;
  box-shadow: 0 0 18px var(--accent-glow);
}

.logo-copy { min-width: 0; }
.logo-name { font-size: 14px; font-weight: 700; }
.logo-sub { font-size: 11px; color: var(--muted); }

.sidebar-actions { padding: 14px 14px 8px; }
.sidebar-section-title {
  padding: 10px 16px 8px;
  color: var(--na);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 10px 10px;
  scrollbar-width: none;
}
.chat-list::-webkit-scrollbar { display: none; }

.chat-list-item {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  padding: 12px 12px;
  border-radius: var(--r-md);
  cursor: pointer;
  display: block;
  margin-bottom: 4px;
}
.chat-list-item:hover { background: rgba(255,255,255,.04); }
.chat-list-item.active { background: var(--accent-dim); border-color: rgba(56,189,248,.2); }
.chat-list-title { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-list-meta { font-size: 11px; color: var(--muted); margin-top: 4px; display: flex; justify-content: space-between; gap: 10px; }

.sidebar-footer { border-top: 1px solid var(--sidebar-border); padding: 10px; }
.env-badge {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border-radius: var(--r-md);
  background: rgba(34,197,94,.08);
  border: 1px solid rgba(34,197,94,.2);
  color: var(--good);
  font-size: 11px;
}
.env-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--good); box-shadow: 0 0 6px var(--good); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  min-height: 68px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  gap: 16px;
  background: linear-gradient(180deg, rgba(255,255,255,.02), rgba(255,255,255,0));
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-title { font-size: 16px; font-weight: 700; }
.topbar-sub { font-size: 12px; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.mobile-menu-btn { display: none; }

.info-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  background: rgba(255,255,255,.03);
  color: var(--muted);
  font-size: 12px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--na); }
.dot.good { background: var(--good); box-shadow: 0 0 10px rgba(34,197,94,.55); }
.dot.bad { background: var(--bad); box-shadow: 0 0 10px rgba(239,68,68,.55); }

.content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 22px 18px;
}

.chat-empty {
  max-width: 720px;
  margin: 48px auto;
  text-align: center;
  padding: 26px;
  border-radius: var(--r-xl);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,.03), rgba(255,255,255,.015));
}
.chat-empty-icon { font-size: 42px; margin-bottom: 12px; }
.chat-empty-title { font-size: 22px; font-weight: 700; margin-bottom: 6px; }
.chat-empty-desc { color: var(--muted); max-width: 560px; margin: 0 auto; }

.chat-thread {
  width: min(920px, 100%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.message-row { display: flex; }
.message-row.user { justify-content: flex-end; }
.message-row.assistant { justify-content: flex-start; }

.message-card {
  max-width: min(760px, 100%);
  border-radius: 18px;
  border: 1px solid var(--line);
  padding: 14px 16px;
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(0,0,0,.18);
}
.message-row.user .message-card {
  background: linear-gradient(135deg, rgba(56,189,248,.17), rgba(129,140,248,.14));
  border-color: rgba(56,189,248,.18);
}
.message-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 8px;
}
.message-role { font-weight: 700; letter-spacing: .4px; text-transform: uppercase; }
.message-text {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
  font-size: 14px;
}
.message-meta { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: var(--r-pill);
  padding: 4px 9px;
  font-size: 11px;
  background: var(--chip);
  color: var(--muted);
  border: 1px solid var(--line);
}

.sources-wrap { margin-top: 12px; }
.sources-dropdown {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,.02);
  overflow: hidden;
}
.sources-summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 14px;
  font-size: 12px;
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.sources-summary::-webkit-details-marker { display: none; }
.sources-list { padding: 0 14px 14px; display: flex; flex-direction: column; gap: 10px; }
.source-card {
  border: 1px solid var(--line);
  background: rgba(255,255,255,.02);
  border-radius: 12px;
  padding: 10px 12px;
}
.source-title { font-size: 12px; font-weight: 700; margin-bottom: 4px; }
.source-meta { font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.source-snippet { white-space: pre-wrap; color: #d6d9df; font-size: 12px; line-height: 1.5; }

.loading-bubble {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  padding: 10px 12px;
  color: var(--muted);
}
.loading-bubble span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1s infinite ease-in-out;
}
.loading-bubble span:nth-child(2) { animation-delay: .15s; }
.loading-bubble span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .35; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }

.composer-wrap {
  border-top: 1px solid var(--line);
  padding: 16px 18px 18px;
  background: linear-gradient(0deg, rgba(11,18,32,1), rgba(11,18,32,.92));
}
.composer {
  width: min(920px, 100%);
  margin: 0 auto;
  display: flex;
  gap: 12px;
  align-items: flex-end;
}
.composer-input {
  flex: 1;
  min-height: 54px;
  max-height: 180px;
  resize: none;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.03);
  color: var(--text);
  padding: 15px 16px;
  outline: none;
}
.composer-input:focus { border-color: rgba(56,189,248,.35); box-shadow: 0 0 0 3px rgba(56,189,248,.08); }
.composer-send { min-width: 108px; height: 54px; }

.btn {
  border: 1px solid var(--line);
  background: rgba(255,255,255,.04);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 14px;
  cursor: pointer;
}
.btn:hover { background: rgba(255,255,255,.07); }
.btn-sm { padding: 8px 12px; border-radius: 10px; }
.btn-full { width: 100%; }
.btn-ghost { background: transparent; }
.btn-primary {
  border-color: rgba(56,189,248,.28);
  background: linear-gradient(135deg, rgba(56,189,248,.16), rgba(129,140,248,.18));
  box-shadow: 0 0 16px rgba(56,189,248,.12);
}
.btn[disabled] { opacity: .55; cursor: not-allowed; }

.auth-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: min(520px, 100%);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,.03), rgba(255,255,255,.015));
  border-radius: 22px;
  padding: 26px;
  text-align: center;
}
.auth-title { font-size: 22px; font-weight: 800; margin: 0 0 8px; }
.auth-desc { color: var(--muted); margin-bottom: 16px; }

#toast-root {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 80;
}
.toast {
  min-width: 260px;
  max-width: 380px;
  border-radius: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: #0e172a;
  color: var(--text);
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
  transition: opacity .25s ease, transform .25s ease;
}
.toast.good { border-color: rgba(34,197,94,.25); }
.toast.bad { border-color: rgba(239,68,68,.25); }
.toast.warn { border-color: rgba(245,158,11,.25); }
.t-title { font-weight: 700; margin-bottom: 4px; }
.t-meta { font-size: 11px; color: var(--muted); margin-top: 4px; }

@media (max-width: 900px) {
  .mobile-menu-btn { display: inline-flex; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    transform: translateX(-100%);
    transition: transform .2s ease;
    z-index: 40;
    max-width: min(86vw, 320px);
  }
  body.mobile-sidebar-open .sidebar { transform: translateX(0); }
  body.mobile-sidebar-open .mobile-overlay { opacity: 1; pointer-events: auto; }
  .topbar-actions .info-pill { display: none; }
  .content { padding: 18px 12px; }
  .composer-wrap { padding: 12px; }
  .composer { gap: 10px; }
  .composer-send { min-width: 88px; }
}
