/* Qoinest base styles: design tokens + shared components (LIGHT design, docs/build_plan.md §5).
   View-specific rules live in callers.css / account.css / tokens.css / rings.css.
   Class names used by js/ui.js components are documented next to each block. */

:root {
  /* surfaces */
  --bg: #131722;
  --pane: #131722;
  --line: #2A2E39;          /* 1px separators */
  --chip: #1E222D;          /* chip fill, tooltip */
  --hover: #2A2E39;         /* hover row */
  --grid: #1E222D;          /* chart grid */
  --plot: #181C27;          /* optional inner plot fill */

  /* text */
  --text: #D1D4DC;
  --text-2: #787B86;
  --text-3: #5D606B;
  --white: #FFFFFF;

  /* meaning (one hue, one meaning) */
  --up: #089981;            /* price only */
  --down: #F23645;          /* price only */
  --blue: #4C8DFF;          /* evidence above chance: solid = beyond luck, hollow = promising */
  --blue-2: #2F5FA8;
  --blue-3: #1E3A66;
  --blue-4: #8FB8FF;
  --sienna: #C9825B;        /* below chance */
  --grey: #787B86;          /* luck / null */
  --band: rgba(120, 123, 134, 0.26);   /* luck / null band: grey fill */
  --band-edge: #4A4E5A;
  --corridor: rgba(209, 212, 220, 0.10);      /* an account's own spread (event study middle half): */
  --corridor-edge: rgba(209, 212, 220, 0.72); /* light fill between solid light edges, never grey like luck */
  --amber: #F5C462;         /* warnings, partial data, run start */
  --amber-bg: #3A2E12;
  --magenta: #FF4FA3;       /* rings only */
  --neutral: #9598A1;       /* entry/now lines, dead x */
  --hatch: #3A3F4C;         /* not collected */

  /* type */
  --font-ui: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --fs: 13px;
  --fs-mono: 12px;
  --fs-small: 11px;
  --fs-title: 12px;

  /* spacing */
  --chrome-h: 44px;
  --pad: 20px;
  --gap: 16px;
  --radius: 4px;

  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--fs);
  line-height: 1.45;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--text); text-decoration: none; }
a:hover { color: var(--white); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
code, kbd, .mono { font-family: var(--font-mono); font-size: var(--fs-mono); }
.num { font-family: var(--font-mono); font-size: var(--fs-mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.up { color: var(--up); }
.down { color: var(--down); }
.blue { color: var(--blue); }
.sienna { color: var(--sienna); }
.amber { color: var(--amber); }
.magenta { color: var(--magenta); }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
::selection { background: var(--blue-3); }
* { scrollbar-color: #363A45 transparent; scrollbar-width: thin; }

/* ---------- chrome (one row, 44px; wraps on narrow screens) ---------- */
.chrome {
  position: sticky; top: 0; z-index: 50;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px;
  min-height: var(--chrome-h); padding: 6px 16px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 600; font-size: 15px; color: var(--white); letter-spacing: .01em; padding-right: 4px; }
.brand:hover { color: var(--white); }
.search {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 8px;
  background: var(--chip); border-radius: var(--radius); position: relative;
}
.search input { background: transparent; border: 0; outline: none; width: 168px; font-family: var(--font-mono); font-size: var(--fs-mono); color: var(--text); }
.search input::placeholder { color: var(--text-3); }
.search:focus-within { outline: 1px solid var(--blue-2); }
.search-msg { position: absolute; top: 32px; left: 0; white-space: nowrap; z-index: 60; }
.nav { display: inline-flex; align-items: stretch; gap: 2px; height: 32px; }
.nav a {
  display: inline-flex; align-items: center; padding: 0 10px; color: var(--text-2);
  border-radius: var(--radius); font-size: var(--fs);
}
.nav a:hover { color: var(--text); background: var(--chip); }
.nav a[aria-current="page"] { color: var(--white); box-shadow: inset 0 -2px 0 var(--blue); border-radius: 0; background: transparent; }
.spacer { flex: 1 1 auto; }
.chrome-chips { display: inline-flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* ---------- page ---------- */
.view { flex: 1 0 auto; padding: 20px 24px 8px; min-width: 0; outline: none; }
.view-host { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }
.footnote {
  padding: 14px 24px 18px; color: var(--text-3); font-size: var(--fs-small);
  font-family: var(--font-mono); line-height: 1.6;
}
.page-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; }
.page-title { margin: 0; font-size: 18px; font-weight: 600; color: var(--white); }
.verdict { margin: 0; font-size: 15px; line-height: 1.5; color: var(--text); max-width: 78ch; }
.verdict strong { color: var(--white); font-weight: 600; }

/* layout helpers */
.layout-main-side { display: grid; grid-template-columns: minmax(0, 65fr) minmax(0, 35fr); gap: var(--gap); align-items: start; }
.stack { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.row-tight { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.joined { display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line); }
.joined > .pane { border: 0; }

/* ---------- pane: .pane > .pane-head (.pane-title, .pane-n, .chip--amber, .pane-tools) + .pane-note + .pane-body ---------- */
.pane { background: var(--pane); border: 1px solid var(--line); min-width: 0; display: flex; flex-direction: column; }
.pane-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 14px var(--pad) 8px; min-height: 44px; }
.pane-title { margin: 0; font-size: var(--fs-title); font-weight: 500; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2); }
.pane-n { font-family: var(--font-mono); font-size: var(--fs-small); color: var(--text-3); font-variant-numeric: tabular-nums; }
.pane-tools { margin-left: auto; display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.pane-note { padding: 0 var(--pad) 8px; color: var(--text-2); font-size: 12px; }
.pane-note--partial { color: var(--amber); }
.pane-body { padding: 4px var(--pad) var(--pad); min-width: 0; flex: 1 1 auto; }
.pane-body--flush { padding: 0; }
.pane-foot { padding: 10px var(--pad) 14px; color: var(--text-3); font-size: var(--fs-small); border-top: 1px solid var(--grid); }

/* ---------- chips ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px;
  border-radius: var(--radius); background: var(--chip); color: var(--text-2);
  font-family: var(--font-mono); font-size: var(--fs-small); white-space: nowrap; border: 1px solid transparent;
  line-height: 1; vertical-align: middle;
}
.chip--ui { font-family: var(--font-ui); font-size: 12px; }
.chip--lg { height: 26px; padding: 0 10px; }
.chip--blue { color: var(--blue); border-color: var(--blue-2); }
.chip--blue-hollow { color: var(--blue); background: transparent; border-color: var(--blue-2); border-style: dashed; }
.chip--amber { color: var(--amber); background: var(--amber-bg); }
.chip--sienna { color: var(--sienna); border-color: #6B4632; }
.chip--magenta { color: var(--magenta); border-color: #7A2A55; }
.chip--up { color: var(--up); }
.chip--down { color: var(--down); }
.chip--faint { color: var(--text-3); background: transparent; border-color: var(--line); }
.chip--outline { background: transparent; border-color: var(--line); color: var(--text); }
.chip--pending { background: transparent; border: 1px dashed var(--text-3); color: var(--text-2); }
.chip--text { color: var(--text); }
a.chip:hover { color: var(--white); border-color: var(--text-3); }
.chip-dot { width: 7px; height: 7px; flex: none; }

/* state dot (inline svg) */
.state-dot { display: inline-block; vertical-align: middle; flex: none; }

/* window chips: .win.win--collected / --partial / --not_collected */
.win {
  display: inline-flex; align-items: center; justify-content: center; height: 22px; min-width: 44px; padding: 0 6px;
  font-family: var(--font-mono); font-size: var(--fs-small); border-radius: 3px; border: 1px solid transparent; white-space: nowrap;
}
.win--collected { background: var(--chip); color: var(--text); border-color: var(--band-edge); }
.win--partial { background: transparent; color: var(--amber); border-color: rgba(245, 196, 98, .45); }
.win--not_collected { color: var(--text-3); border-color: var(--line); background-image: repeating-linear-gradient(45deg, var(--hatch) 0 1px, transparent 1px 5px); }
.win-strip { display: inline-flex; flex-wrap: wrap; gap: 4px; }

/* handle, ticker, community */
.handle { font-family: var(--font-mono); font-size: var(--fs-mono); color: var(--text); white-space: nowrap; }
a.handle:hover { color: var(--white); text-decoration: underline; text-underline-offset: 2px; }
.ticker { font-family: var(--font-mono); font-size: var(--fs-mono); font-weight: 500; color: var(--text); white-space: nowrap; }
a.ticker:hover { color: var(--white); text-decoration: underline; text-underline-offset: 2px; }
.ticker--unresolved { color: var(--text-2); font-weight: 400; }
.handle-chips { display: inline-flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.handle-chips .chip { color: var(--text); }
.community { display: inline-block; width: 12px; text-align: center; font-family: var(--font-mono); font-size: 10px; color: var(--text-3); }

/* ---------- empty / error / loading ---------- */
.empty { padding: 18px 20px; border: 1px dashed var(--line); color: var(--text-2); max-width: 72ch; }
.empty--compact { padding: 12px 14px; }
.empty--partial, .empty--missing, .empty--error { border-style: solid; border-left: 2px solid var(--amber); }
.empty-title { color: var(--text); font-weight: 500; margin-bottom: 4px; }
.empty-text { margin: 0; }
.empty-hint { margin-top: 8px; color: var(--text-2); font-size: 12px; }
.empty-cmd { display: inline-block; margin-top: 8px; padding: 3px 8px; background: var(--chip); border-radius: var(--radius); color: var(--text); font-family: var(--font-mono); font-size: var(--fs-small); user-select: all; }
.empty-detail { margin-top: 6px; font-family: var(--font-mono); font-size: var(--fs-small); color: var(--text-3); word-break: break-word; }
.loading { padding: 18px 0; color: var(--text-3); font-size: 12px; }

/* ---------- tooltip ---------- */
.tooltip {
  position: fixed; z-index: 1000; pointer-events: none; max-width: 320px;
  background: var(--chip); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .45); padding: 8px 10px; font-size: 12px; color: var(--text);
  white-space: pre-line; opacity: 0; transition: opacity .08s;
}
.tooltip[data-show] { opacity: 1; }
.tt-title { font-family: var(--font-mono); color: var(--white); margin-bottom: 4px; white-space: nowrap; }
.tt-rows { display: grid; grid-template-columns: auto auto; gap: 2px 14px; margin: 0; white-space: nowrap; }
.tt-rows dt { color: var(--text-2); margin: 0; }
.tt-rows dd { margin: 0; font-family: var(--font-mono); font-size: var(--fs-small); text-align: right; font-variant-numeric: tabular-nums; }
.tt-foot { margin-top: 6px; color: var(--text-3); font-size: var(--fs-small); }
[data-tip] { cursor: help; }
a[data-tip], button[data-tip] { cursor: pointer; }

/* ---------- table: .tbl-wrap > table.tbl ---------- */
.tbl-wrap { overflow-x: auto; min-width: 0; }
.tbl { width: 100%; border-collapse: collapse; font-size: var(--fs); }
.tbl th {
  text-align: left; font-weight: 500; font-size: var(--fs-small); text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-2); padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--bg);
}
.tbl th.is-sortable { cursor: pointer; user-select: none; }
.tbl th.is-sortable:hover { color: var(--text); }
/* the table wrapper scrolls (overflow) and would clip an outside focus ring: draw it inside */
.tbl th:focus-visible, .tbl tr:focus-visible, .tbl-wrap:focus-visible { outline-offset: -2px; }
.tbl th[aria-sort="ascending"]::after { content: " \2191"; }
.tbl th[aria-sort="descending"]::after { content: " \2193"; }
.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
.tbl .al-right { text-align: right; }
.tbl .al-center { text-align: center; }
.tbl td.is-num { font-family: var(--font-mono); font-size: var(--fs-mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl tbody tr:hover { background: var(--chip); }
.tbl tbody tr.is-link { cursor: pointer; }
.tbl tbody tr.is-selected { box-shadow: inset 0 0 0 1px var(--white); }
.tbl--dense td { padding: 6px 10px; }
.tbl--dense th { padding: 6px 10px; }
.tbl-empty td { padding: 14px 12px; color: var(--text-2); }
.tbl-more { display: flex; justify-content: center; padding: 10px; }
.tbl-sticky th { position: sticky; top: 0; z-index: 1; }
.cell-text { max-width: 46ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }

/* ---------- tabs and segmented ---------- */
.tabs { display: inline-flex; gap: 2px; align-items: center; }
.tab {
  background: transparent; border: 0; color: var(--text-2); padding: 0 10px; height: 26px; border-radius: var(--radius);
  font-size: 12px; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { background: var(--hover); color: var(--white); }
.tab .tab-count { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-3); margin-left: 5px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg button { background: transparent; border: 0; color: var(--text-2); height: 24px; padding: 0 9px; font-family: var(--font-mono); font-size: var(--fs-small); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--hover); color: var(--white); }
.seg button:focus-visible { outline-offset: -2px; }   /* .seg clips overflow: keep the ring inside */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: var(--radius);
  background: transparent; border: 1px solid var(--line); color: var(--text); font-size: 12px;
}
.btn:hover { border-color: var(--text-3); color: var(--white); }
.btn--ghost { border-color: transparent; color: var(--text-2); }

/* ---------- legend ---------- */
.legend { display: inline-flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; color: var(--text-2); font-size: var(--fs-small); }
.legend-item { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }

/* ---------- stats line, key-value ---------- */
.stats { display: flex; flex-wrap: wrap; gap: 6px 22px; align-items: baseline; }
.stat { display: inline-flex; align-items: baseline; gap: 6px; }
.stat-label { color: var(--text-2); font-size: 12px; }
.stat-value { font-family: var(--font-mono); font-size: 13px; color: var(--text); font-variant-numeric: tabular-nums; }
.stat-sub { font-family: var(--font-mono); font-size: var(--fs-small); color: var(--text-3); }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 7px 16px; margin: 0; }
.kv dt { color: var(--text-2); font-size: 12px; }
.kv dd { margin: 0; font-family: var(--font-mono); font-size: var(--fs-mono); font-variant-numeric: tabular-nums; min-width: 0; overflow-wrap: anywhere; }

/* ---------- drawer (Receipt) ---------- */
.drawer {
  position: fixed; top: var(--chrome-h); right: 0; bottom: 0; width: 400px; max-width: 100vw; z-index: 80;
  background: var(--bg); border-left: 1px solid var(--line); box-shadow: -12px 0 32px rgba(0, 0, 0, .4);
  display: flex; flex-direction: column; transform: translateX(105%); transition: transform .16s ease-out; visibility: hidden;
}
.drawer[data-open] { transform: none; visibility: visible; }
.drawer-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); min-height: 48px; }
.drawer-title { margin: 0; font-size: var(--fs-title); font-weight: 500; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2); }
.drawer-sub { color: var(--text); font-family: var(--font-mono); font-size: var(--fs-mono); }
.drawer-close { margin-left: auto; background: transparent; border: 0; color: var(--text-2); width: 28px; height: 28px; border-radius: var(--radius); font-size: 18px; line-height: 1; }
.drawer-close:hover { color: var(--white); background: var(--chip); }
.drawer-body { padding: 16px; overflow-y: auto; flex: 1 1 auto; display: flex; flex-direction: column; gap: 14px; }

/* receipt */
.receipt-text { margin: 0; padding: 10px 12px; border-left: 2px solid var(--line); background: var(--plot); color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; }
.receipt-link { font-size: 12px; color: var(--blue); }
.receipt-link:hover { color: var(--blue-4); }
.receipt-note { color: var(--text-3); font-size: var(--fs-small); }
.receipt-note-v { font-family: var(--font-ui); font-size: 12px; color: var(--text-2); }
.dead-mark { cursor: help; }

/* pending outcome in dense tables: a short dashed mark (dashed = pending, design rule) */
.pending-mark { display: inline-block; width: 14px; height: 0; border-top: 1px dashed var(--text-3); vertical-align: middle; }
td .pending-mark { margin: 0 2px; }

/* sparkline */
.spark { display: block; overflow: visible; }

/* chart containers (lightweight-charts / d3) */
.chart-box { position: relative; width: 100%; min-width: 0; }
.chart-box svg { display: block; }
.axis text { fill: var(--text-2); font-family: var(--font-mono); font-size: 10.5px; }
.axis path, .axis line { stroke: var(--line); }
.gridline line { stroke: var(--grid); }

/* placeholder (stub views; remove when the view is built) */
.placeholder-tag { align-self: flex-start; }

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .layout-main-side { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 720px) {
  :root { --pad: 16px; }
  .chrome { position: static; padding: 6px 12px; gap: 6px 10px; }
  .search { order: 3; flex: 1 1 100%; }
  .search input { width: 100%; }
  .spacer { display: none; }
  .chrome-chips { order: 4; flex: 1 1 100%; flex-wrap: wrap; min-width: 0; padding-bottom: 2px; }
  .drawer { top: 0; }
  .view { padding: 16px 16px 8px; }
  .footnote { padding: 12px 16px 16px; }
  .drawer { width: 100vw; }
  .verdict { font-size: 14px; }
}
