:root {
  --bg: #0e1014; --panel: #161a21; --panel-2: #1d222b; --line: #2a303b; --text: #e8ebf0; --muted: #98a1b0;
  --accent: #7c5cff; --accent-text: #fff; --ok: #3ecf8e; --warn: #f5a524; --bad: #ff5d6c;
  --radius: 14px; --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; -webkit-text-size-adjust: 100%; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* shell: left sidebar on desktop, bottom bar on phones */
.shell { display: grid; grid-template-columns: 220px 1fr; height: 100dvh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: calc(16px + var(--safe-t)) 12px 16px; display: flex; flex-direction: column; gap: 6px; }
.brand { font-weight: 700; font-size: 18px; letter-spacing: .02em; padding: 4px 10px 14px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav button { text-align: left; background: none; border: 0; padding: 10px 12px; border-radius: 10px; color: var(--muted); }
.nav button[aria-current="page"] { background: var(--panel-2); color: var(--text); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; font-size: 13px; color: var(--muted); }
.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .side { order: 2; flex-direction: row; border-right: 0; border-top: 1px solid var(--line); padding: 6px 10px calc(6px + var(--safe-b)); align-items: center; }
  .brand, .side-foot { display: none; }
  .nav { flex-direction: row; flex: 1; }
  .nav button { flex: 1; text-align: center; }
}

/* banners and status chip */
.banners { display: flex; flex-direction: column; }
.banner { padding: 8px 16px; font-size: 13px; background: var(--panel-2); border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: center; }
.banner.warn { color: var(--warn); } .banner.bad { color: var(--bad); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: var(--panel-2); font-size: 12px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }

/* conversation */
.convo { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.transcript { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.empty { margin: auto; text-align: center; color: var(--muted); max-width: 32ch; }
.msg { max-width: min(640px, 88%); padding: 10px 14px; border-radius: var(--radius); background: var(--panel-2); white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-text); }
.msg.note { align-self: center; background: none; color: var(--muted); font-size: 13px; padding: 2px; }
.card { align-self: stretch; max-width: 640px; border: 1px solid var(--warn); border-radius: var(--radius); padding: 12px 14px; background: var(--panel); }
.card .actions { display: flex; gap: 8px; margin-top: 10px; }
.dock { border-top: 1px solid var(--line); background: var(--panel); padding: 12px 16px calc(12px + var(--safe-b)); display: flex; flex-direction: column; gap: 10px; }
.voicebar { display: flex; align-items: center; gap: 12px; }
.status { flex: 1; font-size: 14px; color: var(--muted); display: flex; align-items: center; gap: 8px; min-width: 0; }
.status strong { color: var(--text); font-weight: 600; }
.mic { width: 64px; height: 64px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; flex: none; }
.mic[data-live="true"] { background: var(--bad); }
.mic:disabled { opacity: .5; cursor: not-allowed; }
.mic.pulse { animation: pulse 1.6s ease-out infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(124, 92, 255, .5); } 100% { box-shadow: 0 0 0 16px rgba(124, 92, 255, 0); } }
@media (prefers-reduced-motion: reduce) { .mic.pulse { animation: none; } }
.iconbtn { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel-2); display: grid; place-items: center; }
.iconbtn[aria-pressed="true"] { background: var(--warn); color: #000; }
.textrow { display: flex; gap: 8px; }
.textrow input { flex: 1; min-width: 0; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); }

/* buttons, forms */
.btn { padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { border-color: var(--bad); color: var(--bad); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.login { margin: auto; width: min(360px, 92vw); display: flex; flex-direction: column; gap: 12px; padding: 24px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.login h1 { margin: 0 0 4px; font-size: 20px; }
.login input { padding: 11px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); }
.err { color: var(--bad); font-size: 13px; min-height: 1.2em; }

/* memory view: compact table + editor */
.memory { flex: 1; min-height: 0; display: grid; grid-template-columns: 300px 1fr; }
@media (max-width: 760px) { .memory { grid-template-columns: 1fr; grid-template-rows: auto 1fr; } }
.files { border-right: 1px solid var(--line); overflow: auto; padding: 8px; }
.files table { width: 100%; border-collapse: collapse; font-size: 13px; }
.files td { padding: 7px 8px; border-radius: 8px; }
.files tr[aria-selected="true"] td { background: var(--panel-2); }
.files tr { cursor: pointer; }
.files td.n { text-align: right; color: var(--muted); }
.editor { display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 12px; gap: 10px; }
.editor textarea { flex: 1; min-height: 200px; resize: none; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar .path { font-weight: 600; margin-right: auto; word-break: break-all; }
.note-small { font-size: 12px; color: var(--muted); }

/* reusable info tip (inline SVG icon, never a glyph) */
.tip { position: relative; display: inline-grid; place-items: center; width: 24px; height: 24px; border: 0; background: none; color: var(--muted); padding: 0; border-radius: 50%; }
.tip svg { width: 16px; height: 16px; }
.tip .bubble { position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%); width: max-content; max-width: 240px; padding: 8px 10px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); color: var(--text); font-size: 12px; text-align: left; display: none; z-index: 5; }
.tip:hover .bubble, .tip:focus .bubble, .tip[aria-expanded="true"] .bubble { display: block; }
svg.i { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
a.btn { text-decoration: none; color: inherit; display: inline-block; }
.files td.n { white-space: nowrap; }
