/*
 * Fondval design system: one dark theme for the user app and the admin console.
 *
 * Colours are tokens on :root. Text tokens meet WCAG AA on every surface
 * (--text 14.6:1, --text-2 9.1:1, --muted 5.6:1 on --surface-1). The chart
 * series are the validated dark categorical palette (dataviz reference, checked
 * for colour-blind separation and 3:1 contrast on --surface-1).
 * The admin console (.theme-admin) swaps the accent and tightens the density.
 */
:root {
  color-scheme: dark;
  --bg: #0d1117;
  --surface-1: #161b22;
  --surface-2: #1c232d;
  --surface-3: #252d39;
  --border: rgba(255, 255, 255, .08);
  --border-strong: rgba(255, 255, 255, .16);
  --text: #e6edf3;
  --text-2: #b4bdc8;
  --muted: #8b949e;

  --accent: #6cb0ff;
  --accent-strong: #1f6feb;
  --accent-soft: rgba(56, 139, 253, .15);

  --good: #3fb950;
  --good-soft: rgba(63, 185, 80, .14);
  --bad: #f47067;
  --bad-soft: rgba(244, 112, 103, .14);
  --warn: #e3b341;
  --warn-soft: rgba(227, 179, 65, .14);
  --danger-strong: #c93c37;

  --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-neutral: #6e7681;
  --grid: #2a313c;
  --axis: #3d4550;

  --radius: 12px;
  --radius-small: 8px;
  --gap: 20px;
  --shadow: 0 1px 0 rgba(255, 255, 255, .03) inset, 0 8px 24px rgba(0, 0, 0, .25);
  --font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.theme-admin {
  --accent: #a99ff2;
  --accent-strong: #6e5bd6;
  --accent-soft: rgba(144, 133, 233, .16);
  --gap: 16px;
}

/* Base */
* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  min-height: 100vh; margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.55 var(--font); -webkit-font-smoothing: antialiased;
}
.theme-admin { font-size: 14px; }
a { color: var(--accent); text-underline-offset: .18em; text-decoration-thickness: 1px; }
a:hover { color: var(--text); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .6rem; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .8rem; }
code { font-family: var(--mono); font-size: .88em; padding: 1px 5px; border-radius: 5px; background: var(--surface-3); }
small { font-size: .82rem; }
hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.skip-link { position: absolute; left: -999px; top: 8px; z-index: 100; padding: 8px 14px; background: var(--accent-strong); color: #fff; border-radius: var(--radius-small); }
.skip-link:focus { left: 8px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* App shell: one navigation row (brand, menu, account on the right), then the page */
.topnav { position: sticky; top: 0; z-index: 20; background: rgba(22, 27, 34, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.topnav-inner { display: flex; align-items: center; gap: 24px; max-width: 1360px; min-height: 60px; margin: 0 auto; padding: 0 32px; }
.brand { display: flex; align-items: center; gap: 10px; flex: none; color: var(--text); text-decoration: none; }
.brand:hover { color: var(--text); }
.brand strong { display: block; font-size: .98rem; line-height: 1.2; }
.brand small { display: block; color: var(--muted); font-size: .72rem; line-height: 1.3; }
.brand-mark {
  display: grid; place-items: center; flex: none; width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent-strong), var(--series-3)); color: #fff; font-weight: 700;
}
/* Ten admin pages: the menu shows words only, so it fits the 1360 px row. */
.theme-admin .nav-row .icon { display: none; }
.theme-admin .nav-row .nav-link { padding: 7px 9px; }
.theme-admin .brand-mark { background: linear-gradient(135deg, var(--accent-strong), var(--series-5)); }
.nav-row { display: flex; align-items: center; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.nav-group { display: flex; align-items: center; gap: 2px; }
.nav-divider { width: 1px; height: 22px; margin: 0 8px; background: var(--border-strong); flex: none; }
.nav-link {
  display: inline-flex; align-items: center; gap: 8px; padding: 7px 11px; border-radius: var(--radius-small);
  color: var(--text-2); text-decoration: none; font-weight: 500; white-space: nowrap;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--accent-soft); color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.icon { width: 17px; height: 17px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.account { display: flex; align-items: center; gap: 6px; flex: none; margin-left: auto; }
.account form { margin: 0; }
.account button.nav-link { border: 0; background: none; color: var(--text-2); font-weight: 500; line-height: inherit; padding: 7px 9px; }
.account button.nav-link:hover { filter: none; background: var(--surface-2); color: var(--text); }
.account-user { display: inline-flex; align-items: center; gap: 8px; padding: 4px 10px 4px 4px; border-radius: 999px; color: var(--text-2); text-decoration: none; }
a.account-user:hover, .account-user.active { background: var(--surface-2); color: var(--text); }
.avatar { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--surface-3); color: var(--text); font-size: .8rem; font-weight: 600; }

.content { width: 100%; max-width: 1360px; margin: 0 auto; padding: 24px 32px 40px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 10px 20px; margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: 1.45rem; }
.eyebrow { display: block; color: var(--muted); font-size: .74rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; color: var(--text-2); font-size: .88rem; }
.app-footer { max-width: 1360px; margin: 0 auto; padding: 0 32px 28px; color: var(--muted); font-size: .8rem; }
.env-badge { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: .7rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }

/* Single-card pages without navigation (login, errors when logged out) */
.auth-shell { display: grid; place-items: center; min-height: 100vh; padding: 24px 16px; }
.auth-shell .brand { justify-content: center; margin-bottom: 18px; }
.auth-card { width: 100%; max-width: 420px; }

/* Layout grid for dashboards */
.grid { display: grid; gap: var(--gap); grid-template-columns: repeat(12, minmax(0, 1fr)); margin-bottom: var(--gap); }
.grid > * { grid-column: span 12; min-width: 0; margin-bottom: 0; }
.span-3 { grid-column: span 3 !important; }
.span-4 { grid-column: span 4 !important; }
.span-5 { grid-column: span 5 !important; }
.span-6 { grid-column: span 6 !important; }
.span-7 { grid-column: span 7 !important; }
.span-8 { grid-column: span 8 !important; }

/* Cards */
.card {
  margin-bottom: var(--gap); padding: 20px 22px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-1); box-shadow: var(--shadow);
}
.theme-admin .card { padding: 16px 18px; }
.card.narrow { max-width: 480px; margin-inline: auto; }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 6px 14px; margin-bottom: 10px; }
.card-head h2, .card-head h1 { margin: 0; }
.card-sub { color: var(--muted); font-size: .85rem; }
.callout { border-left: 3px solid var(--accent); }
.muted { color: var(--muted); }
.lead { color: var(--text-2); font-size: 1.02rem; }

/* Landing page */
.market-card { border-left: 3px solid var(--accent); background: linear-gradient(90deg, var(--accent-soft), var(--surface-1) 45%); }
.market-card .lead { max-width: 80ch; margin-bottom: .6rem; color: var(--text); font-size: 1.04rem; line-height: 1.65; }
.source-note { margin: 0; color: var(--muted); font-size: .8rem; }
.card-link { font-size: .85rem; text-decoration: none; }
.row-note { margin-top: 2px; color: var(--muted); font-size: .82rem; line-height: 1.4; }
.small { font-size: .82rem; }
.donut-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.chart.donut { min-height: 300px; }
.chart-legend { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; font-size: .86rem; }
.chart-legend li { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; align-items: center; gap: 10px; color: var(--text-2); }
.chart-legend .swatch { width: 12px; height: 12px; border-radius: 3px; }
.chart-legend .value { color: var(--text); font-variant-numeric: tabular-nums; }

/* Fund page: a fund rail on the left, the overview on the right */
.fund-layout { display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: var(--gap); align-items: start; }
.fund-layout > .card { margin-bottom: 0; }
.fund-rail { position: sticky; top: 76px; display: flex; flex-direction: column; gap: 10px; max-height: calc(100vh - 96px); padding: 12px; }
.rail-filter { width: 100%; }
.rail-list { flex: 1; overflow-y: auto; margin: 0; padding: 0; list-style: none; }
.rail-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 7px 8px; border-radius: var(--radius-small); color: var(--text-2); text-decoration: none; font-size: .88rem; }
.rail-item:hover { background: var(--surface-2); color: var(--text); }
.rail-item.active { background: var(--accent-soft); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.rail-name { display: flex; align-items: center; gap: 6px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-change { flex: none; font-variant-numeric: tabular-nums; font-size: .8rem; }
.held-dot { flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.rail-foot { margin: 0; padding-top: 8px; border-top: 1px solid var(--border); color: var(--muted); font-size: .8rem; }
.fund-main { min-width: 0; }
.fund-header { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 16px 32px; }
.quote-price { font-size: 2.1rem; font-weight: 600; line-height: 1.1; }
.quote-price small { color: var(--muted); font-size: .8rem; font-weight: 600; }
.quote-change { margin-top: 4px; font-size: 1.2rem; font-weight: 600; }
.quote-date { font-size: .85rem; }
.fact-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px 20px; margin: 0; }
.fact-grid dt { color: var(--muted); font-size: .74rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.fact-grid dd { margin: 2px 0 0; color: var(--text); }
.fund-about { grid-column: 1 / -1; padding-top: 12px; border-top: 1px solid var(--border); color: var(--text-2); }
.fund-about p { margin-bottom: .3rem; }
.tile-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: var(--gap); }
.stat-tile { display: flex; flex-direction: column; gap: 6px; }
.stat-tile .kpi-value { margin-top: 0; font-size: 1.35rem; }
.mini-bars { width: 100%; height: 36px; }
.mini-bars rect.pos { fill: var(--series-1); }
.mini-bars rect.neg { fill: var(--bad); }
.mini-bars-axis { stroke: var(--axis); stroke-width: 1; vector-effect: non-scaling-stroke; }
.sparkline { display: block; width: 96px; height: 24px; }
.sparkline polyline { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.period-bar { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 6px; margin-top: 10px; }
.period { display: grid; gap: 2px; padding: 8px 6px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2); font-weight: 500; text-align: center; }
.period strong { font-variant-numeric: tabular-nums; }
.period:hover { filter: none; background: var(--surface-3); color: var(--text); }
.period.active { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.year-table th[scope="row"] { color: var(--text-2); font-weight: 500; white-space: nowrap; }
.year-table td.pos { background: var(--good-soft); color: var(--good); }
.year-table td.neg { background: var(--bad-soft); color: var(--bad); }
.corr-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; font-size: .88rem; }
.corr-list li { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(60px, 1fr) 3.2rem; align-items: center; gap: 10px; }
.corr-list a { overflow: hidden; color: var(--text); text-decoration: none; text-overflow: ellipsis; white-space: nowrap; }
.corr-list a:hover { color: var(--accent); text-decoration: underline; }
.corr-bar { height: 8px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.corr-bar > span { display: block; height: 100%; border-radius: 4px; background: var(--series-1); }
.corr-bar.neg > span { background: var(--series-2); }

/* Market page */
.toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.segmented { display: inline-flex; flex-wrap: wrap; padding: 3px; border: 1px solid var(--border); border-radius: var(--radius-small); background: var(--bg); }
.segment { padding: 5px 12px; border: 0; border-radius: 6px; background: transparent; color: var(--text-2); font-weight: 500; }
.segment:hover { filter: none; background: var(--surface-2); color: var(--text); }
.segment.active { background: var(--accent-soft); color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
a.segment { display: inline-block; text-decoration: none; }
.backtest-tabs { margin-bottom: 16px; }
.ma-cell.pos-1 { background: rgba(63, 185, 80, .08); color: var(--good); }
.ma-cell.pos-2 { background: rgba(63, 185, 80, .16); color: var(--good); }
.ma-cell.pos-3 { background: rgba(63, 185, 80, .28); color: var(--text); }
.ma-cell.neg-1 { background: rgba(244, 112, 103, .08); color: var(--bad); }
.ma-cell.neg-2 { background: rgba(244, 112, 103, .16); color: var(--bad); }
.ma-cell.neg-3 { background: rgba(244, 112, 103, .28); color: var(--text); }

/* Backtest lab */
.lab-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.lab-form fieldset { display: grid; align-content: start; gap: 10px; margin: 0; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-small); }
.lab-form legend { padding: 0 6px; color: var(--muted); font-size: .76rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.lab-form label { display: grid; gap: 4px; color: var(--text-2); font-size: .9rem; }
.lab-form label.checkbox { display: block; line-height: 1.9; }
.lab-form label.checkbox input { margin-right: 6px; vertical-align: -2px; }
.lab-form select { padding: 3px 6px; }
.pick-list { display: grid; gap: 2px; max-height: 230px; overflow-y: auto; }
td.best { font-weight: 700; box-shadow: inset 0 -2px 0 var(--accent); }
.lab-funds td:first-child { min-width: 14rem; }
.lab-funds th { white-space: nowrap; }
.swatch-dot { display: inline-block; width: 10px; height: 10px; margin-right: 8px; border-radius: 50%; background: var(--series-neutral); }

/* KPI tiles */
.kpi-grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: var(--gap); }
.kpi { padding: 16px 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-1); }
.kpi-label { color: var(--muted); font-size: .78rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.kpi-value { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 6px; font-size: 1.6rem; font-weight: 600; line-height: 1.2; }
.kpi-value .badge { font-size: .72rem; }
.kpi-note { margin-top: 4px; color: var(--text-2); font-size: .85rem; }

/* Badges and status */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; white-space: nowrap;
  background: var(--surface-3); color: var(--text-2); font-size: .78rem; font-weight: 600; line-height: 1.6;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.badge-good { background: var(--good-soft); color: var(--good); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-info { background: var(--accent-soft); color: var(--accent); }
.badge-neutral { background: var(--surface-3); color: var(--text-2); }
.signal-arrow { font-size: .9em; }

/* Alerts (flash messages) */
.flash { margin: 0 0 16px; padding: 10px 14px; border: 1px solid var(--border); border-left-width: 3px; border-radius: var(--radius-small); background: var(--surface-2); color: var(--text); }
.flash-success { border-left-color: var(--good); background: var(--good-soft); }
.flash-error { border-left-color: var(--bad); background: var(--bad-soft); }
.flash-warning { border-left-color: var(--warn); background: var(--warn-soft); }
.flash ul { margin: 6px 0 0; padding-left: 20px; }

.commentary { margin: 1rem 0; padding: 12px 16px; border-left: 3px solid var(--accent); border-radius: 0 var(--radius-small) var(--radius-small) 0; background: var(--surface-2); color: var(--text-2); }
.commentary p:last-of-type { margin-bottom: .4rem; }
.commentary footer { font-size: .8rem; }

/* Tables */
.table-wrap { overflow-x: auto; margin: 6px 0 12px; border: 1px solid var(--border); border-radius: var(--radius-small); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.theme-admin th, .theme-admin td { padding: 7px 10px; }
thead th { position: sticky; top: 0; background: var(--surface-2); color: var(--muted); font-size: .76rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: rgba(255, 255, 255, .02); }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]::after { content: " ↕"; opacity: .4; }
th[aria-sort="ascending"]::after { content: " ↑"; opacity: 1; }
th[aria-sort="descending"]::after { content: " ↓"; opacity: 1; }
td a { color: var(--text); text-decoration: none; }
td a:hover { color: var(--accent); text-decoration: underline; }
/* Row actions in tables are quiet; the page's main action keeps the accent. */
td button.small, td .button.small { background: var(--surface-3); border-color: var(--border-strong); color: var(--text); }
td button.small.danger, td .button.small.danger { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
td form.inline + form.inline { margin-top: 4px; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.up { color: var(--good); }
.down { color: var(--bad); }
.cash-row td { background: var(--surface-2); color: var(--text-2); }
tr.inactive td { color: var(--muted); }
tfoot th { color: var(--text); background: var(--surface-2); }
#holdings-total.off { color: var(--bad); }

/* Buttons and forms */
button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 16px;
  border: 1px solid transparent; border-radius: var(--radius-small); background: var(--accent-strong); color: #fff;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; line-height: 1.3;
}
button:hover, .button:hover { filter: brightness(1.12); color: #fff; }
button, .button { white-space: nowrap; }
button.secondary, .button.secondary { background: var(--surface-3); border-color: var(--border-strong); color: var(--text); }
button.small, .button.small { padding: 4px 10px; font-size: .82rem; }
button.danger, .button.danger { background: var(--danger-strong); }
.text-button { padding: 0; border: 0; background: none; color: var(--accent); font-weight: 500; text-decoration: underline; }
input, select, textarea {
  padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-small);
  background: var(--bg); color: var(--text); font: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
input[type="checkbox"] { accent-color: var(--accent-strong); width: 16px; height: 16px; }
textarea { width: 100%; }
label small { font-weight: 400; }
.percent-input { width: 7rem; text-align: right; }
.stack { display: grid; gap: 14px; }
.stack label, .grid-form label { display: grid; gap: 5px; min-width: 0; color: var(--text-2); font-size: .9rem; }
.grid-form select, .grid-form input:not([type="checkbox"]) { min-width: 0; width: 100%; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; align-items: end; margin-bottom: 12px; }
.grid-form .wide { grid-column: 1 / -1; }
.grid-form .checkbox, .stack .checkbox { display: flex; align-items: center; gap: 8px; }
form.inline, .inline { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.code-input { font-family: var(--mono); font-size: .88rem; }
.window-input { width: 4.5rem; text-align: right; }
details > summary { cursor: pointer; }

/* Charts */
.chart { width: 100%; max-width: 100%; min-height: 320px; overflow: hidden; }
.chart.tall { min-height: 440px; }
.chart-missing { display: grid; place-items: center; color: var(--muted); border: 1px dashed var(--border-strong); border-radius: var(--radius-small); }

/* Empty states */
.empty-state { display: grid; justify-items: start; gap: 8px; padding: 22px; border: 1px dashed var(--border-strong); border-radius: var(--radius); color: var(--text-2); }
.empty-state h2 { margin: 0; }

/* Admin console */
.attention { border-left-color: var(--warn); }
.attention ul { margin: 0; padding-left: 20px; color: var(--text-2); }
.attention li { margin-bottom: 4px; }
.filter-bar { gap: 14px; margin-bottom: 12px; }
.filter-bar label { display: flex; align-items: center; gap: 6px; color: var(--text-2); font-size: .88rem; }
.fact-grid.compact { margin-top: 10px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
pre.json { max-height: 480px; overflow: auto; margin: 10px 0 0; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-small); background: var(--bg); color: var(--text-2); font: .82rem/1.5 var(--mono); }

/* Admin ML console */
.feature-table td { vertical-align: top; }
.live-status { margin: 12px 0; padding: 10px 14px; border-radius: var(--radius-small); background: var(--surface-2); }
.live-status progress { width: 100%; height: 8px; accent-color: var(--accent-strong); }
.manual dt { font-weight: 600; margin-top: .9rem; color: var(--text); }
.manual dd { margin: .2rem 0 0 0; color: var(--text-2); }
.manual h3 { margin-top: 1.2rem; }
.manual li { color: var(--text-2); margin-bottom: .3rem; }
.manual-toc ol { columns: 2; margin: .4rem 0 0; }
.glossary dt { margin-top: .6rem; }
.method-help { margin: 0; }
.method-help dt { margin-top: .5rem; font-weight: 600; }
.method-help dd { margin: .1rem 0 0; }
.help-link { display: inline-grid; place-items: center; width: 1.2rem; height: 1.2rem; border-radius: 50%; background: var(--surface-3); color: var(--text-2); font-size: .75rem; text-decoration: none; }

/* Medium screens: the admin row drops link text on the account side first */
/* Hidden text stays readable by screen readers, so icon-only links keep their names. */
@media (max-width: 1520px) {
  .theme-admin .brand small { display: none; }
  .theme-admin .account-name, .theme-admin .account .nav-link span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}
/* Narrow screens: fewer grid columns; the menu wraps to its own scrollable row */
@media (max-width: 1100px) {
  .span-3, .span-4 { grid-column: span 6 !important; }
  .span-5, .span-6, .span-7, .span-8 { grid-column: span 12 !important; }
  .brand small { display: none; }
  .account-name, .account .nav-link span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}
@media (max-width: 1100px) {
  .lab-grid { grid-template-columns: minmax(0, 1fr); }
  .fund-layout { grid-template-columns: minmax(0, 1fr); }
  .fund-rail { position: static; max-height: 260px; }
  .tile-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .topnav-inner { flex-wrap: wrap; gap: 4px 12px; padding: 8px 16px; }
  .nav-row { order: 3; flex-basis: 100%; }
  .content { padding: 16px 16px 32px; }
  .app-footer { padding: 0 16px 24px; }
  .span-3, .span-4 { grid-column: span 12 !important; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .fund-header { grid-template-columns: minmax(0, 1fr); }
  .kpi { padding: 12px; }
  .kpi-value { font-size: 1.25rem; }
  .card { padding: 16px; }
  .manual-toc ol { columns: 1; }
}

/* Chat with Claude: a button in the corner and a pop-up panel */
.chat { position: fixed; right: 20px; bottom: 20px; z-index: 50; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.chat-toggle { display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text); box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35); cursor: pointer; font: inherit; }
.chat-toggle svg { width: 18px; height: 18px; }
.chat.open .chat-toggle-label { display: none; }
.chat-panel { width: min(420px, calc(100vw - 32px)); height: min(560px, calc(100vh - 120px)); display: flex; flex-direction: column; background: var(--surface-1); border: 1px solid var(--border-strong); border-radius: 14px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45); overflow: hidden; }
.chat-panel[hidden] { display: none; }
.chat-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border-strong); }
.chat-head small { display: block; color: var(--muted); font-size: 12px; }
.chat-head-actions { display: flex; gap: 6px; }
.chat-head-actions button { background: none; border: 1px solid var(--border-strong); border-radius: 8px; color: var(--text-2); padding: 4px 10px; cursor: pointer; font: inherit; font-size: 13px; }
.chat-log { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.chat-msg { max-width: 88%; padding: 8px 12px; border-radius: 12px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.chat-user { align-self: flex-end; background: var(--accent-soft); color: var(--text); }
.chat-assistant { align-self: flex-start; background: var(--bg); color: var(--text); border: 1px solid var(--border-strong); }
.chat-waiting { color: var(--muted); font-style: italic; }
.chat-error { align-self: center; color: var(--bad); font-size: 13px; }
.chat-form { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border-strong); }
.chat-form textarea { flex: 1; resize: none; font: inherit; font-size: 14px; }
.chat-note { margin: 0; padding: 0 12px 10px; color: var(--muted); font-size: 11px; }
@media (max-width: 600px) { .chat { right: 12px; bottom: 12px; } }

/* Admin → Playground (Phase 37f) */
.pg-meta { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-bottom: 8px; }
.pg-meta .pg-notes { flex: 1; min-width: 240px; }
.pg-meta .pg-notes input { width: 100%; }
.pg-list { display: grid; gap: 8px; margin: 6px 0 10px; }
.pg-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-small); background: var(--surface-2); }
.pg-row .row-note { flex-basis: 100%; }
.pg-params { display: inline-flex; flex-wrap: wrap; gap: 6px 10px; }
.pg-param { font-size: .85rem; color: var(--text-2); }
.pg-num { width: 6.5em; }
.pg-days { width: 4.2em; }
.pg-key { width: 8em; font-family: var(--mono, monospace); }
.pg-section { margin: 14px 0; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-small); background: var(--bg); }
.pg-section-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin-bottom: 8px; }
.pg-section-head h3 { margin: 0; font-size: 1.05rem; display: inline-flex; align-items: center; gap: 8px; }
.pg-step { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: .8rem; font-weight: 700; }
.pg-kinds { display: grid; gap: 12px; }
.pg-kinds-2 { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.pg-kinds-3 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.pg-kind { padding: 10px 12px; border: 1px solid var(--border); border-left: 4px solid var(--kind, var(--border-strong)); border-radius: var(--radius-small); background: var(--surface-1); }
.pg-kind-buy { --kind: var(--good); }
.pg-kind-sell { --kind: var(--bad); }
.pg-kind-full { --kind: var(--accent); }
.pg-kind-half { --kind: var(--warn); }
.pg-kind-cash { --kind: var(--muted); }
.pg-kind-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.pg-kind-head h4 { margin: 0; font-size: .95rem; color: var(--kind, var(--text)); }
.pg-count { font-size: .8rem; color: var(--muted); }
.pg-kind-note { margin: 2px 0 6px; }
.pg-kind .pg-row { background: var(--surface-2); }
.pg-rule { flex-direction: column; align-items: stretch; }
.pg-rule-head { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.pg-condition { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.pg-condition .row-note { flex-basis: 100%; }
.pg-and { font-size: .75rem; font-weight: 700; color: var(--accent); padding: 1px 6px; border: 1px solid var(--accent); border-radius: 4px; }
.pg-rule > button { align-self: flex-start; }
.pg-mode { display: block; margin: 0 0 10px; font-size: .9rem; }
.pg-mode select { max-width: 100%; }
.pg-run { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 14px; margin-bottom: 10px; }
.pg-run .pg-fund select { max-width: 420px; }
.pg-check { display: inline-flex; align-items: center; gap: 6px; }
.pg-chart { width: 100%; min-height: 520px; }
.pg-chart-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 10px 0 6px; }
.pg-shown-label { font-weight: 600; color: var(--text); }
.pg-shown { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.pg-chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border: 1px solid var(--border-strong); border-radius: 999px; background: var(--surface-2); font-family: var(--mono, monospace); font-size: .85rem; cursor: pointer; }
.pg-chip:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.pg-json { margin-top: 10px; }
.pg-json textarea { font-family: var(--mono, monospace); font-size: .8rem; }
@media (max-width: 720px) {
  .pg-row { padding: 8px; }
  .pg-num { width: 5em; }
  .pg-kinds-2, .pg-kinds-3 { grid-template-columns: 1fr; }
  .pg-section { padding: 10px; }
}
#pg-name { width: 26em; max-width: 100%; }
#pg-load { max-width: 100%; }
.card-head .inline label:has(#pg-load) { max-width: 100%; }
