:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11,11,11,0.10);
  --series-1: #2a78d6; /* blue - NTI / revenue */
  --series-2: #eb6834; /* orange - handle */
  --series-3: #1baf7a; /* aqua - RTP */
  --series-4: #9b59b6; /* purple - revenue split: municipality */
  --series-5: #8a8a86; /* gray - revenue split: terminal system fee */
  --good: #0ca30c;
  --critical: #d03b3b;
  --shadow: 0 1px 2px rgba(11,11,11,0.04), 0 8px 24px rgba(11,11,11,0.06);
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #222221;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255,255,255,0.10);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #b07cc6;
    --series-5: #a3a29c;
    --good: #0ca30c;
    --critical: #e66767;
    --shadow: 0 1px 2px rgba(0,0,0,0.2), 0 8px 24px rgba(0,0,0,0.35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #222221;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255,255,255,0.10);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #b07cc6;
  --series-5: #a3a29c;
  --good: #0ca30c;
  --critical: #e66767;
  --shadow: 0 1px 2px rgba(0,0,0,0.2), 0 8px 24px rgba(0,0,0,0.35);
}

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

.topbar { padding: 28px clamp(16px, 4vw, 48px) 12px; position: relative; }
.topbar-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.topbar h1 { margin: 0 0 6px; font-size: 1.6rem; letter-spacing: -0.01em; text-align: center; }
.subtitle { margin: 0; color: var(--text-secondary); max-width: 60ch; text-align: center; }

/* Pulled out of the centered column so it doesn't skew the title off-center. */
#coverage-badge { position: absolute; top: 28px; right: clamp(16px, 4vw, 48px); }
@media (max-width: 640px) {
  #coverage-badge { position: static; margin-top: 4px; }
}

.badge {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.85rem;
  white-space: nowrap;
}

main {
  padding: 12px clamp(16px, 4vw, 48px) 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px 24px;
  box-shadow: var(--shadow);
}
.panel h2 { margin: 0 0 12px; font-size: 1.15rem; letter-spacing: -0.01em; }
.panel h3 { margin: 0 0 8px; font-size: 0.95rem; color: var(--text-secondary); font-weight: 600; }

.panel-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}
.panel-header h2 { margin: 0; }
.month-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.section-subhead {
  margin: 24px 0 4px;
  font-size: 1rem;
  color: var(--text-primary);
  border-top: 1px solid var(--grid);
  padding-top: 20px;
}

.muted { color: var(--text-muted); font-size: 0.9rem; }

#data-panel { padding: 14px 24px; }
#data-panel summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-secondary);
}
#data-panel summary:hover { color: var(--text-primary); }
#data-panel[open] summary { margin-bottom: 10px; }

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
}
.chart-card {
  min-width: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.chart-card canvas { max-height: 240px; }

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-top: 10px;
}
.inline-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}
input, select, button {
  font: inherit;
  padding: 7px 11px;
  border-radius: 7px;
  border: 1px solid var(--axis);
  background: var(--surface);
  color: var(--text-primary);
}
input:focus, select:focus, button:focus {
  outline: 2px solid var(--series-1);
  outline-offset: 1px;
}
button {
  cursor: pointer;
  background: var(--series-1);
  color: white;
  border: none;
  font-weight: 600;
  padding: 7px 16px;
  transition: opacity 0.15s ease;
}
button:hover { opacity: 0.88; }

.link-button {
  background: none;
  border: none;
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.8rem;
  padding: 4px;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.link-button:hover { opacity: 1; color: var(--text-secondary); }

.search-row { position: relative; margin-bottom: 12px; }
#establishment-search { width: 100%; max-width: 480px; }
.search-results {
  position: absolute;
  z-index: 10;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  max-width: 480px;
  width: 100%;
  max-height: 280px;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.search-results:empty { display: none; }
.search-result-item {
  padding: 9px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--grid);
  transition: background-color 0.1s ease;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--surface-2); }
.search-result-item .muted { display: block; font-size: 0.8rem; }

.search-result-group-header { display: flex; align-items: center; gap: 6px; cursor: default; }
.search-result-group-header:hover { background: var(--surface-2); }
.search-result-group-header .group-name { cursor: pointer; flex: 1; min-width: 0; }
.tree-toggle {
  flex: 0 0 auto;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 4px;
  line-height: 1;
}
.tree-toggle:hover { color: var(--text-primary); }
.search-result-children.hidden { display: none; }
.search-result-child { padding-left: 30px; }

.est-locations { margin: 10px 0 4px; }
.est-locations-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.location-chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.8rem;
  color: var(--text-primary);
  cursor: pointer;
}
.location-chip:hover { background: var(--surface); border-color: var(--axis); }

.split-disclaimer { margin: 10px 0 0; font-size: 0.75rem; line-height: 1.4; }

.hidden { display: none; }

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 16px;
  /* a soft edge hint that there's more to scroll to, without extra markup */
  background:
    linear-gradient(to right, var(--surface) 40%, transparent),
    linear-gradient(to left, var(--surface) 40%, transparent) right,
    linear-gradient(to right, rgba(11,11,11,0.12), transparent 20px),
    linear-gradient(to left, rgba(11,11,11,0.12), transparent 20px) right;
  background-repeat: no-repeat;
  background-size: 24px 100%, 24px 100%, 12px 100%, 12px 100%;
  background-attachment: local, local, scroll, scroll;
}

.data-table {
  width: 100%;
  min-width: 480px;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.data-table th, .data-table td {
  text-align: right;
  padding: 7px 10px;
  border-bottom: 1px solid var(--grid);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.data-table th:first-child, .data-table td:first-child,
.data-table th:nth-child(2), .data-table td:nth-child(2),
.data-table th:nth-child(3), .data-table td:nth-child(3) {
  text-align: left;
}
.data-table thead th { color: var(--text-secondary); font-weight: 600; }
.data-table tbody tr { transition: background-color 0.1s ease; }
.data-table tbody tr:hover { background: var(--surface-2); }

@media (max-width: 640px) {
  .panel { padding: 16px; }
  .data-table { font-size: 0.82rem; }
  .data-table th, .data-table td { padding: 6px 8px; }
}

/* ---- Stat tiles (Monthly spotlight) ---- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin: 14px 0 4px;
}

.stat-tile {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.stat-label {
  font-size: 0.78rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}
.stat-value {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.2;
}
.stat-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stat-delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  font-weight: 600;
  width: fit-content;
  padding: 2px 8px;
  border-radius: 999px;
}
.stat-delta.up { color: var(--good); background: color-mix(in srgb, var(--good) 14%, transparent); }
.stat-delta.down { color: var(--critical); background: color-mix(in srgb, var(--critical) 14%, transparent); }

.page-footer {
  text-align: center;
  padding: 8px clamp(16px, 4vw, 48px) 32px;
  max-width: 1400px;
  margin: 0 auto;
}
.page-footer a { color: var(--series-1); }
