:root {
  --bg: #0a0c10;
  --bg-elev: #0f131a;
  --panel: #131820;
  --panel-2: #171d27;
  --border: #232a36;
  --border-soft: #1b2230;
  --text: #e8ecf2;
  --text-dim: #9aa6b8;
  --muted: #67738a;
  --accent: #2dd4bf;
  --accent-2: #38bdf8;
  --accent-glow: rgba(45, 212, 191, .18);
  --user-bubble: #1a2330;
  --danger: #f87171;
  --ok: #34d399;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0,0,0,.45);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: radial-gradient(1200px 800px at 80% -10%, #11202a 0%, transparent 55%),
              radial-gradient(900px 700px at -10% 110%, #15161f 0%, transparent 50%),
              var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.app { display: grid; grid-template-columns: 264px 1fr; height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  background: linear-gradient(180deg, var(--bg-elev), var(--bg));
  border-right: 1px solid var(--border-soft);
  display: flex; flex-direction: column;
  padding: 18px 14px; gap: 18px;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 6px; }
.brand-mark {
  width: 34px; height: 34px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #04201d; border-radius: 10px; font-size: 16px; font-weight: 700;
  box-shadow: 0 0 18px var(--accent-glow);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-weight: 700; letter-spacing: .14em; font-size: 14px; }
.brand-sub { font-size: 11px; color: var(--muted); letter-spacing: .08em; }

.new-chat {
  background: var(--panel); color: var(--text); border: 1px solid var(--border);
  padding: 11px 14px; border-radius: 12px; font-size: 13.5px; font-weight: 500;
  cursor: pointer; text-align: left; transition: .15s;
}
.new-chat:hover { border-color: var(--accent); color: #fff; background: var(--panel-2); }

.nav-section { display: flex; flex-direction: column; gap: 6px; }
.nav-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; padding: 2px 6px; }
.history { list-style: none; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; max-height: 38vh; }
.history li {
  font-size: 13px; color: var(--text-dim); padding: 9px 10px; border-radius: 9px;
  cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: .12s;
}
.history li:hover { background: var(--panel); color: var(--text); }
.history li.active { background: var(--panel-2); color: #fff; }

.quick-links { margin-top: auto; }
.quick {
  display: block; font-size: 13px; color: var(--text-dim); text-decoration: none;
  padding: 8px 10px; border-radius: 9px; transition: .12s;
}
.quick:hover { background: var(--panel); color: var(--text); }

.status-pill {
  display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--muted);
  padding: 8px 10px; border: 1px solid var(--border-soft); border-radius: 10px; font-family: var(--mono);
}
.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status-pill.ok .dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.status-pill.degraded .dot { background: #fbbf24; box-shadow: 0 0 8px #fbbf24; }
.status-pill.down .dot { background: var(--danger); }

/* ---------- Main ---------- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100vh; }
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 16px 26px;
  border-bottom: 1px solid var(--border-soft);
}
.topbar-title { display: flex; align-items: baseline; gap: 10px; flex: 1; }
.topbar-title h1 { font-size: 17px; font-weight: 600; letter-spacing: .01em; }
.muted { color: var(--muted); font-size: 12.5px; }
.mode-toggle { display: flex; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.mode {
  background: transparent; border: 0; color: var(--text-dim); font-size: 12.5px; font-weight: 500;
  padding: 6px 14px; border-radius: 8px; cursor: pointer; transition: .15s;
}
.mode.active { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #04201d; }

.icon-btn { background: none; border: 0; color: var(--text); font-size: 20px; cursor: pointer; }
.mobile-only { display: none; }

/* ---------- Thread ---------- */
.thread { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 28px 26px 10px; scroll-behavior: smooth; }
.thread::-webkit-scrollbar, .history::-webkit-scrollbar { width: 9px; }
.thread::-webkit-scrollbar-thumb, .history::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }

.welcome { max-width: 640px; margin: 6vh auto 0; text-align: center; }
.welcome-mark {
  width: 56px; height: 56px; margin: 0 auto 18px; display: grid; place-items: center; font-size: 24px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #04201d;
  border-radius: 16px; box-shadow: 0 0 36px var(--accent-glow);
}
.welcome h2 { font-size: 26px; font-weight: 600; margin-bottom: 10px; letter-spacing: -.01em; }
.welcome p { max-width: 460px; margin: 0 auto 26px; line-height: 1.5; }
.suggestions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.chip {
  background: var(--panel); border: 1px solid var(--border); color: var(--text-dim);
  padding: 10px 14px; border-radius: 11px; font-size: 13px; cursor: pointer; transition: .15s;
}
.chip:hover { border-color: var(--accent); color: #fff; transform: translateY(-1px); }

.msg { display: flex; gap: 14px; max-width: 820px; margin: 0 auto 24px; animation: rise .35s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.msg .avatar {
  width: 30px; height: 30px; border-radius: 9px; flex-shrink: 0; display: grid; place-items: center;
  font-size: 13px; font-weight: 700;
}
.msg.user .avatar { background: var(--user-bubble); color: var(--text-dim); border: 1px solid var(--border); }
.msg.jarvis .avatar { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #04201d; }
.msg .body { flex: 1; min-width: 0; }
.msg .who { font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 500; }
.msg .content {
  font-size: 14.5px; line-height: 1.62; color: var(--text); word-wrap: break-word;
}
.msg.user .content { color: var(--text-dim); }
.msg .content p { margin: 0 0 10px; }
.msg .content p:last-child { margin-bottom: 0; }
.msg .content h1, .msg .content h2, .msg .content h3 { margin: 16px 0 8px; font-weight: 600; line-height: 1.3; }
.msg .content h1 { font-size: 18px; } .msg .content h2 { font-size: 16px; } .msg .content h3 { font-size: 14.5px; }
.msg .content ul, .msg .content ol { margin: 0 0 10px; padding-left: 20px; }
.msg .content li { margin: 4px 0; }
.msg .content code {
  font-family: var(--mono); font-size: 12.5px; background: var(--bg-elev);
  border: 1px solid var(--border-soft); padding: 1px 6px; border-radius: 5px;
}
.msg .content pre {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px; overflow-x: auto; margin: 0 0 12px;
}
.msg .content pre code { background: none; border: 0; padding: 0; }
.msg .content strong { color: #fff; font-weight: 600; }
.msg .content a { color: var(--accent); }
.msg .meta-tag {
  display: inline-flex; gap: 6px; align-items: center; margin-top: 10px;
  font-size: 11px; color: var(--muted); font-family: var(--mono);
}
.msg .meta-tag b { color: var(--accent); font-weight: 500; }

/* ---------- Panel indicator ---------- */
/* ---------- panel reasoning expander ---------- */
.panel-reasoning { margin-top: 12px; border: 1px solid var(--border-soft); border-radius: 10px; background: var(--bg-elev); overflow: hidden; }
.panel-reasoning summary {
  cursor: pointer; padding: 10px 14px; font-size: 12.5px; color: var(--text-dim);
  font-family: var(--mono); list-style: none; user-select: none; transition: color .15s;
}
.panel-reasoning summary::-webkit-details-marker { display: none; }
.panel-reasoning summary::before { content: "▸ "; color: var(--accent); }
.panel-reasoning[open] summary::before { content: "▾ "; }
.panel-reasoning summary:hover { color: var(--text); }
.panel-reasoning .pa { padding: 12px 14px; border-top: 1px solid var(--border-soft); }
.panel-reasoning .pa-h { font-size: 12px; font-weight: 600; color: var(--accent); margin-bottom: 5px; font-family: var(--mono); }
.panel-reasoning .pa-b { font-size: 13px; line-height: 1.55; color: var(--text-dim); }
.panel-reasoning .pa-b p { margin: 0 0 6px; }
.panel-reasoning .pa-b ul { margin: 0 0 6px; padding-left: 18px; }

.panel-indicator[hidden], .wave[hidden] { display: none !important; }
.panel-indicator {
  display: flex; align-items: center; gap: 12px; max-width: 820px; margin: 0 auto;
  padding: 12px 18px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; font-size: 13px; color: var(--text-dim);
}
.spinner {
  width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.agent-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.agent-chips span {
  font-size: 10.5px; font-family: var(--mono); padding: 3px 8px; border-radius: 6px;
  background: var(--bg-elev); border: 1px solid var(--border-soft); color: var(--text-dim);
  animation: rise .3s ease;
}

/* ---------- Composer ---------- */
.composer { padding: 14px 26px 18px; border-top: 1px solid var(--border-soft); }
.composer-inner {
  max-width: 820px; margin: 0 auto; display: flex; align-items: flex-end; gap: 10px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 8px 8px 8px 16px;
  transition: border-color .15s, box-shadow .15s;
}
.composer-inner:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
#input {
  flex: 1; background: none; border: 0; resize: none; color: var(--text); font-family: var(--font);
  font-size: 14.5px; line-height: 1.5; max-height: 180px; padding: 8px 0; outline: none;
}
#input::placeholder { color: var(--muted); }
.mic-btn, .send-btn {
  width: 40px; height: 40px; border-radius: 11px; border: 0; cursor: pointer; flex-shrink: 0;
  display: grid; place-items: center; transition: .15s; position: relative;
}
.mic-btn { background: var(--bg-elev); color: var(--text-dim); border: 1px solid var(--border); }
.mic-btn:hover { color: var(--text); border-color: var(--accent); }
.mic-btn.recording { background: var(--danger); color: #fff; border-color: var(--danger); }
.send-btn { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #04201d; font-size: 18px; font-weight: 700; }
.send-btn:hover { filter: brightness(1.1); }
.send-btn:disabled { opacity: .4; cursor: default; filter: none; }
.composer-hint { text-align: center; margin-top: 9px; font-size: 11px; }

.wave { position: absolute; display: flex; gap: 2px; align-items: center; height: 16px; }
.wave i { width: 2px; height: 4px; background: #fff; border-radius: 2px; animation: wv .8s ease infinite; }
.wave i:nth-child(2){animation-delay:.1s}.wave i:nth-child(3){animation-delay:.2s}.wave i:nth-child(4){animation-delay:.3s}.wave i:nth-child(5){animation-delay:.4s}
@keyframes wv { 0%,100%{height:4px}50%{height:14px} }

/* ---------- Login overlay ---------- */
.login-overlay[hidden] { display: none !important; }
.login-overlay {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  background: radial-gradient(800px 600px at 50% 30%, #11202a 0%, transparent 60%), rgba(6,8,11,.96);
  backdrop-filter: blur(6px);
}
.login-card {
  width: min(360px, 90vw); display: flex; flex-direction: column; align-items: center;
  gap: 12px; padding: 36px 30px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 18px; box-shadow: var(--shadow); text-align: center;
}
.login-mark {
  width: 52px; height: 52px; display: grid; place-items: center; font-size: 22px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #04201d;
  border-radius: 14px; box-shadow: 0 0 30px var(--accent-glow);
}
.login-card h2 { font-size: 20px; letter-spacing: .14em; font-weight: 700; }
.login-card p { margin-bottom: 4px; }
.login-card input {
  width: 100%; background: var(--bg-elev); border: 1px solid var(--border); color: var(--text);
  padding: 12px 14px; border-radius: 11px; font-size: 14px; font-family: var(--font); outline: none;
}
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.login-card button {
  width: 100%; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #04201d;
  border: 0; padding: 12px; border-radius: 11px; font-weight: 600; font-size: 14px; cursor: pointer;
}
.login-card button:hover { filter: brightness(1.08); }
.login-error[hidden] { display: none; }
.login-error { color: var(--danger); font-size: 12.5px; }
.quick.logout[hidden] { display: none; }
.quick.logout { background: none; border: 0; text-align: left; width: 100%; cursor: pointer; font-family: var(--font); }

/* ---------- Message actions / meta ---------- */
.msg .stamp { color: var(--muted); font-size: 11px; font-weight: 400; margin-left: 8px; }
.msg .actions { margin-top: 8px; display: flex; gap: 8px; opacity: 0; transition: opacity .15s; }
.msg:hover .actions { opacity: 1; }
.copy-btn {
  background: var(--bg-elev); border: 1px solid var(--border-soft); color: var(--text-dim);
  font-size: 11px; padding: 4px 10px; border-radius: 7px; cursor: pointer; font-family: var(--font);
}
.copy-btn:hover { color: var(--text); border-color: var(--accent); }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 30; width: 264px; height: 100%; transform: translateX(-100%); transition: transform .25s; }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  .mobile-only { display: block; }
  .welcome h2 { font-size: 22px; }
}
