/* Design system: "Dark Mode (OLED)" with the dashboard density scale, from the
   ui-ux-pro-max reasoning tables. Committed to dark on purpose — the style is
   flagged light-not-recommended, and this is read next to a broker app.
   Typography: Fira Sans for prose, Fira Code wherever digits have to line up. */

:root {
  color-scheme: dark;

  /* surfaces */
  --bg:        #020617;
  --card:      #0E1223;
  --muted:     #1A1E2F;
  --border:    #334155;
  --border-soft: #1E2439;

  /* ink */
  --fg:        #F8FAFC;
  --fg-muted:  #94A3B8;
  --fg-dim:    #64748B;

  /* semantics: separate from the accent, and never the only signal */
  --accent:    #22C55E;
  --on-accent: #0F172A;
  --up:        #26A69A;
  --down:      #EF5350;
  --warn:      #F0B429;
  --danger:    #EF4444;

  /* dense dashboard scale */
  --s1: .25rem; --s2: .5rem; --s3: .75rem; --s4: 1rem;
  --s5: 1.5rem; --s6: 2rem;  --s7: 3rem;

  --r1: 6px; --r2: 10px; --r3: 14px;
  --tap: 44px;              /* iOS minimum; Android 48dp is met by padding */
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);

  --f-sans: "Fira Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono: "Fira Code", ui-monospace, "SF Mono", Menlo, monospace;

  --ease: cubic-bezier(.2, .7, .3, 1);
  --fast: 160ms;
  --slow: 280ms;
}

* { box-sizing: border-box; }

/* A class that sets display beats the user agent's [hidden] rule, which is how
   a "hidden" flex button ends up visible. Restate it with weight. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--f-sans);
  font-size: 16px;
  line-height: 1.5;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  /* room for the bottom bar plus the home indicator */
  padding-bottom: calc(64px + var(--s5) + var(--safe-b));
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r1);
}

.tnum { font-variant-numeric: tabular-nums; }

/* --- app bar -------------------------------------------------------------- */

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: calc(var(--s3) + var(--safe-t)) var(--s4) var(--s3);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-soft);
}

.top h1 {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: .01em;
  margin: 0;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  margin-left: calc(var(--s2) * -1);
  background: none;
  border: none;
  border-radius: var(--r2);
  color: var(--accent);
  cursor: pointer;
  transition: background var(--fast) var(--ease);
}
.icon-btn:hover { background: var(--muted); }
.icon-btn:active { background: var(--border-soft); }
.icon-btn svg { width: 22px; height: 22px; }

/* Status is a dot plus a word: colour is never the only signal. */
.status {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  font-family: var(--f-mono);
  font-size: .68rem;
  font-weight: 500;
  letter-spacing: .02em;
  padding: var(--s1) var(--s2);
  border-radius: var(--r1);
  background: var(--muted);
  color: var(--fg-muted);
  white-space: nowrap;
}
.status .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.status.ok    { color: var(--up); }
.status.stale { color: var(--warn); }
.status.bad   { color: var(--down); }

/* --- layout --------------------------------------------------------------- */

main { padding: var(--s4); max-width: 56rem; margin: 0 auto; }
.view[hidden], .panel[hidden] { display: none; }

@media (min-width: 768px) { main { padding: var(--s5); } }

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

.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s3); }
@media (min-width: 700px) { .cards.grid2 { grid-template-columns: 1fr 1fr; } }

.row {
  background: var(--card);
  border: 1px solid var(--border-soft);
  border-radius: var(--r3);
  padding: var(--s3) var(--s4);
  min-height: var(--tap);
  display: grid;
  gap: var(--s2);
  cursor: pointer;
  transition: border-color var(--fast) var(--ease), background var(--fast) var(--ease);
}
.row:hover { border-color: var(--border); background: #101529; }
.row:active { background: var(--muted); }

.row-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s3);
}
.sym { font-size: 1.05rem; font-weight: 600; letter-spacing: .02em; }
.row-price { font-family: var(--f-mono); font-size: 1.05rem; font-weight: 500; }

.row-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  font-size: .78rem;
  color: var(--fg-dim);
}
.facts { display: flex; gap: var(--s3); flex-wrap: wrap; font-family: var(--f-mono); }

/* --- chips ---------------------------------------------------------------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s1);
  font-family: var(--f-mono);
  font-size: .66rem;
  font-weight: 500;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: .2em .5em;
  border-radius: var(--r1);
  border: 1px solid currentColor;
  white-space: nowrap;
}
.chip.up, .chip.alcista { color: var(--up); }
.chip.down, .chip.bajista { color: var(--down); }
.chip.neutral, .chip.info { color: var(--fg-dim); }
.chip.warning { color: var(--warn); }
.chip.critical { color: var(--danger); }
.chip.on { color: var(--accent); }
.chip.off { color: var(--fg-dim); }
.chip.solid { background: color-mix(in srgb, currentColor 14%, transparent); border-color: transparent; }

/* --- detail head ---------------------------------------------------------- */

.head { margin-bottom: var(--s4); }
.head-price {
  display: flex;
  align-items: baseline;
  gap: var(--s3);
  flex-wrap: wrap;
}
.big {
  font-family: var(--f-mono);
  font-size: clamp(2rem, 9vw, 2.6rem);
  font-weight: 600;
  letter-spacing: -.02em;
  line-height: 1.05;
}
.delta { font-family: var(--f-mono); font-size: 1rem; font-weight: 500; }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }

.coverage {
  margin: var(--s2) 0 0;
  font-size: .74rem;
  color: var(--fg-dim);
  font-family: var(--f-mono);
}

/* --- tabs ----------------------------------------------------------------- */

.tabs {
  display: flex;
  gap: var(--s1);
  background: var(--muted);
  padding: var(--s1);
  border-radius: var(--r2);
  margin-bottom: var(--s4);
}
.tab {
  flex: 1;
  min-height: 38px;
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--fg-muted);
  font: inherit;
  font-size: .86rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}
.tab:hover { color: var(--fg); }
.tab[aria-selected="true"] {
  background: var(--card);
  color: var(--fg);
  font-weight: 600;
  /* Two dark greys a shade apart is not enough to say which one is on. */
  box-shadow: inset 0 -2px 0 var(--accent);
}

/* --- ranges --------------------------------------------------------------- */

.ranges { display: flex; gap: var(--s2); margin-bottom: var(--s3); flex-wrap: wrap; }
.range {
  min-width: 46px;
  min-height: var(--tap);
  padding: 0 var(--s3);
  background: var(--card);
  border: 1px solid var(--border-soft);
  border-radius: var(--r2);
  color: var(--fg-muted);
  font-family: var(--f-mono);
  font-size: .78rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color var(--fast) var(--ease), color var(--fast) var(--ease);
}
.range:hover { color: var(--fg); border-color: var(--border); }
.range[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--card));
}

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

.chart {
  background: var(--card);
  border: 1px solid var(--border-soft);
  border-radius: var(--r3);
  padding: var(--s2) var(--s1) 0;
  min-height: 220px;
  overflow: hidden;
}

.legend {
  display: flex;
  gap: var(--s4);
  flex-wrap: wrap;
  font-family: var(--f-mono);
  font-size: .72rem;
  color: var(--fg-muted);
  margin: var(--s3) 0 var(--s4);
}
.legend span { display: inline-flex; align-items: center; gap: var(--s2); }
/* Series differ by dash pattern as well as hue, so the chart still reads
   without colour vision. */
.legend i { width: 16px; height: 0; border-top-width: 2px; border-top-style: solid; }

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

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr));
  gap: var(--s2);
  margin: 0;
}
.stat {
  background: var(--card);
  border: 1px solid var(--border-soft);
  border-radius: var(--r2);
  padding: var(--s2) var(--s3);
}
.stat dt {
  font-size: .62rem;
  font-weight: 500;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--fg-dim);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat dd {
  margin: 0;
  font-family: var(--f-mono);
  font-size: 1.02rem;
  font-weight: 500;
  letter-spacing: -.01em;
}
.stat dd.na { color: var(--fg-dim); font-weight: 400; }
.stat dd.up { color: var(--up); }
.stat dd.down { color: var(--down); }

/* A hairline that encodes the reading's position in its own range. */
.gauge {
  height: 3px;
  background: var(--muted);
  border-radius: 2px;
  margin-top: var(--s2);
  overflow: hidden;
  color: var(--accent);
}
.gauge i { display: block; height: 100%; background: currentColor; border-radius: 2px; }
/* The tile's own tone wins when the reading is at an extreme. */
.stat dd.up + .gauge { color: var(--up); }
.stat dd.down + .gauge { color: var(--down); }

/* --- alerts --------------------------------------------------------------- */

.alert {
  background: var(--card);
  border: 1px solid var(--border-soft);
  border-left: 3px solid var(--border);
  border-radius: var(--r2);
  padding: var(--s3) var(--s4);
  display: grid;
  gap: var(--s2);
}
.alert.is-on { border-left-color: var(--accent); }
.alert.is-off { border-left-color: var(--border-soft); opacity: .68; }
.alert-name { font-family: var(--f-mono); font-size: .92rem; font-weight: 500; }
.params {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
  font-family: var(--f-mono);
  font-size: .72rem;
  color: var(--fg-muted);
}
.params b { background: var(--muted); padding: .1em .4em; border-radius: var(--r1); font-weight: 400; }

.event { border-left-width: 3px; }
.event.info { border-left-color: var(--fg-dim); }
.event.warning { border-left-color: var(--warn); }
.event.critical { border-left-color: var(--danger); }

/* --- misc ----------------------------------------------------------------- */

.field { display: grid; gap: var(--s2); margin-bottom: var(--s3); }
.field span { font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; color: var(--fg-dim); }
select {
  font: inherit;
  font-family: var(--f-sans);
  min-height: var(--tap);
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--border-soft);
  border-radius: var(--r2);
  padding: 0 var(--s3);
  cursor: pointer;
}
select:hover { border-color: var(--border); }

.section-h {
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--fg-dim);
  margin: var(--s5) 0 var(--s3);
}

.note { font-size: .76rem; color: var(--fg-dim); font-family: var(--f-mono); margin: var(--s3) 0 0; }

.notice {
  background: var(--card);
  border: 1px solid var(--border-soft);
  border-radius: var(--r2);
  padding: var(--s4);
  font-size: .86rem;
  color: var(--fg-muted);
}
.notice code {
  font-family: var(--f-mono);
  font-size: .85em;
  background: var(--muted);
  padding: .12em .4em;
  border-radius: var(--r1);
  color: var(--fg);
}

.toast {
  position: fixed;
  left: var(--s4);
  right: var(--s4);
  bottom: calc(var(--s4) + var(--safe-b));
  z-index: 20;
  background: var(--card);
  border: 1px solid var(--danger);
  border-radius: var(--r2);
  padding: var(--s3) var(--s4);
  font-size: .84rem;
  color: var(--down);
  box-shadow: 0 8px 28px rgb(2 6 23 / .6);
}

/* Subtle entrance: 300ms, one direction, disabled when asked. */
.reveal { opacity: 0; transform: translateY(8px); }
.reveal.in {
  opacity: 1;
  transform: none;
  transition: opacity var(--slow) var(--ease), transform var(--slow) var(--ease);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .reveal { opacity: 1; transform: none; }
}

/* uPlot theming */
.u-select { background: color-mix(in srgb, var(--accent) 20%, transparent); }
.u-cursor-x, .u-cursor-y { border-color: var(--border) !important; }


/* --- bottom navigation ---------------------------------------------------- */
/* Two destinations today, room for five. Above that a bar stops being a map
   and starts being a menu. */

.bottom {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  gap: var(--s1);
  padding: var(--s2) var(--s2) calc(var(--s2) + var(--safe-b));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-soft);
}

.nav-item {
  flex: 1;
  min-height: var(--tap);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: var(--s1);
  background: none;
  border: none;
  border-radius: var(--r2);
  color: var(--fg-dim);
  font: inherit;
  font-size: .68rem;
  font-weight: 500;
  letter-spacing: .02em;
  cursor: pointer;
  transition: color var(--fast) var(--ease), background var(--fast) var(--ease);
}
.nav-item svg { width: 21px; height: 21px; }
.nav-item:hover { color: var(--fg-muted); }
.nav-item[aria-current="page"] { color: var(--accent); background: color-mix(in srgb, var(--accent) 9%, transparent); }

@media (min-width: 768px) {
  .bottom { max-width: 22rem; margin: 0 auto var(--s4); border-radius: var(--r3); border: 1px solid var(--border-soft); }
}

/* --- portfolio ------------------------------------------------------------ */

.kicker {
  margin: 0 0 var(--s1);
  font-size: .66rem;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--fg-dim);
}

.notice.warn { border-color: var(--warn); color: var(--warn); }

/* A holding row carries its own weight bar: the allocation is the thing you
   scan for, and a number alone does not show concentration. */
.holding {
  background: var(--card);
  border: 1px solid var(--border-soft);
  border-radius: var(--r3);
  padding: var(--s3) var(--s4);
  display: grid;
  gap: var(--s2);
  cursor: pointer;
  transition: border-color var(--fast) var(--ease), background var(--fast) var(--ease);
}
.holding:hover { border-color: var(--border); background: #101529; }
.holding:active { background: var(--muted); }

.holding .qty { font-family: var(--f-mono); font-size: .76rem; color: var(--fg-dim); }
.holding .value { font-family: var(--f-mono); font-size: 1.05rem; font-weight: 500; }
.holding .pnl { font-family: var(--f-mono); font-size: .8rem; font-weight: 500; }
.holding .pnl.up { color: var(--up); }
.holding .pnl.down { color: var(--down); }

.weight {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: var(--s3);
}
.weight-bar { height: 4px; background: var(--muted); border-radius: 2px; overflow: hidden; }
.weight-bar i { display: block; height: 100%; background: var(--accent); opacity: .75; border-radius: 2px; }
.weight-pct { font-family: var(--f-mono); font-size: .7rem; color: var(--fg-dim); min-width: 3.2em; text-align: right; }

/* --- ledger rows ---------------------------------------------------------- */

.tx {
  background: var(--card);
  border: 1px solid var(--border-soft);
  border-left: 3px solid var(--border-soft);
  border-radius: var(--r2);
  padding: var(--s2) var(--s3);
  display: grid;
  gap: 2px;
}
.tx.buy { border-left-color: var(--up); }
.tx.sell { border-left-color: var(--down); }
.tx.dividend { border-left-color: var(--accent); }
.tx.split { border-left-color: var(--warn); }
.tx.fee { border-left-color: var(--fg-dim); }

.tx-top { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s3); }
.tx-kind { font-family: var(--f-mono); font-size: .8rem; font-weight: 500; }
.tx-cash { font-family: var(--f-mono); font-size: .84rem; }
.tx-cash.in { color: var(--up); }
.tx-cash.out { color: var(--fg-muted); }
.tx-sub { font-family: var(--f-mono); font-size: .7rem; color: var(--fg-dim); display: flex; gap: var(--s3); flex-wrap: wrap; }

/* --- section headings with an action -------------------------------------- */

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
}
.section-head .section-h { margin-bottom: var(--s3); }

.add {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  min-height: 36px;
  padding: 0 var(--s3);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: var(--r2);
  color: var(--accent);
  font: inherit;
  font-size: .8rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--fast) var(--ease);
}
.add:hover { background: color-mix(in srgb, var(--accent) 20%, transparent); }
.add svg { width: 15px; height: 15px; }

/* --- row actions ---------------------------------------------------------- */

.alert-actions { display: flex; gap: var(--s2); }

.mini {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s1);
  min-width: 36px;
  min-height: 36px;
  padding: 0 var(--s2);
  background: none;
  border: 1px solid var(--border-soft);
  border-radius: var(--r1);
  color: var(--fg-muted);
  font: inherit;
  font-size: .7rem;
  cursor: pointer;
  transition: color var(--fast) var(--ease), border-color var(--fast) var(--ease);
}
.mini:hover { color: var(--fg); border-color: var(--border); }
.mini.danger:hover { color: var(--danger); border-color: var(--danger); }
.mini svg { width: 15px; height: 15px; }

/* --- bottom sheet --------------------------------------------------------- */
/* <dialog> gives the focus trap, Esc and inertness for free; reimplementing
   any of that by hand is how a modal ends up unusable with a keyboard. */

.sheet {
  width: 100%;
  max-width: 32rem;
  margin: auto auto 0;
  padding: 0;
  border: 1px solid var(--border-soft);
  border-bottom: none;
  border-radius: var(--r3) var(--r3) 0 0;
  background: var(--card);
  color: var(--fg);
  max-height: 88dvh;
}
.sheet::backdrop { background: rgb(2 6 23 / .72); backdrop-filter: blur(3px); }

@media (min-width: 640px) {
  .sheet { margin: auto; border-radius: var(--r3); border-bottom: 1px solid var(--border-soft); }
}

.sheet form { display: flex; flex-direction: column; max-height: 88dvh; }

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  padding: var(--s4) var(--s4) var(--s3);
  border-bottom: 1px solid var(--border-soft);
}
.sheet-head h2 { margin: 0; font-size: 1.02rem; font-weight: 600; }

.sheet-body {
  padding: var(--s4);
  padding-bottom: var(--s3);
  overflow-y: auto;
  display: grid;
  gap: var(--s3);
}

.sheet-foot {
  display: flex;
  gap: var(--s2);
  padding: var(--s3) var(--s4) calc(var(--s4) + var(--safe-b));
  border-top: 1px solid var(--border-soft);
}

.btn {
  flex: 1;
  min-height: var(--tap);
  border-radius: var(--r2);
  border: 1px solid transparent;
  font: inherit;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease);
}
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 88%, #fff); }
.btn.primary:disabled { opacity: .55; cursor: progress; }
.btn.ghost { background: none; border-color: var(--border-soft); color: var(--fg-muted); }
.btn.ghost:hover { color: var(--fg); border-color: var(--border); }

/* --- form fields ---------------------------------------------------------- */
/* Labels are always visible: a placeholder disappears the moment there is a
   value, exactly when the user needs to know what the field was. */

.f {
  display: grid;
  gap: var(--s2);
}
.f > label {
  font-size: .72rem;
  font-weight: 500;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--fg-dim);
}
.f input, .f select, .f textarea {
  font: inherit;
  font-family: var(--f-mono);
  font-size: .92rem;
  min-height: var(--tap);
  width: 100%;
  background: var(--muted);
  color: var(--fg);
  border: 1px solid var(--border-soft);
  border-radius: var(--r2);
  padding: var(--s2) var(--s3);
}
.f textarea { font-family: var(--f-sans); min-height: 68px; resize: vertical; }
/* The report context is a page of pasted text, not a note. */
#f-context { min-height: 180px; font-size: .86rem; line-height: 1.5; }
.f input:hover, .f select:hover { border-color: var(--border); }
.f input:focus, .f select:focus, .f textarea:focus { border-color: var(--accent); }
.f .hint { font-size: .74rem; color: var(--fg-dim); font-family: var(--f-sans); }

.f-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }

.params-box {
  display: grid;
  gap: var(--s3);
  padding: var(--s3);
  background: var(--muted);
  border-radius: var(--r2);
}
.params-box:empty { display: none; }

.sheet-error {
  margin: 0 var(--s4);
  padding: var(--s3);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border: 1px solid var(--danger);
  border-radius: var(--r2);
  color: var(--down);
  font-size: .84rem;
}

.toast.ok { border-color: var(--accent); color: var(--accent); }

/* --- login gate ----------------------------------------------------------- */
/* Shown before anything else when the deployment asks for a credential. The
   app behind it is never rendered with empty data first: a dashboard that
   flashes zeros and then asks who you are looks broken. */

.gate {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: var(--s4);
  background: var(--bg);
}

.gate-card {
  width: 100%;
  max-width: 22rem;
  display: grid;
  gap: var(--s3);
  justify-items: center;
  text-align: center;
}
.gate-mark { width: 56px; height: 56px; color: var(--accent); }
.gate-card h1 { margin: 0; font-size: 1.3rem; font-weight: 600; letter-spacing: -.01em; }
.gate-lead { margin: 0; font-size: .88rem; color: var(--fg-muted); }
.gate-card form { width: 100%; display: grid; gap: var(--s3); margin-top: var(--s2); }
.gate-card .sheet-error { margin: 0; }
#gate-fields { display: grid; gap: var(--s3); }

.logout {
  position: fixed;
  right: var(--s4);
  bottom: calc(76px + var(--safe-b));
  z-index: 9;
  min-height: 34px;
  padding: 0 var(--s3);
  background: var(--card);
  border: 1px solid var(--border-soft);
  border-radius: var(--r2);
  color: var(--fg-dim);
  font: inherit;
  font-size: .74rem;
  cursor: pointer;
}
.logout:hover { color: var(--fg-muted); border-color: var(--border); }

/* --- AI report and suggestions -------------------------------------------- */

.suggestion {
  background: var(--card);
  border: 1px solid var(--border-soft);
  border-left: 3px solid var(--accent);
  border-radius: var(--r2);
  padding: var(--s3) var(--s4);
  display: grid;
  gap: var(--s2);
}
/* An "action" is advice the engine cannot run; it should not look like a rule
   waiting to be switched on. */
.suggestion.advice { border-left-color: var(--fg-dim); }
.suggestion .why { font-size: .85rem; color: var(--fg-muted); margin: 0; }

.priority { font-family: var(--f-mono); font-size: .64rem; text-transform: uppercase; letter-spacing: .06em; }
.priority.high { color: var(--down); }
.priority.medium { color: var(--warn); }
.priority.low { color: var(--fg-dim); }

.report {
  background: var(--card);
  border: 1px solid var(--border-soft);
  border-radius: var(--r2);
  margin-bottom: var(--s3);
  overflow: hidden;
}
.report summary {
  padding: var(--s3) var(--s4);
  cursor: pointer;
  font-family: var(--f-mono);
  font-size: .78rem;
  color: var(--fg-muted);
  list-style: none;
  display: flex;
  justify-content: space-between;
  gap: var(--s3);
  align-items: baseline;
}
.report summary::-webkit-details-marker { display: none; }
.report summary:hover { color: var(--fg); }
.report[open] summary { border-bottom: 1px solid var(--border-soft); }
.report .body {
  padding: var(--s4);
  font-size: .88rem;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.report .prov {
  font-family: var(--f-mono);
  font-size: .7rem;
  color: var(--fg-dim);
  padding: 0 var(--s4) var(--s4);
  overflow-wrap: anywhere;
}

/* Minimal markdown, rendered from escaped text — see renderReportBody(). */
.report .body .md-h {
  display: block;
  margin: var(--s4) 0 var(--s2);
  color: var(--fg);
  font-size: .94rem;
  letter-spacing: -.01em;
}
.report .body .md-h:first-child { margin-top: 0; }
.report .body .md-li { display: block; padding-left: var(--s3); text-indent: -0.7rem; }
.report .body .md-li::before { content: "· "; color: var(--accent); }
.report .body .md-hr {
  display: block;
  height: 1px;
  background: var(--border-soft);
  margin: var(--s4) 0;
}

/* --- fundamentals table --------------------------------------------------- */
/* Periods across, metrics down: the comparison people actually make is one
   line through time, and that reads better as a row than as a column. */

.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-bottom: var(--s3); }

table.grid {
  border-collapse: collapse;
  font-family: var(--f-mono);
  font-size: .8rem;
  font-variant-numeric: tabular-nums;
  min-width: 100%;
}
table.grid th, table.grid td { padding: .45rem .7rem; white-space: nowrap; text-align: right; }

table.grid thead th {
  font-size: .68rem;
  letter-spacing: .05em;
  color: var(--fg-dim);
  border-bottom: 1px solid var(--border);
  font-weight: 500;
}

/* The metric name is the row header and has to stay put while the periods
   scroll sideways. */
table.grid th[scope="row"], table.grid thead th:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  text-align: left;
  background: var(--bg);
  font-family: var(--f-sans);
  font-size: .76rem;
  color: var(--fg-muted);
  font-weight: 400;
  padding-left: 0;
}
table.grid tbody tr { border-bottom: 1px solid var(--border-soft); }
table.grid tbody tr:last-child { border-bottom: none; }
table.grid td { color: var(--fg); }
table.grid td.na { color: var(--fg-dim); }
table.grid td.up { color: var(--up); }
table.grid td.down { color: var(--down); }

/* --- working indicator ---------------------------------------------------- */
/* A report takes tens of seconds, so a bare spinner would be an unexplained
   wait. It names the step it is on — the server reports the real one — and
   counts, so the wait has a shape. */

.working {
  display: flex;
  align-items: center;
  gap: var(--s3);
  background: var(--card);
  border: 1px solid var(--border-soft);
  border-radius: var(--r2);
  padding: var(--s3) var(--s4);
  margin-bottom: var(--s3);
  /* Reserved height, so appearing and disappearing does not shift the list. */
  min-height: 60px;
}

.working-text { display: grid; gap: 2px; min-width: 0; }
.working-text b { font-size: .88rem; font-weight: 500; }
.working-text small {
  font-family: var(--f-mono);
  font-size: .72rem;
  color: var(--fg-dim);
  font-variant-numeric: tabular-nums;
}

.spinner {
  flex: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--muted);
  border-top-color: var(--accent);
  animation: spin 720ms linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  /* No rotation: a complete ring still reads as "busy" beside the live text,
     and the step name is what actually carries the information. */
  .spinner {
    animation: none;
    border-color: var(--accent);
    opacity: .55;
  }
}

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

.search { display: flex; gap: var(--s2); margin-bottom: var(--s3); }
.search input {
  flex: 1;
  min-width: 0;
  min-height: var(--tap);
  font: inherit;
  font-family: var(--f-mono);
  font-size: .92rem;
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--border-soft);
  border-radius: var(--r2);
  padding: 0 var(--s3);
}
.search input::placeholder { color: var(--fg-dim); }
.search input:hover { border-color: var(--border); }
.search input:focus { border-color: var(--accent); }
.search .add { min-height: var(--tap); }

/* Visible to a screen reader, not on screen: the placeholder is a hint, and a
   field with only a hint has no name once it has a value. */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* A quiet aside in the legend: how to undo a drag-zoom, where the zoom is. */
.legend .hint-inline { color: var(--fg-dim); font-size: .68rem; }

/* How much of a list is on screen, next to its heading. */
.count {
  font-family: var(--f-mono);
  font-size: .68rem;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: var(--fg-dim);
  margin-left: var(--s2);
}
#tx-more { margin-top: var(--s2); }

/* --- pager ---------------------------------------------------------------- */
/* Two arrows and a position. Numbered pages would be more control than a list
   of this size ever needs, and more to hit on a phone. */

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s3);
  margin-top: var(--s3);
}

.pager button {
  min-width: var(--tap);
  min-height: var(--tap);
  background: var(--card);
  border: 1px solid var(--border-soft);
  border-radius: var(--r2);
  color: var(--fg-muted);
  font: inherit;
  font-size: 1rem;
  cursor: pointer;
  transition: color var(--fast) var(--ease), border-color var(--fast) var(--ease);
}
.pager button:hover:not(:disabled) { color: var(--fg); border-color: var(--border); }
.pager button:disabled { opacity: .35; cursor: default; }

.pager .position {
  font-family: var(--f-mono);
  font-size: .76rem;
  color: var(--fg-dim);
  font-variant-numeric: tabular-nums;
  min-width: 8em;
  text-align: center;
}

/* The movements heading is just a count now; keep it aligned with its button. */
#ptab-movements .section-head { align-items: center; margin-bottom: var(--s3); }
#ptab-movements .count { margin-left: 0; }

/* The curve carries two controls: what it shows, and how far back. */
.curve-controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s3);
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--s3);
}
.curve-controls .ranges { margin-bottom: 0; }

/* Money entering or leaving the account, rather than moving between cash and
   shares — a different kind of event, so a different edge. */
.tx.deposit { border-left-color: var(--accent); }
.tx.withdraw { border-left-color: var(--warn); }

/* A quiet action that sits inside a line of text: it has to be reachable
   without competing with the reading it belongs to. */
.linkish {
  background: none;
  border: 0;
  padding: 8px 4px;          /* keeps the 44px target without a visible box */
  min-height: 44px;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.linkish svg { width: 14px; height: 14px; fill: currentColor; }
.linkish:disabled { color: var(--muted); cursor: default; }
.linkish.working svg { animation: spin 1s linear infinite; }
@media (prefers-reduced-motion: reduce) {
  .linkish.working svg { animation: none; }
}
