:root {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1a2336;
  --border: #243047;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --blue: #38bdf8;
  --green: #22c55e;
  --amber: #f59e0b;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Header */
.header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--border);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  display: block;
}

.brand-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.dot-sep {
  opacity: 0.5;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.status-ok {
  color: #86efac;
  border-color: rgba(34, 197, 94, 0.35);
  background: rgba(34, 197, 94, 0.1);
}

.status-warn {
  color: #fcd34d;
  border-color: rgba(245, 158, 11, 0.4);
  background: rgba(245, 158, 11, 0.12);
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.pulse-dot.green {
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
}

.pulse-dot.amber {
  background: var(--amber);
}

/* Main Split Workspace */
.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* Sidebar */
.sidebar {
  width: 380px;
  min-width: 310px;
  max-width: 430px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-top {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  color: var(--muted);
}

.search-box input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 13px;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 2px 5px;
  border-radius: 6px;
}

.icon-btn:hover {
  color: var(--text);
  background: rgba(148, 163, 184, 0.15);
}

.filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.time-window-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.time-window-label {
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 600;
}

.time-window-pills {
  display: inline-flex;
  gap: 4px;
}

.time-pill {
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}

.time-pill:hover {
  color: var(--text);
}

.time-pill.active {
  background: rgba(56, 189, 248, 0.18);
  border-color: rgba(56, 189, 248, 0.55);
  color: #fff;
}

.filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
}

.filter-pill.active {
  background: rgba(239, 68, 68, 0.18);
  border-color: rgba(239, 68, 68, 0.55);
  color: #fff;
}

.pill-count {
  font-size: 10.5px;
  opacity: 0.8;
}

.incident-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty-state {
  margin: auto;
  text-align: center;
  padding: 28px 18px;
  color: var(--muted);
}

.empty-state h3 {
  margin: 0 0 6px;
  color: var(--text);
  font-size: 15px;
}

.empty-state p {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
}

.incident-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.incident-card:hover {
  border-color: #3b4d6e;
}

.incident-card.selected {
  border-color: var(--blue);
  background: #1d2b44;
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.25);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.cat-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  border: 1px solid transparent;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.time-ago {
  font-size: 11px;
  color: var(--muted);
}

.card-title {
  margin: 7px 0 5px;
  font-size: 14.5px;
  font-weight: 700;
  color: var(--text);
}

.card-location {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: #cbd5e1;
  flex-wrap: wrap;
}

.precision-tag {
  font-size: 10.5px;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 600;
}

.prec-exact {
  background: rgba(34, 197, 94, 0.16);
  color: #86efac;
}

.prec-street {
  background: rgba(56, 189, 248, 0.16);
  color: #7dd3fc;
}

.prec-city {
  background: rgba(245, 158, 11, 0.16);
  color: #fcd34d;
}

.prec-none {
  background: rgba(239, 68, 68, 0.16);
  color: #fca5a5;
}

.card-summary {
  margin: 7px 0;
  font-size: 12.5px;
  line-height: 1.45;
  color: #cbd5e1;
}

.unit-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.unit-chip {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 5px;
  background: #0f172a;
  border: 1px solid var(--border);
  color: #e2e8f0;
}

.tac-chip {
  border-color: rgba(56, 189, 248, 0.45);
  color: #7dd3fc;
}

/* Map Area */
.map-shell {
  flex: 1;
  position: relative;
  min-width: 0;
}

.leaflet-canvas {
  width: 100%;
  height: 100%;
  background: #0b1120;
}

.basemap-dark .leaflet-tile-pane {
  filter: invert(100%) hue-rotate(180deg) brightness(92%) contrast(92%) saturate(70%);
}

.map-overlay-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 500;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.basemap-switcher {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px 4px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(17, 24, 39, 0.92);
  backdrop-filter: blur(8px);
}

.switcher-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
}

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

.switcher-btn.active {
  background: rgba(56, 189, 248, 0.2);
  color: #fff;
}

.map-chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(17, 24, 39, 0.92);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(8px);
}

.map-chip-btn:hover {
  background: rgba(30, 41, 59, 0.96);
}

.map-chip-btn.active {
  border-color: rgba(248, 113, 113, 0.6);
  background: rgba(239, 68, 68, 0.2);
  color: #fecaca;
}

.map-legend {
  position: absolute;
  bottom: 18px;
  left: 12px;
  z-index: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(17, 24, 39, 0.92);
  backdrop-filter: blur(8px);
  font-size: 11.5px;
  color: #cbd5e1;
}

.legend-count {
  font-weight: 700;
  color: #fff;
  padding-right: 6px;
  border-right: 1px solid var(--border);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

/* Pins & Popups */
.incident-pin-wrapper,
.station-pin-wrapper {
  background: transparent;
  border: none;
}

.pin-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pin-pulse {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2.5px solid #ef4444;
  animation: pinPulse 1.8s ease-out infinite;
  pointer-events: none;
}

@keyframes pinPulse {
  0% {
    transform: scale(0.8);
    opacity: 0.9;
  }
  100% {
    transform: scale(1.75);
    opacity: 0;
  }
}

.station-pin {
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.55));
  transition: transform 0.12s ease;
}

.station-pin:hover {
  transform: scale(1.16);
}

.leaflet-popup-content-wrapper {
  background: #111827 !important;
  color: #f1f5f9 !important;
  border: 1px solid #2b3a55;
  border-radius: 10px !important;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55) !important;
}

.leaflet-popup-tip {
  background: #111827 !important;
}

.incident-popup {
  min-width: 230px;
  font-size: 12.5px;
}

.popup-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.popup-cat {
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid transparent;
  text-transform: uppercase;
}

.popup-time {
  color: #94a3b8;
  font-size: 11px;
}

.popup-title {
  margin: 0 0 4px;
  font-size: 14px;
  color: #fff;
}

.popup-loc {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.popup-precision {
  font-size: 10px;
  color: #7dd3fc;
  white-space: nowrap;
}

.popup-meta {
  font-size: 11.5px;
  color: #94a3b8;
  margin-bottom: 3px;
}

.popup-summary {
  margin: 6px 0;
  line-height: 1.45;
  color: #cbd5e1;
}

.popup-units {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.popup-unit-chip {
  font-size: 10.5px;
  padding: 2px 6px;
  border-radius: 4px;
  background: #1e293b;
  color: #e2e8f0;
}

.station-popup-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(248, 113, 113, 0.16);
  border: 1px solid rgba(248, 113, 113, 0.45);
  color: #fca5a5;
  margin-bottom: 5px;
}

@media (max-width: 900px) {
  .workspace {
    flex-direction: column-reverse;
  }
  .sidebar {
    width: 100%;
    max-width: none;
    height: 46%;
    border-right: none;
    border-top: 1px solid var(--border);
  }
}
