:root {
  --bg: #0a0c12;
  --panel: #1b1f2a;
  --panel-2: #202433;
  --text: #dde3f0;
  --muted: #8e97ad;
  --accent: #2ad28f;
  --accent-soft: rgba(42, 210, 143, 0.14);
  --ok: #2ad28f;
  --border: #31374a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(circle at 14% 16%, #161b28 0%, #0a0c12 46%);
  color: var(--text);
  font-family: "Space Grotesk", sans-serif;
}

.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 30px 30px;
  opacity: 0.08;
}

.page {
  position: relative;
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.control-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #1a1e2a;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.control-label {
  color: var(--muted);
  font-size: 0.82rem;
  letter-spacing: 0.03em;
}

.scope-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.scope-btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.scope-btn.active {
  color: var(--text);
  border-color: #4f5770;
  background: #2b3142;
}

.control-note {
  color: var(--muted);
  font-size: 0.82rem;
}

.control-side {
  display: flex;
  align-items: center;
  gap: 10px;
}

.eyebrow {
  color: var(--muted);
  margin: 0;
  letter-spacing: 0.12em;
  font-size: 12px;
}

h1 {
  margin: 4px 0 0;
  font-size: clamp(1.3rem, 2vw, 2rem);
}

.sync-btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 600;
  cursor: pointer;
}

.sync-btn:hover {
  border-color: var(--accent);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card,
.map-panel,
.table-panel {
  background: linear-gradient(165deg, var(--panel-2), var(--panel));
  border: 1px solid var(--border);
  border-radius: 14px;
}

.stat-card {
  padding: 14px;
}

.stat-card h2 {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0;
}

.stat-card p {
  margin: 10px 0 0;
  font-size: 1.6rem;
  font-weight: 700;
}

.map-panel {
  padding: 12px;
  margin-bottom: 14px;
}

.map-header {
  display: flex;
  justify-content: flex-start;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 10px;
}

.map-header h2,
.table-panel h2 {
  margin: 0;
  font-size: 1rem;
}

#statusText {
  color: var(--muted);
  font-size: 0.9rem;
  margin-left: auto;
}

#missingNote {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.25;
}

.year-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.year-link {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.8rem;
  cursor: pointer;
}

.year-link.active {
  color: var(--text);
  border-color: var(--year-color, #4f5770);
  background: var(--year-soft, #2b3142);
}

#map {
  width: 100%;
  height: min(60vh, 620px);
  border-radius: 10px;
  overflow: hidden;
}

.pin-badge {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--marker-soft, var(--accent-soft));
  border: 2px solid var(--marker-color, var(--accent));
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  box-shadow: 0 0 0 5px var(--marker-glow, rgba(42, 210, 143, 0.12));
}

.table-panel {
  padding: 12px;
}

.feed-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.feed-count {
  color: var(--muted);
  font-size: 0.82rem;
}

.incident-table-wrap {
  max-height: min(60vh, 620px);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.incident-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.incident-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #262c3d;
  color: #b6bfd4;
  text-align: left;
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-weight: 600;
  padding: 7px 8px;
  border-bottom: 1px solid var(--border);
}

.incident-table tbody td {
  padding: 7px 8px;
  border-bottom: 1px solid #2c3245;
  font-size: 0.76rem;
  line-height: 1.2;
}

.incident-table tbody tr:nth-child(odd) {
  background: #1b1f2a;
}

.incident-table tbody tr:nth-child(even) {
  background: #1f2433;
}

.incident-table tbody tr:hover {
  background: #293044;
}

.incident-table th:first-child,
.incident-table td:first-child {
  width: 96px;
}

.incident-table th:last-child,
.incident-table td:last-child {
  width: 132px;
}

.incident-location-cell {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.incident-time-cell {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  font-size: 0.72rem;
}

.incident-tag {
  color: var(--text);
  background: #2a3042;
  border: 1px solid #3b435a;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 0.66rem;
  font-weight: 600;
}

.incident-index {
  color: var(--muted);
  font-size: 0.78rem;
}

.table-actions {
  margin-top: 10px;
  display: flex;
  justify-content: flex-end;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(7, 9, 14, 0.78);
  display: grid;
  place-items: center;
  z-index: 2000;
  padding: 14px;
}

.modal-backdrop.hidden {
  display: none;
}

.insights-modal {
  width: min(980px, 100%);
  max-height: 90vh;
  overflow: auto;
  border: 1px solid var(--border);
  background: linear-gradient(165deg, var(--panel-2), var(--panel));
  border-radius: 14px;
  padding: 14px;
}

.insights-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.insights-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.insights-scope {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.85rem;
}

.insights-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.insight-card,
.insight-panel {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: linear-gradient(165deg, #20263a, #1b2132);
  padding: 10px;
  position: relative;
  overflow: hidden;
}

.insight-card h3,
.insight-panel h3 {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
}

.insight-card p {
  margin: 8px 0 0;
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.01em;
}

.insight-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 1px solid transparent;
  margin-bottom: 6px;
}

.chip-alltime {
  color: #b8c8f0;
  background: rgba(125, 155, 230, 0.16);
  border-color: rgba(125, 155, 230, 0.35);
}

.chip-scope {
  color: #ffd6dc;
  background: rgba(255, 98, 122, 0.15);
  border-color: rgba(255, 98, 122, 0.38);
}

.insights-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 10px;
}

.year-heat {
  display: grid;
  gap: 7px;
  margin-top: 8px;
}

.year-heat-row {
  display: grid;
  grid-template-columns: 52px 1fr 56px;
  gap: 8px;
  align-items: center;
  font-size: 0.8rem;
}

.year-heat-label,
.year-heat-count {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.year-heat-bar-wrap {
  height: 10px;
  border-radius: 999px;
  background: #2b3042;
  overflow: hidden;
}

.year-heat-bar {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #657ca8, #8eaaf0);
  transform-origin: left;
  animation: growBar 420ms ease both;
  transition: filter 160ms ease;
}

.year-heat-bar:hover {
  filter: brightness(1.15);
}

.top-locations {
  margin: 10px 0 0;
  padding: 0;
  display: grid;
  gap: 7px;
  font-size: 0.82rem;
}

.top-location-row {
  display: grid;
  grid-template-columns: 28px 1fr 52px;
  gap: 8px;
  align-items: center;
  padding: 7px 8px;
  border: 1px solid #303850;
  border-radius: 8px;
  background: rgba(18, 24, 38, 0.55);
}

.top-location-rank {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: #d7e2ff;
  font-size: 0.7rem;
  font-weight: 700;
  background: #2f3a57;
}

.top-location-name {
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-location-count {
  justify-self: end;
  color: #dbe6ff;
  font-size: 0.74rem;
  font-weight: 700;
  border: 1px solid #445170;
  border-radius: 999px;
  padding: 2px 8px;
}

.top-location-track {
  grid-column: 2 / span 2;
  height: 5px;
  border-radius: 999px;
  background: #2b3247;
  overflow: hidden;
}

.top-location-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #6f89bf, #9db7ff);
}

.top-location-row.top-1 .top-location-rank {
  background: #b98b2f;
}

.top-location-row.top-2 .top-location-rank {
  background: #7d879f;
}

.top-location-row.top-3 .top-location-rank {
  background: #8b5f45;
}

@keyframes growBar {
  from {
    transform: scaleX(0.02);
  }
  to {
    transform: scaleX(1);
  }
}

/* Dark themed scrollbars for consistency across panels. */
* {
  scrollbar-width: thin;
  scrollbar-color: #444c63 #161b27;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: #161b27;
}

::-webkit-scrollbar-thumb {
  background: #444c63;
  border-radius: 999px;
  border: 2px solid #161b27;
}

::-webkit-scrollbar-thumb:hover {
  background: #596381;
}

@media (max-width: 768px) {
  .page {
    padding: 14px;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .topbar-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .control-bar {
    flex-direction: column;
    align-items: flex-start;
  }

  .control-side {
    width: 100%;
    justify-content: space-between;
  }

  .incident-table th:last-child,
  .incident-table td:last-child {
    width: 130px;
  }

  .insights-summary,
  .insights-grid {
    grid-template-columns: 1fr;
  }

  #map {
    height: 52vh;
  }
}
