:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #15181d;
  --muted: #5f6773;
  --accent: #2554d9;
  --accent-text: #ffffff;
  --up: #12813f;
  --down: #c62828;
  --up-bg: #e5f5ec;
  --up-text: #0f7336; /* green text on a tinted background (the up-bg chips, the selected fund card): 4.5:1 there */
  --down-bg: #fbe9e9;
  --warn-bg: #fff4d6;
  --warn-text: #6b4a00;
  --radius: 10px;
  /* Charts: the validated categorical palette (identity), chrome, and the de-emphasis grey. */
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #4a3aa7; --series-8: #e34948;
  --series-other: #b4b2aa;
  --series-cash: #7d7b74;
  --series-compare: #898781; /* the index line: grey, but at least 3:1 on the surface */
  --grid: #eceae4;
  --axis: #c3c2b7;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1f232b;
    --border: #2a2f39;
    --text: #e8eaee;
    --muted: #98a0ad;
    --accent: #6d8ff5;
    --accent-text: #0b0d12;
    --up: #3ccf78;
    --down: #ff6b6b;
    --up-bg: #133222;
    --up-text: #3ccf78;
    --down-bg: #3a1a1c;
    --warn-bg: #3a3014;
    --warn-text: #f3d68a;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
    --series-other: #5d5c57;
    --series-cash: #8e8c85;
    --series-compare: #898781;
    --grid: #2a2e36;
    --axis: #3b404b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
.show-sm, .show-md { display: none; }
/* The trade history drops its money columns below 800px: price and realized profit go under the shares. */
@media (max-width: 800px) {
  .hide-md { display: none; }
  .show-md { display: inline; }
  #trades .chip { display: table; margin: 2px 0 0; }
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
h1 { font-size: 18px; }
h2 { font-size: 16px; }
h3 { font-size: 18px; margin-bottom: 12px; }
h4 { font-size: 14px; margin: 18px 0 4px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.up { color: var(--up); }
.down { color: var(--down); }

button, .file-btn {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
}
button:hover, .file-btn:hover { background: var(--surface-2); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.primary:hover { filter: brightness(1.08); background: var(--accent); }
button.danger { color: var(--down); border-color: var(--down); }
button.small-btn { padding: 3px 10px; font-size: 13px; }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select {
  font: inherit;
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
label { display: block; font-size: 13px; color: var(--muted); }
label input { margin-top: 4px; color: var(--text); }

.top {
  display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between;
  padding: 14px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; gap: 8px; align-items: center; }
.brand svg { width: 22px; height: 22px; fill: none; stroke: var(--up); stroke-width: 2; }
.top-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.settings-btn { display: inline-flex; gap: 6px; align-items: center; }
.settings-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.connections { list-style: none; padding: 0; margin: 0 0 8px; display: grid; gap: 8px; }
.connections li { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; font-size: 14px; }
.connections .conn-head { display: flex; flex-wrap: wrap; gap: 4px 10px; justify-content: space-between; align-items: baseline; }
.connections .ok { color: var(--up); font-weight: 600; }
.connections .off { color: var(--warn-text); font-weight: 600; }
.connections p { margin: 4px 0 0; }
.connections code { font-size: 12px; overflow-wrap: anywhere; }

.banner { padding: 10px 16px; background: var(--warn-bg); color: var(--warn-text); font-size: 14px; }

main { max-width: 1100px; margin: 0 auto; padding: 16px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; margin-bottom: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.card .label { font-size: 13px; color: var(--muted); }
.card .big { font-size: 26px; font-weight: 650; margin: 2px 0; font-variant-numeric: proportional-nums; }
.card .sub { font-size: 13px; color: var(--muted); display: grid; grid-template-columns: auto auto; gap: 2px 12px; margin-top: 8px; }
.card .sub span:nth-child(even) { text-align: right; color: var(--text); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; flex-wrap: wrap; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 5px 12px; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-selected="true"], .seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }
.seg.wide { display: flex; margin-bottom: 14px; }
.seg.wide button { flex: 1; padding: 8px; }
#side button[data-side="sell"][aria-pressed="true"] { background: var(--down); color: #fff; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 550; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
td .name { display: block; font-size: 12px; color: var(--muted); max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.empty { color: var(--muted); padding: 12px 10px; white-space: normal; }
.chip { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); color: var(--muted); margin-left: 6px; vertical-align: 1px; }
.chip.buy { background: var(--up-bg); color: var(--up-text); }
.chip.sell { background: var(--down-bg); color: var(--down); }
.chip.results { background: var(--warn-bg); color: var(--warn-text); white-space: nowrap; }
/* the ten-year memory: a pattern that held on the held-out years, and today's regime (descriptive) */
.chip.held { background: var(--up-bg); color: var(--up-text); }
.chip.regime-chip { margin-left: 0; white-space: normal; max-width: 100%; }
.regime-line { margin: 4px 0 10px; }
.regime-line .chip { margin-right: 6px; }
.spark { width: 90px; height: 26px; display: block; }
.spark polyline { fill: none; stroke-width: 1.5; }

.foot { margin: 8px 0 32px; }

dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 20px;
  background: var(--surface); color: var(--text);
  width: min(420px, calc(100vw - 32px));
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
.qty-row { display: flex; gap: 8px; margin-top: 4px; }
.qty-row input { margin-top: 0; }
.facts { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; margin: 10px 0 6px; font-size: 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; text-align: right; }
.note { font-size: 13px; color: var(--muted); margin: 6px 0; }
.error { color: var(--down); font-size: 13px; min-height: 1em; margin: 6px 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 8px 0 10px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }

/* tabs */
.tabs { display: flex; gap: 2px; overflow-x: auto; padding: 0 12px; background: var(--surface); border-bottom: 1px solid var(--border); scrollbar-width: none; }
.tabs a { padding: 10px 12px; color: var(--muted); text-decoration: none; white-space: nowrap; border-bottom: 2px solid transparent; font-size: 14px; }
.tabs a:hover { color: var(--text); }
.tabs a[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

/* notices */
.notices { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.notices:empty { display: none; }
.notice { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-top: 10px; padding: 8px 12px; border-radius: 8px; background: var(--up-bg); font-size: 14px; }
.notice.warn { background: var(--warn-bg); color: var(--warn-text); }
.notice .muted { color: inherit; opacity: .75; }

/* shared bits */
.row { align-items: center; }
.lead { font-size: 16px; }
.sentence { margin: 4px 0; font-weight: 550; }
.sources { font-size: 12px; color: var(--muted); margin: 6px 0; overflow-wrap: anywhere; }
.sources a { color: var(--accent); }
code { font-size: 13px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
select { width: 100%; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; align-items: end; margin: 10px 0; }
.form-grid .wide { grid-column: 1 / -1; }
.form-grid .unit { align-self: center; padding-top: 18px; }
.form-grid .check { display: flex; gap: 8px; align-items: center; color: var(--text); }
.form-grid .check input { width: auto; margin: 0; }
.spacer { flex: 1; }
[hidden] { display: none !important; }

/* AI picks */
.pick-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 8px; }
.col-head { font-size: 14px; margin: 4px 0 8px; }
.pick { border: 1px solid var(--border); border-left: 3px solid var(--up); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; }
.pick.short { border-left-color: var(--down); }
.pick header { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; }
.pick .chips .chip { margin-left: 0; margin-right: 4px; }
.pick p { margin: 6px 0; }
.pick details p { margin: 4px 0 0; }
.pick footer { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 6px; }

/* rules */
.rule { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); align-items: start; }
.rule-body p { margin: 2px 0; }
.rule-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.switch { position: relative; display: inline-block; width: 38px; height: 22px; margin-top: 2px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--border); border-radius: 99px; cursor: pointer; transition: background .15s; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: var(--surface); border-radius: 50%; transition: transform .15s; }
.switch input:checked + span { background: var(--up); }
.switch input:checked + span::before { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* strategist + fund */
.strategy, .decision { border-top: 1px solid var(--border); padding: 12px 0; }
.strategy header, .decision header { display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: baseline; }
.strategy p, .decision p { margin: 6px 0; }
.rules-list, .orders { margin: 6px 0; padding-left: 20px; }
.orders { list-style: none; padding-left: 0; }
.orders li { margin: 4px 0; }
.orders .chip { margin: 0 6px 0 0; }
.backtest { background: var(--surface-2); border-radius: 8px; padding: 8px 12px; margin: 8px 0; }
.backtest .facts { margin: 4px 0; }

/* charts */
.chart { display: block; max-width: 100%; height: auto; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .ref { fill: none; stroke: var(--series-other); stroke-width: 1; stroke-dasharray: 4 4; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line2 { fill: none; stroke: var(--series-compare); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.scorecard { margin-top: 14px; }
.chart .cross { stroke: var(--muted); stroke-width: 1; }
.chart .dot, .chart .end-dot { fill: var(--series-1); stroke: var(--halo, var(--surface)); stroke-width: 2; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart.line-chart { touch-action: pan-y; border-radius: 4px; }
.chart.line-chart:focus { outline: none; }
.chart.line-chart:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tooltip { position: fixed; z-index: 10; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 13px; box-shadow: 0 4px 14px rgb(0 0 0 / .12); width: max-content; max-width: min(320px, calc(100vw - 16px)); }

/* orders waiting for the open */
.pending { border-top: 1px solid var(--border); margin-top: 8px; padding-top: 8px; }
.pending li { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
.pending li button { margin-left: auto; }

/* AI fund controls */
.fund-form { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.fund-new { margin-top: 12px; }
.fund-new summary { cursor: pointer; color: var(--accent); font-size: 14px; }
.fund-form .wide { grid-column: 1 / -1; margin: 0; }
.fund-alert { margin: 0 0 12px; }
.approvals { border-color: var(--accent); }
.approvals li { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; padding: 6px 0; border-top: 1px solid var(--border); }
.approvals li .row { margin-left: auto; }

/* accounts */
.user-chip { display: inline-flex; gap: 8px; align-items: center; flex-wrap: wrap; }
body.locked { overflow: hidden; }
.auth { position: fixed; inset: 0; z-index: 20; background: var(--bg); display: flex; align-items: flex-start; justify-content: center; padding: 10vh 16px 16px; overflow-y: auto; }
.auth-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 24px; }
.auth-card .brand { margin-bottom: 16px; }
.auth-card h2 { font-size: 18px; margin: 0 0 4px; }
.auth-card form { display: grid; gap: 10px; margin-top: 8px; }
.auth-card .links { margin-top: 12px; }
.auth-card a { color: var(--accent); }
.wide-btn { width: 100%; padding: 9px; }
.google { width: 100%; display: flex; gap: 10px; align-items: center; justify-content: center; padding: 9px; margin-top: 12px; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 14px 0 4px; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.invites-list { list-style: none; padding: 0; margin: 8px 0; max-height: 280px; overflow-y: auto; }
.invites-list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--border); overflow-wrap: anywhere; }

@media (max-width: 560px) {
  .fund-form { grid-template-columns: 1fr; }
  .pick-cols { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .unit { padding-top: 0; }
  .rule { grid-template-columns: auto 1fr; }
  .rule-actions { grid-column: 1 / -1; justify-content: flex-start; }
  .card .big { font-size: 22px; }
  .hide-sm { display: none; }
  .show-sm { display: inline; }
  #scorecard th { white-space: normal; }
  th, td { padding: 8px 6px; }
  td:first-child { white-space: normal; }
  #trades td.when { white-space: nowrap; }
  td .name { max-width: 120px; white-space: nowrap; }
  #markets .chip { display: none; }
  #markets .chip.results { display: inline-block; }
  /* the results chip may wrap onto its own line rather than widen the table */
  .chip.results { white-space: normal; display: inline-block; max-width: 100%; margin-left: 0; }
}

.lessons { padding-left: 18px; display: grid; gap: 8px; margin: 8px 0; }
.lessons li { font-size: 14px; }
.lesson-form { margin: 8px 0; }
.lesson-form input { flex: 1; min-width: 0; }
/* the owner's lesson: which of its ideas it's about (optional), so it's tracked like the others */
.lesson-filter { margin-top: 6px; }
.lesson-filter summary { cursor: pointer; color: var(--accent); font-size: 13px; }
.lesson-filter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px 10px; margin: 8px 0 4px; }
.lesson-filter-grid select { margin-top: 4px; }
.lesson-filter-grid .claim { grid-column: span 2; }
.lesson-actions { display: inline-block; white-space: nowrap; }
.lesson-filter p { margin: 4px 0 0; }
/* each lesson's record: learned when, and how it has done since */
.lessons .since { display: inline-block; margin-top: 2px; }
.chip.warn { background: var(--warn-bg); color: var(--warn-text); }
.track-record { margin: 8px 0; }
.decision-skip { margin: 6px 0; }
/* an AI thesis: under a fund position's name, an order or a proposal */
.thesis { display: block; color: var(--muted); white-space: normal; max-width: 360px; margin-top: 2px; }
.orders .thesis { max-width: none; }
.chip.lesson-chip { margin: 2px 0 0 6px; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }
.orders .chip.lesson-chip { margin: 2px 6px 0 0; }
.cal-head { margin-top: 18px; }
.calibration td:first-child { white-space: normal; }
.calibration th { white-space: normal; vertical-align: bottom; }
@media (max-width: 560px) {
  .thesis { max-width: 190px; }
  .calibration th, .calibration td { padding: 8px 5px; }
  .calibration td:first-child { max-width: 90px; } /* so Expected and Realised fit next to it */
}
/* a chart's Table whose headers may wrap, so it fits without scrolling sideways on a desktop */
.chart-table.wrap-head th { white-space: normal; vertical-align: bottom; }
.chart-table.long-table td:first-child { white-space: nowrap; } /* the ten-year studies: each row's name on one line; the table scrolls */

/* ---------- charts ---------- */
.chart text { font-size: 12px; font-family: inherit; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .cat { fill: var(--text); }
.chart .cat-sub { fill: var(--muted); font-size: 11px; }
.chart .cat, .chart .ref-label { paint-order: stroke; stroke: var(--halo); stroke-width: 4px; stroke-linejoin: round; }
.chart { --halo: var(--surface); }
.backtest .chart { --halo: var(--surface-2); }
.chart .val { fill: var(--text); font-weight: 600; paint-order: stroke; stroke: var(--halo); stroke-width: 3px; stroke-linejoin: round; }
.chart .marker { stroke: var(--text); stroke-width: 2; stroke-linecap: round; }
.chart .hit { fill: transparent; pointer-events: all; }
.chart .ring { fill: none; stroke: none; pointer-events: none; }
.chart.stack [data-tip]:focus-visible .hit { stroke: none; }
.chart.stack [data-tip]:focus-visible .ring { stroke: var(--accent); stroke-width: 2; }
.chart [data-tip] { cursor: default; outline: none; }
.chart [data-tip].hot .bar, .chart [data-tip].hot .seg, .chart [data-tip].hot path, .chart [data-tip].hot rect:not(.hit) { filter: brightness(1.12); }
.chart [data-tip].hot .hit { fill: var(--surface-2); opacity: .6; }
.chart [data-tip]:focus-visible .hit, .chart [data-tip].hot:focus-visible .hit { fill: none; stroke: var(--accent); stroke-width: 2; opacity: 1; }
.chart .seg { stroke: none; }
.chart .range { fill: var(--series-1); opacity: .8; } /* about 3:1 on the background in both themes */
.chart .est { fill: var(--series-1); stroke: var(--halo); stroke-width: 2; }
.chart [data-tip].hot .range { opacity: .9; }
.legend-list .swatch-range { width: 16px; height: 6px; border-radius: 3px; background: var(--series-1); opacity: .8; margin-top: 6px; }
.legend-list .swatch-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--series-1); }
.legend-list { list-style: none; display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 0; margin: 6px 0 0; font-size: 13px; }
.legend-list li { display: inline-flex; align-items: flex-start; gap: 6px; }
.legend-list .swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; flex: none; margin-top: 4px; }
.legend-list .swatch.track { box-shadow: inset 0 0 0 1px var(--axis); }
.legend-list .swatch-tick { width: 2px; height: 12px; border-radius: 1px; background: var(--text); margin-top: 3px; }
.legend-list .line-key { width: 16px; height: 2px; border-radius: 1px; background: var(--series-1); display: inline-block; flex: none; margin-top: 9px; }
.legend-list .line-key.compare { background: var(--series-compare); }
.legend-list .line-key.ref { background: none; border-top: 1px dashed var(--muted); height: 0; }
.chart .seg.track { stroke: var(--axis); stroke-width: 1; }
#tooltip .tip-row { display: flex; align-items: center; gap: 6px; }
#tooltip .tip-key { width: 12px; height: 2px; border-radius: 1px; display: inline-block; }
.chart-card { margin: 10px 0 4px; }
.chart-card h3 { font-size: 14px; margin: 0 0 2px; }
.chart-card .caption { margin: 0 0 6px; }
.chart-table { margin-top: 4px; }
.chart-table summary { font-size: 12px; color: var(--muted); cursor: pointer; }
.chart-table .table-wrap { max-height: 320px; overflow: auto; }
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); gap: 12px 20px; }
.chart-grid > * { min-width: 0; }
.chart-grid { align-items: start; }

/* ---------- stock notes: each stock's own history and risk (dossier.js) ---------- */
/* a stock's symbol opens its notes */
.stock-link { font: inherit; font-weight: 650; background: none; border: 0; padding: 0; border-radius: 3px; color: inherit; cursor: pointer; text-decoration: underline dotted; text-decoration-color: var(--muted); text-underline-offset: 3px; white-space: nowrap; }
.stock-link:hover { background: none; color: var(--accent); }
.stock-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.pick-actions { margin-top: 0; justify-content: flex-end; flex-wrap: nowrap; flex: none; }
.stock-dialog { width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow-y: auto; }
.stock-dialog h3 { margin-bottom: 2px; padding-right: 40px; }
/* a close button that stays in reach while the notes scroll */
.dialog-x { position: sticky; top: 0; float: right; z-index: 1; margin: -6px -6px 0 0; background: var(--surface); }
.stock-dialog h4 { margin: 14px 0 4px; }
.stock-sub { margin: 0 0 8px; }
.stock-sub .chip.results { margin-left: 6px; }
.stock-position { margin: 6px 0 4px; padding: 8px 10px; background: var(--surface-2); border-radius: 8px; }
.stock-facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 12px 0; font-size: 14px; }
.stock-facts dt { color: var(--muted); font-size: 13px; padding-top: 1px; }
.stock-facts dd { margin: 0; }
.stock-results-note { margin: 12px 0 4px; }
.stock-records { padding-left: 18px; margin: 4px 0; }
.stock-records li { margin: 4px 0; }
.stock-note textarea { margin-top: 4px; }
.stock-honest { margin-top: 12px; }
textarea { font: inherit; width: 100%; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); resize: vertical; }
/* the owner's note under a fund's position in the stock */
.owner-note { display: block; white-space: normal; max-width: 360px; margin-top: 2px; }
.stock-note .owner-note { max-width: none; margin: 4px 0; }
/* the fund's stops and risk */
.risk-head { margin-top: 16px; }
.risk-uneven { margin: 6px 0 8px; }
.risk-notes { padding-left: 18px; margin: 6px 0; }
.risk-notes li { margin: 3px 0; }
/* markers on a line chart: results days, ex-dates and trades */
.chart .mark { stroke: var(--halo); stroke-width: 1.5; }
.legend-list .marker-key { width: 10px; height: 10px; flex: none; margin-top: 4px; background: var(--c); }
.legend-list .marker-key.dot { border-radius: 50%; }
.legend-list .marker-key.diamond { transform: rotate(45deg) scale(.8); border-radius: 1px; }
.legend-list .marker-key.up { clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.legend-list .marker-key.down { clip-path: polygon(0 0, 100% 0, 50% 100%); }
#tooltip .tip-key.tip-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.chart-table.stock-table td:nth-child(2) { white-space: normal; text-align: left; min-width: 160px; }
@media (max-width: 560px) {
  .stock-results th, .stock-results td { padding: 8px 5px; }
  .stock-facts { grid-template-columns: 1fr; gap: 0; }
  .stock-facts dd { margin-bottom: 8px; }
  .owner-note { max-width: 190px; }
  .stock-dialog { padding: 16px 14px; }
}

/* ---------- the weekly report ("This week", report.js) and your calls ---------- */
.weekly { border-left: 3px solid var(--accent); }
.weekly .panel-head h2 { margin: 0; }
.weekly-fund { font-weight: 400; font-size: 15px; }
.week-pick { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.week-pick select { width: auto; padding: 4px 8px; }
.report-head { margin: 4px 0 6px; }
.report-lines { margin: 6px 0; padding-left: 18px; display: grid; gap: 6px; font-size: 14px; }
.report-lines .report-summary { color: var(--muted); }
/* a lesson's trend line, on its own line under its numbers */
.spark-box { display: inline-block; width: 88px; height: 24px; vertical-align: middle; margin: 2px 0 0; }
.chart.spark-trend .line { stroke-width: 2; }
.chart.spark-trend .pt { fill: var(--series-1); }
.chart.spark-trend .baseline { stroke-dasharray: 2 2; }
.chart-card.table-only { margin: 4px 0; }
.trend-note { margin: 4px 0 0; }
/* Reject asks why: the four reasons under the trade */
.decline-why { flex-basis: 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 2px 0 4px; }
.reason-btn { font-size: 13px; padding: 4px 12px; border-radius: 99px; background: var(--surface-2); min-height: 32px; }
.reason-btn:hover { border-color: var(--accent); }
.calls-head { margin-top: 18px; }
.calls td:first-child { white-space: normal; }
.calls td:first-child .chip { white-space: nowrap; } /* "the AI sees it" on one line, not a word a line */
.calls th { white-space: normal; vertical-align: bottom; }
@media (max-width: 560px) {
  .calls th, .calls td { padding: 8px 5px; }
  .calls td .small { white-space: normal; } /* "4 separate bets" wraps rather than widen the table */
  .week-pick { width: 100%; }
  .week-pick select { flex: 1; }
}
/* the reading guide (home) */
.reading-honest { margin: 10px 0 4px; }
.reading-list li { margin: 8px 0; overflow-wrap: anywhere; }
.reading-list .chip { margin: 0 6px 0 0; }
.reading-own { margin-top: 18px; }
.reading-form, .ask-form { margin: 10px 0 4px; max-width: 640px; }
.reading-form label, .ask-form label { margin-top: 8px; }
.reading-form input, .reading-form textarea, .ask-form textarea { margin-top: 4px; }
.ask-list li { overflow-wrap: anywhere; }
.chart-table.reading-table td:last-child, .chart-table.reading-table th:last-child { text-align: left; white-space: normal; min-width: 170px; }
/* the factor and regime lab (fund page) */
.lab-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 24px; }
.lab-cell { min-width: 0; }
.lab-title { font-size: 13px; font-weight: 600; margin: 10px 0 0; }
.lab-splits { padding-left: 18px; }
.lab-splits li { margin: 6px 0; }
.lab-splits .chip { white-space: normal; }
.chart .bar-row.muted-row .cat, .chart .bar-row.muted-row .val { fill: var(--muted); }
.chart-table tr.muted-row td { color: var(--muted); }
@media (max-width: 800px) {
  .lab-grid { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- the AI fund page: switcher, fund header and sub-tabs, overview, all funds ---------- */
.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; }
.fund-switcher { margin-bottom: 14px; }
/* what a visually hidden text is placed against, so it never widens a row that scrolls */
.fund-card, .fund-tabs, .fund-alert { position: relative; }
.fs-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 4px 12px; margin-bottom: 8px; }
.fs-title { font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.fund-cards { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.fund-cards > li { display: flex; min-width: 0; }
.fund-card { display: flex; flex-direction: column; gap: 2px; width: 100%; min-height: 112px; padding: 12px 14px; text-align: left; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); color: var(--text); }
.fund-card:hover { background: var(--surface); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.fund-card.selected { border: 2px solid var(--accent); padding: 11px 13px; background: var(--surface-2); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.fund-card.selected .up { color: var(--up-text); }
.fund-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.fund-card.stopped { border-style: dashed; }
.fund-card.stopped .fc-name { color: var(--muted); }
.fund-card.add { flex-direction: row; align-items: center; justify-content: center; gap: 8px; border-style: dashed; color: var(--muted); font-weight: 600; }
.fund-card.add:hover, .fund-card.add[aria-expanded="true"] { color: var(--text); }
.fund-card.add svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; flex: none; }
.fc-head { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 4px 8px; }
.fc-name { font-weight: 700; font-size: 16px; min-width: 0; overflow-wrap: anywhere; }
.fc-chips { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
.fc-chips .chip, .fc-head .chip { margin: 0; white-space: nowrap; }
.fc-style, .fc-stocks, .fc-compact { font-size: 13px; color: var(--muted); }
.fc-value { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 0 8px; margin-top: auto; padding-top: 6px; }
.fc-value .v { font-size: 17px; font-weight: 700; }
.fc-compact { display: none; }
.fund-status { margin: -6px 0 12px; }
.fund-status:empty { display: none; }
.fund-start .fund-form { margin-top: 0; }

/* the fund's header: its name, what it is, its main actions and its sub-tabs */
.fund-head { padding-bottom: 0; }
.fund-head-top { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 12px 24px; }
.fund-head-text { min-width: 0; flex: 1 1 320px; }
.fund-head h2 { font-size: 24px; overflow-wrap: anywhere; }
.fund-head-text > p { margin: 6px 0 0; }
.combined-head { padding-bottom: 14px; }
.fund-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.fund-chips .chip { margin: 0; font-size: 13px; padding: 3px 10px; white-space: normal; max-width: 100%; }
.chip.ok { background: var(--up-bg); color: var(--up-text); font-weight: 600; }
.fund-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.fund-actions button { min-height: 44px; padding: 0 18px; font-weight: 600; }
.fund-tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; margin: 14px -16px 0; padding: 0 10px; border-top: 1px solid var(--border); }
.fund-tabs [role="tab"] { flex: none; min-height: 44px; padding: 0 12px; border: 0; border-radius: 0; border-bottom: 3px solid transparent; background: none; color: var(--muted); white-space: nowrap; font-size: 14px; }
.fund-tabs [role="tab"]:hover { color: var(--text); background: var(--surface-2); }
.fund-tabs [role="tab"][aria-selected="true"] { color: var(--text); font-weight: 700; border-bottom-color: var(--accent); }
.fund-tabs [role="tab"]:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tab-count { display: inline-block; font-size: 12px; font-weight: 400; padding: 0 7px; border-radius: 99px; background: var(--surface-2); color: var(--text); margin-left: 2px; }
.link-btn { min-height: 44px; padding: 0 2px; border: 0; background: none; color: var(--accent); font-size: 14px; }
.link-btn:hover { background: none; text-decoration: underline; }
.link-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.link-btn.fund-link { min-height: 32px; font-size: 14px; font-weight: 700; color: var(--text); text-align: left; text-decoration: underline dotted; text-decoration-color: var(--muted); text-underline-offset: 3px; }
.link-btn.fund-link:hover { color: var(--accent); }

/* the fund in four tiles */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpis .card { min-width: 0; }
.kpis .card .big { overflow-wrap: anywhere; }
.inv-bar { display: flex; gap: 2px; height: 8px; margin: 8px 0 6px; border-radius: 4px; overflow: hidden; }
.inv-bar .inv { background: var(--series-1); }
.inv-bar .rest { flex: 1; background: var(--series-cash); }
/* shares as bars, beside their numbers */
.share-bar { display: block; height: 8px; min-width: 40px; border-radius: 4px; overflow: hidden; background: var(--grid); }
.share-bar > span { display: block; height: 100%; border-radius: 4px; background: var(--series-1); }
.share-cell { display: flex; align-items: center; gap: 8px; min-width: 130px; }
.share-cell .share-bar { flex: 1; }
.share-cell .hl-num { min-width: 44px; }
.hl-num { text-align: right; white-space: nowrap; }
.ov-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 0 16px; align-items: start; }
.ov-grid > .panel { min-width: 0; }
.hold-list { list-style: none; margin: 4px 0 8px; padding: 0; display: grid; gap: 10px; }
.hold-list li { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(40px, 1fr) auto auto; gap: 4px 10px; align-items: center; font-size: 14px; }
.hl-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hl-name .chip { margin-left: 4px; }
.needs-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: 14px; }
.needs-list li { padding-left: 12px; border-left: 3px solid var(--up); }
.needs-list li.warn-item { border-left-color: var(--warn-text); }
/* all funds: the funds side by side and every holding */
.by-fund td:first-child, .all-holdings td:first-child { white-space: normal; min-width: 150px; }
.by-fund td .name { max-width: 260px; white-space: normal; }
.by-fund .share-cell { min-width: 110px; }
.held-by { white-space: normal; }
.held-by .chip { margin: 2px 4px 2px 0; }
.held-by .chip { white-space: nowrap; }
.name.show-sm { display: none; }
@media (max-width: 560px) { .name.show-sm { display: block; } td .held-by-sm { white-space: normal; max-width: 160px; } }
/* on a phone the two tables fit their main columns: headings that wrap, a narrower name column and a
   short share bar by each fund (every holding's weight goes under its name, app.js) */
@media (max-width: 600px) {
  .by-fund th, .all-holdings th { white-space: normal; letter-spacing: 0; }
  .by-fund th, .by-fund td, .all-holdings th, .all-holdings td { padding-left: 4px; padding-right: 4px; }
  .by-fund td:first-child, .all-holdings td:first-child { min-width: 104px; }
  .by-fund td .name, .all-holdings td .name, td .held-by-sm { max-width: 116px; }
  .by-fund .share-cell { min-width: 0; gap: 6px; }
  .by-fund .share-cell .share-bar { min-width: 16px; }
  .by-fund .share-cell .hl-num { min-width: 0; }
}
.table-wrap[tabindex]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
tr.muted-row td { color: var(--muted); }
.fund-alert { flex-wrap: wrap; }
.fund-alert .small-btn { flex: none; min-height: 44px; }
@media (max-width: 900px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ov-grid { grid-template-columns: minmax(0, 1fr); }
}
/* on a phone: the funds as a row of chips that scrolls sideways, and compact tiles */
@media (max-width: 600px) {
  .fund-cards { display: flex; overflow-x: auto; gap: 8px; padding: 3px; margin: -3px; scrollbar-width: none; }
  .fund-cards > li { flex: none; }
  .fund-card { min-height: 44px; width: auto; max-width: 72vw; padding: 7px 12px; gap: 1px; }
  .fund-card.selected { padding: 6px 11px; }
  .fund-card.add { padding: 7px 12px; }
  .fc-style, .fc-value, .fc-stocks, .fc-chips { display: none; }
  .fc-compact { display: block; white-space: nowrap; font-size: 12px; }
  .fc-name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; overflow-wrap: normal; }
  .fund-head h2 { font-size: 20px; }
  .fund-chips .chip { font-size: 12px; padding: 2px 8px; }
  .fund-actions { width: 100%; }
  .fund-actions button { flex: 1; }
  .kpis { gap: 10px; }
  .kpis .card { padding: 12px; }
  .kpis .card .big { font-size: 17px; overflow-wrap: normal; }
  .kpis .card .sub { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .kpis .card .sub span:nth-child(even) { text-align: left; margin-bottom: 4px; }
  .hold-list { gap: 2px; }
  .hold-list li { grid-template-columns: minmax(0, 1fr) auto auto; row-gap: 0; }
  /* each stock a full-size tap target */
  .hold-list .stock-link { display: inline-flex; align-items: center; min-height: 44px; min-width: 44px; }
  .hold-list .stock-link:focus-visible { outline-offset: -2px; } /* inside the name cell, which clips */
  .hold-list .share-bar { grid-column: 1 / -1; grid-row: 2; }
}
@media (max-width: 360px) {
  .kpis { grid-template-columns: minmax(0, 1fr); }
}
