:root {
  color-scheme: dark;
  --bg: #0e0f0c; --surface: #151610; --surface2: #1b1c15; --line: #2a2b22; --line2: #383a2f;
  --ink: #ece7dc; --muted: #918c80; --brass: #d7a35c; --onbrass: #1a1409;
  --pos: #9fc79a; --neg: #e0958a; --mix: #d7c07a; --unc: #8d8a80;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
}
html[data-theme="light"] .logo.mark { background: var(--surface); }
html[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f1ea; --surface: #fffdf8; --surface2: #efeae0; --line: #e2d9cc; --line2: #d3c8b6;
  --ink: #1c1914; --muted: #6d675c; --brass: #8a6230; --onbrass: #fffdf8;
  --pos: #2f7d46; --neg: #a33b32; --mix: #8a6a12; --unc: #6d675c;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); min-height: 100%; max-width: 100%; overflow-x: hidden; }
html { touch-action: manipulation; }
body { font-family: var(--sans); font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; text-align: inherit; }
a { color: var(--brass); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, p { margin: 0; }
.brand { color: var(--brass); font-size: 11px; letter-spacing: .18em; text-transform: uppercase; }
.muted { color: var(--muted); }
.error { color: var(--neg); min-height: 1.3em; margin-top: 10px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(400px, 100%); }
.login-card h1 { font-family: var(--serif); font-weight: 400; font-size: 34px; margin: 8px 0 22px; }
label { display: block; color: var(--muted); font-size: 12px; margin: 14px 0 4px; }
input, select, textarea { width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 9px 11px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--brass); }
.primary { background: var(--brass); color: var(--onbrass); border-radius: 6px; padding: 9px 16px; font-weight: 600; margin-top: 18px; }
.ghost { border: 1px solid var(--line2); border-radius: 6px; padding: 7px 12px; color: var(--ink); }
.ghost:hover { border-color: var(--brass); }

/* shell */
.app { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; border-right: 1px solid var(--line); padding: 22px 14px; display: flex; flex-direction: column; gap: 22px; background: var(--bg); overflow: auto; }
.side-brand { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 8px; }
.theme { margin: 0; padding: 4px 10px; font-size: 12px; }
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-label { color: var(--muted); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; padding: 0 8px 6px; }
.nav { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border-radius: 6px; color: var(--ink); }
.nav:hover { background: var(--surface); }
.nav.on { background: var(--surface2); box-shadow: inset 2px 0 0 var(--brass); }
.nav.off { color: var(--muted); cursor: default; }
.nav small { color: var(--muted); font-size: 11px; }
.side-foot { margin-top: auto; padding: 0 8px; display: grid; gap: 8px; color: var(--muted); font-size: 12px; }
.side-foot button { color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.stage { min-width: 0; padding: 0 32px 96px; }
.top { padding: 26px 0 14px; }
.crumbs { margin-bottom: 8px; }
.back { color: var(--ink); font-size: 22px; line-height: 1; padding: 2px 4px; }
.back:hover { color: var(--brass); }
.top-bar { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; }
.refresh { display: flex; align-items: center; gap: 12px; text-align: right; flex: none; }
.refresh .k { color: var(--muted); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.refresh .when { font-size: 13px; }
.ring { position: relative; width: 48px; height: 48px; }
.ring span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 11px; }
.ring-bg, .ring-fg { fill: none; stroke-width: 3; }
.ring-bg { stroke: var(--line); }
.ring-fg { stroke: var(--brass); stroke-linecap: round; transform: rotate(-90deg); transform-origin: 18px 18px; }
.top h1 { font-family: var(--serif); font-weight: 400; font-size: 34px; }
.top .lede { color: var(--muted); margin-top: 6px; max-width: 70ch; }
.tabs-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; border-bottom: 1px solid var(--line); margin: 18px 0 26px; }
.tabs { display: flex; gap: 22px; border-bottom: 0; margin: 0; flex-wrap: wrap; }
.numrow { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 14px; margin: 10px 0 4px; }
.numrow.tight { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.numrow .k { margin: 0; font-size: 11px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.numrow p { margin: 2px 0 0; font-variant-numeric: tabular-nums; }
.textbtn { font: inherit; color: inherit; padding: 0; text-align: left; }
.insight h2 { margin: 0; }
.primary.slim { margin: 0 0 8px; }
.tab { padding: 8px 0; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.on { color: var(--ink); border-color: var(--brass); }
.view { display: grid; gap: 30px; }
h2 { font-family: var(--serif); font-weight: 400; font-size: 21px; }
.sec-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.fold { display: inline-flex; align-items: center; gap: 8px; }
.fold .caret { color: var(--brass); font-size: 16px; width: 14px; }
.sec-head .muted { font-size: 12px; }

/* kpis and cards */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi, .card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.kpi.click { cursor: pointer; text-align: left; width: 100%; }
.kpi.click:hover { border-color: var(--brass); }
.kpi .k { color: var(--muted); font-size: 12px; }
.kpi .v { font-family: var(--serif); font-size: 27px; margin-top: 4px; }
.kpi .s { color: var(--muted); font-size: 12px; margin-top: 2px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 14px; align-items: start; }
.clip { max-height: 720px; overflow: auto; }
.modal-back { position: fixed; inset: 0; background: rgba(8, 8, 6, .62); z-index: 40; display: grid; place-items: center; padding: 20px; }
.modal { width: min(560px, 100%); max-height: min(86vh, 720px); overflow: auto; }
.ref-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.ref-tile { aspect-ratio: 1; display: flex; flex-direction: column; justify-content: space-between; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px; min-width: 0; }
.ref-tile strong { font-size: 15px; font-weight: 600; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.ref-tile a { color: inherit; text-decoration: none; }
.ref-tile a:hover { text-decoration: underline; }
.ref-tile .rate { min-width: 0; width: 100%; }
.ref-tile .rate input[type=range] { width: 100%; }
.rate { display: flex; align-items: center; gap: 8px; min-width: 200px; margin: 0; }
.rate input[type=range] { width: 120px; }
.rate-num { min-width: 1.4em; font-weight: 600; }
.rate-pill { font-size: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.card.click { cursor: pointer; transition: border-color .15s; }
.card.click:hover { border-color: var(--brass); }
.card { position: relative; }
.card h3 { font-size: 15px; font-weight: 600; }
.card.co h3 { padding-right: 44px; }
.logo { position: absolute; top: 14px; right: 14px; width: 32px; height: 32px; border-radius: 8px; object-fit: cover; background: #1c1d18; }
.logo.mark { display: grid; place-items: center; font-size: 11px; letter-spacing: .04em; color: var(--brass); border: 1px solid var(--line); }
.holdline { font-variant-numeric: tabular-nums; margin: 8px 28px 0 0; }
.ghost.short.on { border-color: var(--neg); color: var(--neg); }
.ghost.long.on { border-color: var(--pos); color: var(--pos); }
.daynote { margin: 0 0 14px; }
.daynote .k { margin: 0 0 4px; font-size: 11px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
textarea { width: 100%; min-height: 88px; background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; resize: vertical; }
.card .sub { color: var(--muted); font-size: 12px; }
.big { font-family: var(--serif); font-size: 30px; margin: 8px 0 2px; }
.big small { font-family: var(--sans); font-size: 12px; color: var(--muted); margin-left: 6px; }
.src { color: var(--muted); font-size: 11.5px; margin-top: 8px; line-height: 1.5; }
.src a { color: var(--brass); }
.pos { color: var(--pos); } .neg { color: var(--neg); }

/* chips */
.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; border: 1px solid currentColor; white-space: nowrap; }
.chip.positive { color: var(--pos); } .chip.negative { color: var(--neg); } .chip.mixed { color: var(--mix); } .chip.unclear { color: var(--unc); }
.badge { display: inline-block; font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; padding: 1px 7px; border-radius: 4px; background: var(--surface2); color: var(--muted); }
.badge.verified { color: var(--pos); } .badge.reported { color: var(--mix); } .badge.withheld, .badge.stale { color: var(--neg); }
.badge.held { color: var(--brass); }

/* tables */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; color: var(--muted); font-weight: 400; font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr.row { cursor: pointer; }
.tbl tr.row:hover td { background: var(--surface); }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.scroll { overflow-x: auto; }
.why { color: var(--muted); font-size: 13px; max-width: 46ch; }
.detail td { background: var(--surface); }
.signals { display: grid; gap: 10px; padding: 4px 0 6px; }
.signal { display: grid; grid-template-columns: 14px 1fr; gap: 8px; font-size: 13px; }
.signal i { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; background: var(--unc); }
.signal.p i { background: var(--pos); } .signal.n i { background: var(--neg); }
.cols2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.hd { color: var(--muted); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; margin-bottom: 6px; }

/* feed */
.feed { display: grid; gap: 0; }
.entry { padding: 12px 0; border-bottom: 1px solid var(--line); display: grid; gap: 4px; }
.entry .t { font-weight: 500; }
.entry.unread .t::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--brass); margin-right: 8px; }
.entry .m { color: var(--muted); font-size: 12.5px; }
.entry .r { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 12px; color: var(--muted); }

/* charts */
.chart { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: 12px; margin-top: 8px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 6px; }
.layers { margin-top: 10px; font-size: 12.5px; }
.layers summary { cursor: pointer; color: var(--brass); }
.layers table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.layers td, .layers th { padding: 4px 6px; border-bottom: 1px solid var(--line); text-align: left; font-weight: 400; }
.layers th { color: var(--muted); }

/* forms */
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; align-items: end; }
.form .primary { margin: 0; }
.suggest { position: relative; }
.suggest-list { position: absolute; z-index: 6; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface2); border: 1px solid var(--line2); border-radius: 8px; max-height: 260px; overflow: auto; box-shadow: 0 12px 30px rgba(0,0,0,.35); }
.suggest-list button { display: flex; flex-direction: column; gap: 2px; width: 100%; text-align: left; padding: 8px 10px; }
.suggest-list button:hover { background: var(--surface); }
.suggest-list strong { font-weight: 600; }
.progress { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 12px 0 6px; }
.progress > i { display: block; height: 100%; background: var(--brass); border-radius: 99px; transition: width .4s ease; }
.note { color: var(--muted); font-size: 12.5px; }
.empty { padding: 26px; border: 1px dashed var(--line2); border-radius: 10px; color: var(--muted); text-align: center; }

/* feedback dock */
.dock-tab { position: fixed; right: 0; top: 46%; transform: translateY(-50%); background: var(--surface2); border: 1px solid var(--line2); border-right: 0; border-radius: 10px 0 0 10px; padding: 14px 10px; writing-mode: vertical-rl; letter-spacing: .12em; text-transform: uppercase; font-size: 11px; z-index: 30; color: var(--ink); display: flex; gap: 8px; align-items: center; }
.dock-tab:hover { border-color: var(--brass); }
.dock-tab .rec { width: 9px; height: 9px; border-radius: 50%; background: #e2554a; animation: pulse 1.1s infinite; }
@keyframes pulse { 50% { opacity: .25; } }
.panel { position: fixed; right: 18px; bottom: 18px; width: min(390px, calc(100vw - 24px)); height: min(620px, calc(100vh - 36px)); background: var(--surface); border: 1px solid var(--line2); border-radius: 14px; display: flex; flex-direction: column; z-index: 40; box-shadow: 0 20px 60px rgba(0, 0, 0, .55); }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.panel-head h3 { font-family: var(--serif); font-weight: 400; font-size: 18px; }
.panel-head .sub { color: var(--muted); font-size: 12px; }
.msgs { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { align-self: flex-end; max-width: 88%; background: var(--surface2); border: 1px solid var(--line); border-radius: 12px 12px 3px 12px; padding: 9px 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.sys { align-self: flex-start; background: transparent; border-style: dashed; color: var(--muted); border-radius: 12px 12px 12px 3px; }
.msg small { display: block; color: var(--muted); font-size: 11px; margin-top: 4px; }
.msg-del { margin-left: 8px; padding: 0; border: 0; background: transparent; color: var(--muted); font-size: 11px; text-decoration: underline; text-underline-offset: 2px; }
.msg-del:hover { color: #e2554a; }
.composer { border-top: 1px solid var(--line); padding: 10px 12px 12px; display: grid; gap: 8px; }
.composer textarea { resize: none; height: 58px; }
.composer .row { display: flex; gap: 8px; align-items: center; }
.mic { border: 1px solid var(--line2); border-radius: 999px; padding: 8px 14px; display: flex; gap: 8px; align-items: center; }
.mic.on { border-color: #e2554a; color: #ffb1a9; }
.mic .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--brass); }
.mic.on .dot { background: #e2554a; animation: pulse 1.1s infinite; }
.composer .send { margin-left: auto; background: var(--brass); color: var(--onbrass); border-radius: 6px; padding: 8px 14px; font-weight: 600; }

@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; height: 100dvh; overflow: hidden; }
  .side { position: sticky; top: 0; z-index: 20; height: auto; max-height: 46dvh; flex: none; border-right: 0; border-bottom: 1px solid var(--line); padding: 12px 14px; gap: 12px; }
  .stage { height: 100%; overflow: auto; -webkit-overflow-scrolling: touch; padding: 0 14px 88px; }
  .top { padding-top: 14px; }
  .top-bar { flex-direction: column; }
  .refresh { align-self: flex-end; }
  .top h1 { font-size: 28px; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; gap: 16px; }
  .tab { flex: none; }
  .grid2, .grid3, .cols2, .kpis, .numrow, .numrow.tight, .form { grid-template-columns: 1fr; }
  .ref-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rate { min-width: 0; }
  input, select, textarea { font-size: 16px; }
  .dock-tab { top: auto; bottom: 10px; right: 10px; transform: none; writing-mode: horizontal-tb; letter-spacing: .08em; border-radius: 999px; border: 1px solid var(--line2); padding: 10px 14px; }
  .panel { left: 8px; right: 8px; width: auto; bottom: 8px; height: min(70dvh, 620px); }
  .modal-back { padding: 10px; align-items: end; }
  .modal { width: 100%; max-height: 88dvh; }
}
