/* AIsistant — porcelain & cobalt. Display: Bricolage Grotesque; body: Atkinson Hyperlegible;
   data: JetBrains Mono. The pulse trace in the header is the signature element. */

@font-face { font-family: "Bricolage"; src: url("/static/fonts/bricolage-normal-200-800.woff2") format("woff2");
  font-weight: 200 800; font-display: swap; }
@font-face { font-family: "Atkinson"; src: url("/static/fonts/atkinson-normal-400.woff2") format("woff2");
  font-weight: 400; font-display: swap; }
@font-face { font-family: "Atkinson"; src: url("/static/fonts/atkinson-normal-700.woff2") format("woff2");
  font-weight: 700; font-display: swap; }
@font-face { font-family: "Atkinson"; src: url("/static/fonts/atkinson-italic-400.woff2") format("woff2");
  font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "JetMono"; src: url("/static/fonts/jetbrains-normal-400-700.woff2") format("woff2");
  font-weight: 400 700; font-display: swap; }

:root {
  --bg: #F3F5F8;          /* porcelain */
  --surface: #FFFFFF;
  --surface-2: #E9EEF4;
  --ink: #101828;
  --ink-2: #55607A;
  --ink-3: #8A94A8;
  --line: #D8DFE8;
  --cobalt: #1F3A93;      /* delft */
  --signal: #2F62E8;      /* interactive */
  --signal-soft: #E5ECFD;
  --ok: #1D9A67;
  --warn: #D68A1A;
  --crit: #D03D3A;
  --unknown: #9AA3B5;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px -12px rgba(31, 58, 147, .18);
  --radius: 14px;
  --display: "Bricolage", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --body: "Atkinson", "Helvetica Neue", Arial, system-ui, sans-serif;
  --mono: "JetMono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --top-h: 64px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0E1420;
  --surface: #151C2B;
  --surface-2: #1B2537;
  --ink: #E9EDF5;
  --ink-2: #A3ADC2;
  --ink-3: #6E7A92;
  --line: #273246;
  --cobalt: #8EA8FF;
  --signal: #7C98FF;
  --signal-soft: #1E2B4D;
  --ok: #34C08A;
  --warn: #F0A43A;
  --crit: #F06A66;
  --unknown: #66708A;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px -14px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--body); font-size: 15px;
  line-height: 1.5; -webkit-font-smoothing: antialiased; overflow: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--signal); }
code, pre, .mono { font-family: var(--mono); font-size: .86em; }
pre { background: var(--surface-2); padding: 10px 12px; border-radius: 10px; overflow: auto; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
pre code { background: none; padding: 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }
[hidden] { display: none !important; }
.inline { display: inline; }

/* ---------- header ---------- */
.top {
  height: var(--top-h); display: grid; grid-template-columns: 200px 1fr auto; align-items: center;
  gap: 16px; padding: 0 18px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: relative; z-index: 3;
}
.brand { display: flex; flex-direction: column; line-height: 1.05; }
.brand-name { font-family: var(--display); font-weight: 600; font-size: 26px; letter-spacing: -.02em; font-variation-settings: "opsz" 48; }
.brand-state { color: var(--ink-3); font-size: 12.5px; margin-top: 3px; }
.pulse { width: 100%; height: 48px; display: block; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.overall {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px 6px 8px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); font-size: 13px;
}
.overall:hover { border-color: var(--signal); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: var(--unknown); flex: none; }
.dot-ok { background: var(--ok); } .dot-warn { background: var(--warn); } .dot-crit { background: var(--crit); }
.dot-unknown { background: var(--unknown); }
.dot-crit { box-shadow: 0 0 0 4px color-mix(in srgb, var(--crit) 25%, transparent); }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid transparent; background: transparent;
  color: var(--ink-2); display: inline-grid; place-items: center; font-size: 16px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn[aria-pressed="true"] { color: var(--signal); background: var(--signal-soft); }

/* ---------- app grid ---------- */
.app { display: grid; grid-template-columns: 236px 1fr 300px; height: calc(100% - var(--top-h)); }
.side { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--surface); }
.side-new {
  margin: 12px; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  text-align: left; color: var(--ink);
}
.side-new:hover { border-color: var(--signal); color: var(--signal); }
.conv-list { list-style: none; margin: 0; padding: 0 8px; overflow: auto; flex: 1; min-height: 60px; }
.conv-list li { padding: 7px 10px; border-radius: 9px; font-size: 13.5px; color: var(--ink-2); cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; gap: 6px; align-items: center; }
.conv-list li:hover { background: var(--surface-2); color: var(--ink); }
.conv-list li.active { background: var(--signal-soft); color: var(--cobalt); }
.conv-list li .unread { width: 7px; height: 7px; border-radius: 50%; background: var(--signal); flex: none; }
.conv-list li.system::before { content: "✦"; color: var(--cobalt); font-size: 11px; }
.side-nav { border-top: 1px solid var(--line); padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.nav { text-align: left; padding: 8px 12px; border: 0; background: transparent; border-radius: 9px; color: var(--ink-2);
  display: flex; justify-content: space-between; align-items: center; }
.nav:hover { background: var(--surface-2); color: var(--ink); }
.nav.active { color: var(--cobalt); background: var(--signal-soft); font-weight: 700; }
.badge { background: var(--crit); color: #fff; font-size: 11px; padding: 1px 7px; border-radius: 999px; font-weight: 700; }
.badge.soft { background: var(--signal); }
.side-foot { padding: 8px 14px; font-size: 11px; color: var(--ink-3); font-family: var(--mono); }

.stage { min-width: 0; min-height: 0; position: relative; }
.panel { display: none; height: 100%; overflow: auto; padding: 22px 28px 32px; }
.panel.active { display: block; }
.panel-talk { display: none; flex-direction: column; padding: 0; }
.panel-talk.active { display: flex; }

.rail { border-left: 1px solid var(--line); background: var(--surface); overflow: auto; padding: 14px; display: flex;
  flex-direction: column; gap: 14px; }
.rail-block h4 { margin: 0 0 8px; font-family: var(--display); font-weight: 600; font-size: 15px; letter-spacing: -.01em; }

/* ---------- conversation ---------- */
.thread { flex: 1; overflow: auto; padding: 26px 8% 16px; display: flex; flex-direction: column; gap: 18px; scroll-behavior: smooth; }
.greeting { margin: auto 0; text-align: left; max-width: 640px; }
.greeting h2 { font-family: var(--display); font-weight: 500; font-size: 34px; letter-spacing: -.025em; line-height: 1.12; margin: 0 0 10px;
  font-variation-settings: "opsz" 72; }
.greeting p { color: var(--ink-2); margin: 0 0 16px; }
.greeting .chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; font-size: 13px; color: var(--ink-2); }
.chip-btn:hover { border-color: var(--signal); color: var(--signal); }
.msg { max-width: 760px; }
.msg.user { align-self: flex-end; background: var(--signal-soft); color: var(--ink); padding: 10px 14px; border-radius: 16px 16px 4px 16px; white-space: pre-wrap; }
.msg.assistant { align-self: stretch; }
.msg-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 4px; }
.msg-who { font-family: var(--display); font-weight: 600; font-size: 14px; color: var(--cobalt); }
.msg-time { font-family: var(--mono); font-size: 11px; color: var(--ink-3); }
.msg-body p { margin: 0 0 .7em; } .msg-body p:last-child { margin-bottom: 0; }
.msg-body ul, .msg-body ol { margin: .3em 0 .7em; padding-left: 1.4em; }
.msg-body h1, .msg-body h2, .msg-body h3 { font-family: var(--display); font-weight: 600; margin: .8em 0 .3em; line-height: 1.2; }
.msg-body h1 { font-size: 20px; } .msg-body h2 { font-size: 18px; } .msg-body h3 { font-size: 16px; }
.msg-body table { border-collapse: collapse; font-size: 13.5px; margin: .4em 0 .8em; }
.msg-body td, .msg-body th { border: 1px solid var(--line); padding: 4px 8px; text-align: left; }
.msg-body blockquote { border-left: 3px solid var(--line); margin: .4em 0; padding: 2px 12px; color: var(--ink-2); }
.tools { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 8px; }
.tool { font-family: var(--mono); font-size: 11.5px; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2);
  border: 1px solid transparent; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tool.running { border-color: var(--signal); color: var(--signal); }
.tool.error { border-color: var(--crit); color: var(--crit); }
.tool b { font-weight: 700; }
.notice { font-size: 13px; color: var(--warn); font-style: italic; }
.thinking { display: inline-flex; gap: 4px; align-items: center; height: 18px; }
.thinking i { width: 6px; height: 6px; border-radius: 50%; background: var(--signal); opacity: .35; animation: blink 1.2s infinite; }
.thinking i:nth-child(2) { animation-delay: .2s; } .thinking i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }
.cursor::after { content: "▍"; color: var(--signal); animation: blink 1s infinite; }

.composer { display: grid; grid-template-columns: auto 1fr auto auto; gap: 10px; align-items: end; padding: 12px 8% 6px; }
.composer textarea {
  resize: none; max-height: 200px; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface);
  box-shadow: var(--shadow); line-height: 1.4;
}
.composer textarea:focus { border-color: var(--signal); outline: none; }
.send { width: 44px; height: 44px; border-radius: 12px; border: 0; background: var(--cobalt); color: #fff; font-size: 18px; }
.send:hover { background: var(--signal); }
.send:disabled { opacity: .5; cursor: default; }
.mic { position: relative; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; }
.mic-ico { width: 12px; height: 18px; border-radius: 6px; background: var(--ink-2); position: relative; }
.mic-ico::after { content: ""; position: absolute; left: -5px; right: -5px; bottom: -6px; height: 10px; border: 2px solid var(--ink-2); border-top: 0; border-radius: 0 0 11px 11px; }
.mic-ring { position: absolute; inset: -1px; border-radius: 50%; border: 2px solid transparent; }
.mic[data-state="standby"] { border-color: var(--cobalt); }
.mic[data-state="standby"] .mic-ring { border-color: var(--cobalt); opacity: .5; }
.mic[data-state="listening"] { border-color: var(--signal); background: var(--signal-soft); }
.mic[data-state="listening"] .mic-ico, .mic[data-state="listening"] .mic-ico::after { background: var(--signal); border-color: var(--signal); }
.mic[data-state="listening"] .mic-ring { border-color: var(--signal); animation: ring 1.6s ease-out infinite; }
.mic[data-state="speaking"] { border-color: var(--ok); }
.mic[data-state="unsupported"] { opacity: .35; cursor: not-allowed; }
@keyframes ring { 0% { transform: scale(1); opacity: .8; } 100% { transform: scale(1.7); opacity: 0; } }
.composer-hint { padding: 0 8% 12px; font-size: 12px; color: var(--ink-3); min-height: 24px; font-family: var(--mono); }

/* ---------- generic panel bits ---------- */
.panel h2 { font-family: var(--display); font-weight: 600; font-size: 26px; letter-spacing: -.02em; margin: 0 0 4px; }
.panel .lede { color: var(--ink-2); margin: 0 0 20px; }
.panel h3 { font-family: var(--display); font-weight: 600; font-size: 16px; margin: 22px 0 8px; letter-spacing: -.01em; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card .k { font-size: 12px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .06em; }
.card .v { font-family: var(--display); font-size: 26px; font-weight: 500; letter-spacing: -.02em; line-height: 1.15; margin-top: 2px; }
.card .s { font-size: 12.5px; color: var(--ink-2); margin-top: 4px; font-family: var(--mono); }
.card.ok .v { color: var(--ok); } .card.warn .v { color: var(--warn); } .card.crit .v { color: var(--crit); }
.meter { height: 6px; background: var(--surface-2); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--cobalt); border-radius: 3px; }
.meter.warn i { background: var(--warn); } .meter.crit i { background: var(--crit); }
.rows { display: flex; flex-direction: column; gap: 2px; }
.row { display: grid; grid-template-columns: 14px 1fr auto auto; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 10px; font-size: 13.5px; }
.row:hover { background: var(--surface-2); }
.row .name { font-family: var(--mono); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .detail { color: var(--ink-2); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .lat { font-family: var(--mono); font-size: 11.5px; color: var(--ink-3); }
.row.disabled { opacity: .45; }
.row-actions { display: flex; gap: 4px; }
.btn, .btn-primary, .btn-danger {
  border-radius: 9px; padding: 6px 12px; font-size: 13px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.btn:hover { border-color: var(--signal); color: var(--signal); }
.btn-primary { background: var(--cobalt); border-color: var(--cobalt); color: #fff; }
.btn-primary:hover { background: var(--signal); border-color: var(--signal); }
.btn-danger { color: var(--crit); }
.btn-danger:hover { border-color: var(--crit); }
.btn.sm, .btn-primary.sm, .btn-danger.sm { padding: 3px 9px; font-size: 12px; }
.btn:disabled, .btn-primary:disabled { opacity: .5; cursor: default; }
.item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
.item.sev-critical { border-left: 4px solid var(--crit); } .item.sev-warning { border-left: 4px solid var(--warn); }
.item .t { font-weight: 700; } .item .m { color: var(--ink-2); font-size: 13px; margin-top: 3px; }
.item .meta { font-family: var(--mono); font-size: 11.5px; color: var(--ink-3); margin-top: 6px; }
.item .acts { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.item pre { margin: 8px 0 0; font-size: 12px; max-height: 240px; }
.empty { color: var(--ink-3); padding: 24px 0; font-style: italic; }
.form { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); align-items: end; margin: 8px 0 16px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); }
.form input, .form select, .form textarea, .search {
  padding: 8px 10px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); width: 100%;
}
.form textarea { min-height: 80px; resize: vertical; }
.form .full { grid-column: 1 / -1; }
.search { max-width: 420px; margin-bottom: 12px; }
.tag { display: inline-block; font-family: var(--mono); font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); margin-right: 4px; }
.kind { color: var(--cobalt); font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar select { padding: 7px 10px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.data td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data td.mono { font-size: 12px; }
.status-line { font-family: var(--mono); font-size: 12px; color: var(--ink-2); }
.rail-row { display: grid; grid-template-columns: 10px 1fr auto; gap: 8px; align-items: center; padding: 5px 6px; border-radius: 8px; font-size: 12.5px; }
.rail-row .name { font-family: var(--mono); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rail-row .lat { font-family: var(--mono); font-size: 11px; color: var(--ink-3); }
.rail-mini { display: flex; gap: 3px; flex-wrap: wrap; margin: 4px 0 10px; }
.rail-mini i { width: 9px; height: 9px; border-radius: 2px; background: var(--unknown); }
.rail-mini i.ok { background: var(--ok); } .rail-mini i.warn { background: var(--warn); } .rail-mini i.crit { background: var(--crit); }
.rail-item { padding: 8px 10px; border-radius: 10px; background: var(--surface-2); font-size: 12.5px; margin-bottom: 6px; }
.rail-item .t { font-weight: 700; }
.rail-item .acts { margin-top: 6px; display: flex; gap: 4px; }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: 380px; }
.toast { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--signal); border-radius: 12px; padding: 10px 14px;
  box-shadow: var(--shadow); font-size: 13.5px; animation: rise .25s ease-out; }
.toast.warn { border-left-color: var(--warn); } .toast.crit { border-left-color: var(--crit); } .toast.ok { border-left-color: var(--ok); }
.toast .t { font-weight: 700; } .toast .m { color: var(--ink-2); font-size: 12.5px; margin-top: 2px; white-space: pre-line; }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- tab bar (mobile) ---------- */
.tabbar { display: none; }
.more-sheet { position: fixed; left: 0; right: 0; bottom: 56px; background: var(--surface); border-top: 1px solid var(--line); padding: 8px; z-index: 40;
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }

/* ---------- login ---------- */
.login-body { overflow: auto; }
.login { max-width: 420px; margin: 12vh auto; padding: 0 20px; text-align: center; }
.login-pulse { height: 80px; margin-bottom: 12px; }
.login-name { font-family: var(--display); font-weight: 600; font-size: 44px; letter-spacing: -.03em; margin: 0 0 6px; font-variation-settings: "opsz" 96; }
.login-sub { color: var(--ink-2); margin: 0 0 22px; }
.login-error { color: var(--crit); font-size: 13.5px; }
.login-form { display: grid; gap: 10px; }
.login-form input { padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 16px; text-align: center; }
.login-form .btn-primary { padding: 11px; border-radius: 12px; font-size: 15px; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .app { grid-template-columns: 220px 1fr; }
  .rail { display: none; }
}
@media (max-width: 760px) {
  .top { grid-template-columns: 1fr auto; gap: 8px; padding: 0 12px; }
  .pulse { position: absolute; left: 0; right: 0; bottom: -1px; height: 22px; opacity: .9; pointer-events: none; }
  .brand-state { display: none; }
  .overall-text { display: none; }
  .app { grid-template-columns: 1fr; height: calc(100% - var(--top-h) - 56px); }
  .side { display: none; }
  .side.open { display: flex; position: fixed; inset: var(--top-h) 0 56px 0; z-index: 30; }
  .thread { padding: 18px 14px 12px; }
  .composer { padding: 10px 12px 4px; grid-template-columns: auto 1fr auto; }
  .composer .speak { display: none; }
  .composer-hint { padding: 0 12px 8px; }
  .panel { padding: 16px 14px 28px; }
  .tabbar { display: grid; grid-template-columns: repeat(4, 1fr); height: 56px; border-top: 1px solid var(--line); background: var(--surface);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 35; }
  .tab { border: 0; background: transparent; color: var(--ink-2); font-size: 13px; }
  .tab.active { color: var(--cobalt); font-weight: 700; }
  .greeting h2 { font-size: 26px; }
}

@media (prefers-reduced-motion: reduce) {
  .mic-ring, .thinking i, .cursor::after, .toast { animation: none !important; }
  .thread { scroll-behavior: auto; }
}
