:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --border: #2d3a4f;
  --text: #e7ecf3;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --positive: #22c55e;
  --negative: #ef4444;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.header {
  padding: 1.5rem 2rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
}

.nav {
  display: flex;
  gap: 0.5rem;
}

.nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  border: 1px solid transparent;
}

.nav a:hover {
  color: var(--text);
  border-color: var(--border);
}

.nav a.nav-active {
  color: var(--text);
  background: var(--panel);
  border-color: var(--border);
}

.subtitle {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 1rem 2rem;
  padding: 1rem 1.25rem;
}

.filters {
  margin-top: 1rem;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
}

.filter-row label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
  min-width: 160px;
}

.filter-row select,
.filter-row input[type="search"] {
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}

.filter-row input[type="search"] {
  min-width: 220px;
}

button {
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: none;
  font-size: 0.9rem;
  cursor: pointer;
  font-family: inherit;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  color: var(--text);
}

.filter-summary {
  margin: 0.75rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.backfill-notice {
  margin: 0.5rem 0 0;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  color: #fbbf24;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: 6px;
}

.backfill-mark {
  color: #fbbf24;
  font-size: 0.75rem;
  margin-left: 0.25rem;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin: 0 2rem;
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

.layout .panel {
  margin: 0 0 1rem;
}

.layout .charts-panel {
  margin-right: 0.5rem;
}

.layout .table-panel {
  margin-left: 0.5rem;
}

@media (max-width: 1100px) {
  .layout .charts-panel,
  .layout .table-panel {
    margin: 0 0 1rem;
  }
}

h2 {
  margin: 0 0 1rem;
  font-size: 1.1rem;
  font-weight: 600;
}

h3 {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 500;
}

.charts-wrap {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.chart-box {
  position: relative;
  height: 220px;
}

.chart-box canvas {
  max-height: 200px;
}

.empty-state {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 2rem 0;
  text-align: center;
}

.hidden {
  display: none !important;
}

.table-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.table-header h2 {
  margin: 0;
}

.badge {
  background: var(--border);
  color: var(--muted);
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}

.table-scroll {
  overflow-x: auto;
  max-height: 360px;
  overflow-y: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th,
td {
  padding: 0.5rem 0.65rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--muted);
  font-weight: 500;
  position: sticky;
  top: 0;
  background: var(--panel);
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: rgba(59, 130, 246, 0.08);
}

tbody tr.selected {
  background: rgba(59, 130, 246, 0.15);
  outline: 1px solid var(--accent);
}

.num-positive {
  color: var(--positive);
}

.num-negative {
  color: var(--negative);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 0.75rem;
}

.pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.metrics-table-panel {
  margin-bottom: 2rem;
}

.metrics-table-panel .table-scroll {
  max-height: 280px;
}

#pageInfo {
  font-size: 0.85rem;
  color: var(--muted);
}

.categories-panel {
  margin-bottom: 2rem;
}

.categories-scroll {
  max-height: none;
}

.num-col {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.cat-link {
  color: var(--accent);
  text-decoration: none;
}

.cat-link:hover {
  text-decoration: underline;
}

.trend-up {
  color: var(--positive);
  font-weight: 500;
}

.trend-down {
  color: var(--negative);
  font-weight: 500;
}

.trend-flat {
  color: var(--muted);
}
