/* MyEcho Trader. Colour roles follow a CVD-checked categorical palette; up/down also differ by shape (hollow/filled). */
:root {
  color-scheme: light;
  --bg: #f4f4f2; --surface: #fcfcfb; --surface-2: #f0efec; --line: #dddcd7; --grid: #e9e8e4;
  --text: #0b0b0b; --text-2: #52514e; --muted: #75746f;
  --accent: #2a78d6; --accent-ink: #fff;
  --up: #1baf7a; --down: #e34948; --up-ink: #0b7a52; --down-ink: #b3302f;
  --s1: #2a78d6; --s2: #eb6834; --s3: #4a3aa7; --s4: #e87ba4;
  --warn-bg: #fff4d6; --warn-ink: #6b4a00; --warn-line: #fab219;
  --demo-bg: #efe9ff; --demo-ink: #4a3aa7;
  --ok-bg: #e3f5e3; --ok-ink: #0a6b0a;
  --bad-bg: #fde7e7; --bad-ink: #a32727;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --line: #34342f; --grid: #2a2a27;
    --text: #fff; --text-2: #c3c2b7; --muted: #9b9a90;
    --accent: #3987e5;
    --up: #199e70; --down: #e66767; --up-ink: #4fd3a0; --down-ink: #ff8f8f;
    --s1: #3987e5; --s2: #d95926; --s3: #9085e9; --s4: #d55181;
    --warn-bg: #3a2e0c; --warn-ink: #ffd56b; --warn-line: #c98500;
    --demo-bg: #2b2547; --demo-ink: #c4bdff;
    --ok-bg: #12301a; --ok-ink: #7fdc8b;
    --bad-bg: #3a1717; --bad-ink: #ff9b9b;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.1rem; } h3 { font-size: .95rem; }
p { margin: .4rem 0; }
.skip { position: absolute; left: -999px; top: 0; background: var(--surface); padding: .5rem; z-index: 10; }
.skip:focus { left: .5rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: .92em; word-break: break-all; }
.muted { color: var(--muted); } .small { font-size: .85em; }
.up { color: var(--up-ink); } .down { color: var(--down-ink); }

/* Header */
.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top-row { display: flex; align-items: center; gap: .6rem; padding: .55rem 1rem; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 1.05rem; color: var(--text); text-decoration: none; }
.brand span { color: var(--accent); }
.spacer { flex: 1; }
.who { color: var(--text-2); }
.tabs { display: flex; gap: .25rem; padding: 0 .75rem; overflow-x: auto; scrollbar-width: thin; }
.tabs a { padding: .55rem .7rem; color: var(--text-2); text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .12rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 600; border: 1px solid transparent; white-space: nowrap; }
.badge-paper { background: var(--warn-bg); color: var(--warn-ink); border-color: var(--warn-line); }
.badge-paper::before { content: "⚠"; }
.badge.demo { background: var(--demo-bg); color: var(--demo-ink); }
.badge.demo::before { content: "◇"; }
.badge.streaming, .badge.live, .badge.open { background: var(--ok-bg); color: var(--ok-ink); }
.badge.delayed { background: var(--warn-bg); color: var(--warn-ink); }
.badge.delayed::before { content: "⏱"; }
.badge.streaming::before { content: "●"; }
.badge.stale, .badge.empty, .badge.unavailable { background: var(--bad-bg); color: var(--bad-ink); }
.badge.stale::before { content: "!"; }
.badge.imported, .badge.closed, .badge.pre, .badge.post, .badge.unknown { background: var(--surface-2); color: var(--text-2); border-color: var(--line); }

/* Layout */
main { padding: 1rem; max-width: 1400px; margin: 0 auto; outline: none; }
.foot { padding: 1.5rem 1rem 2rem; text-align: center; color: var(--muted); font-size: .8rem; max-width: 900px; margin: 0 auto; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem; min-width: 0; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.grid { display: grid; gap: 1rem; }
.grid.two { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid.half { grid-template-columns: 1fr 1fr; }
.grid.side { grid-template-columns: 260px minmax(0, 1fr); }
@media (max-width: 960px) { .grid.two, .grid.half, .grid.side { grid-template-columns: minmax(0, 1fr); } }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: .6rem; }
.banner { border-radius: var(--radius); padding: .7rem 1rem; margin-bottom: 1rem; border: 1px solid; }
.banner.paper { background: var(--warn-bg); color: var(--warn-ink); border-color: var(--warn-line); font-weight: 600; }
.banner.demo { background: var(--demo-bg); color: var(--demo-ink); border-color: transparent; }
.banner.error { background: var(--bad-bg); color: var(--bad-ink); border-color: transparent; }
.narrow { max-width: 420px; margin: 2rem auto; }

/* Controls */
.btn { font: inherit; padding: .45rem .8rem; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; min-height: 36px; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--down-ink); }
.btn.ghost { background: transparent; }
.btn.small { padding: .2rem .5rem; min-height: 28px; font-size: .85rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow-x: auto; max-width: 100%; }
.seg button { flex: none; }
.seg button { font: inherit; border: 0; background: var(--surface); color: var(--text-2); padding: .35rem .6rem; cursor: pointer; min-height: 32px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
label { display: block; font-weight: 600; font-size: .85rem; margin: .5rem 0 .2rem; color: var(--text-2); }
label.inline { display: inline-flex; align-items: center; gap: .3rem; font-weight: 400; margin: 0; color: var(--text); }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .42rem .55rem; min-height: 36px; max-width: 100%; }
input[type="checkbox"] { min-height: auto; }
textarea { width: 100%; min-height: 70px; resize: vertical; }
.field { width: 100%; }
.error { color: var(--bad-ink); min-height: 1.2em; }
.hint { color: var(--muted); font-size: .85rem; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: .45rem .5rem; border-bottom: 1px solid var(--grid); text-align: left; vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tbody tr:hover { background: var(--surface-2); }
td a { text-decoration: none; font-weight: 600; }

/* Stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .6rem; }
.tile { background: var(--surface-2); border-radius: 8px; padding: .6rem .7rem; }
.tile .k { font-size: .75rem; color: var(--muted); }
.tile .v { font-size: 1.2rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.tile .s { font-size: .78rem; color: var(--text-2); }
.tile .def { font-size: .75rem; color: var(--muted); margin-top: .25rem; }

/* Charts */
.chart { position: relative; width: 100%; user-select: none; touch-action: pan-y; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart:focus-visible { outline: 2px solid var(--accent); }
.chart text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-line { stroke: var(--line); }
.chart .wick { stroke-width: 1; }
.chart .c-up { stroke: var(--up); fill: var(--surface); }
.chart .c-down { stroke: var(--down); fill: var(--down); }
.chart .vol-up { fill: var(--up); opacity: .45; }
.chart .vol-down { fill: var(--down); opacity: .45; }
.chart .price-line { stroke: var(--s1); stroke-width: 2; fill: none; }
.chart .series { stroke-width: 2; fill: none; stroke-linejoin: round; }
.chart .ser-1 { stroke: var(--s1); } .chart .ser-2 { stroke: var(--s2); } .chart .ser-3 { stroke: var(--s3); } .chart .ser-4 { stroke: var(--s4); }
.chart .ref { stroke: var(--line); stroke-dasharray: 4 4; }
.chart .cross { stroke: var(--text-2); stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }
.chart .pane-label { fill: var(--text-2); font-weight: 600; }
.tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .45rem .55rem; font-size: .8rem; box-shadow: 0 4px 16px rgba(0,0,0,.15); min-width: 150px; z-index: 2; }
.tip b { display: block; margin-bottom: .15rem; }
.tip .r { display: flex; justify-content: space-between; gap: .8rem; font-variant-numeric: tabular-nums; }
.legend { display: flex; flex-wrap: wrap; gap: .8rem; font-size: .82rem; color: var(--text-2); margin: .3rem 0; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: .3rem; }
.legend .l1 { background: var(--s1); } .legend .l2 { background: var(--s2); } .legend .l3 { background: var(--s3); } .legend .l4 { background: var(--s4); }
.tv-frame { width: 100%; height: 520px; border: 0; border-radius: 8px; background: var(--surface-2); }

/* Bars (allocation) */
.hbar { display: grid; grid-template-columns: minmax(90px, 160px) 1fr 64px; gap: .5rem; align-items: center; margin: .3rem 0; font-size: .85rem; }
.hbar .track { background: var(--surface-2); border-radius: 4px; height: 12px; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--s1); border-radius: 0 4px 4px 0; }
.hbar .fill.cash { background: var(--muted); }

/* Search */
.search { position: relative; flex: 1; min-width: 220px; }
.search input { width: 100%; }
.results { position: absolute; top: 100%; left: 0; right: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; margin-top: 4px; z-index: 4; max-height: 320px; overflow-y: auto; box-shadow: 0 8px 24px rgba(0,0,0,.15); }
.results button { display: flex; width: 100%; text-align: left; gap: .5rem; justify-content: space-between; border: 0; background: none; color: var(--text); padding: .5rem .6rem; font: inherit; cursor: pointer; }
.results button:hover, .results button:focus { background: var(--surface-2); }

/* Rules editor */
.rule { display: flex; gap: .35rem; align-items: center; flex-wrap: wrap; padding: .4rem; border: 1px dashed var(--line); border-radius: 8px; margin: .3rem 0; }
.rule input[type="number"] { width: 5.5rem; }
.list-btn { display: block; width: 100%; text-align: left; border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: .5rem .6rem; border-radius: 8px; margin-bottom: .35rem; cursor: pointer; font: inherit; }
.list-btn[aria-current="true"] { border-color: var(--accent); background: var(--surface-2); }

/* AI */
.answer { white-space: pre-wrap; background: var(--surface-2); border-radius: 8px; padding: .7rem .8rem; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip { font: inherit; font-size: .82rem; border: 1px solid var(--line); background: var(--surface); color: var(--text-2); border-radius: 999px; padding: .2rem .6rem; cursor: pointer; }
pre.code { background: var(--surface-2); border-radius: 8px; padding: .7rem; overflow: auto; max-height: 260px; font-size: .78rem; }
details > summary { cursor: pointer; font-weight: 600; margin: .3rem 0; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: .25rem .8rem; margin: 0; font-size: .88rem; }
dl.kv dt { color: var(--muted); } dl.kv dd { margin: 0; }
.empty-state { text-align: center; color: var(--muted); padding: 1.5rem .5rem; }
.loading { color: var(--muted); padding: 1rem 0; }
.loading::after { content: " …"; }
.toast { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 8px; z-index: 20; max-width: calc(100% - 2rem); }
.toast.bad { background: var(--down); color: #fff; }
@media (max-width: 600px) { main { padding: .6rem; } .card { padding: .75rem; } .tile .v { font-size: 1.05rem; } }
@media (forced-colors: active) { .badge { border: 1px solid CanvasText; } .chart .c-down { fill: CanvasText; } }
