/* Mimir. Dark by default ("the well at night"), light when the system asks for it. */
:root {
  --bg: #0a0d12;
  --bg-2: #10151c;
  --surface: #141a22;
  --surface-2: #1a212b;
  --line: #232c38;
  --text: #e8ecf1;
  --muted: #8b97a6;
  --faint: #5d6877;
  --water: #5eead4;
  --water-2: #38bdf8;
  --gold: #e8c27a;
  --danger: #f87171;
  --ok: #4ade80;
  --bubble: #1b2430;
  --glow: rgba(94, 234, 212, 0.16);
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  --radius: 16px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --serif: 'Fraunces', Georgia, serif;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme='dark']) {
    --bg: #f6f4ef; --bg-2: #efece5; --surface: #ffffff; --surface-2: #f3f1ec; --line: #e3dfd6;
    --text: #1a1f26; --muted: #5f6873; --faint: #8f97a1; --water: #0f9488; --water-2: #0284c7; --gold: #a87a26;
    --bubble: #ebe7de; --glow: rgba(15, 148, 136, 0.12); --shadow: 0 10px 30px rgba(30, 30, 20, 0.12);
    color-scheme: light;
  }
}
:root[data-theme='light'] {
  --bg: #f6f4ef; --bg-2: #efece5; --surface: #ffffff; --surface-2: #f3f1ec; --line: #e3dfd6;
  --text: #1a1f26; --muted: #5f6873; --faint: #8f97a1; --water: #0f9488; --water-2: #0284c7; --gold: #a87a26;
  --bubble: #ebe7de; --glow: rgba(15, 148, 136, 0.12); --shadow: 0 10px 30px rgba(30, 30, 20, 0.12);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 50% -10%, var(--glow), transparent 60%), var(--bg);
  color: var(--text); font: 15.5px/1.55 var(--font); -webkit-font-smoothing: antialiased;
  overflow: hidden; overscroll-behavior: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

#app { height: 100dvh; display: flex; flex-direction: column; }
#app.booting { opacity: 0; }
.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* ---------- brand ---------- */
.wordmark { font-family: var(--serif); font-weight: 500; letter-spacing: 0.02em; margin: 0; font-size: 34px; }
.wordmark.sm { font-size: 20px; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); }
.brand-rune { width: 22px; height: 22px; color: var(--gold); }
.brand-mark { width: 64px; height: 64px; margin: 0 auto 8px; color: var(--gold); filter: drop-shadow(0 0 18px rgba(232, 194, 122, 0.35)); }
.brand-mark svg { width: 64px; height: 64px; }

/* ---------- login ---------- */
#login { align-items: center; justify-content: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 360px; text-align: center; padding: 36px 28px 28px; background: color-mix(in srgb, var(--surface) 86%, transparent); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); backdrop-filter: blur(12px); }
.login-card .wordmark { margin-bottom: 24px; }
.stack { display: flex; flex-direction: column; gap: 12px; text-align: left; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.field input, .otp, .input {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .otp:focus, .input:focus, textarea:focus { border-color: var(--water); box-shadow: 0 0 0 3px var(--glow); }
.otp { text-align: center; letter-spacing: 0.5em; font-size: 22px; font-variant-numeric: tabular-nums; }
.hint { color: var(--muted); font-size: 14px; margin: 0; text-align: center; }
.err { color: var(--danger); min-height: 1.4em; font-size: 14px; margin: 12px 0 0; }
.qr { background: #fff; border-radius: 12px; padding: 10px; width: 220px; margin: 4px auto; }
.qr svg { width: 200px; height: 200px; stroke: none; }
.secret { display: block; font-size: 12px; color: var(--faint); word-break: break-all; text-align: center; }
.btn { border: 1px solid var(--line); background: var(--surface-2); border-radius: 12px; padding: 11px 16px; font-weight: 500; transition: transform .08s, background .15s; }
.btn:active { transform: scale(.98); }
.btn.primary { background: linear-gradient(135deg, var(--water), var(--water-2)); color: #04211e; border: none; }
.btn.danger { background: color-mix(in srgb, var(--danger) 18%, transparent); border-color: color-mix(in srgb, var(--danger) 45%, transparent); color: var(--danger); }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 9px; }

/* ---------- top bar ---------- */
.topbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: max(10px, env(safe-area-inset-top)) 16px 10px; border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent); }
.top-actions { display: flex; justify-content: flex-end; gap: 4px; }
.modes { display: flex; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.modes button { border: 0; background: transparent; color: var(--muted); padding: 6px 14px; border-radius: 999px; font-size: 13.5px; font-weight: 500; }
.modes button[aria-selected='true'] { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.icon-btn { position: relative; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent; color: var(--muted); }
.icon-btn:hover { color: var(--text); background: var(--surface); }
.icon-btn.ghost:hover { background: var(--surface-2); }
.icon-btn .dot { position: absolute; top: 9px; right: 10px; width: 8px; height: 8px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 10px var(--gold); }
.killbar { background: color-mix(in srgb, var(--danger) 20%, var(--bg)); color: var(--danger); text-align: center; font-size: 13.5px; padding: 8px 16px; }

/* ---------- chat ---------- */
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.msgs { flex: 1; min-height: 0; overflow-y: auto; padding: 20px 16px 8px; scroll-behavior: smooth; }
.msgs > * { max-width: 720px; margin-left: auto; margin-right: auto; }
.msg { margin-bottom: 18px; display: flex; flex-direction: column; animation: rise .25s ease-out; }
.msg .body { white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-items: flex-end; }
.msg.user .body { background: var(--bubble); padding: 10px 14px; border-radius: 18px 18px 4px 18px; max-width: 85%; }
.msg.assistant .body { max-width: 92%; font-size: 16px; }
.msg.assistant .body a { color: var(--water); }
.msg .meta { font-size: 11.5px; color: var(--faint); margin-top: 4px; display: flex; gap: 8px; align-items: center; }
.msg .meta button { border: 0; background: none; color: var(--faint); padding: 0; font-size: 11.5px; }
.msg .meta button:hover { color: var(--water); }
.msg.proactive .body { border-left: 2px solid var(--gold); padding-left: 12px; }
.msg.proactive .tag { font-size: 11px; color: var(--gold); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 4px; }
.msg img.att { max-width: 220px; border-radius: 12px; margin-bottom: 6px; }
.day-sep { text-align: center; color: var(--faint); font-size: 12px; margin: 10px auto 18px; }
.empty { text-align: center; color: var(--muted); margin-top: 18vh; }
.empty .wordmark { font-size: 40px; color: var(--text); margin-bottom: 8px; }
.caret::after { content: ''; display: inline-block; width: 7px; height: 1.1em; vertical-align: -0.2em; margin-left: 2px; background: var(--water); animation: blink 1s steps(2) infinite; border-radius: 2px; }

.status { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13.5px; padding: 4px 16px 8px; max-width: 720px; margin: 0 auto; width: 100%; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--water); box-shadow: 0 0 0 0 var(--water); animation: pulse 1.4s infinite; }

.composer { padding: 8px 12px max(12px, env(safe-area-inset-bottom)); max-width: 760px; width: 100%; margin: 0 auto; }
.composer-row { display: flex; align-items: flex-end; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 6px; box-shadow: var(--shadow); }
.composer-row:focus-within { border-color: color-mix(in srgb, var(--water) 55%, var(--line)); }
textarea#input { flex: 1; resize: none; border: 0; background: transparent; outline: none; padding: 9px 6px; max-height: 180px; line-height: 1.45; }
.send { width: 40px; height: 40px; border-radius: 50%; border: 0; display: grid; place-items: center; background: linear-gradient(135deg, var(--water), var(--water-2)); color: #04211e; flex-shrink: 0; transition: opacity .15s, transform .08s; }
.send:disabled { opacity: .35; }
.send:active { transform: scale(.94); }
.send.stop { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
#b-mic.on { color: var(--danger); }
.speak-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--faint); margin: 8px 6px 0; }
.attach-preview { display: flex; gap: 8px; margin: 0 6px 8px; }
.attach-preview img { height: 64px; border-radius: 10px; border: 1px solid var(--line); }

/* ---------- voice (minimal) ---------- */
.voice { align-items: center; justify-content: center; padding: 24px 16px max(24px, env(safe-area-inset-bottom)); text-align: center; }
.well-wrap { flex: 1; display: grid; place-items: center; width: 100%; max-height: 62vh; }
.orb { --lvl: 0; position: relative; width: min(56vw, 260px); aspect-ratio: 1; border: 0; background: transparent; border-radius: 50%; }
.orb .core { position: absolute; inset: 18%; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #c9fff5 0%, var(--water) 30%, #0e7490 70%, #082f49 100%); box-shadow: 0 0 60px var(--glow), 0 0 120px color-mix(in srgb, var(--water) 25%, transparent), inset 0 -20px 40px rgba(0,0,0,.35); transform: scale(calc(1 + var(--lvl) * .18)); transition: transform .08s linear; }
.orb .ring { position: absolute; inset: 6%; border-radius: 50%; border: 1px solid color-mix(in srgb, var(--water) 40%, transparent); opacity: .5; }
.orb .r2 { inset: -4%; opacity: .25; border-color: color-mix(in srgb, var(--gold) 50%, transparent); }
.orb.idle .core { animation: breathe 5s ease-in-out infinite; }
.orb.listening .ring { animation: ripple 1.6s ease-out infinite; }
.orb.listening .r2 { animation-delay: .5s; }
.orb.thinking .core { animation: think 1.2s ease-in-out infinite; filter: hue-rotate(25deg); }
.orb.speaking .r1 { opacity: calc(.3 + var(--lvl)); }
.voice-line { font-family: var(--serif); font-size: clamp(20px, 5vw, 28px); line-height: 1.35; margin: 18px auto 6px; max-width: 640px; min-height: 2.7em; }
.voice-sub { color: var(--muted); font-size: 14px; min-height: 1.4em; margin: 0 auto 18px; max-width: 560px; }
.voice-controls { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 999px; padding: 7px 14px; font-size: 13px; font-weight: 500; display: inline-flex; align-items: center; gap: 8px; }
.chip.toggle input { accent-color: var(--water); }

/* ---------- panel ---------- */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; animation: fade .2s; }
.panel { position: fixed; z-index: 21; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); background: var(--bg-2); border-left: 1px solid var(--line); display: flex; flex-direction: column; box-shadow: var(--shadow); animation: slide .22s ease-out; }
.panel-head { display: flex; align-items: center; gap: 6px; padding: max(10px, env(safe-area-inset-top)) 10px 8px 12px; border-bottom: 1px solid var(--line); }
.tabs { flex: 1; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs button { border: 0; background: transparent; color: var(--muted); padding: 8px 11px; border-radius: 10px; font-size: 13.5px; white-space: nowrap; font-weight: 500; }
.tabs button[aria-selected='true'] { color: var(--text); background: var(--surface); }
.panel-body { flex: 1; overflow-y: auto; padding: 16px; }
.panel-body h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); margin: 20px 0 8px; font-weight: 600; }
.panel-body h3:first-child { margin-top: 0; }
.list { display: flex; flex-direction: column; gap: 6px; }
.item { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: flex; gap: 10px; align-items: flex-start; }
.item .txt { flex: 1; min-width: 0; }
.item .sub { font-size: 12px; color: var(--faint); margin-top: 2px; }
.item .subject { color: var(--gold); font-weight: 500; }
.item .acts { display: flex; gap: 2px; opacity: .6; }
.item:hover .acts { opacity: 1; }
.item .acts button { border: 0; background: none; color: var(--muted); padding: 2px 4px; border-radius: 6px; font-size: 12.5px; }
.item .acts button:hover { color: var(--text); background: var(--surface-2); }
.item.off { opacity: .5; }
.item textarea { width: 100%; background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px; resize: vertical; min-height: 60px; outline: none; }
.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); margin-left: 4px; vertical-align: 1px; }
.badge.lock { color: var(--gold); }
.badge.high, .badge.critical { color: var(--danger); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.kpi b { display: block; font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi span { font-size: 12px; color: var(--faint); }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 90px; margin-top: 8px; }
.bars i { flex: 1; background: linear-gradient(to top, var(--water-2), var(--water)); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t td, table.t th { padding: 7px 6px; border-bottom: 1px solid var(--line); text-align: left; }
table.t th { color: var(--faint); font-weight: 500; }
table.t td.n { text-align: right; font-variant-numeric: tabular-nums; }
select.input { padding: 6px 10px; }
.kill { border: 1px solid color-mix(in srgb, var(--danger) 40%, var(--line)); border-radius: 14px; padding: 14px; background: color-mix(in srgb, var(--danger) 6%, var(--surface)); }
.drop { border: 1.5px dashed var(--line); border-radius: 14px; padding: 18px; text-align: center; color: var(--muted); }
.drop.over { border-color: var(--water); color: var(--text); }

/* ---------- toasts ---------- */
.toasts { position: fixed; top: max(64px, calc(env(safe-area-inset-top) + 56px)); left: 0; right: 0; z-index: 40; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; padding: 0 16px; }
.toast { pointer-events: auto; background: color-mix(in srgb, var(--surface) 92%, transparent); border: 1px solid var(--line); backdrop-filter: blur(10px); border-radius: 12px; padding: 9px 14px; font-size: 13.5px; box-shadow: var(--shadow); max-width: 520px; animation: drop .25s ease-out; display: flex; gap: 8px; align-items: center; }
.toast .ico { color: var(--gold); }
.toast.alert { border-color: color-mix(in srgb, var(--danger) 50%, var(--line)); }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@keyframes drop { from { opacity: 0; transform: translateY(-8px); } }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(30px); opacity: .4; } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--water) 60%, transparent); } 100% { box-shadow: 0 0 0 10px transparent; } }
@keyframes breathe { 50% { transform: scale(1.04); filter: brightness(1.08); } }
@keyframes ripple { from { transform: scale(.92); opacity: .7; } to { transform: scale(1.35); opacity: 0; } }
@keyframes think { 50% { transform: scale(.96) rotate(8deg); filter: hue-rotate(40deg) brightness(1.1); } }

@media (max-width: 560px) {
  .topbar { padding-left: 12px; padding-right: 8px; }
  .brand .wordmark { display: none; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .panel { width: 100vw; border-left: 0; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
