/* ── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Tokens ─────────────────────────────────────────────── */
html[data-theme="dark"] {
  --bg:          #111110;
  --surface:     #1c1c1b;
  --surface2:    #252524;
  --border:      #303030;
  --text:        #e5e4dc;
  --text-muted:  #7a7975;
  --accent:      #5b8ef0;
  --danger:      #e05252;
}
html[data-theme="light"] {
  --bg:          #f0efe9;
  --surface:     #ffffff;
  --surface2:    #e8e7e1;
  --border:      #d0cfc8;
  --text:        #1a1918;
  --text-muted:  #6e6d68;
  --accent:      #1d4ed8;
  --danger:      #dc2626;
}

/* ── Base ───────────────────────────────────────────────── */
body {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background 0.15s, color 0.15s;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Header ─────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-title {
  font-size: 14px;
  font-weight: 600;
}
.header-title span {
  color: var(--text-muted);
  font-weight: 400;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
#loading-msg {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
}
.theme-btn {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  padding: 4px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
}
.theme-btn:hover { border-color: var(--text-muted); }

/* ── Layout ─────────────────────────────────────────────── */
.main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── Card ───────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
}
.card-header {
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.card-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.card-body {
  padding: 12px;
}

/* ── Form controls ──────────────────────────────────────── */
select, input[type="number"], input[type="text"] {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 7px;
  outline: none;
  height: 28px;
}
select { cursor: pointer; }
select:focus, input:focus { border-color: var(--accent); }

/* ── Graph controls ─────────────────────────────────────── */
.graph-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
}
.ctrl-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.ctrl-label {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Filters ────────────────────────────────────────────── */
.filters-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}
.filter-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.filter-sep {
  color: var(--text-muted);
  font-size: 11px;
  padding: 0 2px;
}
.btn-remove {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  padding: 4px 8px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  height: 28px;
  line-height: 1;
}
.btn-remove:hover { border-color: var(--danger); color: var(--danger); }
.btn-add {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  padding: 4px 10px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  height: 28px;
}
.btn-add:hover { border-color: var(--accent); color: var(--accent); }

/* ── Badge ──────────────────────────────────────────────── */
.badge {
  font-size: 11px;
  padding: 2px 7px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Chart ──────────────────────────────────────────────── */
.chart-wrap {
  position: relative;
  height: 400px;
}
.chart-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-style: italic;
  font-size: 12px;
}

/* ── Table ──────────────────────────────────────────────── */
.table-scroll {
  overflow-x: auto;
  max-height: 420px;
  overflow-y: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
th {
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  padding: 5px 10px;
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}
td {
  padding: 5px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface2); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.dim { color: var(--text-muted); }

/* ── Sortable headers ───────────────────────────────────── */
th.sortable {
  cursor: pointer;
  user-select: none;
}
th.sortable:hover { color: var(--text); }
th .sort-arrow {
  display: inline-block;
  margin-left: 4px;
  opacity: 0.35;
  font-style: normal;
}
th.sort-active { color: var(--accent); }
th.sort-active .sort-arrow { opacity: 1; }

/* ── Chart hover tooltip ────────────────────────────────── */
#chart-tooltip {
  position: absolute;
  pointer-events: none;
  z-index: 50;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 8px 10px;
  font-size: 11px;
  line-height: 1.5;
  min-width: 340px;
  max-width: 480px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  display: none;
}
#chart-tooltip.visible { display: block; }
.tt-title {
  font-weight: 600;
  font-size: 11px;
  margin-bottom: 6px;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tt-table { width: 100%; border-collapse: collapse; }
.tt-table th {
  /* override sticky */
  position: static;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  padding: 2px 7px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  white-space: nowrap;
}
.tt-table td {
  padding: 2px 7px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tt-table tr:last-child td { border-bottom: none; }
.tt-more {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  font-style: italic;
}

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 640px) {
  .header { flex-wrap: wrap; gap: 6px; }
  .filter-row { gap: 4px; }
  select, input { max-width: 150px; }
}
