:root {
  color-scheme: light;
  --bg: #f6f6f3;
  --surface: #ffffff;
  --surface-2: #f0efeb;
  --border: #e3e2dc;
  --border-strong: #cfcdc5;
  --text: #121211;
  --text-2: #52514e;
  --text-3: #85847e;
  --accent: #2a78d6;
  --accent-soft: #e3eefb;
  --bench: #eb6834;
  --up: #0f8a4a;
  --up-soft: #e2f4ea;
  --down: #d03b3b;
  --down-soft: #fbe7e7;
  --warn: #b57800;
  --warn-soft: #fbf1db;
  --grid: #ebeae5;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --c1: #2a78d6; --c2: #eb6834; --c3: #1baf7a; --c4: #eda100;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --border: #2e2e2b; --border-strong: #3d3d39;
    --text: #f0efec; --text-2: #c3c2b7; --text-3: #8a897f;
    --accent: #4d94ea; --accent-soft: #1b2b40; --bench: #e0703f;
    --up: #3cc47c; --up-soft: #15301f; --down: #f06a6a; --down-soft: #3a1b1b; --warn: #e2a72e; --warn-soft: #362a10;
    --grid: #262624; --shadow: 0 1px 2px rgba(0,0,0,.3);
    --c1: #3987e5; --c2: #d95926; --c3: #199e70; --c4: #c98500;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --border: #2e2e2b; --border-strong: #3d3d39;
  --text: #f0efec; --text-2: #c3c2b7; --text-3: #8a897f;
  --accent: #4d94ea; --accent-soft: #1b2b40; --bench: #e0703f;
  --up: #3cc47c; --up-soft: #15301f; --down: #f06a6a; --down-soft: #3a1b1b; --warn: #e2a72e; --warn-soft: #362a10;
  --grid: #262624; --shadow: 0 1px 2px rgba(0,0,0,.3);
  --c1: #3987e5; --c2: #d95926; --c3: #199e70; --c4: #c98500;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: "Oxygen Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.small { font-size: 11.5px; }
.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--text-2); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap-ok { flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- top bar */
.topbar { position: sticky; top: 0; z-index: 30; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.topbar .wrap { display: flex; align-items: center; gap: 14px; height: 54px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); font-size: 14px; letter-spacing: -.02em; }
.brand:hover { text-decoration: none; }
.brand .logo { width: 24px; height: 24px; border-radius: 6px; background: var(--text); color: var(--bg);
  display: grid; place-items: center; font-size: 13px; }
.ticker { display: flex; gap: 18px; overflow-x: auto; scrollbar-width: none; flex: 1; min-width: 0; }
.ticker::-webkit-scrollbar { display: none; }
.tick { display: flex; align-items: center; gap: 8px; white-space: nowrap; font-size: 12px; }
.tick b { font-weight: 600; color: var(--text-2); }
.status-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; padding: 3px 9px; border-radius: 99px;
  border: 1px solid var(--border); background: var(--surface); white-space: nowrap; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); }
.dot.live { background: var(--up); box-shadow: 0 0 0 0 var(--up); animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--up) 60%, transparent); } 70% { box-shadow: 0 0 0 6px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

/* ---------- buttons & inputs */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border-strong); background: var(--surface);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; font-size: 12.5px; white-space: nowrap; }
.btn:hover { border-color: var(--text-3); }
.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn.primary:hover { opacity: .88; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--down); }
.btn.sm { padding: 4px 8px; font-size: 11.5px; border-radius: 6px; }
.btn.icon { padding: 6px 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--border-strong); background: var(--surface);
  border-radius: 8px; padding: 8px 10px; outline: none; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label.field { display: grid; gap: 4px; font-size: 11.5px; color: var(--text-2); }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 8px; padding: 2px; background: var(--surface); gap: 2px; }
.seg button { border: 0; background: transparent; padding: 5px 10px; border-radius: 6px; cursor: pointer; font-size: 12px; color: var(--text-2); white-space: nowrap; }
.seg button.on { background: var(--text); color: var(--bg); }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: transparent; color: var(--text-2); padding: 3px 9px; border-radius: 99px; cursor: pointer; font-size: 11.5px; }
.chip.on { border-color: var(--text); color: var(--text); background: var(--surface-2); }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 10.5px; padding: 2px 7px; border-radius: 99px;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; text-transform: uppercase; letter-spacing: .03em; }
.tag.edit { color: var(--up); background: var(--up-soft); border-color: transparent; }
.tag.view { color: var(--warn); background: var(--warn-soft); border-color: transparent; }

/* ---------- cards & grids */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; gap: 10px; padding: 14px 16px 0; flex-wrap: wrap; }
.card-h h3 { margin: 0; font-size: 13px; font-weight: 700; }
.card-h .sub { color: var(--text-3); font-size: 11.5px; }
.card-b { padding: 14px 16px 16px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 900px) { .g2, .g3, .g-main { grid-template-columns: 1fr; } }
section { margin: 18px 0; }

/* ---------- KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 10px; }
.kpis.kpis-3 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.kpi .k { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; display: flex; align-items: center; gap: 6px; }
.kpi .v { font-size: 20px; font-weight: 700; margin-top: 4px; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .s { font-size: 12px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi.kpi-hero .v { font-size: 26px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.stat { background: var(--surface); padding: 10px 12px; min-width: 0; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); margin: 0 -1px -1px 0; }
.stat .k { font-size: 11px; color: var(--text-3); display: flex; gap: 4px; align-items: center; }
.stat .v { font-size: 14px; font-weight: 600; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .s { font-size: 11px; color: var(--text-3); }
.help { display: inline-grid; place-items: center; width: 13px; height: 13px; border-radius: 50%; border: 1px solid var(--border-strong);
  font-size: 9px; color: var(--text-3); cursor: help; flex: none; }

/* ---------- arrows & badges */
.chg { display: inline-flex; align-items: center; gap: 3px; font-weight: 600; white-space: nowrap; }
.chg .arw { font-size: .8em; }
.pill-chg { display: inline-flex; align-items: center; gap: 3px; padding: 1px 7px; border-radius: 6px; font-weight: 600; font-size: 12px; white-space: nowrap; }
.pill-chg.up { background: var(--up-soft); }
.pill-chg.down { background: var(--down-soft); }
.pill-chg.flat { background: var(--surface-2); }
.flash-up { animation: flashUp 1.2s ease-out; }
.flash-down { animation: flashDown 1.2s ease-out; }
@keyframes flashUp { from { background: var(--up-soft); } to { background: transparent; } }
@keyframes flashDown { from { background: var(--down-soft); } to { background: transparent; } }

/* ---------- page header */
.phead { display: flex; align-items: flex-start; gap: 14px; margin: 22px 0 14px; flex-wrap: wrap; }
.phead h1 { margin: 0; font-size: 22px; letter-spacing: -.03em; line-height: 1.2; }
.phead .desc { color: var(--text-2); margin-top: 4px; max-width: 70ch; }
.phead .meta { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; align-items: center; }
.editable { border-radius: 6px; padding: 0 4px; margin: 0 -4px; cursor: text; }
.editable:hover { background: var(--surface-2); }
.refresh { font-size: 11.5px; color: var(--text-3); display: flex; align-items: center; gap: 6px; }

/* ---------- tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; scrollbar-width: none;
  position: sticky; top: 54px; background: var(--bg); z-index: 20; }
.tabs button { border: 0; background: transparent; padding: 10px 14px; cursor: pointer; color: var(--text-2); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button.on { color: var(--text); border-bottom-color: var(--text); font-weight: 600; }

/* ---------- tables */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.t th { text-align: right; font-weight: 500; color: var(--text-3); font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0; background: var(--surface); cursor: pointer; user-select: none; }
table.t th:first-child, table.t td:first-child { text-align: left; }
table.t th.sorted { color: var(--text); }
table.t td { text-align: right; padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: middle; }
table.t tbody tr { cursor: pointer; }
table.t tbody tr:hover td { background: var(--surface-2); }
table.t tfoot td { font-weight: 700; border-top: 1px solid var(--border-strong); border-bottom: 0; }
table.t td.l, table.t th.l { text-align: left; }
.sym { font-weight: 700; }
.sym-name { color: var(--text-3); font-size: 11px; max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.cell-sub { font-size: 11px; color: var(--text-3); }

/* ---------- bars */
.bar-list { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 180px) 1fr 64px; align-items: center; gap: 10px; font-size: 12px; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 10px; background: var(--surface-2); border-radius: 4px; position: relative; overflow: hidden; }
.bar-fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); border-radius: 0 4px 4px 0; }
.bar-target { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--text); }
.stack { display: flex; height: 14px; border-radius: 4px; overflow: hidden; gap: 2px; }
.stack > div { height: 100%; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 11.5px; color: var(--text-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.range52 { position: relative; height: 6px; background: linear-gradient(90deg, var(--down-soft), var(--surface-2), var(--up-soft)); border-radius: 3px; min-width: 80px; }
.range52 .mark { position: absolute; top: -3px; width: 3px; height: 12px; background: var(--text); border-radius: 2px; transform: translateX(-1px); }
.split-bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; gap: 2px; }

/* ---------- charts */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px;
  padding: 7px 9px; font-size: 11.5px; box-shadow: var(--shadow); white-space: nowrap; z-index: 5; display: none; }
.axis text { fill: var(--text-3); font-size: 10.5px; font-family: inherit; }
.gridline { stroke: var(--grid); stroke-width: 1; }
.spark { display: block; }

/* ---------- heat grid */
.heat { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 4px; }
.heat div { border-radius: 6px; padding: 6px 8px; font-size: 11.5px; }
.heat .p { font-size: 10.5px; color: var(--text-2); }

/* ---------- home */
.home-hero { padding: 40px 0 10px; text-align: center; }
.home-hero h1 { font-size: 30px; letter-spacing: -.04em; margin: 0 0 8px; }
.home-hero p { color: var(--text-2); margin: 0 auto; max-width: 62ch; }
.create { max-width: 640px; margin: 24px auto 0; }
.pf-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.pf-item { display: block; padding: 14px; color: var(--text); }
.pf-item:hover { text-decoration: none; border-color: var(--text-3); }
.pf-item .n { font-weight: 700; font-size: 14px; }
.empty { text-align: center; padding: 50px 20px; color: var(--text-2); }
.empty .big { font-size: 34px; margin-bottom: 6px; }

/* ---------- modal / drawer */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow-y: auto; }
.modal { width: 100%; max-width: 560px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.2); }
.modal.wide { max-width: 980px; }
.modal-h { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal-h h2 { margin: 0; font-size: 15px; }
.modal-b { padding: 16px; }
.modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }
.ac { position: relative; }
.ac-list { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px;
  box-shadow: var(--shadow); z-index: 60; max-height: 300px; overflow-y: auto; }
.ac-item { padding: 8px 10px; cursor: pointer; display: flex; gap: 8px; align-items: baseline; }
.ac-item.on, .ac-item:hover { background: var(--surface-2); }
.ac-item .nm { color: var(--text-3); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.copy-row { display: flex; gap: 6px; }
.copy-row .input { font-size: 12px; }
.note { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; font-size: 12px; color: var(--text-2); }
.note.warn { background: var(--warn-soft); color: var(--text); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 9px 16px;
  border-radius: 8px; z-index: 90; font-size: 12.5px; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 6px; }
@keyframes sk { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.lots td { font-size: 12px; }
.footer { color: var(--text-3); font-size: 11.5px; text-align: center; padding: 30px 0 40px; }
@media (max-width: 640px) {
  .kpis, .kpis.kpis-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi { padding: 10px 11px; }
  .kpi .v, .kpi.kpi-hero .v { font-size: 17px; }
  .kpi .s { white-space: normal; }
  .phead h1 { font-size: 19px; }
}
