:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-equity: #2a78d6;   /* categorical slot 1 blue */
  --series-commodity: #eb6834; /* categorical slot 2 orange */
  --series-other: #c3c2b7;
  --good: #006300;
  --bad: #d03b3b;
  --chip-bg: #f0efec;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-equity: #3987e5;
    --series-commodity: #d95926;
    --series-other: #383835;
    --good: #0ca30c;
    --bad: #e66767;
    --chip-bg: #232320;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --series-equity: #3987e5;
  --series-commodity: #d95926;
  --series-other: #383835;
  --good: #0ca30c;
  --bad: #e66767;
  --chip-bg: #232320;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 20px 8px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}
.brand h1 { font-size: 20px; margin: 0 0 2px; }
.brand .sub { margin: 0; font-size: 13px; color: var(--text-secondary); }
.meta { text-align: right; font-size: 12px; color: var(--text-muted); }
.updated { display: block; }
.errors-badge {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bad);
  color: white;
  font-size: 11px;
}

.tabs {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  gap: 4px;
  overflow-x: auto;
}
.tab {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab:hover { color: var(--text-primary); }
.tab.active {
  color: var(--series-equity);
  border-bottom-color: var(--series-equity);
}

#app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}
.loading { color: var(--text-muted); padding: 40px 0; text-align: center; }

.section {
  margin-bottom: 36px;
}
.section-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-title .note {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
@media (max-width: 640px) {
  .stat-grid { grid-template-columns: 1fr; }
}

.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}
.stat-label { font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; }
.stat-value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; margin-bottom: 12px; }

.meter-track {
  display: flex;
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--gridline);
  gap: 2px;
}
.meter-seg { height: 100%; }
.meter-equity { background: var(--series-equity); }
.meter-commodity { background: var(--series-commodity); }

.meter-legend {
  display: flex;
  gap: 16px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  flex-wrap: wrap;
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-item b { color: var(--text-primary); font-variant-numeric: tabular-nums; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-equity { background: var(--series-equity); }
.dot-commodity { background: var(--series-commodity); }

.table-wrap {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: auto;
  max-height: 520px;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
thead th {
  position: sticky;
  top: 0;
  background: var(--surface-1);
  text-align: right;
  color: var(--text-muted);
  font-weight: 500;
  padding: 8px 12px;
  border-bottom: 1px solid var(--gridline);
  white-space: nowrap;
}
thead th:first-child, thead th:nth-child(2) { text-align: left; }
tbody td {
  padding: 7px 12px;
  text-align: right;
  border-bottom: 1px solid var(--gridline);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
tbody td:first-child, tbody td:nth-child(2) { text-align: left; font-variant-numeric: normal; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--chip-bg); }
.rank-cell { color: var(--text-muted); width: 32px; }
.chip {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--text-secondary);
  font-size: 11px;
  margin-left: 6px;
}
.up { color: var(--good); }
.down { color: var(--bad); }

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 800px) {
  .two-col { grid-template-columns: 1fr; }
}

.refresh-btn {
  border: 1px solid var(--series-equity);
  background: transparent;
  color: var(--series-equity);
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.refresh-btn:hover { background: var(--chip-bg); }
.refresh-status {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
  min-height: 14px;
}
.refresh-status.refresh-error { color: var(--bad); cursor: help; }

.empty-note {
  color: var(--text-muted);
  font-size: 13px;
  padding: 16px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.page-footer {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
}
.page-footer a { color: var(--series-equity); }

.range-row {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
}
.range-btn {
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}
.range-btn:hover { color: var(--text-primary); }
.range-btn.active {
  color: white;
  background: var(--series-equity);
  border-color: var(--series-equity);
}

.trend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}
.trend-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  overflow: hidden;
}
.trend-card-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
}
.trend-legend {
  display: flex;
  gap: 14px;
  margin-bottom: 6px;
  font-size: 11px;
  color: var(--text-secondary);
}
.trend-legend-item { display: flex; align-items: center; gap: 5px; }
.trend-legend-swatch {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  display: inline-block;
}

.trend-chart-wrap {
  position: relative;
  overflow-x: auto;
}
.trend-svg { display: block; }
.trend-gridline { stroke: var(--gridline); stroke-width: 1; }
.trend-ylabel, .trend-xlabel {
  fill: var(--text-muted);
  font-size: 9px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
.trend-hit {
  fill: transparent;
  cursor: crosshair;
}
.trend-hit:focus { outline: none; }
.trend-crosshair {
  stroke: var(--baseline);
  stroke-width: 1;
  opacity: 0;
  pointer-events: none;
}
.trend-hoverdot {
  opacity: 0;
  pointer-events: none;
}

.trend-subchart + .trend-subchart { margin-top: 4px; }
.trend-sublabel {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.trend-tooltip {
  position: absolute;
  z-index: 5;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  pointer-events: none;
  min-width: 150px;
}
.trend-tooltip-date {
  color: var(--text-muted);
  font-size: 11px;
  margin-bottom: 4px;
}
.trend-tooltip-row {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: space-between;
  padding: 1px 0;
}
.trend-tooltip-row b { font-variant-numeric: tabular-nums; }
.trend-tooltip-key {
  width: 7px;
  height: 7px;
  border-radius: 2px;
  display: inline-block;
  flex-shrink: 0;
}
