/* ---------- tokens ---------- */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --danger: #d03b3b;
  --good: #006300;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 16px rgba(11, 11, 11, 0.04);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232322;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --accent-ink: #ffffff;
    --danger: #e66767;
    --good: #0ca30c;
    --shadow: none;
  }
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.92em; background: var(--surface-2); padding: 0 4px; border-radius: 4px; }
.muted { color: var(--muted); }
h1 { font-size: 30px; line-height: 1.2; margin: 0 0 10px; letter-spacing: -0.01em; }
h2 { font-size: 15px; font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase; color: var(--ink-2); margin: 36px 0 12px; }
h3 { font-size: 15px; font-weight: 600; margin: 0; }

.page { max-width: 1180px; margin: 0 auto; padding: 24px 20px 60px; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--page) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1180px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 600; }
.brand-mark { width: 26px; height: 26px; color: var(--accent); }
.topbar-actions { display: flex; align-items: center; gap: 10px; min-width: 0; }
.file-chip { font-size: 13px; color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--border); padding: 4px 10px; border-radius: 999px; max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- buttons ---------- */
.btn { font: inherit; font-size: 14px; font-weight: 500; color: var(--ink); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 12px; cursor: pointer; box-shadow: var(--shadow); }
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, .tab:focus-visible, .dropzone:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-ghost { box-shadow: none; background: transparent; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

/* ---------- upload ---------- */
.upload-view { max-width: 760px; margin: 30px auto 0; }
.hero { margin-bottom: 24px; }
.lede { font-size: 16px; color: var(--ink-2); margin: 0; }
.dropzone { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; padding: 44px 24px; border: 1.5px dashed var(--axis); border-radius: var(--radius); background: var(--surface); color: var(--ink-2); cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone svg { color: var(--accent); }
.dropzone strong { color: var(--ink); font-weight: 600; }
.dropzone:hover, .dropzone.is-over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, var(--surface)); }
.privacy { font-size: 13px; text-align: center; margin: 12px 0 0; }
.load-status { margin-top: 20px; display: flex; flex-direction: column; gap: 8px; font-size: 14px; color: var(--ink-2); }
.progress { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.error { margin-top: 16px; padding: 12px 14px; border-radius: 8px; border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent); background: color-mix(in srgb, var(--danger) 8%, var(--surface)); color: var(--ink); font-size: 14px; }

/* ---------- summary tiles ---------- */
.summary { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 4px 0 20px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.tile .label { font-size: 12px; color: var(--muted); margin: 0 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .value { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.2; overflow-wrap: anywhere; }
.tile .value small { font-size: 13px; font-weight: 500; color: var(--ink-2); margin-left: 4px; }
.tile .sub { font-size: 12px; color: var(--ink-2); margin: 3px 0 0; }

/* ---------- toolbar ---------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 8px; }
.toolbar-right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.tabs { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 3px; }
.tab { font: inherit; font-size: 14px; font-weight: 500; color: var(--ink-2); background: transparent; border: 0; border-radius: 7px; padding: 5px 14px; cursor: pointer; }
.tab.is-active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.check { display: inline-flex; align-items: center; gap: 7px; font-size: 14px; color: var(--ink-2); cursor: pointer; }
.check input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }
.hint { font-size: 13px; margin: 8px 0 0; }

/* ---------- chart cards ---------- */
.chart-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
.chart-grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(440px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px 10px; min-width: 0; }
.chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.chart-head .sub { font-size: 13px; color: var(--muted); margin: 0; }
.chart-plot { position: relative; min-height: 60px; }
.chart-strip .chart-head { margin-bottom: 2px; }
.chart-strip h3 { font-size: 14px; }
.empty-note { font-size: 13px; color: var(--muted); padding: 8px 0 4px; }

/* uPlot chrome overrides */
.uplot { font-family: inherit; }
.uplot .u-wrap { user-select: none; }
.uplot .u-select { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.uplot .u-legend { display: block; font-size: 12px; margin: 6px 0 0; text-align: left; }
.uplot .u-legend tbody { display: flex; flex-wrap: wrap; gap: 2px 18px; }
.uplot .u-legend .u-series { display: inline-flex; align-items: baseline; gap: 6px; padding: 2px 0; cursor: pointer; }
.uplot .u-legend .u-series > * { padding: 0; }
.uplot .u-legend .u-series .u-marker { width: 14px; height: 0; border-top-width: 3px !important; border-bottom: 0 !important; border-left: 0 !important; border-right: 0 !important; border-radius: 2px; align-self: center; }
.uplot .u-legend .u-series th { font-weight: 500; color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; }
.uplot .u-legend .u-series .u-value { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; min-width: 5.5ch; }
.uplot .u-legend .u-series.u-off { opacity: 0.4; }
.uplot .u-legend .u-series.u-off .u-marker { border-top-style: dotted !important; }
.uplot .u-legend .u-series:first-child .u-value { min-width: 0; }
.uplot .u-legend .u-series:first-child th { color: var(--muted); }
.uplot .u-cursor-x { border-right: 1px solid var(--muted); }
.uplot .u-cursor-pt { box-shadow: 0 0 0 2px var(--surface); }

/* ---------- table view ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
table { border-collapse: collapse; font-size: 13px; width: 100%; }
th, td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { color: var(--ink-2); font-weight: 600; font-size: 12px; background: var(--surface-2); position: sticky; top: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }
.pager { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 10px 0 18px; font-size: 14px; color: var(--ink-2); }
.pager input { font: inherit; width: 90px; padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--ink); }
.table-section h2 { margin-top: 24px; }

.footer { max-width: 1180px; margin: 0 auto; padding: 0 20px 30px; font-size: 12px; }

@media (max-width: 640px) {
  h1 { font-size: 24px; }
  .page { padding: 16px 14px 40px; }
  .file-chip { display: none; }
  .chart-grid.cols-2 { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { .progress-bar, .dropzone { transition: none; } }
