:root {
  --bg: #f4f6f2;
  --panel: #ffffff;
  --panel-strong: #111312;
  --text: #171918;
  --muted: #626861;
  --line: #d7ddd2;
  --line-strong: #b8c1b4;
  --accent: #ffb000;
  --accent-strong: #f28c00;
  --danger: #e3392f;
  --danger-dark: #8f1d18;
  --safe: #168a54;
  --info: #0a8aa3;
  --shadow: 0 18px 60px rgba(22, 25, 22, 0.14);
  --radius: 8px;
  --topbar-height: 72px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  color: var(--text);
  background:
    linear-gradient(135deg, rgba(255, 176, 0, 0.12), transparent 34%),
    linear-gradient(315deg, rgba(10, 138, 163, 0.12), transparent 28%),
    var(--bg);
  overflow: hidden;
}

/* Critical Leaflet fallback in case the CDN stylesheet is blocked. */
.leaflet-container {
  overflow: hidden;
  position: relative;
  outline: 0;
}

.leaflet-pane,
.leaflet-map-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  position: absolute;
  left: 0;
  top: 0;
}

.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow {
  user-select: none;
  -webkit-user-drag: none;
}

.leaflet-tile {
  max-width: none;
  max-height: none;
}

.leaflet-control {
  position: relative;
  z-index: 800;
  pointer-events: auto;
}

.leaflet-top,
.leaflet-bottom {
  position: absolute;
  z-index: 800;
  pointer-events: none;
}

.leaflet-top {
  top: 0;
}

.leaflet-right {
  right: 0;
}

.leaflet-bottom {
  bottom: 0;
}

.leaflet-left {
  left: 0;
}

.leaflet-tile-pane {
  z-index: 200;
}

.leaflet-overlay-pane {
  z-index: 400;
}

.leaflet-shadow-pane {
  z-index: 500;
}

.leaflet-marker-pane {
  z-index: 600;
}

.leaflet-tooltip-pane {
  z-index: 650;
}

.leaflet-popup-pane {
  z-index: 700;
}

.leaflet-control-layers {
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 24px rgba(22, 25, 22, 0.16);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 0.82rem;
  overflow: hidden;
}

.leaflet-control-layers-list {
  padding: 8px 10px;
}

.leaflet-control-layers label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 4px 0;
  font-weight: 700;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.topbar {
  min-height: var(--topbar-height);
  display: grid;
  grid-template-columns: minmax(230px, 0.9fr) minmax(260px, 1.2fr) auto;
  align-items: center;
  gap: 20px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(14px);
  z-index: 500;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  background:
    linear-gradient(160deg, #fff4c2 0 28%, transparent 28% 100%),
    linear-gradient(135deg, #171918 0 45%, #ffb000 45% 100%);
  position: relative;
  box-shadow: inset 0 0 0 1px rgba(23, 25, 24, 0.12);
  flex: 0 0 auto;
}

.brand-mark::after {
  content: "";
  position: absolute;
  inset: 9px 14px 8px 12px;
  background: #ffffff;
  clip-path: polygon(45% 0, 100% 0, 64% 42%, 94% 42%, 22% 100%, 42% 54%, 6% 54%);
}

.brand strong,
.brand small {
  display: block;
  white-space: nowrap;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.78rem;
}

.topbar-status {
  justify-self: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.92rem;
  min-width: 0;
}

.topbar-status span {
  white-space: nowrap;
}

.live-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--safe);
  box-shadow: 0 0 0 6px rgba(22, 138, 84, 0.16);
}

.live-dot.warning {
  background: var(--accent);
  box-shadow: 0 0 0 6px rgba(255, 176, 0, 0.2);
}

.live-dot.error {
  background: var(--danger);
  box-shadow: 0 0 0 6px rgba(227, 57, 47, 0.18);
}

.divider {
  width: 1px;
  height: 18px;
  background: var(--line);
}

.topbar-actions {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 10px;
}

.primary-button,
.ghost-button,
.wide-button {
  border: 0;
  border-radius: var(--radius);
  min-height: 42px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 700;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
}

.primary-button {
  color: #171918;
  background: var(--accent);
  box-shadow: 0 10px 24px rgba(242, 140, 0, 0.22);
}

.primary-button:hover,
.wide-button:hover,
.ghost-button:hover {
  transform: translateY(-1px);
}

.primary-button:active,
.wide-button:active,
.ghost-button:active {
  transform: translateY(0);
}

.primary-button.compact {
  min-height: 38px;
}

.ghost-button {
  color: var(--text);
  background: #eef2eb;
  box-shadow: inset 0 0 0 1px var(--line);
}

.ghost-button.tiny {
  min-height: 30px;
  padding: 0 10px;
  font-size: 0.82rem;
}

.wide-button {
  width: 100%;
  color: #ffffff;
  background: var(--panel-strong);
  margin-top: 12px;
}

.location-icon {
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  position: relative;
}

.location-icon::after {
  content: "";
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.dashboard {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr) minmax(280px, 340px);
  gap: 14px;
  padding: 14px;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 28px rgba(22, 25, 22, 0.08);
  overflow: hidden;
}

.controls-panel,
.alert-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: auto;
}

.panel-section {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.panel-section:last-child {
  border-bottom: 0;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  font-weight: 800;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.section-heading .eyebrow {
  margin-bottom: 0;
}

.search-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

input[type="search"],
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  color: var(--text);
  background: #ffffff;
  padding: 0 12px;
  outline: none;
}

input[type="search"]:focus,
select:focus,
.range:focus {
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 4px rgba(255, 176, 0, 0.18);
}

.search-results {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.search-result-button {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8faf6;
  color: var(--text);
  padding: 10px;
  text-align: left;
}

.search-result-button strong {
  display: block;
  margin-bottom: 2px;
}

.search-result-button span {
  color: var(--muted);
  font-size: 0.82rem;
}

.hint {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
  margin: 12px 0 0;
}

.field-label {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  margin: 14px 0 6px;
}

.field-label:first-of-type {
  margin-top: 0;
}

.range {
  width: 100%;
  accent-color: var(--accent-strong);
}

.range-labels {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.78rem;
}

.switches {
  display: grid;
  gap: 12px;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 700;
  line-height: 1.35;
}

.switch-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-strong);
}

.map-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  height: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #dfe7da;
  box-shadow: var(--shadow);
}

#map {
  width: 100%;
  height: 100%;
  z-index: 1;
}

.map-overlay {
  position: absolute;
  z-index: 420;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(215, 221, 210, 0.92);
  box-shadow: 0 12px 28px rgba(22, 25, 22, 0.1);
  backdrop-filter: blur(12px);
}

.map-overlay.top-left {
  left: 14px;
  top: 14px;
  max-width: min(360px, calc(100% - 28px));
  padding: 12px 14px;
}

.map-overlay.top-left strong,
.map-overlay.top-left span {
  display: block;
}

.map-overlay.top-left span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.86rem;
}

.legend {
  left: 14px;
  bottom: 14px;
  padding: 10px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-dot,
.legend-ring {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  display: inline-block;
}

.legend-dot.fresh {
  background: var(--danger);
}

.legend-dot.recent {
  background: var(--accent);
}

.legend-dot.older {
  background: #8f948d;
}

.legend-ring {
  border: 2px solid var(--info);
}

.alert-card {
  padding: 18px;
  color: #ffffff;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.08), transparent 52%),
    var(--panel-strong);
}

.alert-card.safe {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.1), transparent 52%),
    var(--safe);
}

.alert-card.danger {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.1), transparent 52%),
    var(--danger-dark);
}

.alert-card h1 {
  margin: 0;
  font-size: clamp(1.55rem, 2.5vw, 2.3rem);
  line-height: 1;
}

.alert-card p:last-child {
  margin: 10px 0 0;
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.82);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
}

.metric {
  min-width: 0;
  padding: 14px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.metric:nth-child(2n) {
  border-right: 0;
}

.metric:nth-last-child(-n + 2) {
  border-bottom: 0;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 800;
}

.metric strong {
  display: block;
  margin-top: 4px;
  font-size: 1.45rem;
}

.recent-section {
  min-height: 0;
}

.timeline-section {
  display: grid;
  gap: 12px;
}

.timeline-heading strong {
  font-size: 0.86rem;
}

.timeline-range-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.timeline-range-button {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: #f8faf6;
  font-size: 0.78rem;
  font-weight: 800;
}

.timeline-range-button.active,
.timeline-play-button.active {
  color: #171918;
  background: var(--accent);
  border-color: rgba(242, 140, 0, 0.7);
  box-shadow: 0 8px 18px rgba(242, 140, 0, 0.16);
}

.timeline-controls {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.timeline-play-button {
  min-width: 54px;
}

.timeline-slider {
  width: 100%;
  accent-color: var(--accent-strong);
}

.timeline-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.timeline-meta span:first-child {
  overflow-wrap: anywhere;
}

.timeline-bars {
  min-height: 76px;
  display: grid;
  grid-template-columns: repeat(var(--timeline-bars, 96), minmax(1px, 1fr));
  align-items: end;
  gap: 1px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8faf6;
}

.timeline-bar {
  min-height: 5px;
  border-radius: 5px 5px 2px 2px;
  background: linear-gradient(180deg, var(--danger), var(--accent));
  position: relative;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.timeline-bar.quiet {
  background: #c8d0c4;
}

.timeline-bar.active {
  outline: 2px solid var(--panel-strong);
  outline-offset: 1px;
}

.timeline-bar::after {
  content: attr(data-count);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 4px);
  transform: translateX(-50%);
  color: var(--muted);
  font-size: 0.62rem;
  opacity: 0;
  pointer-events: none;
}

.timeline-bar:hover::after,
.timeline-bar:focus::after {
  opacity: 1;
}

.alert-list,
.feed-list {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
  padding-right: 2px;
}

.feed-list {
  max-height: 260px;
}

.alert-item,
.feed-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8faf6;
  padding: 10px;
  display: grid;
  gap: 4px;
}

.alert-item {
  border-color: rgba(227, 57, 47, 0.34);
  background: #fff7f5;
}

.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.item-row strong,
.item-row span {
  overflow-wrap: anywhere;
}

.item-row span,
.feed-item small,
.alert-item small {
  color: var(--muted);
}

.empty-state {
  color: var(--muted);
  margin: 0;
  line-height: 1.45;
}

.status-strip {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 18px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  color: var(--muted);
  font-size: 0.84rem;
}

.toast-stack {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 900;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 36px));
}

.toast {
  border-radius: var(--radius);
  color: #ffffff;
  background: var(--panel-strong);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  animation: toast-in 240ms ease-out;
}

.toast.danger {
  background: var(--danger-dark);
}

.toast.success {
  background: var(--safe);
}

.strike-marker {
  width: 34px;
  height: 34px;
  position: relative;
  transform: translate(-17px, -17px);
}

.strike-marker .strike-ring,
.strike-marker .strike-core,
.strike-marker .strike-bolt {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.strike-marker .strike-ring {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 2px solid rgba(227, 57, 47, 0.7);
  animation: pulse-ring 1.8s ease-out infinite;
}

.strike-marker .strike-core {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: var(--danger);
  box-shadow:
    0 0 16px rgba(227, 57, 47, 0.8),
    0 0 34px rgba(255, 176, 0, 0.55);
}

.strike-marker .strike-bolt {
  width: 15px;
  height: 22px;
  background: #ffffff;
  clip-path: polygon(45% 0, 100% 0, 62% 42%, 90% 42%, 20% 100%, 39% 55%, 4% 55%);
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.34));
}

.strike-marker.age-recent .strike-ring {
  border-color: rgba(255, 176, 0, 0.74);
}

.strike-marker.age-recent .strike-core {
  background: var(--accent);
  box-shadow:
    0 0 16px rgba(255, 176, 0, 0.9),
    0 0 34px rgba(255, 176, 0, 0.45);
}

.strike-marker.age-older .strike-ring {
  border-color: rgba(143, 148, 141, 0.58);
}

.strike-marker.age-older .strike-core {
  background: #8f948d;
  box-shadow: 0 0 14px rgba(143, 148, 141, 0.58);
}

.strike-marker.nearby .strike-ring {
  border-color: rgba(227, 57, 47, 0.95);
  animation-duration: 900ms;
}

.user-marker {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: var(--info);
  border: 3px solid #ffffff;
  box-shadow:
    0 0 0 8px rgba(10, 138, 163, 0.18),
    0 10px 26px rgba(10, 138, 163, 0.36);
}

.search-marker {
  width: 22px;
  height: 22px;
  background: var(--panel-strong);
  border: 3px solid #ffffff;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  box-shadow: 0 10px 24px rgba(22, 25, 22, 0.22);
}

.leaflet-popup-content-wrapper {
  border-radius: var(--radius);
}

.popup-title {
  font-weight: 800;
  margin-bottom: 6px;
}

.popup-meta {
  color: var(--muted);
  line-height: 1.45;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes pulse-ring {
  0% {
    opacity: 0.92;
    transform: translate(-50%, -50%) scale(0.35);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.65);
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1180px) {
  .dashboard {
    grid-template-columns: minmax(250px, 310px) minmax(0, 1fr);
  }

  .alert-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(240px, 0.8fr) minmax(280px, 1fr) minmax(280px, 1fr);
    max-height: 260px;
    overflow: auto;
  }

  .alert-card,
  .metric-grid,
  .alert-panel .panel-section {
    border-bottom: 0;
    border-right: 1px solid var(--line);
  }

  .alert-panel .panel-section:last-child {
    border-right: 0;
  }
}

@media (max-width: 860px) {
  :root {
    --topbar-height: auto;
  }

  body {
    overflow: auto;
  }

  .app-shell {
    min-height: 100dvh;
    height: auto;
    overflow: visible;
  }

  .topbar {
    position: static;
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .topbar-status {
    justify-self: start;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .topbar-actions {
    justify-self: stretch;
  }

  .topbar-actions > * {
    flex: 1;
  }

  .dashboard {
    grid-template-columns: 1fr;
    padding: 10px;
    height: auto;
    overflow: visible;
  }

  .controls-panel {
    order: 2;
    max-height: none;
  }

  .map-stage {
    order: 1;
    height: 58dvh;
    min-height: 360px;
  }

  .alert-panel {
    order: 3;
    grid-column: auto;
    display: block;
    max-height: none;
  }

  .alert-card,
  .metric-grid,
  .alert-panel .panel-section {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

@media (max-width: 560px) {
  .brand strong {
    white-space: normal;
  }

  .search-form {
    grid-template-columns: 1fr;
  }

  .map-overlay.top-left {
    left: 10px;
    top: 10px;
  }

  .legend {
    left: 10px;
    right: 10px;
    bottom: 10px;
  }

  .metric-grid {
    grid-template-columns: 1fr 1fr;
  }
}
