:root{
  color-scheme:dark;

  /* -- grounds ------------------------------------------------------ */
  --plane:#16161e;            /* page */
  --surface-1:#1a1b26;        /* card fill */
  --surface-2:#1f2030;        /* floating / hover */
  --border:#292e42;           /* hairline */
  --border-hi:#3b4261;        /* hairline, emphasised */
  --focus:#7aa2f7;            /* interactive, active edge */

  /* -- text --------------------------------------------------------
     Measured against --surface-1. Floor is 4.5:1, because all three
     carry information a reader must actually read. Tokyo Night's
     comment colour (2.8:1) is deliberately absent: it was designed to
     be skipped, not read. test_tui.py enforces the floor.            */
  --text-primary:#c0caf5;     /* 10.6:1 */
  --text-secondary:#9aa5ce;   /*  7.0:1 */
  --muted:#7c85ae;            /*  4.7:1 -- the floor */

  /* -- chart furniture: not text, so no contrast floor --------------- */
  --grid:#232433;
  --axis:#3b4261;

  /* -- categorical series ------------------------------------------- */
  --s1:#7aa2f7; --s2:#ff9e64; --s3:#9ece6a; --s4:#bb9af7; --s5:#7dcfff;

  /* -- sequential ramp, dark ground -> accent ----------------------- */
  --seq-100:#1f2335; --seq-250:#2e4a73; --seq-400:#4a7ec4; --seq-550:#7aa2f7;

  /* -- semantic status: never decorative ---------------------------- */
  --good:#9ece6a; --warn:#e0af68; --critical:#f7768e; --up:#9ece6a;

  /* -- type & geometry ---------------------------------------------- */
  --mono:ui-monospace,SFMono-Regular,"SF Mono",Menlo,Consolas,
         "Liberation Mono",monospace;
  --r:6px;
}

*{box-sizing:border-box}

body{
  margin:0;background:var(--plane);color:var(--text-primary);
  font:400 16px/1.6 var(--mono);
  -webkit-font-smoothing:antialiased;
}

.wrap{max-width:1000px;margin:0 auto;padding:28px 16px 72px}
.wrap-wide{max-width:1200px;margin:0 auto;padding:28px 16px 72px}

header{display:flex;flex-wrap:wrap;gap:14px;align-items:baseline;
  justify-content:space-between;margin-bottom:24px}
h1{font-size:30px;font-weight:700;margin:0 0 4px;letter-spacing:-.02em;
  line-height:1.2}
.sub{color:var(--muted);font-size:14px;font-style:italic}

/* -- card ----------------------------------------------------------- */
.card{background:var(--surface-1);border:1px solid var(--border);
  border-radius:var(--r);padding:16px;margin-bottom:16px;overflow-x:auto}
.card h2{font-size:15px;margin:0 0 2px;font-weight:600}
.card .note{color:var(--muted);font-size:14px;margin:0 0 14px;
  font-style:italic}
.card.is-active{border-color:var(--focus)}

/* -- card grid, for dashboards that tile their cards ---------------- */
.grid{display:grid;gap:16px;
  grid-template-columns:repeat(auto-fit,minmax(340px,1fr))}
.grid .card{margin-bottom:0}

/* -- stat tiles ----------------------------------------------------- */
.tiles{display:grid;grid-template-columns:repeat(auto-fit,minmax(168px,1fr));
  gap:12px;margin-bottom:16px}
.tile{background:var(--surface-1);border:1px solid var(--border);
  border-radius:var(--r);padding:14px 16px}
.tile .k{font-size:14px;color:var(--text-secondary);margin-bottom:6px}
.tile .v{font-size:32px;font-weight:700;letter-spacing:-.02em;line-height:1.1;
  font-variant-numeric:tabular-nums}
.tile .u{font-size:16px;font-weight:400;color:var(--muted)}
.tile .d{font-size:14px;color:var(--muted);margin-top:5px}
.tile .d.up{color:var(--up)} .tile .d.down{color:var(--critical)}

/* -- source freshness ----------------------------------------------- */
.feeds{display:flex;flex-direction:column;gap:9px}
.feed{display:flex;align-items:center;gap:10px;font-size:15px;flex-wrap:wrap}
.dot{width:9px;height:9px;border-radius:50%;flex:none}
.feed .name{min-width:150px;font-weight:500}
.feed .meta{color:var(--muted);font-size:14px;font-style:italic}

/* -- legend --------------------------------------------------------- */
.legend{display:flex;flex-wrap:wrap;gap:16px;margin:0 0 10px;font-size:14px;
  color:var(--text-secondary)}
.legend span{display:inline-flex;align-items:center;gap:7px}
.legend i{width:11px;height:11px;border-radius:3px;display:inline-block}

/* -- charts --------------------------------------------------------- */
.chart{position:relative;width:100%}
svg{display:block;width:100%;height:auto;overflow:visible}

/* -- tooltip: a panel, not a floating shadow ------------------------ */
.tip{position:fixed;pointer-events:none;z-index:9;background:var(--surface-2);
  border:1px solid var(--border-hi);border-radius:var(--r);padding:9px 11px;
  font-size:14px;opacity:0;transition:opacity .1s;max-width:240px;
  font-variant-numeric:tabular-nums}
.tip.on{opacity:1}
.tip b{display:block;margin-bottom:5px;font-weight:600}
.tip div{display:flex;justify-content:space-between;gap:14px;white-space:nowrap}
.tip em{font-style:normal;color:var(--muted)}

/* -- disclosure ----------------------------------------------------- */
details{margin-top:8px}
summary{cursor:pointer;font-size:14px;color:var(--text-secondary)}
summary:hover{color:var(--text-primary)}

/* -- table ---------------------------------------------------------- */
table{border-collapse:collapse;width:100%;font-size:14px;margin-top:12px;
  font-variant-numeric:tabular-nums}
th,td{text-align:right;padding:7px 10px;border-bottom:1px solid var(--grid)}
th:first-child,td:first-child{text-align:left}
th{color:var(--muted);font-weight:600}

/* -- tabs ----------------------------------------------------------- */
.tabs{display:flex;gap:6px;flex-wrap:wrap}
.tabs button{font:inherit;font-size:14px;padding:5px 13px;border-radius:999px;
  border:1px solid var(--border-hi);background:transparent;
  color:var(--text-secondary);cursor:pointer}
.tabs button:hover{background:var(--surface-2);color:var(--text-primary)}
.tabs button[aria-selected=true]{background:var(--text-primary);
  color:var(--plane);border-color:var(--text-primary)}
:focus-visible{outline:2px solid var(--focus);outline-offset:2px}

/* -- states --------------------------------------------------------- */
.empty{color:var(--muted);font-size:14px;padding:28px 0;text-align:center}
.stale{opacity:.7}

footer{color:var(--muted);font-size:14px;font-style:italic;margin-top:26px}

/* --- notes --- */
/* Notes — app layer on top of the tui design language (/root/design-system/tui.py,
   prepended by server.py). Uses its tokens only; dark only, monospace. */

[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; background: var(--plane); }
body { padding-bottom: env(safe-area-inset-bottom); }
button, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--focus); }
::selection { background: var(--seq-250); }

/* -- shell ----------------------------------------------------------- */
header.top {
  position: sticky; top: 0; z-index: 5; margin: 0;
  padding: calc(env(safe-area-inset-top) + 14px) 16px 12px;
  background: color-mix(in srgb, var(--plane) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  align-items: center;
}
header.top h1 { font-size: 22px; margin: 0; }
header.top h1 .chev { color: var(--focus); margin-right: .35em; }
.badge {
  display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 6px;
  border-radius: 999px; background: var(--focus); color: var(--plane);
  font-size: 12px; line-height: 20px; text-align: center; font-weight: 700;
}
.tabs button[aria-selected=true] .badge { background: var(--plane); color: var(--text-primary); }

main { max-width: 680px; margin: 0 auto; padding: 18px 16px 72px; }

/* -- composer -------------------------------------------------------- */
.composer {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r);
  padding: 10px; transition: border-color .15s;
}
.composer:focus-within { border-color: var(--border-hi); }
.composer textarea {
  width: 100%; border: 0; background: transparent; resize: none; outline: none;
  padding: 4px 4px 8px; min-height: 52px; max-height: 40vh; line-height: 1.5;
}
.composer textarea::placeholder { color: var(--muted); }
.composer-row { display: flex; align-items: center; gap: 10px; }
.mic {
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--border-hi);
  background: var(--surface-2); display: grid; place-items: center; flex: none;
}
.mic:hover { border-color: var(--focus); }
.mic svg { width: 20px; height: 20px; fill: var(--text-primary); }
.mic.recording { background: var(--critical); border-color: var(--critical); }
.mic.recording svg { fill: var(--plane); }
.rec { display: flex; align-items: center; gap: 8px; color: var(--critical); font-variant-numeric: tabular-nums; }
.rec .dot { background: var(--critical); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.composer-row .primary { margin-left: auto; }

/* -- buttons --------------------------------------------------------- */
.primary {
  background: var(--focus); color: var(--plane); border: 1px solid var(--focus);
  border-radius: var(--r); padding: 9px 18px; font-weight: 700; min-height: 44px;
}
.primary:hover { filter: brightness(1.08); }
.primary:disabled { opacity: .5; }
.secondary {
  background: transparent; border: 1px solid var(--border-hi); border-radius: var(--r);
  padding: 9px 16px; min-height: 44px; color: var(--text-primary);
}
.secondary:hover { background: var(--surface-2); }
.link { background: none; border: 0; color: var(--text-secondary); text-decoration: underline; text-underline-offset: 3px; padding: 4px; }
.link:hover { color: var(--text-primary); }

/* -- processing strip ------------------------------------------------ */
.processing {
  margin-top: 14px; padding: 10px 14px; border-radius: var(--r);
  border: 1px dashed var(--border-hi); color: var(--text-secondary); font-size: 14px;
}
.processing ul { margin: 6px 0 0; padding: 0; list-style: none; }
.processing li { display: flex; gap: 8px; padding: 3px 0; min-width: 0; }
.processing li span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-primary); }
.spinner { width: 1ch; flex: none; color: var(--focus); }
.spinner::before { content: "⠋"; animation: braille 0.8s steps(1) infinite; }
@keyframes braille {
  0% { content: "⠋"; } 12% { content: "⠙"; } 25% { content: "⠹"; } 37% { content: "⠸"; }
  50% { content: "⠼"; } 62% { content: "⠴"; } 75% { content: "⠦"; } 87% { content: "⠧"; }
}

/* -- review card ----------------------------------------------------- */
.card { padding: 0; overflow: visible; margin: 16px 0 0; }
.card.error { border-color: var(--critical); }
.card-head {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  padding: 12px 16px 0; color: var(--muted); font-size: 13px;
}
.note-title { padding: 8px 16px 0; font-weight: 700; font-size: 17px; line-height: 1.35; }
.note-text { padding: 8px 16px 14px; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text-secondary); }
audio { display: block; width: calc(100% - 32px); margin: 10px 16px 0; height: 36px; color-scheme: dark; }
.err-msg {
  margin: 0 16px 12px; padding: 10px 12px; border-radius: var(--r); font-size: 14px;
  border: 1px solid var(--critical); color: var(--critical); background: color-mix(in srgb, var(--critical) 8%, transparent);
}

.choices { border-top: 1px solid var(--border); padding: 12px 12px 4px; display: grid; gap: 8px; }
.choice {
  display: block; width: 100%; text-align: left; background: transparent;
  border: 1px solid var(--border); border-radius: var(--r); padding: 10px 12px 10px 36px;
  position: relative; transition: border-color .12s, background .12s;
}
.choice::before {
  content: "○"; position: absolute; left: 13px; top: 10px; color: var(--muted);
}
.choice:hover { border-color: var(--border-hi); }
.choice[aria-checked="true"] { border-color: var(--focus); background: color-mix(in srgb, var(--focus) 9%, transparent); }
.choice[aria-checked="true"]::before { content: "●"; color: var(--focus); }
.choice .label { font-weight: 700; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.choice .sub { color: var(--text-secondary); font-size: 14px; font-style: normal; margin-top: 3px; }
.choice .why { font-size: 14px; color: var(--muted); font-style: italic; margin-top: 4px; }
.conf { font-size: 12px; font-weight: 600; padding: 0 8px; border-radius: 999px; border: 1px solid currentColor; }
.conf.high { color: var(--good); }
.conf.medium { color: var(--s5); }
.conf.low { color: var(--warn); }

.question {
  margin: 4px 16px 0; padding: 10px 12px; border-radius: var(--r); font-size: 14px;
  border-left: 3px solid var(--warn); color: var(--warn); background: color-mix(in srgb, var(--warn) 8%, transparent);
}
.comment { padding: 10px 12px 0; }
.comment textarea {
  width: 100%; border: 1px solid var(--border); background: var(--plane); border-radius: var(--r);
  padding: 8px 10px; resize: vertical; min-height: 44px; outline: none;
}
.comment textarea:focus { border-color: var(--focus); }
.comment textarea::placeholder { color: var(--muted); }
.actions { display: flex; gap: 10px; padding: 12px; align-items: center; flex-wrap: wrap; }
.actions .primary { flex: 1; }

.empty { padding: 56px 16px; }
.empty strong { display: block; color: var(--text-primary); font-size: 17px; margin-bottom: 6px; }

/* -- history --------------------------------------------------------- */
.filters { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters button {
  font-size: 14px; padding: 5px 13px; border-radius: 999px; white-space: nowrap;
  border: 1px solid var(--border-hi); background: transparent; color: var(--text-secondary);
}
.filters button:hover { background: var(--surface-2); color: var(--text-primary); }
.filters button[aria-pressed="true"] { background: var(--text-primary); color: var(--plane); border-color: var(--text-primary); }
.history { list-style: none; margin: 12px 0 0; padding: 0; }
.day { margin: 22px 0 8px; color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.item { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r); margin-bottom: 8px; }
.item.open { border-color: var(--border-hi); }
.item > button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 10px 12px; }
.item-top { display: flex; gap: 8px; align-items: baseline; }
.item-title { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-meta { color: var(--muted); font-size: 13px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { font-size: 12px; font-weight: 600; padding: 0 8px; border-radius: 999px; flex: none; border: 1px solid currentColor; }
.pill.filed { color: var(--good); }
.pill.archived { color: var(--muted); }
.pill.open { color: var(--warn); }
.pill.error { color: var(--critical); }
.item-body { padding: 0 12px 12px; font-size: 14px; display: none; }
.item.open .item-body { display: block; }
.item-body p { margin: 6px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.item-body .k { color: var(--muted); }
.item-body audio { width: 100%; margin: 6px 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 20;
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--surface-2); color: var(--text-primary); border: 1px solid var(--border-hi);
  padding: 9px 14px; border-radius: var(--r); transition: .2s; max-width: calc(100% - 32px); font-size: 14px;
}
.toast.show { opacity: 1; transform: translateX(-50%); }

/* -- login ----------------------------------------------------------- */
.login-page {
  min-height: 100vh; min-height: 100dvh; display: grid; place-items: center;
  background:
    radial-gradient(60rem 40rem at 50% -10%, color-mix(in srgb, var(--focus) 7%, transparent), transparent 70%),
    var(--plane);
}
.login { width: 100%; max-width: 360px; padding: 32px 20px calc(32px + env(safe-area-inset-bottom)); }
.brand { font-size: 34px; font-weight: 700; letter-spacing: -.02em; line-height: 1; display: flex; align-items: center; }
.brand .chev { color: var(--focus); margin-right: .35em; }
.caret {
  display: inline-block; width: .55em; height: .95em; margin-left: .12em;
  background: var(--focus); animation: blink 1.1s steps(1) infinite;
}
.greet { margin: 22px 0 2px; color: var(--text-primary); }
.tagline { margin: 0 0 28px; color: var(--muted); font-style: italic; font-size: 14px; }
.login-form { display: grid; gap: 0; }
.line {
  display: flex; align-items: center; gap: 14px; padding: 12px 2px;
  border-bottom: 1px solid var(--border); transition: border-color .15s;
}
.line:focus-within { border-color: var(--focus); }
.line .k { color: var(--muted); font-size: 13px; width: 4ch; flex: none; }
.line:focus-within .k { color: var(--focus); }
.line input {
  flex: 1; min-width: 0; border: 0; outline: none; background: transparent;
  color: var(--text-primary); font-size: 16px; padding: 2px 0; caret-color: var(--focus);
}
.line input:-webkit-autofill {
  -webkit-text-fill-color: var(--text-primary);
  -webkit-box-shadow: 0 0 0 40px var(--plane) inset; transition: background-color 9999s;
}
.login-form button {
  margin-top: 26px; min-height: 46px; border-radius: var(--r); font-weight: 700;
  background: transparent; color: var(--focus); border: 1px solid var(--focus);
  transition: background .15s, color .15s;
}
.login-form button:hover, .login-form button:focus-visible { background: var(--focus); color: var(--plane); }
.login-form.ok button { background: var(--good); border-color: var(--good); color: var(--plane); }
.msg { min-height: 1.6em; margin: 12px 0 0; color: var(--critical); font-size: 14px; }
.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.login-foot { margin-top: 48px; font-size: 12px; font-style: normal; color: var(--muted); letter-spacing: .02em; }
@media (prefers-reduced-motion: reduce) { .caret, .rec .dot, .spinner::before, .shake { animation: none; } }
