/* Dashboard styles. Design tokens first; everything else uses them. The page
   runs under a strict CSP, so no inline style= anywhere (states are body or
   element classes). Layout is one column, 900px on desktop, edge-to-edge
   cards on phones. Theme: the light tokens are the default; the dark set
   applies under the device's prefers-color-scheme and the chart reads the
   same tokens at render time (app.js cssVar), so both follow the device. */
:root {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  color-scheme: light dark;
  --bg: #f5f6f8; --card: #fff; --card-alt: #fafbfc; --chip: #f5f6f8; --line: #e6e8ec; --line-strong: #cfd3da;
  --ink: #1a1a2e; --ink2: #3f4453; --muted: #5f6675; --faint: #778;
  --header-bg: #1a1a2e; --header-ink: #fff; --header-btn: #888; --header-btn-ink: #ddd;
  --pill-bg: rgba(255,255,255,.14); --pill-ink: #f3d9a4; --pill-line: rgba(243,217,164,.5);
  --up: #0a7c42; --up-bg: #e3f3ea; --down: #c0392b; --down-bg: #fdecea;
  --queued: #2b5fb3; --queued-bg: #e8effa;
  --warn: #7a5200; --warn-bg: #fff4e5; --warn-line: #f0c36d;
  --bad: #8f2a1f; --bad-bg: #fdecea; --bad-line: #f1b0a7;
  --series1: #1a1a2e; --series2: #9aa0aa; --series2-ink: #5f6675; --grid: #eef0f3;
  --tooltip-bg: #1a1a2e; --tooltip-ink: #fff;
  --bar-bg: #e6e8ec; --bar-fill: #1a1a2e; --cash-seg: #b9c0cc;
  --sk1: #eceef2; --sk2: #f6f7f9; --modal-bg: #fff; --btn-bg: #eee; --scrim: rgba(0,0,0,.45);
  --radius: 10px; --shadow: 0 1px 3px rgba(0,0,0,.08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161d; --card: #1d2029; --card-alt: #22252f; --chip: #262a35; --line: #2f3340; --line-strong: #444a5a;
    --ink: #eceef3; --ink2: #c3c7d1; --muted: #9aa0ad; --faint: #8a90a0;
    --header-bg: #0f1117; --header-ink: #f2f3f7; --header-btn: #5b6272; --header-btn-ink: #c9cdd6;
    --pill-bg: rgba(243,217,164,.12); --pill-ink: #f3d9a4; --pill-line: rgba(243,217,164,.45);
    --up: #4cc38a; --up-bg: #163526; --down: #ef6b5c; --down-bg: #3a1f1c;
    --queued: #7aa5ec; --queued-bg: #1e2a40;
    --warn: #f0c36d; --warn-bg: #33290f; --warn-line: #7a5f22;
    --bad: #ffb4a8; --bad-bg: #3a1f1c; --bad-line: #7a3b33;
    --series1: #eceef3; --series2: #8a90a0; --series2-ink: #b0b5c1; --grid: #2a2e3a;
    --tooltip-bg: #2a2e3a; --tooltip-ink: #eceef3;
    --bar-bg: #2f3340; --bar-fill: #d5d8e1; --cash-seg: #4a5062;
    --sk1: #22252f; --sk2: #2a2e3a; --modal-bg: #1d2029; --btn-bg: #2f3340; --scrim: rgba(0,0,0,.65);
    --shadow: 0 1px 3px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.5;
       font-variant-numeric: tabular-nums; }
header { background: var(--header-bg); color: var(--header-ink); padding: 12px 20px;
         display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
header h1 { font-size: 18px; margin: 0; font-weight: 600; }
.pill { font-size: 12px; padding: 3px 10px; border-radius: 999px; background: var(--pill-bg);
        color: var(--pill-ink); border: 1px solid var(--pill-line); white-space: nowrap; }
.lang { display: flex; gap: 6px; flex: none; }
.lang button { background: none; border: 1px solid var(--header-btn); color: var(--header-btn-ink);
               padding: 5px 12px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.lang button.on { background: var(--header-ink); color: var(--header-bg); border-color: var(--header-ink); }
main { max-width: 900px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border-radius: 12px; padding: 18px 20px;
        margin-bottom: 16px; box-shadow: var(--shadow); }
h2 { font-size: 15px; margin: 0 0 10px; color: var(--ink2); font-weight: 600; }
h3 { font-size: 14px; margin: 18px 0 8px; color: var(--muted); font-weight: 600;
     text-transform: none; }
.hint { color: var(--muted); font-size: 14px; margin: 4px 0 0; }

/* status line + banners */
.status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; color: var(--ink2);
          font-size: 14px; margin: 0 4px 14px; }
.status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--up); flex: none; }
.status.stale .dot { background: var(--warn-line); }
.status.failed .dot { background: var(--down); }
.status .sep { color: var(--muted); }
.warn { background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--warn);
        padding: 12px 14px; border-radius: var(--radius); margin-bottom: 16px;
        font-size: 14px; display: none; }
.warn.on { display: block; }
.warn.bad { background: var(--bad-bg); border-color: var(--bad-line); color: var(--bad); }
.warn strong { display: block; margin-bottom: 2px; }
#demoTag { display: none; }
body.demo #demoTag { display: block; text-align: center; font-size: 12px; color: var(--warn);
                     background: var(--warn-bg); padding: 4px; }

/* hero: value + deltas + allocation + stat tiles */
.big { font-size: 34px; font-weight: 700; letter-spacing: -.01em; line-height: 1.15; }
.deltas { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 4px; font-size: 15px; }
.deltas .l { color: var(--muted); }
.up { color: var(--up); } .down { color: var(--down); } .flat { color: var(--ink2); }
.alloc { margin: 16px 0 4px; }
.alloc .bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--line); gap: 2px; }
.alloc .inv { background: var(--ink); }
.alloc .cashseg { background: var(--cash-seg); }
.alloc .lbl { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink2); margin-top: 6px; }
.alloc .lbl b { color: var(--ink); font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0 0; }
.stat { background: var(--chip); border-radius: var(--radius); padding: 10px 12px; }
.stat .v { font-size: 18px; font-weight: 600; }
.stat .v.pos { color: var(--up); } .stat .v.neg { color: var(--down); }
.stat .l { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* chart */
.legend { display: flex; gap: 18px; font-size: 13px; color: var(--ink2); margin-bottom: 8px; }
.legend span::before { content: ""; display: inline-block; width: 18px; height: 0; vertical-align: middle;
                       margin-right: 6px; border-top: 2px solid var(--ink); }
.legend .spy::before { border-top-style: dashed; border-color: var(--series2); }
.chartWrap { position: relative; height: 240px; }

/* activity + decisions */
.item { display: grid; grid-template-columns: auto 1fr; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.item:first-child { border-top: none; padding-top: 4px; }
.badge { width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
         font-size: 16px; font-weight: 700; flex: none; background: var(--chip); color: var(--ink2); }
.badge.filled { background: var(--up-bg); color: var(--up); }
.badge.queued { background: var(--queued-bg); color: var(--queued); border: 2px dashed var(--queued); }
.badge.stopped, .badge.blocked { background: var(--down-bg); color: var(--down); }
.item .who { font-weight: 600; }
.item .who .tk { color: var(--muted); font-weight: 500; font-size: 13px; margin-left: 6px; }
.item .what { color: var(--ink2); font-size: 14px; }
.tag { display: inline-block; font-size: 12px; padding: 2px 9px; border-radius: 10px;
       background: var(--chip); color: var(--ink2); margin-left: 8px; vertical-align: middle; }
.tag.executed { background: var(--up-bg); color: var(--up); }
.tag.queued { background: var(--queued-bg); color: var(--queued); border: 1px dashed var(--queued); }
.tag.blocked, .tag.cancelled, .tag.expired { background: var(--down-bg); color: var(--down); }
.tag.skipped { background: var(--chip); color: var(--ink2); }
.tag.stale { background: var(--warn-bg); color: var(--warn); margin-left: 6px; }
.group { margin: 12px 0 0; }
.group .gh { font-size: 13px; font-weight: 600; color: var(--ink2); margin-bottom: 2px; }
.group.queued .gh { color: var(--queued); }
.group.filled .gh { color: var(--up); }
.quiet { color: var(--ink2); background: var(--chip); border-radius: var(--radius); padding: 12px 14px; }
#decisionsWrap > summary { cursor: pointer; color: var(--queued); font-size: 15px; padding: 8px 0; list-style: none; }
#decisionsWrap > summary::before { content: "▸ "; font-size: 12px; }
#decisionsWrap[open] > summary::before { content: "▾ "; }
.decision { border-left: 4px solid var(--line-strong); padding: 8px 14px; margin: 8px 0;
            background: var(--card-alt); border-radius: 0 8px 8px 0; }
.decision.executed { border-color: var(--up); }
.decision.queued { border-color: var(--queued); border-left-style: dashed; }
.decision.blocked, .decision.cancelled, .decision.expired { border-color: var(--down); }
.decision .head { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 0; }
.decision .head .act { margin-left: 6px; color: var(--ink2); }
/* execution facts (fill date/price, cancel reason, stop events) are always
   visible; .detail below is the judge-score card behind the toggle */
.exec-detail { font-size: 0.92em; color: var(--ink2); margin: 4px 0; }
.help { font-size: 14px; color: var(--muted); margin: 2px 0 0; }
.summary { margin: 6px 0 0; font-size: 15px; line-height: 1.6; white-space: pre-line; }
details.why { margin-top: 4px; }
details.why summary { cursor: pointer; font-size: 15px; color: var(--queued); list-style: none; padding: 6px 0; min-height: 24px; }
details.why summary::before { content: "▸ "; font-size: 12px; }
details[open].why summary::before { content: "▾ "; }
details.why .summary { margin: 6px 0 4px; }
.judge { font-size: 12px; color: var(--faint); margin-top: 4px; display: none; }
body.detail-on .judge { display: block; }
body.detail-on .detail { display: block; }
.detail { display: none; }
#detailToggle { font-size: 13px; color: var(--muted); cursor: pointer; text-decoration: underline; background: none; border: none; }
.clickable { cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }

/* holdings: a grid that reflows on phones */
.pos .row { display: grid; grid-template-columns: 1.7fr 1fr 1fr 1fr; gap: 8px 12px; align-items: center;
            padding: 10px 0; border-top: 1px solid var(--line); }
.pos .row.head { border-top: none; padding: 0 0 6px; color: var(--muted); font-size: 12px; font-weight: 500; }
.pos .row.foot { font-weight: 600; }
.pos .num { text-align: right; }
.pos .sub { color: var(--muted); font-size: 13px; font-weight: 400; }
.pos .more { display: none; }
.pos .lbl { display: none; }                 /* phones: labels replace the hidden header row */
.pos .name { font-weight: 600; }
.pos .name .tk { color: var(--muted); font-weight: 500; font-size: 13px; margin-left: 6px; }
.wbar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 4px; }
.wbar i { display: block; height: 100%; background: var(--ink); border-radius: 3px; }
/* SVG bars (app.js bar()): colours from the tokens, so they follow the theme */
.wbar .bg { fill: var(--bar-bg); } .wbar .fg { fill: var(--bar-fill); }
.pos .row .w { font-size: 13px; color: var(--ink2); }

/* ledger table */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
.num { text-align: right; }
#costLine, #winLine { color: var(--muted); font-size: 13px; }
.center { text-align: center; }

/* loading skeleton: shown until the first render() */
.sk { display: none; background: linear-gradient(90deg, var(--sk1), var(--sk2), var(--sk1)); background-size: 200% 100%;
      border-radius: 6px; height: 14px; animation: sk 1.2s linear infinite; }
body.loading .sk { display: block; }
body.loading .live { display: none; }
.sk.tall { height: 34px; width: 55%; }
.sk.wide { height: 200px; }
.sk.mid { width: 70%; }
@keyframes sk { from { background-position: 200% 0; } to { background-position: -200% 0; } }

#modal { display: none; position: fixed; inset: 0; background: var(--scrim); z-index: 10; }
#modal .inner { background: var(--modal-bg); max-width: 640px; margin: 6vh auto; max-height: 82vh; overflow-y: auto;
                border-radius: 14px; padding: 18px 20px; }
#modalClose { float: right; border: none; background: var(--btn-bg); color: var(--ink); border-radius: 8px; padding: 4px 10px; cursor: pointer; }
footer { text-align: center; color: var(--muted); font-size: 12px; padding: 12px 16px 24px; }

@media (max-width: 640px) {
  body { font-size: 16px; }
  header { padding: 10px 14px; }
  main { padding: 10px; }
  .card { padding: 14px; border-radius: var(--radius); }
  .big { font-size: 30px; }
  .stats { grid-template-columns: 1fr; }
  .stat { display: flex; align-items: baseline; gap: 10px; }
  .stat .l { margin: 0; }
  .chartWrap { height: 200px; }
  /* holdings: two compact rows (name | value, gain | share), details behind "more" */
  .pos .row { grid-template-columns: 1fr auto; gap: 4px 12px; }
  .pos .row.head { display: none; }
  .pos .sub.desk, .pos .wbar { display: none; }
  .pos .row .w { text-align: right; }
  .pos .row .w .sub { font-size: 14px; color: var(--ink2); }
  .pos .lbl { display: inline; color: var(--muted); font-size: 13px; font-weight: 400; }
  .pos .sub { font-size: 14px; }
  .pos .more { display: block; grid-column: 1 / -1; }
  .pos .more summary { cursor: pointer; font-size: 14px; color: var(--queued); list-style: none; padding: 4px 0; }
  .pos .more summary::before { content: "▸ "; font-size: 12px; }
  .pos details[open].more summary::before { content: "▾ "; }
  .item .what, .summary { font-size: 15px; }
  .status { font-size: 15px; }
  details.why summary { padding: 8px 0; }
  .item { gap: 10px; }
}

/* welcome / sign-in page (server-rendered by dashboard/app.py) */
.login main { max-width: 440px; padding-top: 6vh; }
.login .card h2 { font-size: 17px; color: var(--ink); margin-bottom: 14px; }
.login label { display: block; font-size: 14px; color: var(--ink2); margin: 10px 0 6px; }
.login .pwrow { display: flex; gap: 8px; }
.login input[type=password], .login input[type=text] { flex: 1; font-size: 17px; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--card); color: var(--ink); min-width: 0; }
.login #showPw { font-size: 14px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--chip); color: var(--ink2); cursor: pointer; white-space: nowrap; }
.login .remember { display: flex; align-items: center; gap: 8px; margin: 14px 0 4px; font-size: 14px; color: var(--ink2); }
.login .remember input { width: 18px; height: 18px; }
.login .go { display: block; width: 100%; margin-top: 16px; font-size: 17px; padding: 12px; border-radius: 8px; border: none;
  background: var(--ink); color: var(--card); cursor: pointer; }
.login .err { background: var(--bad-bg); border: 1px solid var(--bad-line); color: var(--bad); padding: 10px 12px;
  border-radius: 8px; font-size: 14px; margin-bottom: 12px; }
.login .lang a { display: inline-block; text-decoration: none; border: 1px solid var(--header-btn); color: var(--header-btn-ink);
  padding: 5px 12px; border-radius: 6px; font-size: 14px; }
.login .lang a.on { background: var(--header-ink); color: var(--header-bg); border-color: var(--header-ink); }
.login .note { color: var(--muted); font-size: 13px; margin-top: 12px; }
footer form { display: inline; }
footer .link { background: none; border: none; color: var(--muted); font-size: 12px; text-decoration: underline; cursor: pointer; padding: 0 6px; }
