:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1c2024;
  --muted: #6b7280;
  --border: #e3e6ea;
  --header-bg: #f0f2f5;
  --row-alt: #fafbfc;
  --accent: #2563eb;
  --accent-soft: #e8effd;
  --sd-text: #8a6d3b;
  --low: #b91c1c;
  --low-soft: #fbe9e9;
  --high: #15803d;
  --high-soft: #e6f4ea;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a;
    --surface: #1c2024;
    --text: #e6e8ea;
    --muted: #9aa3ad;
    --border: #2c3238;
    --header-bg: #232a30;
    --row-alt: #1f2429;
    --accent: #5b8cff;
    --accent-soft: #21304d;
    --sd-text: #d7b676;
    --low: #ff8080;
    --low-soft: #3a2020;
    --high: #4ade80;
    --high-soft: #17301f;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

header {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 5;
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

h1 {
  margin: 0 0 2px;
  font-size: 1.15rem;
  font-weight: 650;
}

.refresh-btn {
  flex: 0 0 auto;
  padding: 7px 14px;
  font-size: 0.82rem;
  font-weight: 550;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 999px;
  cursor: pointer;
}
.refresh-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

#meta {
  font-size: 0.78rem;
  color: var(--muted);
}

.refresh-status {
  font-size: 0.75rem;
  color: var(--muted);
  min-height: 1.1em;
  margin-top: 2px;
}

/* segmented toggle */
.seg {
  display: flex;
  gap: 4px;
  margin-top: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.seg-btn {
  flex: 0 0 auto;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 550;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, color .12s, border-color .12s;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent);
}

/* report */
.report {
  display: none;
  padding: 14px 16px 40px;
  max-width: 640px;
  height: calc(100vh - 150px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.report-meta {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 16px;
}

.report-section {
  margin-bottom: 22px;
}
.report-section h2 {
  margin: 0 0 4px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  padding-bottom: 7px;
}

.report-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.report-row:last-child { border-bottom: none; }

.report-label {
  flex: 1 1 auto;
  min-width: 0;
}

.report-badge {
  flex: 0 0 auto;
  font-size: 0.7rem;
  font-weight: 650;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}
.report-badge.high {
  background: var(--high-soft);
  color: var(--high);
}
.report-badge.low {
  background: var(--low-soft);
  color: var(--low);
}

.report-value {
  flex: 0 0 auto;
  min-width: 64px;
  text-align: right;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.report-date {
  flex: 0 0 auto;
  min-width: 84px;
  text-align: right;
  font-size: 0.72rem;
  color: var(--muted);
}

.report-empty {
  font-size: 0.82rem;
  color: var(--muted);
  font-style: italic;
  padding: 8px 0;
}

@media (max-width: 480px) {
  .report-row {
    flex-wrap: wrap;
  }
  .report-value, .report-date {
    min-width: 0;
  }
}

/* table */
.table-wrap {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  height: calc(100vh - 150px);
}

table {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.82rem;
  white-space: nowrap;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--header-bg);
  color: var(--muted);
  font-weight: 600;
  text-align: right;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
thead th:hover { color: var(--text); }
thead th.txt { text-align: left; }
thead th.sd { color: var(--sd-text); font-style: italic; }

tbody td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
tbody td.txt { text-align: left; color: var(--muted); }
tbody td.sd { color: var(--sd-text); }

tbody tr:nth-child(even) { background: var(--row-alt); }

/* sticky first column (Date) */
th:first-child, td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  text-align: left;
  font-weight: 600;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
thead th:first-child { z-index: 4; background: var(--header-bg); }
tbody tr:nth-child(even) td:first-child { background: var(--row-alt); }
