/* Design tokens.
 *
 * Light and dark are both selected sets, not an automatic inversion. Series
 * slots 1-3 are validated against each surface for CVD separation and
 * contrast; do not substitute hexes without re-running the validator.
 *
 * `--surface-2` and `--surface-3` are chrome only -- rails, headers, row
 * stripes. No datum is ever encoded in them, so they sit outside the
 * validated set.
 */
:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --surface-2: #f2f2ef;
  --surface-3: #e9e9e4;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);

  --series-1: #2a78d6; /* buy side */
  --series-2: #eb6834; /* sell side */
  --series-3: #1baf7a;

  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --success-text: #006300;

  --sequential-mid: #86b6ef;

  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, monospace;

  --rail-width: 172px;
  --row-height: 28px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --surface-2: #141413;
    --surface-3: #262624;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;

    --success-text: #0ca30c;
    --sequential-mid: #184f95;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --surface-2: #141413;
  --surface-3: #262624;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;

  --success-text: #0ca30c;
  --sequential-mid: #184f95;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--page);
  color: var(--text-primary);
  font-size: 13px;
  line-height: 1.45;
  overflow: hidden;
}

a {
  color: var(--series-1);
}

::selection {
  background: color-mix(in srgb, var(--series-1) 30%, transparent);
}

/* --- shell ------------------------------------------------------------ */

.shell {
  display: grid;
  grid-template-rows: 30px 40px 1fr;
  grid-template-columns: var(--rail-width) 1fr;
  grid-template-areas:
    "ticker ticker"
    "topbar topbar"
    "rail   workspace";
  height: 100vh;
}

.shell[data-rail="collapsed"] {
  --rail-width: 52px;
}

/* --- ticker ----------------------------------------------------------- */

.ticker {
  grid-area: ticker;
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  font-variant-numeric: tabular-nums;
}

.ticker-strip {
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 0 14px;
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1;
}

.ticker-strip::-webkit-scrollbar {
  display: none;
}

.ticker-item {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  font-size: 12px;
}

.ticker-item .t-name {
  color: var(--text-secondary);
}

.ticker-item .t-price {
  font-weight: 600;
}

.ticker-fixed {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 14px;
  border-left: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 12px;
  flex: none;
}

.ticker-fixed .metric {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
}

.ticker-fixed .metric .label {
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.ticker-fixed .metric .value {
  font-weight: 600;
}

/* --- topbar ----------------------------------------------------------- */

.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 7px;
  font-weight: 650;
  letter-spacing: -0.01em;
  margin-right: 4px;
}

.brand .mark {
  color: var(--series-1);
}

.brand small {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 11px;
}

.topbar .grow {
  flex: 1;
}

.cmd-hint {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 8px;
  min-width: 220px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--page);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
}

.cmd-hint:hover {
  border-color: var(--axis);
}

kbd {
  font-family: var(--mono);
  font-size: 10px;
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text-secondary);
}

/* --- rail ------------------------------------------------------------- */

.rail {
  grid-area: rail;
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.rail-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 8px;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  font: inherit;
  text-align: left;
  width: 100%;
}

.rail-item .glyph {
  width: 18px;
  text-align: center;
  flex: none;
  font-size: 13px;
}

.rail-item .count {
  margin-left: auto;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  background: var(--surface-3);
  border-radius: 999px;
  padding: 0 6px;
}

.rail-item .key {
  margin-left: auto;
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--mono);
}

.rail-item:hover {
  background: var(--surface-3);
  color: var(--text-primary);
}

.rail-item[aria-current="true"] {
  background: color-mix(in srgb, var(--series-1) 14%, transparent);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: inset 2px 0 0 var(--series-1);
}

.rail-spacer {
  flex: 1;
}

.shell[data-rail="collapsed"] .rail-item .label,
.shell[data-rail="collapsed"] .rail-item .key,
.shell[data-rail="collapsed"] .rail-item .count {
  display: none;
}

/* --- workspace -------------------------------------------------------- */

.workspace {
  grid-area: workspace;
  display: flex;
  min-width: 0;
  overflow: hidden;
}

.main-pane {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.pane-scroll {
  overflow: auto;
  padding: 10px 12px 40px;
  flex: 1;
}

.splitter {
  width: 5px;
  cursor: col-resize;
  background: var(--border);
  flex: none;
}

.splitter:hover,
.splitter[data-dragging="true"] {
  background: var(--series-1);
}

.side-pane {
  width: 460px;
  flex: none;
  background: var(--surface-1);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  min-width: 320px;
}

.side-pane[hidden],
.splitter[hidden] {
  display: none;
}

/* --- item page (/item/<slug>) ------------------------------------------- */
/* The side pane is repurposed as a full-width, centered page so the existing
 * detail render and its actions all keep working on a shareable URL. */
.shell[data-mode="item-page"] .main-pane,
.shell[data-mode="item-page"] .splitter {
  display: none;
}
.shell[data-mode="item-page"] .side-pane {
  width: auto;
  flex: 1;
  min-width: 0;
  max-width: 880px;
  margin: 0 auto;
  border-left: none;
  background: var(--surface-0, transparent);
}
.shell[data-mode="item-page"] .pane-body {
  padding: 16px 20px 60px;
}

/* --- filter row: one row above everything it scopes ------------------- */

.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  flex: none;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.field label,
.field-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

input[type="text"],
input[type="number"],
select {
  font: inherit;
  font-size: 12px;
  padding: 4px 7px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--text-primary);
  min-width: 92px;
}

input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--series-1);
  outline-offset: 1px;
}

/* Links that do a button's job -- Upgrade, Manage billing. They are
   anchors because they leave the app, and they look like buttons because
   that is what they are. */
button,
a.btn-link {
  font: inherit;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--text-primary);
  cursor: pointer;
}

button:hover,
a.btn-link:hover {
  border-color: var(--axis);
}

a.btn-link {
  display: inline-block;
  text-decoration: none;
}

button.primary,
a.btn-link.primary {
  background: var(--series-1);
  border-color: transparent;
  color: #fff;
  font-weight: 550;
}

button.ghost,
a.btn-link.ghost {
  background: transparent;
  color: var(--text-secondary);
}

button.tiny,
a.btn-link.tiny {
  padding: 1px 6px;
  font-size: 11px;
}

button.icon {
  padding: 3px 7px;
}

.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 5px;
  overflow: hidden;
}

.seg button {
  border: none;
  border-radius: 0;
  background: var(--page);
  padding: 4px 9px;
}

.seg button + button {
  border-left: 1px solid var(--border);
}

.seg button[aria-pressed="true"] {
  background: color-mix(in srgb, var(--series-1) 18%, transparent);
  font-weight: 600;
}

/* Market preset chips -- the All / High volume / F2P / High alch row that
   narrows the board in one click. Quieter than the segmented column toggle:
   these are starting points, not a current state the user is editing. */
.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 0 2px;
}

button.chip {
  padding: 3px 10px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--page);
  color: var(--text-muted);
  cursor: pointer;
}

button.chip:hover {
  border-color: var(--series-1);
  color: var(--text-primary);
}

button.chip.active {
  background: color-mix(in srgb, var(--series-1) 18%, transparent);
  border-color: color-mix(in srgb, var(--series-1) 55%, var(--border));
  color: var(--text-primary);
  font-weight: 600;
}

/* The "?" beside a piece of jargon, and the bubble it opens. Deliberately
   quiet until hovered: on a board of sixteen columns, sixteen bright help
   markers are noise, and the person who already knows what ROI is should
   not have to read past them. */
button.term {
  margin-left: 4px;
  padding: 0;
  width: 13px;
  height: 13px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: transparent;
  color: var(--text-secondary);
  font-size: 9px;
  line-height: 1;
  vertical-align: middle;
  opacity: 0.55;
}

button.term:hover {
  opacity: 1;
  color: var(--series-1);
  border-color: var(--series-1);
}

.glossary {
  position: fixed;
  z-index: 60;
  width: min(320px, calc(100vw - 16px));
  padding: 10px 12px 12px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.32);
}

.glossary h4 {
  margin: 0 0 5px;
  font-size: 12px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.glossary p {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-primary);
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-secondary);
}

/* --- stat tiles ------------------------------------------------------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
}

.tile .tile-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

/* Proportional figures on standalone numbers -- tabular only in columns. */
.tile .tile-value {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-top: 1px;
}

.tile .tile-note {
  font-size: 11px;
  color: var(--text-secondary);
}

/* --- cards & tables --------------------------------------------------- */

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 10px;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.card-head h2,
.card-head h3 {
  font-size: 12px;
  margin: 0;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.card-head .spacer {
  margin-left: auto;
}

.card-head .sub {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 10px;
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

.data-table th,
.data-table td {
  padding: 3px 8px;
  text-align: left;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
  height: var(--row-height);
}

.data-table th {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-1);
  height: 24px;
}

.data-table th.sortable {
  cursor: pointer;
  user-select: none;
}

.data-table th.sortable[data-active="true"] {
  color: var(--text-primary);
}

.data-table th .sort-arrow {
  font-size: 10px;
  margin-left: 2px;
  opacity: 0.75;
}

.data-table tbody tr:nth-child(even) {
  background: color-mix(in srgb, var(--surface-3) 45%, transparent);
}

.data-table tbody tr:hover {
  background: color-mix(in srgb, var(--series-1) 10%, transparent);
}

.data-table tbody tr[aria-selected="true"] {
  background: color-mix(in srgb, var(--series-1) 18%, transparent);
  box-shadow: inset 2px 0 0 var(--series-1);
}

.data-table td.num,
.data-table th.num {
  text-align: right;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table.compact td,
.data-table.compact th {
  height: 24px;
  padding: 2px 8px;
}

.item-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.item-cell img {
  width: 18px;
  height: 18px;
  object-fit: contain;
  flex: none;
}

.item-cell button {
  border: none;
  background: none;
  padding: 0;
  color: var(--text-primary);
  font-weight: 550;
  cursor: pointer;
  text-align: left;
  font-size: 12px;
}

.item-cell button:hover {
  text-decoration: underline;
}

.pill {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0 5px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  white-space: nowrap;
}

.pill[data-state="buying"] {
  border-color: var(--series-1);
  color: var(--series-1);
}

.pill[data-state="holding"] {
  border-color: var(--warning);
  color: var(--text-primary);
}

.pill[data-state="selling"] {
  border-color: var(--series-2);
  color: var(--series-2);
}

.pill[data-state="closed"] {
  border-color: var(--good);
  color: var(--success-text);
}

.pill[data-state="cancelled"] {
  color: var(--text-muted);
}

.pos {
  color: var(--success-text);
}

.neg {
  color: var(--critical);
}

.muted {
  color: var(--text-muted);
}

.mono {
  font-family: var(--mono);
}

.empty {
  padding: 22px 14px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
}

.bar-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 110px;
}

.bar-track {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: var(--surface-3);
  overflow: hidden;
  min-width: 46px;
}

.bar-fill {
  height: 100%;
  background: var(--series-1);
}

.bar-fill[data-tone="warn"] {
  background: var(--warning);
}

.bar-fill[data-tone="full"] {
  background: var(--critical);
}

/* --- status: never colour alone, always icon + label ------------------ */

.status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 550;
  white-space: nowrap;
}

.status .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: none;
}

.status[data-severity="good"] .dot { background: var(--good); }
.status[data-severity="warning"] .dot { background: var(--warning); }
.status[data-severity="serious"] .dot { background: var(--serious); }
.status[data-severity="critical"] .dot { background: var(--critical); }
.status[data-severity="info"] .dot { background: var(--text-muted); }

.conn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-secondary);
}

.conn .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
}

.conn[data-live="true"] .dot {
  background: var(--good);
}

.conn[data-live="false"] .dot {
  background: var(--warning);
}

/* --- charts ----------------------------------------------------------- */

.chart-block {
  position: relative;
  padding: 6px 4px 0;
}

.chart {
  display: block;
  overflow: visible;
}

.gridline {
  stroke: var(--grid);
  stroke-width: 1;
}

.axis-rule {
  stroke: var(--axis);
  stroke-width: 1;
}

.axis-label {
  fill: var(--text-muted);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.series-line {
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.series-end-label {
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.crosshair {
  stroke: var(--axis);
  stroke-width: 1;
}

/* 2px surface ring so overlapping markers stay separable. */
.hover-marker {
  stroke: var(--surface-1);
  stroke-width: 2;
}

.volume-bar {
  fill: var(--sequential-mid);
}

.pnl-bar-pos {
  fill: var(--good);
}

.pnl-bar-neg {
  fill: var(--critical);
}

.scatter-point {
  fill: var(--series-1);
  stroke: var(--surface-1);
  stroke-width: 2;
}

.parity-line {
  stroke: var(--axis);
  stroke-width: 1;
}

.sparkline path {
  fill: none;
  stroke: var(--series-1);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.legend {
  display: flex;
  gap: 14px;
  padding: 2px 0 6px 56px;
  font-size: 11px;
  color: var(--text-secondary);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.swatch {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  flex: none;
}

.chart-tooltip {
  position: absolute;
  min-width: 150px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 9px;
  font-size: 12px;
  pointer-events: none;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.16);
  z-index: 5;
}

.tt-time {
  color: var(--text-muted);
  margin-bottom: 3px;
}

.tt-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}

.tt-row .tt-label {
  color: var(--text-secondary);
}

.tt-row .tt-value {
  margin-left: auto;
  font-weight: 600;
}

.tt-derived {
  border-top: 1px solid var(--grid);
  margin-top: 3px;
  padding-top: 3px;
}

/* --- side pane -------------------------------------------------------- */

.pane-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  position: sticky;
  top: 0;
  z-index: 3;
}

.pane-head h2 {
  margin: 0;
  font-size: 15px;
}

.pane-head .sub {
  font-size: 11px;
  color: var(--text-muted);
}

.pane-body {
  padding: 10px 12px 40px;
}

.pane-section {
  margin-top: 14px;
}

.pane-section > h3 {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0 0 6px;
}

.kv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
  gap: 6px;
}

.kv {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
}

.kv .k {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.kv .v {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: flex-end;
}

.subtabs {
  display: flex;
  gap: 2px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.subtab {
  padding: 5px 9px;
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--text-secondary);
  font-size: 12px;
}

.subtab[aria-selected="true"] {
  color: var(--text-primary);
  border-bottom-color: var(--series-1);
  font-weight: 600;
}

/* Refetch holds the previous render rather than flashing a skeleton. */
.refreshing {
  opacity: 0.55;
  transition: opacity 120ms ease;
}

/* --- command palette -------------------------------------------------- */

.palette-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.42);
  z-index: 60;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 12vh;
}

.palette-backdrop[hidden] {
  display: none;
}

.palette {
  width: min(620px, 92vw);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.palette input {
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding: 12px 14px;
  font-size: 15px;
  background: transparent;
}

.palette input:focus-visible {
  outline: none;
}

.palette-list {
  max-height: 46vh;
  overflow-y: auto;
}

.palette-row {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 7px 14px;
  border: none;
  border-radius: 0;
  background: none;
  text-align: left;
  font-size: 13px;
}

.palette-row .glyph {
  width: 18px;
  text-align: center;
  color: var(--text-muted);
}

.palette-row .hint {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-muted);
}

.palette-row[data-active="true"] {
  background: color-mix(in srgb, var(--series-1) 16%, transparent);
}

.palette-group {
  padding: 5px 14px 2px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: var(--surface-2);
}

/* --- toast & modal ---------------------------------------------------- */

.toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 14px;
  z-index: 80;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.2);
  font-size: 12px;
}

.toast[hidden] {
  display: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.42);
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: min(560px, 92vw);
  max-height: 80vh;
  overflow-y: auto;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.modal h2 {
  margin: 0 0 10px;
  font-size: 15px;
}

.shortcut-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  font-size: 12px;
  align-items: center;
}

.search-results {
  position: absolute;
  z-index: 30;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 7px;
  max-height: 300px;
  overflow-y: auto;
  min-width: 260px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.18);
}

.search-results[hidden] {
  display: none;
}

.search-results button {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  border-radius: 0;
  background: none;
  padding: 5px 10px;
}

.search-results button:hover {
  background: color-mix(in srgb, var(--series-1) 12%, transparent);
}

.search-wrap {
  position: relative;
}

.note {
  font-size: 11px;
  color: var(--text-secondary);
  margin: 8px 0 0;
}

.hint-row {
  font-size: 11px;
  color: var(--text-muted);
  padding: 4px 2px 0;
}

/* --- playbook ---------------------------------------------------------- */

.play-group {
  margin: 14px 0 0;
}

.play-group-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 0 2px 6px;
}

.play-group-head h3 {
  margin: 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.play-group-head .sub {
  font-size: 11px;
  color: var(--text-muted);
}

.play-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-left: 3px solid var(--text-muted);
  border-radius: var(--radius);
  padding: 10px 12px 12px;
  margin-bottom: 8px;
}

/* The stripe repeats the severity the chip already states in words. */
.play-card[data-severity="good"] { border-left-color: var(--good); }
.play-card[data-severity="warning"] { border-left-color: var(--warning); }
.play-card[data-severity="serious"] { border-left-color: var(--serious); }
.play-card[data-severity="critical"] { border-left-color: var(--critical); }

.play-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.play-head h4 {
  margin: 0;
  font-size: 14px;
}

.play-why {
  margin: 6px 0 8px;
  font-size: 12px;
  color: var(--text-secondary);
  max-width: 78ch;
}

.play-steps {
  margin: 10px 0 0;
  padding-left: 18px;
  font-size: 12px;
  display: grid;
  gap: 2px;
}

.play-risks {
  margin: 8px 0 0;
  padding-left: 18px;
  font-size: 11.5px;
  color: var(--text-secondary);
  display: grid;
  gap: 2px;
}

.play-risks li::marker {
  color: var(--warning);
}

.play-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  flex-wrap: wrap;
}

/* --- the AI panel ------------------------------------------------------ */

.ai-card {
  margin-top: 12px;
}

.ai-headline {
  margin: 10px 12px 6px;
  font-size: 14px;
  font-weight: 600;
}

.ai-observations {
  display: grid;
  gap: 6px;
  padding: 0 12px;
}

.ai-obs {
  display: grid;
  grid-template-columns: 78px 1fr;
  gap: 8px;
  align-items: start;
  font-size: 12px;
}

.ai-obs p {
  margin: 2px 0 0;
  color: var(--text-secondary);
}

.ai-card .grid-2 {
  padding: 10px 12px 0;
}

.ai-card .note {
  padding: 0 12px 10px;
}

/* --- analytics drill-down ---------------------------------------------- */

.range-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  padding: 0 2px 8px;
}

.hero-chart {
  margin-bottom: 10px;
}

.series-dot {
  opacity: 0.85;
}

.chart-marker {
  fill: none;
  stroke: var(--text-secondary);
  stroke-width: 1.5;
}

.chart-selection {
  fill: color-mix(in srgb, var(--series-1) 12%, transparent);
}

.chart-brush {
  fill: color-mix(in srgb, var(--series-1) 20%, transparent);
  stroke: var(--series-1);
  stroke-width: 1;
}

/* Full screen: the charts get the window, the chrome steps out of the way. */
.shell[data-fullscreen="true"] {
  grid-template-rows: 0 0 1fr;
  grid-template-columns: 0 1fr;
}

.shell[data-fullscreen="true"] .ticker,
.shell[data-fullscreen="true"] .topbar,
.shell[data-fullscreen="true"] .rail {
  display: none;
}

/* --- trade ticket ------------------------------------------------------ */

.modal.ticket {
  width: min(640px, 94vw);
}

.ticket-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.ticket-head h2 {
  margin: 0;
  font-size: 15px;
}

.ticket-item {
  margin-bottom: 10px;
}

.ticket-item input {
  width: 100%;
}

.ticket-fields {
  align-items: flex-end;
  gap: 10px;
}

.ticket-fields .field {
  flex: 1 1 120px;
}

.ticket-fields input {
  width: 100%;
}

.field-hint {
  font-size: 10px;
  color: var(--text-muted);
}

.ticket-summary {
  margin-top: 12px;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.ticket-summary .kv-grid {
  padding: 0;
}

.ticket-error {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--critical);
}

@media (max-width: 900px) {
  .shell {
    grid-template-columns: 52px 1fr;
  }
  .side-pane {
    position: fixed;
    top: 70px;
    right: 0;
    bottom: 0;
    width: min(520px, 96vw);
    z-index: 45;
    box-shadow: -12px 0 30px rgba(0, 0, 0, 0.25);
  }
  .splitter {
    display: none;
  }
}

/* --- phones -----------------------------------------------------------
 *
 * A trading terminal is a desktop shape: a left rail, a wide table, a pane
 * beside it. None of that survives a 390px screen, so below 700px the shell
 * becomes an app -- navigation at the bottom where a thumb is, one column of
 * content, the detail pane over the top of it rather than beside it.
 *
 * The board keeps its horizontal scroll rather than reflowing into cards:
 * columns of numbers are compared down the column, and stacked cards throw
 * that away. Simple is the default column set, which is what makes the
 * remaining scroll short.
 */
@media (max-width: 700px) {
  .shell {
    grid-template-rows: 26px 42px 1fr 50px;
    grid-template-columns: 1fr;
    grid-template-areas:
      "ticker"
      "topbar"
      "workspace"
      "rail";
    /* dvh, not vh: mobile browsers count their own address bar in vh and
       push the nav under it. */
    height: 100dvh;
  }

  /* The scrolling item strip is desktop ambience; the account metrics are
     the part worth 26px of a phone. */
  .ticker-strip {
    display: none;
  }
  .ticker-fixed {
    border-left: none;
    justify-content: space-between;
    width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .brand small,
  .cmd-hint,
  #show-help,
  .conn span:not(.dot) {
    display: none;
  }
  .topbar {
    gap: 6px;
    padding: 0 8px;
  }

  .rail {
    flex-direction: row;
    gap: 0;
    padding: 3px 4px;
    border-right: none;
    border-top: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: none;
  }
  .rail-item {
    flex: none;
    width: auto;
    flex-direction: column;
    justify-content: center;
    gap: 1px;
    padding: 4px 9px;
    font-size: 9px;
    text-align: center;
  }
  .rail-item .glyph {
    font-size: 15px;
    width: auto;
  }
  .rail-item .key,
  .rail-item .count {
    display: none;
  }
  .rail-item[aria-current="true"] {
    box-shadow: inset 0 2px 0 var(--series-1);
  }
  .rail-spacer,
  #toggle-rail {
    display: none;
  }

  .side-pane {
    top: 68px;
    bottom: 50px;
    width: 100vw;
    min-width: 0;
  }

  .pane-scroll {
    padding: 8px 8px 24px;
  }
  /* Wrapped, the six filters became six full-width rows and pushed the board
     off the screen. One scrolling row instead: the first two are the ones
     anyone touches, and the view name is already lit up in the nav. */
  .filter-row {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    align-items: center;
    padding: 6px 8px;
    gap: 8px;
  }
  .filter-row > * {
    flex: none;
  }
  .filter-row .field-label,
  .filter-row .spacer {
    display: none;
  }
  .filter-row input[type="number"],
  .filter-row input[type="text"],
  .filter-row select {
    min-width: 76px;
  }
  .grid-2 {
    grid-template-columns: 1fr;
  }
  .card-head {
    flex-wrap: wrap;
  }
  /* The card heading and its counts wrap to two lines; the controls that
     were pushed right by .spacer would otherwise land alone on a third. */
  .card-head .spacer {
    margin-left: 0;
  }
  .tiles {
    grid-template-columns: repeat(2, 1fr);
  }
  .tile .tile-value {
    font-size: 17px;
  }

  /* Touch targets: 11px buttons are a desktop affordance. */
  button.tiny,
  a.btn-link.tiny {
    padding: 5px 10px;
    font-size: 12px;
  }
  button.term {
    width: 18px;
    height: 18px;
    font-size: 11px;
    opacity: 1;
  }
  .glossary {
    width: calc(100vw - 16px);
  }
}

/* --- sign-in page ------------------------------------------------------ */

.auth-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  background: var(--page);
}

.auth-card {
  width: min(420px, 100%);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 22px 24px 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.auth-brand .mark {
  color: var(--series-1);
  font-size: 20px;
}

.auth-brand h1 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0.02em;
}

.auth-brand small {
  font-size: 11px;
  color: var(--text-muted);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 16px;
}

.auth-form h2 {
  margin: 0;
  font-size: 14px;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.auth-field > span {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.auth-field > span em {
  font-style: normal;
  text-transform: none;
  letter-spacing: 0;
}

.auth-field input {
  font: inherit;
  font-size: 13px;
  padding: 7px 9px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--text-primary);
  width: 100%;
}

.auth-field input.mono {
  font-family: var(--mono);
  letter-spacing: 0.08em;
}

.auth-field small {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}

.auth-form button.primary {
  padding: 8px 12px;
  font-size: 13px;
}

.auth-row {
  display: flex;
  gap: 8px;
}

.auth-switch {
  margin: 0;
  font-size: 12px;
  color: var(--text-secondary);
}

.auth-check {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--text-secondary);
}

button.linky {
  border: none;
  background: none;
  padding: 0;
  color: var(--series-1);
  font-size: inherit;
  text-decoration: underline;
}

.auth-qr {
  display: grid;
  place-items: center;
  padding: 10px;
  background: #fff;
  border-radius: var(--radius);
}

.auth-qr svg {
  width: 168px;
  height: 168px;
}

.recovery-codes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 12px;
  margin: 0;
  padding: 10px 12px 10px 30px;
  background: var(--surface-3);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 12px;
}

.auth-foot {
  margin: 16px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.5;
}

.toast[data-tone="good"] {
  border-color: var(--good);
}

.toast[data-tone="critical"] {
  border-color: var(--critical);
}

/* --- account chrome ---------------------------------------------------- */

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px 2px 3px;
  border-radius: 999px;
  background: transparent;
  font-size: 12px;
  color: var(--text-secondary);
}

.user-chip[data-warn="true"] {
  border-color: var(--warning);
}

.user-chip .avatar {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--series-1);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
}

.user-chip .who {
  max-width: 12ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pill[data-tone="warning"] {
  border-color: var(--warning);
  color: var(--warning);
}

.pill[data-tone="good"] {
  border-color: var(--good);
  color: var(--good);
}

/* The line under a truncated board. Dashed, because it is a boundary the
   data does not have -- not another row. */
.withheld {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 9px 14px;
  border-top: 1px dashed var(--border);
  font-size: 12px;
  color: var(--text-muted);
}

.withheld strong {
  color: var(--text-primary);
}

.withheld a {
  margin-left: auto;
}

.mfa-setup {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.mfa-setup .field input {
  min-width: 240px;
}

input[type="password"] {
  font: inherit;
  font-size: 12px;
  padding: 4px 7px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--text-primary);
  min-width: 92px;
}

/* A secret the server will never show again: given room, not a dialog. */
.one-shot {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 0 12px 12px;
  padding: 10px 12px;
  border: 1px solid var(--series-1);
  border-radius: var(--radius);
  background: var(--surface-3);
}

.one-shot .sub {
  display: block;
}

.one-shot code {
  flex: 1;
  min-width: 180px;
  font-size: 14px;
  letter-spacing: 0.06em;
  user-select: all;
}

/* Trading styles: three cards, one of them lit. A preset is a claim about
   how the whole strategy hangs together, so it gets prose, not a radio. */
.style-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
  padding: 12px;
}

.style {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  text-align: left;
  font: inherit;
  color: var(--text-primary);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}

.style:hover {
  border-color: var(--series-1);
}

.style[aria-pressed="true"] {
  border-color: var(--series-1);
  background: var(--surface-3);
  box-shadow: inset 2px 0 0 var(--series-1);
}

.style strong {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.style .sub {
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.45;
  white-space: normal;
}

.style-facts {
  margin-top: auto;
  padding-top: 4px;
  color: var(--text-muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  white-space: normal;
}

/* A preset trimmed to fit the bank. Amber rather than muted: it is a change
   to what the card above it promises, not a footnote. */
.style-note {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
  color: var(--warning);
  font-size: 11px;
  line-height: 1.45;
  white-space: normal;
}

/* --- first-run setup ---------------------------------------------------- */

/* The dialog is a frame with two panes: the questions scroll inside it, the
   buttons are always on screen. A short laptop viewport otherwise hides the
   only way out of the form below the fold. */
.modal.setup {
  width: min(700px, 94vw);
  max-height: 92vh;
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.setup-scroll {
  overflow-y: auto;
  /* A flex child only scrolls if it is allowed to shrink past its content. */
  min-height: 0;
  padding: 16px 18px 6px;
}

.setup-foot {
  border-top: 1px solid var(--border);
  padding: 10px 18px 12px;
  background: var(--surface-1);
}

.setup-foot .note {
  margin: 8px 0 0;
}

/* Three choices side by side in a dialog, not the two-and-a-stray-one the
   card grid falls into at this width. */
.modal.setup .style-grid {
  grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
  gap: 8px;
  padding: 0;
}

.modal.setup .style {
  padding: 10px;
  gap: 4px;
}

/* --- legal pages -------------------------------------------------------
   Long-form prose, which the rest of this stylesheet has no use for: wider
   line height, a readable measure, and nothing else on the page. */

body.legal-page {
  display: block;
  background: var(--page);
  overflow: auto;
}

.legal {
  max-width: 720px;
  margin: 0 auto;
  padding: 32px 20px 64px;
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.65;
}

.legal h1 {
  margin: 4px 0 8px;
  font-size: 26px;
  letter-spacing: -0.01em;
}

.legal h2 {
  margin: 32px 0 8px;
  font-size: 15px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.legal p,
.legal li {
  color: var(--text-primary);
}

.legal ul {
  margin: 8px 0;
  padding-left: 20px;
}

.legal li {
  margin-bottom: 6px;
}

.legal-summary {
  margin: 0;
  padding: 12px 14px;
  background: var(--surface-2);
  border-left: 3px solid var(--series-1);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-secondary);
}

.legal-back,
.legal-date {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

.legal-date {
  margin-top: 10px;
}

.legal a {
  color: var(--series-1);
}

.legal-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin-top: 40px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
}

.auth-legal {
  margin-top: 8px;
  padding-top: 0;
  border-top: 0;
  text-align: center;
}

.auth-legal a {
  color: var(--text-secondary);
}
