/* Investing dashboard — light theme, mobile-first.
   No CDNs, no external fonts: the CSP allows 'self' only.

   Colour discipline, applied throughout:
     - green and red mean gain and loss. Nothing else is ever green or red.
     - one brand blue, reserved for interactive things (links, focus, the
       portfolio series, active nav).
     - everything else is greyscale.
     - no gradients, no shadows deeper than a 1px hairline border.

   Numbers are tabular and right-aligned everywhere, so columns of figures line
   up digit under digit and can be compared by eye without reading them. */

:root {
    --bg:        #f4f5f7;
    --surface:   #ffffff;
    --border:    #e3e6ea;
    --border-sf: #eef0f3;
    --text:      #16191d;
    --text-soft: #5c6570;
    --text-dim:  #8a939e;

    /* The single brand blue. `--brand` is an alias: calculator.js's stylesheet
       rules were written against that name and would otherwise resolve to
       nothing, which silently drew invisible chart lines. */
    --accent:    #2563eb;
    --brand:     #2563eb;
    --accent-sf: #eff4fe;
    --accent-bd: #cfe0fb;

    --pos:       #0f7b43;
    --neg:       #c02b2b;
    --pos-sf:    #edf7f1;
    --neg-sf:    #fdf0f0;

    --warn-bg:   #fbf6e9;
    --warn-fg:   #7a5a10;
    --warn-bd:   #ead9b0;
    --ok-bg:     #eaf7f0;

    --radius:    8px;
    --sidebar-w: 232px;

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
            "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}

* { box-sizing: border-box; }

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 400 14.5px/1.5 var(--font);
    font-variant-numeric: tabular-nums;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.006em; }

a { color: var(--accent); }

/* Every numeric cell: same figure width, right aligned. */
.num, .kpi-value, .stat-v, .n-int, .n-dec, .tip-v, .detail-v {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
}

/* Headline numbers: the integer carries the weight, cents and symbol recede. */
.n-int { font-weight: 600; }
.n-dec { font-size: .72em; font-weight: 500; color: var(--text-soft); }
.n-sym { font-size: .72em; font-weight: 500; color: var(--text-dim); margin-left: .18em; }

.pos { color: var(--pos); }
.neg { color: var(--neg); }
.warn { color: var(--warn-fg); }
.muted { color: var(--text-soft); }
.sym { font-weight: 600; }

/* ------------------------------------------------------------- sidebar --- */

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 30;
}
.sidebar-head { padding: .9rem .85rem .7rem; border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 600; font-size: .92rem; }
.brand-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }

.freshness {
    display: flex; align-items: center; gap: .4rem;
    margin-top: .5rem; font-size: .76rem; color: var(--text-soft);
    cursor: default; border-radius: 4px; padding: .1rem .15rem;
}
.freshness:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.fresh-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--text-dim); }
.fresh-fresh { background: var(--pos); }
.fresh-aging { background: #b8860b; }
.fresh-stale { background: var(--neg); }
.fresh-none  { background: var(--text-dim); }

.nav { flex: 1; overflow-y: auto; padding: .4rem 0; }
.nav-item {
    display: flex; align-items: center; gap: .6rem;
    padding: .45rem .85rem .45rem calc(.85rem - 3px);
    color: var(--text-soft); text-decoration: none;
    font-size: .875rem;
    border-left: 3px solid transparent;
}
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.nav-active {
    background: var(--accent-sf);
    color: var(--accent);
    border-left-color: var(--accent);
    font-weight: 500;
}
.nav-icon {
    width: 17px; height: 17px; flex: none; fill: none; stroke: currentColor;
    stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
}

.sidebar-foot {
    border-top: 1px solid var(--border);
    padding: .6rem .85rem;
    display: flex; align-items: center; justify-content: space-between; gap: .5rem;
}
.user-chip {
    color: var(--text-soft); font-size: .8rem;
    max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.inline-form { margin: 0; }

/* ------------------------------------------------------------- content --- */

.content {
    margin-left: var(--sidebar-w);
    padding: 1.1rem 1.4rem 3rem;
    max-width: 1200px;
}
.route[hidden] { display: none; }

.source-line {
    margin: 0 0 .9rem;
    font-size: .78rem;
    color: var(--text-dim);
}

.banner {
    background: var(--warn-bg);
    color: var(--warn-fg);
    border-bottom: 1px solid var(--warn-bd);
    padding: .5rem 1rem .5rem calc(var(--sidebar-w) + 1.4rem);
    font-size: .84rem;
}
.banner-hidden { display: none; }

/* ------------------------------------------------------------------ kpi --- */

.kpi-grid {
    display: grid;
    grid-template-columns: 1.35fr 1fr 1fr 1fr;
    gap: 1px;
    background: var(--border);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 1rem;
}
.kpi-grid-3 { grid-template-columns: repeat(4, 1fr); margin-bottom: 1.2rem; }
.kpi {
    background: var(--surface);
    padding: .7rem .85rem .75rem;
    display: flex; flex-direction: column; gap: .1rem;
    min-width: 0;
}
.kpi-label {
    font-size: .7rem; color: var(--text-dim);
    text-transform: uppercase; letter-spacing: .05em; font-weight: 500;
}
.kpi-value { font-size: 1.28rem; font-weight: 600; letter-spacing: -.015em; overflow-wrap: anywhere; }
.kpi-primary .kpi-value { font-size: 1.85rem; }
.kpi-sub { font-size: .76rem; color: var(--text-soft); }

/* The venue qualification under the NAV figure. Deliberately quiet — it is a
   permanent property of the price source, not an alert — but never hidden:
   a number whose provenance differs from the broker's says so where it is read. */
.kpi-note {
    display: block;
    margin-top: .3rem;
    font-size: .7rem;
    line-height: 1.35;
    color: var(--text-dim);
    max-width: 34rem;
}
.kpi-note:empty { display: none; }

/* Flex token expiry. Quiet while the date is far off, amber inside 30 days,
   red once it has passed — the three states a credential actually has. */
.token-expiry {
    margin: .2rem 0 0;
    padding: .5rem .65rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: .85rem;
    line-height: 1.5;
    color: var(--text-soft);
}
.token-expiry-due {
    background: var(--warn-bg);
    border-color: var(--warn-bd);
    color: var(--warn-fg);
    font-weight: 500;
}
.token-expiry-expired {
    background: var(--neg-sf);
    border-color: var(--neg);
    color: var(--neg);
    font-weight: 600;
}
.token-expiry-unknown { background: var(--warn-bg); border-color: var(--warn-bd); color: var(--warn-fg); }

/* Same statement in the reconciliation panel, where it explains why a residual
   difference against the broker is expected rather than a defect. */
.venue-gap-note {
    margin: .1rem 0 .6rem;
    padding: .45rem .6rem;
    border-left: 2px solid var(--border);
    font-size: .78rem;
    line-height: 1.45;
    color: var(--text-soft);
}
.venue-gap-note:empty { display: none; }

/* --------------------------------------------------------------- card --- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .85rem .95rem 1rem;
    margin-bottom: 1rem;
}
.card-head {
    display: flex; align-items: baseline; justify-content: space-between;
    gap: .75rem; margin-bottom: .7rem; flex-wrap: wrap;
    padding-bottom: .55rem;
    border-bottom: 1px solid var(--border-sf);
}
.card-head h2 { font-size: .95rem; font-weight: 600; }
.hint { font-size: .76rem; color: var(--text-dim); font-weight: 400; }
.empty { color: var(--text-dim); font-size: .87rem; margin: .5rem 0; }

/* Two cards side by side on wide screens; the whitespace goes between the
   groups rather than inside them. */
.card-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.card-row > .card { margin-bottom: 1rem; }

.sub-head {
    font-size: .8rem; font-weight: 600; color: var(--text-soft);
    text-transform: uppercase; letter-spacing: .04em;
    margin: 1.1rem 0 .4rem;
}

.panel-line { font-size: .85rem; color: var(--text-soft); margin: .6rem 0 0; }

/* A statement of fact that needs attention but is not an error. */
.notice {
    font-size: .82rem;
    background: var(--warn-bg);
    color: var(--warn-fg);
    border: 1px solid var(--warn-bd);
    border-radius: 6px;
    padding: .45rem .6rem;
    margin: .6rem 0 0;
}

/* -------------------------------------------------------------- tables --- */

.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: .85rem; min-width: 760px; }
.data-table-tight { font-size: .82rem; min-width: 560px; }
.data-table th, .data-table td { padding: .42rem .55rem; text-align: left; white-space: nowrap; }
.data-table thead th {
    font-size: .71rem; font-weight: 600; color: var(--text-dim);
    text-transform: uppercase; letter-spacing: .045em;
    border-bottom: 1px solid var(--border);
    padding-bottom: .35rem;
}
.data-table tbody tr { border-bottom: 1px solid var(--border-sf); }
.data-table tbody tr:last-child { border-bottom: none; }
.data-table td.num, .data-table th.num { text-align: right; }
.sortable { cursor: pointer; user-select: none; }
.sortable:hover { color: var(--accent); }
.sort-asc::after  { content: " ▲"; font-size: .7em; }
.sort-desc::after { content: " ▼"; font-size: .7em; }
.msg-cell { max-width: 34ch; overflow-wrap: anywhere; white-space: normal; color: var(--text-soft); font-size: .8rem; }

.table-rows tbody tr.row-expandable { cursor: pointer; }
.table-rows tbody tr.row-expandable:hover { background: var(--accent-sf); }
.table-rows tbody tr.row-expandable:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.row-caret { color: var(--text-dim); display: inline-block; width: 1em; }
.row-chart > td { padding: .4rem .55rem 1rem; background: var(--bg); white-space: normal; }
.row-chart-head {
    display: flex; align-items: baseline; justify-content: space-between;
    gap: .6rem; margin-bottom: .4rem;
}

/* An end-of-day price, labelled where it is read. */
.tag-eod {
    display: inline-block; margin-left: .4rem;
    font-size: .64rem; font-weight: 500; letter-spacing: .02em;
    color: var(--text-dim); border: 1px solid var(--border);
    border-radius: 3px; padding: 0 .25rem;
}

.badge {
    display: inline-block; font-size: .7rem; padding: .05rem .35rem;
    border: 1px solid var(--border); border-radius: 4px; color: var(--text-soft);
}
.badge-eu { background: var(--bg); }
.badge-us { background: var(--bg); }

/* Mobile position cards */
.card-list { display: none; flex-direction: column; gap: .55rem; }
.pos-card { border: 1px solid var(--border); border-radius: var(--radius); padding: .65rem .7rem; }
.pos-card-top { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.pos-card-grid {
    display: grid; grid-template-columns: auto 1fr; gap: .18rem .6rem;
    margin-top: .5rem; font-size: .82rem;
}
.pos-card-grid span:nth-child(odd) { color: var(--text-dim); }
.pos-card-grid span:nth-child(even) { text-align: right; }

/* --------------------------------------------------------------- stats --- */

.stat-list { display: flex; flex-direction: column; gap: .1rem; margin-top: .3rem; }
.stat-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: baseline;
    gap: .3rem .8rem;
    padding: .42rem 0;
    border-bottom: 1px solid var(--border-sf);
}
.stat-row:last-child { border-bottom: none; }
.stat-k { font-size: .85rem; color: var(--text-soft); }
.stat-v { font-size: .95rem; font-weight: 600; text-align: right; }
.stat-sub { grid-column: 1 / -1; font-size: .74rem; color: var(--text-dim); }

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

.chart { width: 100%; overflow-x: auto; }
.chart svg { display: block; max-width: 100%; height: auto; }
.legend {
    font-size: .77rem; color: var(--text-soft); margin: .6rem 0 0;
    display: flex; gap: 1rem; align-items: center; flex-wrap: wrap;
}
.swatch { display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-right: .3rem; vertical-align: middle; }
.swatch-nav  { background: var(--accent); }
.swatch-cost { background: var(--text-dim); }

/* ---------------------------------------------------------- candlestick --- */

.candles { margin-top: .2rem; }
.candles-bar {
    display: flex; align-items: center; justify-content: space-between;
    gap: .75rem; flex-wrap: wrap; margin-bottom: .5rem;
}
.candles-ranges { display: flex; gap: 2px; }
.range-btn {
    font: inherit; font-size: .74rem; font-weight: 500;
    padding: .2rem .5rem; cursor: pointer;
    background: var(--surface); color: var(--text-soft);
    border: 1px solid var(--border); border-radius: 5px;
}
.range-btn:hover { color: var(--text); border-color: var(--text-dim); }
.range-btn[aria-pressed="true"] {
    background: var(--accent); border-color: var(--accent); color: #fff;
}
.range-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.candles-toggles { display: flex; gap: .8rem; font-size: .76rem; color: var(--text-soft); }
.candles-toggle { display: flex; align-items: center; gap: .3rem; cursor: pointer; }
.candles-toggle-off { opacity: .45; cursor: not-allowed; }
.toggle-swatch { display: inline-block; width: 12px; height: 2px; border-radius: 1px; }

.candles-plot { position: relative; }
.candles-plot svg { display: block; width: 100%; height: auto; }
.candles-plot svg:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.candles-tip {
    position: absolute; top: 6px;
    transform: translateX(10px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: .4rem .55rem;
    font-size: .76rem;
    pointer-events: none;
    min-width: 8.5rem;
    z-index: 5;
}
.candles-tip.tip-left { transform: translateX(-100%) translateX(-10px); }
.tip-date { font-weight: 600; margin-bottom: .2rem; }
.tip-grid { display: grid; grid-template-columns: auto 1fr; gap: .05rem .6rem; }
.tip-k { color: var(--text-dim); }
.tip-v { text-align: right; font-weight: 500; }
.candles-note { font-size: .74rem; color: var(--text-dim); margin: .45rem 0 0; }

/* ------------------------------------------------------ position detail --- */

.detail-meta {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: .1rem .9rem; margin-bottom: .9rem;
}
.detail-item {
    display: flex; justify-content: space-between; gap: .6rem;
    padding: .3rem 0; border-bottom: 1px solid var(--border-sf);
    font-size: .84rem;
}
.detail-k { color: var(--text-soft); }
.detail-v { font-weight: 500; text-align: right; }

/* --------------------------------------------------------- DCA tranche --- */

.next-tranche { padding: .2rem 0 .5rem; border-bottom: 1px solid var(--border-sf); }
.next-tranche:last-child { border-bottom: none; }
.next-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.next-date { font-size: .8rem; color: var(--text-soft); }
.next-big { display: flex; align-items: baseline; gap: .6rem; flex-wrap: wrap; margin: .3rem 0 .15rem; }
.next-amount { font-size: 1.5rem; font-weight: 600; letter-spacing: -.015em; }
.next-buys { font-size: .85rem; color: var(--text-soft); }

/* ------------------------------------------------------------ DCA bars --- */

.bar-row { margin-bottom: .8rem; }
.bar-top { display: flex; justify-content: space-between; font-size: .84rem; margin-bottom: .3rem; gap: .5rem; }
.bar-track { height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; border: 1px solid var(--border); }
.bar-fill  { height: 100%; background: var(--accent); width: 0; }
.bar-fill-pos { background: var(--pos); }
.bar-fill-neg { background: var(--neg); }
.bar-meta { font-size: .76rem; color: var(--text-soft); margin-top: .25rem; }

.stack { display: flex; height: 10px; border-radius: 5px; overflow: hidden; border: 1px solid var(--border); background: var(--bg); }
.stack-principal { background: #7d8894; }
.stack-contrib   { background: var(--accent); }
.stack-growth    { background: #b9d3fb; }
.stack-seg { display: block; height: 100%; }
.seg-contrib { background: #94a3b8; }
.seg-growth  { background: var(--brand); }
.seg-fees    { background: #b0783a; }

/* ---------------------------------------------------- indicators / news --- */

.ind-item, .news-item { padding: .6rem 0; border-bottom: 1px solid var(--border-sf); }
.ind-item:last-child, .news-item:last-child { border-bottom: none; }
.ind-head { display: flex; justify-content: space-between; gap: .5rem; align-items: baseline; }
.ind-metrics { display: grid; grid-template-columns: 1fr; gap: .18rem; margin-top: .35rem; font-size: .83rem; color: var(--text-soft); }

.news-head { display: flex; gap: .5rem; align-items: baseline; flex-wrap: wrap; }
.news-title { font-weight: 500; }
.news-title a { color: var(--text); text-decoration: none; }
.news-title a:hover { color: var(--accent); text-decoration: underline; }
.news-sum { font-size: .85rem; color: var(--text-soft); margin: .3rem 0 .25rem; }
.news-meta { font-size: .75rem; color: var(--text-dim); display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.ai-tag {
    font-size: .68rem; text-transform: uppercase; letter-spacing: .04em;
    color: var(--text-dim); border: 1px solid var(--border);
    border-radius: 3px; padding: 0 .25rem; margin-right: .3rem;
}
.chip { font-size: .7rem; padding: .05rem .35rem; border-radius: 4px; border: 1px solid var(--border); color: var(--text-soft); }
.chip-positive { background: var(--pos-sf); color: var(--pos); border-color: #bfe3ce; }
.chip-negative { background: var(--neg-sf); color: var(--neg); border-color: #f0c4c4; }
.chip-neutral  { background: var(--bg); color: var(--text-soft); }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.stars { color: var(--text-dim); letter-spacing: .05em; }

/* ----------------------------------------------------------- scenarios --- */

.tabs { display: flex; gap: .3rem; flex-wrap: wrap; margin-bottom: .8rem; }
.tab {
    font: inherit; font-size: .82rem; padding: .3rem .65rem; cursor: pointer;
    background: var(--surface); color: var(--text-soft);
    border: 1px solid var(--border); border-radius: 6px;
}
.tab:hover { color: var(--text); border-color: var(--text-dim); }
.tab-active { background: var(--accent); border-color: var(--accent); color: #fff; }

.band { padding: .7rem 0; border-bottom: 1px solid var(--border-sf); }
.band:last-child { border-bottom: none; }
.band-top { display: flex; justify-content: space-between; align-items: baseline; gap: .6rem; flex-wrap: wrap; }
.band-name { font-weight: 600; }
.band-value { font-size: 1.05rem; font-weight: 600; }
.band-assumption { font-size: .77rem; color: var(--text-soft); margin-top: .25rem; }
.dca-proj { margin-top: .35rem; font-size: .81rem; color: var(--text-soft); }
.dca-proj-legend { display: flex; gap: .9rem; flex-wrap: wrap; font-size: .73rem; margin-top: .3rem; color: var(--text-dim); }
.drawdown-line { font-size: .82rem; color: var(--text-soft); margin: .8rem 0 0; }

.disclaimer {
    margin-top: .9rem; padding: .55rem .7rem;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: 6px; font-size: .78rem; color: var(--text-soft);
}
.disclaimer-soft { background: transparent; }

/* --------------------------------------------------------- calculator --- */

.calc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 .9rem; }
.chips { display: flex; gap: .35rem; margin: .25rem 0 1rem; flex-wrap: wrap; }
.calc-headline { margin: .8rem 0 .4rem; }
.calc-headline-label { font-size: .8rem; color: var(--text-soft); }
.calc-headline-value { font-size: 1.55rem; font-weight: 600; letter-spacing: -.02em; }
.breakdown p { margin: .28rem 0; font-size: .88rem; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: .45rem; }
.dot-contrib { background: #94a3b8; }
.dot-growth  { background: var(--brand); }
.dot-fees    { background: #b0783a; }
.calc-chart { width: 100%; height: auto; display: block; margin: .5rem 0; }
.calc-chart .axis { stroke: var(--border); stroke-width: 1; }
.calc-chart .ln-value { fill: none; stroke: var(--brand); stroke-width: 2; }
.calc-chart .ln-base  { fill: none; stroke: #94a3b8; stroke-width: 1.5; stroke-dasharray: 4 3; }
.rate-cards { display: grid; gap: .5rem; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); margin: .5rem 0 1rem; }
.rate-card { border: 1px solid var(--border); border-radius: 6px; padding: .5rem .6rem; }
.rate-card-active { border-color: var(--accent); background: var(--accent-sf); }
.rate-card-label { font-size: .77rem; color: var(--text-soft); }
.rate-card-value { font-size: 1.02rem; font-weight: 600; }
.rate-card-sub { font-size: .74rem; color: var(--text-dim); }
.reality { font-size: .82rem; color: var(--text-soft); margin-top: .6rem; }
.year-table { margin-top: .8rem; }
.year-table summary { cursor: pointer; color: var(--text-soft); font-size: .88rem; }

/* -------------------------------------------------------------- forms --- */

.field { display: flex; flex-direction: column; gap: .22rem; margin-bottom: .65rem; }
.field-label { font-size: .77rem; color: var(--text-soft); }
input[type=text], input[type=password], input[type=number], input[type=date], .select {
    font: inherit; font-size: .88rem;
    padding: .38rem .5rem;
    border: 1px solid var(--border); border-radius: 6px;
    background: var(--surface); color: var(--text);
    width: 100%;
}
input:focus, .select:focus, .btn:focus-visible, .tab:focus-visible, a:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 1px;
}
.select { width: auto; }
.editor-grid { display: grid; grid-template-columns: 1fr; gap: 0 .8rem; }
.editor-actions { display: flex; gap: .5rem; align-items: center; margin-top: .2rem; flex-wrap: wrap; }
.inline-editor { margin-top: .9rem; padding-top: .8rem; border-top: 1px solid var(--border-sf); }
.hidden { display: none; }

.btn {
    font: inherit; font-size: .88rem; cursor: pointer;
    padding: .38rem .7rem;
    border: 1px solid var(--border); border-radius: 6px;
    background: var(--surface); color: var(--text);
    text-decoration: none; display: inline-block;
}
.btn:hover { border-color: var(--text-dim); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #1d4fd8; border-color: #1d4fd8; }
.btn-ghost { background: transparent; }
.btn-sm { padding: .28rem .55rem; font-size: .82rem; }
.btn-block { width: 100%; padding: .55rem; }
.btn-link { background: none; border: none; color: var(--text-soft); cursor: pointer; font: inherit; font-size: .78rem; padding: 0; text-decoration: underline; }
.btn-link:hover { color: var(--neg); }

.form-msg { font-size: .84rem; margin: .5rem 0 0; }
.form-msg.ok  { color: var(--pos); }
.form-msg.err { color: var(--neg); }

.alert { padding: .55rem .7rem; border-radius: 6px; font-size: .86rem; margin: 0 0 .9rem; }
.alert-error { background: var(--neg-sf); color: var(--neg); border: 1px solid #f0c4c4; }

/* -------------------------------------------------------------- login --- */

.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; }
.login-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.6rem; width: 100%; max-width: 360px;
}
.login-title { font-size: 1.15rem; margin-bottom: .25rem; }
.login-sub { color: var(--text-soft); font-size: .86rem; margin: 0 0 1.1rem; }
.login-foot { font-size: .75rem; color: var(--text-dim); margin: 1rem 0 0; text-align: center; }

.foot { text-align: center; color: var(--text-dim); font-size: .75rem; padding: 1.2rem 0 0; }

/* --------------------------------------------------------- responsive --- */

@media (min-width: 640px) {
    .editor-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .editor-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .editor-grid-3 .editor-actions, .editor-grid-2 .editor-actions { grid-column: 1 / -1; }
}

.hamburger { display: none; }
.scrim { display: none; }

@media (max-width: 1080px) {
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .kpi-grid-3 { grid-template-columns: repeat(2, 1fr); }
    .card-row { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
    :root { --sidebar-w: 0px; }

    .sidebar {
        width: 250px;
        transform: translateX(-100%);
        transition: transform .18s ease-out;
    }
    .sidebar.open { transform: translateX(0); }

    .content { margin-left: 0; padding: 3.2rem 0.9rem 3rem; }
    .banner { padding-left: 1rem; }

    .hamburger {
        display: flex; align-items: center; justify-content: center;
        position: fixed; top: .55rem; left: .6rem; z-index: 40;
        width: 38px; height: 38px; padding: 0;
        background: var(--surface); border: 1px solid var(--border);
        border-radius: 7px; cursor: pointer;
    }
    .hamburger svg { width: 21px; height: 21px; fill: none; stroke: var(--text); stroke-width: 1.8; stroke-linecap: round; }
    .scrim { display: block; position: fixed; inset: 0; background: rgba(16,25,29,.32); z-index: 25; }
    .scrim[hidden] { display: none; }

    /* Below this width the position table cannot be read without horizontal
       scrolling, so the same rows are shown as cards instead. */
    .positions-scroll { display: none; }
    .card-list { display: flex; }
}

@media (max-width: 560px) {
    body { font-size: 14px; }
    .kpi-grid, .kpi-grid-3 { grid-template-columns: 1fr 1fr; }
    .kpi-primary { grid-column: 1 / -1; }
    .kpi-primary .kpi-value { font-size: 1.7rem; }
    .content { padding: 3.2rem .7rem 2.5rem; }
    .card { padding: .75rem .7rem .85rem; }
    .candles-bar { gap: .5rem; }
    .detail-meta { grid-template-columns: 1fr; }
}

/* ===================================================== phase 4: refresh ==== */

/* The manual refresh control. Lives in the sidebar head and again on #/overview;
   one stylesheet block serves both so the two copies cannot drift apart. */
.refresh-box {
    padding: .5rem .85rem .7rem;
    border-top: 1px solid var(--border-sf);
}

.refresh-btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    width: 100%;
    justify-content: center;
}

.overview-actions .refresh-btn { width: auto; }

.refresh-btn[disabled] { opacity: .6; cursor: default; }

/* The spinner occupies its box at all times, so the label does not jump
   sideways the instant a refresh starts. */
.refresh-spin {
    width: 12px;
    height: 12px;
    flex: 0 0 12px;
    border-radius: 50%;
    border: 2px solid currentColor;
    border-right-color: transparent;
    opacity: 0;
}

.refresh-btn.is-refreshing .refresh-spin {
    opacity: 1;
    animation: refresh-spin .8s linear infinite;
}

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

/* Motion is decoration here; the label text already says what is happening. */
@media (prefers-reduced-motion: reduce) {
    .refresh-btn.is-refreshing .refresh-spin { animation: none; }
}

.refresh-msg {
    margin: .45rem 0 0;
    font-size: .76rem;
    line-height: 1.35;
    color: var(--text-soft);
    word-break: break-word;
}
.refresh-msg.ok   { color: var(--pos); }
.refresh-msg.warn { color: var(--warn-fg); }
.refresh-msg.err  { color: var(--neg); }

/* What the button can and cannot move. Stated next to it, not in a tooltip. */
.refresh-note {
    margin: .4rem 0 0;
    font-size: .71rem;
    line-height: 1.4;
    color: var(--text-dim);
}
.refresh-note strong { color: var(--text-soft); font-weight: 600; }

.overview-actions {
    display: flex;
    align-items: center;
    gap: .75rem;
    flex-wrap: wrap;
    margin-bottom: .9rem;
}
.overview-actions .refresh-msg { margin: 0; }

/* A KPI with no number is muted rather than rendered as a strong zero. */
.kpi-value.kpi-muted { color: var(--text-dim); }

.tag-manual {
    color: var(--accent);
    font-size: .78rem;
}

/* ====================================================== phase 4: parity ==== */

.parity-table td { vertical-align: top; }

.parity-mark {
    width: 1.8rem;
    text-align: center;
    font-size: .95rem;
    line-height: 1.4;
}

.parity-table tr.parity-warn { background: var(--warn-bg); }
.parity-table tr.parity-fail { background: var(--neg-sf); }

.parity-table td.msg-cell {
    max-width: 34rem;
    white-space: normal;
    font-size: .78rem;
    line-height: 1.45;
    color: var(--text-soft);
}

/* The only actionable part of the panel, so it sits above the table. */
.parity-todo {
    background: var(--warn-bg);
    border: 1px solid var(--warn-bd);
    border-radius: var(--radius);
    padding: .7rem .9rem;
    margin-bottom: .9rem;
}
.parity-todo h3 {
    margin: 0 0 .4rem;
    font-size: .82rem;
    font-weight: 600;
    color: var(--warn-fg);
}
.parity-todo ul { margin: 0; padding-left: 1.1rem; }
.parity-todo li {
    font-size: .79rem;
    line-height: 1.5;
    color: var(--text-soft);
    margin-bottom: .35rem;
}
.parity-todo li strong { color: var(--warn-fg); }

@media (max-width: 900px) {
    .refresh-box { padding: .5rem .7rem .6rem; }
    .parity-table td.msg-cell { max-width: 18rem; }
}

/* ============================== phase 5: broker vocabulary + price authority = */

/* Five cards, matching IBKR's account summary block. */
.kpi-grid-5 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

/* B3 — fidelity strip, directly under the header cards. */
.parity-strip {
    display: flex;
    align-items: center;
    gap: .6rem;
    flex-wrap: wrap;
    padding: .5rem .8rem;
    margin: 0 0 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: inherit;
    font-size: .79rem;
}
.parity-strip:hover { border-color: var(--accent-bd); background: var(--accent-sf); }
.parity-strip-label { font-weight: 600; color: var(--text-soft); }
.parity-strip-counts { font-variant-numeric: tabular-nums; }
.parity-strip-counts.all-ok   { color: var(--pos); }
.parity-strip-counts.has-warn { color: var(--warn-fg); }
.parity-strip-counts.has-fail { color: var(--neg); }
.parity-strip-src {
    margin-left: auto;
    color: var(--text-dim);
    font-size: .75rem;
}

/* INSTRUMENT cell: symbol over full name, the way IBKR stacks it. */
.instrument-cell { white-space: normal; }
.instrument-wrap { display: inline-flex; flex-direction: column; line-height: 1.25; }
.instrument-sym  { font-weight: 600; }
.instrument-name {
    font-size: .72rem;
    color: var(--text-dim);
    font-weight: 400;
    max-width: 15rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Every numeric column lines up on the decimal point. */
.data-table td.num,
.data-table th.num { font-variant-numeric: tabular-nums; text-align: right; }

/* A cell carrying a primary figure and a quieter secondary one beneath. */
.cell-primary   { display: block; }
.cell-secondary { display: block; font-size: .72rem; opacity: .75; }

/* LAST column: broker mark primary, the other venue's quote beneath it. */
.price-cell { white-space: nowrap; }
.price-tag {
    display: block;
    font-size: .68rem;
    color: var(--text-dim);
    font-weight: 400;
}
.price-alt {
    display: block;
    font-size: .72rem;
    color: var(--text-soft);
    font-variant-numeric: tabular-nums;
}
/* A quote taken while the venue is shut is not a price anyone could trade at. */
.price-alt-indicative { color: var(--text-dim); }
.price-indicative {
    display: block;
    font-size: .66rem;
    font-style: italic;
    color: var(--text-dim);
}

@media (max-width: 1100px) {
    .instrument-name { max-width: 9rem; }
}
@media (max-width: 900px) {
    .parity-strip-src { margin-left: 0; width: 100%; }
}
