:root {
  --bg: #0f1419;
  --panel: #1a2029;
  --border: #2a3340;
  --text: #e4e6eb;
  --muted: #8b94a3;
  --accent: #e89f3c;
  --accent-hot: #ff6b35;
  --liquor: #e89f3c;
  --wine: #c1365b;
  --beer: #e8c547;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; font-family: -apple-system, system-ui, sans-serif; }
body { background: var(--bg); color: var(--text); font-size: 13px; }

#app { display: grid; grid-template-columns: 340px 1fr; height: 100vh; }

#sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex; flex-direction: column;
}

#sidebar header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
#sidebar h1 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: 0.3px; }
#sidebar .sub { color: var(--muted); font-size: 11px; margin-top: 2px; }

.panel {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.panel label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
  margin-bottom: 6px;
}
.panel label.check { text-transform: none; letter-spacing: 0; color: var(--text); font-size: 12px; margin-top: 10px; }
.panel input[type=text],
.panel input[type=number],
.panel input[type=month] {
  width: 100%;
  padding: 7px 9px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}
.panel .row { display: flex; align-items: center; gap: 6px; }
.panel .row input { flex: 1; }
.panel .row span { color: var(--muted); }

.quick { display: flex; gap: 4px; margin-top: 8px; }
.quick button {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
}
.quick button:hover { border-color: var(--accent); color: var(--accent); }
.quick button.active { border-color: var(--accent); color: var(--accent); background: rgba(232,159,60,0.1); }

.stats { font-size: 12px; color: var(--muted); }
.stats strong { color: var(--text); }
.stats .row { display: flex; justify-content: space-between; margin: 3px 0; }

#detailPanel { position: relative; }
#detailPanel h2 { margin: 0 0 2px; font-size: 15px; color: var(--accent); padding-right: 20px; }
#detailPanel h3 { margin: 14px 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); }
#detailPanel .sub { color: var(--muted); font-size: 11px; margin-bottom: 10px; }
#detailPanel table { width: 100%; font-size: 11px; margin-top: 8px; }
#detailPanel table td { padding: 2px 0; vertical-align: top; }
#detailPanel table td:first-child { color: var(--muted); width: 90px; text-transform: uppercase; letter-spacing: 0.5px; font-size: 10px; }
#detailPanel .close {
  position: absolute; top: 10px; right: 12px;
  background: none; border: none; color: var(--muted);
  font-size: 22px; cursor: pointer; line-height: 1;
}
#detailPanel .close:hover { color: var(--accent); }
#detailPanel canvas { background: var(--bg); border: 1px solid var(--border); border-radius: 4px; width: 100%; height: auto; }
.chart-legend { display: flex; gap: 12px; font-size: 11px; color: var(--muted); margin-top: 6px; }
.chart-legend .swatch { display: inline-block; width: 10px; height: 10px; margin-right: 4px; border-radius: 2px; vertical-align: middle; }
.chart-legend .liquor { background: var(--liquor); }
.chart-legend .wine { background: var(--wine); }
.chart-legend .beer { background: var(--beer); }

.leaderboard-panel ol {
  list-style: none;
  margin: 0;
  padding: 0;
}
.leaderboard-panel ol li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 80ms linear;
}
.leaderboard-panel ol li:hover { background: rgba(232,159,60,0.08); }
.leaderboard-panel ol li:last-child { border-bottom: none; }
.leaderboard-panel ol li .rank {
  font-weight: 700;
  color: var(--muted);
  text-align: right;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.leaderboard-panel ol li:nth-child(-n+3) .rank { color: var(--accent-hot); }
.leaderboard-panel ol li .lb-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.leaderboard-panel ol li .lb-name {
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.leaderboard-panel ol li .lb-city {
  font-size: 10px;
  color: var(--muted);
}
.leaderboard-panel ol li .lb-total {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.leaderboard-panel ol li.empty {
  display: block;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 12px 0;
  cursor: default;
  border-bottom: none;
}
.leaderboard-panel label {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.leaderboard-panel label #lbScope {
  color: var(--muted);
  font-size: 10px;
  text-transform: none;
  letter-spacing: 0;
}

.state-btn {
  width: 100%;
  margin-top: 10px;
  padding: 8px 10px;
  background: linear-gradient(135deg, rgba(232,159,60,0.15), rgba(255,107,53,0.1));
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  text-align: left;
}
.state-btn:hover { background: linear-gradient(135deg, rgba(232,159,60,0.25), rgba(255,107,53,0.18)); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.72);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  max-width: 1000px;
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  padding: 26px 30px;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal h2 {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 18px;
}
.modal .modal-sub {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 16px;
}
.modal-close {
  position: absolute;
  top: 12px; right: 16px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 28px;
  cursor: pointer;
  line-height: 1;
}
.modal-close:hover { color: var(--accent); }
.modal-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}
.modal-summary .card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 12px;
}
.modal-summary .card .k {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}
.modal-summary .card .v {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.modal-summary .card .delta {
  font-size: 11px;
  margin-top: 2px;
}
.modal-summary .card .delta.up { color: #2ec27e; }
.modal-summary .card .delta.down { color: var(--accent-hot); }

#stateChart {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  width: 100%;
  height: auto;
}

.modal-table {
  width: 100%;
  margin-top: 20px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  border-collapse: collapse;
}
.modal-table thead th {
  text-align: right;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  padding: 6px 8px;
  font-weight: 500;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.6px;
}
.modal-table thead th:first-child { text-align: left; }
.modal-table tbody td {
  text-align: right;
  padding: 4px 8px;
  border-bottom: 1px solid rgba(42,51,64,0.5);
}
.modal-table tbody td:first-child { text-align: left; color: var(--muted); }
.modal-table tbody tr:last-child td { font-weight: 700; color: var(--text); border-top: 1px solid var(--border); }
.modal-table tbody tr:hover { background: rgba(232,159,60,0.05); }
.modal-footer {
  margin-top: 14px;
  font-size: 10px;
  color: var(--muted);
}
.modal-footer a { color: var(--muted); }

.popup-rank {
  display: inline-block;
  background: var(--accent-hot);
  color: #0f1419;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: middle;
}

#sidebar footer {
  margin-top: auto;
  padding: 10px 16px;
  font-size: 10px;
  color: var(--muted);
  border-top: 1px solid var(--border);
}
#sidebar footer a { color: var(--muted); }
#sidebar footer div { margin: 2px 0; }

#map { height: 100vh; }

/* Hex tooltip */
.hex-tooltip {
  position: fixed;
  z-index: 1500;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 12px;
  pointer-events: none;
  line-height: 1.35;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}
.hex-tooltip[hidden] { display: none; }
.hex-tooltip strong { color: var(--accent); }

/* Venue circles */
.venue-circle {
  background: rgba(232,159,60,0.55);
  border: 1.5px solid var(--accent);
  border-radius: 50%;
}
.venue-circle.hot {
  background: rgba(255,107,53,0.7);
  border-color: var(--accent-hot);
}

/* Marker cluster override */
.marker-cluster { background: rgba(232,159,60,0.35); }
.marker-cluster div { background: rgba(232,159,60,0.7); color: #0f1419; font-weight: 600; }

#toast {
  position: absolute;
  bottom: 20px; left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 4px;
  font-size: 12px;
  z-index: 1000;
  color: var(--accent);
}

/* Leaflet popup tweaks */
.leaflet-popup-content-wrapper {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px;
}
.leaflet-popup-tip { background: var(--panel); border: 1px solid var(--border); }
.leaflet-popup-content { margin: 10px 12px; font-size: 12px; }
.leaflet-popup-content .vname { font-weight: 600; color: var(--accent); margin-bottom: 4px; }
.leaflet-popup-content .vaddr { color: var(--muted); margin-bottom: 6px; }
.leaflet-popup-content .vnum { color: var(--text); }
.leaflet-popup-content a { color: var(--accent); font-size: 11px; }
