:root {
  color-scheme: light;
  /* Neutrals + brand accent match placealert.org's own design tokens
     (/var/www/website/assets/style.css --msu-* / --bg-* / --text-* vars).
     --low/--moderate/--high/--very-high are the map's risk-level color
     coding, not branding — left untouched intentionally. */
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --text: #1f2937;
  --muted: #4b5563;
  --border: #e5e7eb;
  --low: #2f855a;
  --moderate: #d69e2e;
  --high: #dd6b20;
  --very-high: #c53030;
  --accent: #1e3a8a;
  --accent-soft: #dbeafe;
  --shadow: 0 2px 15px rgba(30, 58, 138, 0.08), 0 8px 30px -12px rgba(30, 58, 138, 0.18);
  --radius: 12px;
  --content-max-width: none;
}

/* Dark mode: only chrome (backgrounds/text/borders) changes. --low/--moderate/
   --high/--very-high (the map's risk color coding) are intentionally NOT
   redefined here, so they stay identical in both themes. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273449;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --border: #334155;
  --accent: #60a5fa;
  --accent-soft: #1e3a5f;
  --shadow: 0 2px 15px rgba(0, 0, 0, 0.35), 0 8px 30px -12px rgba(0, 0, 0, 0.5);
}

/* A few spots use one-off colors instead of the theme variables above
   (gradients, status tints, table hover, the map's pre-tile-load placeholder)
   and need their own dark-mode variant. */
:root[data-theme="dark"] .topbar {
  background: linear-gradient(180deg, #1e293b, #0f172a);
}

:root[data-theme="dark"] .status-pill {
  border-color: #16a34a;
  background: #052e1c;
  color: #6ee7b7;
}

:root[data-theme="dark"] .status-pill.status-error {
  border-color: #dc2626;
  background: #2c0b0b;
  color: #fca5a5;
}

:root[data-theme="dark"] #map {
  background: #1e293b;
}

:root[data-theme="dark"] tr:hover td {
  background: var(--surface-2);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Arial, Helvetica, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
p {
  margin: 0;
}

.topbar {
  flex: none;
  border-bottom: 1px solid var(--border);
  border-top: 6px solid var(--accent);
  background: linear-gradient(180deg, #ffffff, #fbfcfd);
  position: sticky;
  top: 0;
  /* Leaflet's own panes/controls go up to z-index 1000 (see leaflet's
     CSS), so the sticky header needs to sit above that or the map renders
     on top of it while scrolling. */
  z-index: 1001;
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 18px;
  max-width: var(--content-max-width);
  margin: 0 auto;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  height: 34px;
  width: 34px;
  display: block;
  object-fit: contain;
}

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

#data-warning {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  max-width: 62ch;
}

#data-warning a {
  color: inherit;
  font-weight: 700;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-right .ghost-button {
  min-height: 30px;
  padding: 5px 10px;
  font-size: 12.5px;
}

#theme-toggle {
  min-height: 30px;
  min-width: 30px;
  padding: 5px 8px;
  font-size: 15px;
  line-height: 1;
}

.status-pill {
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  border: 1px solid #6ee7b7;
  background: #ecfdf5;
  color: #065f46;
}

.status-pill.status-error {
  border-color: #fca5a5;
  background: #fef2f2;
  color: #991b1b;
}

.dashboard {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  padding: 16px 18px 24px;
  max-width: var(--content-max-width);
  margin: 0 auto;
}

.toolbar {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  margin-bottom: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

select,
button,
.button-link,
.ghost-button {
  min-height: 38px;
  border-radius: 9px;
  padding: 8px 12px;
  font-size: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
}

button,
.button-link,
.ghost-button {
  cursor: pointer;
  text-decoration: none;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
}

button:hover,
.button-link:hover,
.ghost-button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

#refresh-button {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

#refresh-button:hover {
  opacity: 0.88;
  color: #fff;
}

.summary-grid {
  flex: none;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metric,
.map-panel,
.detail-panel,
.table-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.metric {
  padding: 12px 16px;
}

.metric-alert strong {
  color: var(--high);
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.metric strong {
  display: block;
  margin-top: 4px;
  font-size: 23px;
  letter-spacing: -0.01em;
}

.content-grid {
  flex: 1 1 auto;
  min-height: 380px;
  display: grid;
  grid-template-columns: minmax(0, 1.75fr) minmax(320px, 0.85fr);
  gap: 16px;
  align-items: stretch;
}

.map-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-head {
  flex: none;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.panel-head h2 {
  font-size: 15px;
  font-weight: 700;
}

.panel-sub {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12.5px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: end;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

#map {
  width: 100%;
  flex: 1 1 auto;
  min-height: 320px;
  background: #dfe9ee;
  border-radius: 0 0 var(--radius) var(--radius);
}

.leaflet-tooltip {
  font-family: inherit;
  font-size: 12.5px;
  border-radius: 6px;
  box-shadow: var(--shadow);
}

:root[data-theme="dark"] .leaflet-tooltip {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

:root[data-theme="dark"] .leaflet-tooltip::before {
  border-top-color: var(--surface);
  border-right-color: var(--surface);
}

:root[data-theme="dark"] .leaflet-bar a,
:root[data-theme="dark"] .leaflet-control-attribution {
  background: var(--surface);
  color: var(--text);
}

:root[data-theme="dark"] .leaflet-bar a:hover {
  background: var(--surface-2);
}

:root[data-theme="dark"] .leaflet-control-attribution a {
  color: var(--accent);
}

.detail-panel {
  min-height: 320px;
  padding: 16px;
  overflow-y: auto;
}

.detail-panel h2#detail-title {
  font-size: 17px;
}

.detail-body {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}

.section-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  margin-bottom: 4px;
}

.detail-stat {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.detail-stat span {
  color: var(--muted);
}

.risk-badge {
  display: inline-block;
  border-radius: 999px;
  padding: 5px 10px;
  color: #ffffff;
  font-size: 12.5px;
  font-weight: 700;
}

.actions {
  margin: 0;
  padding-left: 18px;
  line-height: 1.55;
}

.sparkline-wrap {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 10px 10px 4px;
}

.sparkline {
  width: 100%;
  height: 70px;
  display: block;
}

.sparkline-labels {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 10.5px;
  padding: 2px 2px 4px;
}

.table-panel {
  flex: none;
  margin-top: 16px;
}

.field-hint {
  font-size: 10.5px;
  font-weight: 500;
  text-transform: none;
  color: var(--muted);
  letter-spacing: normal;
}

.field-hint.warning {
  color: var(--very-high);
  font-weight: 700;
}

#date-select:invalid,
#date-select.unavailable {
  border-color: var(--very-high);
}

/* Native date inputs already grey out/disable calendar days outside
   min/max; this just makes the field itself look inert when a bad value
   somehow ends up in it (typed, or a gap day). */
.how-to-use-modal {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(560px, 92vw);
  max-height: 82vh;
  overflow: hidden;
}

.how-to-use-modal::backdrop {
  background: rgba(15, 23, 42, 0.55);
}

.how-to-use-modal .modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.how-to-use-modal .modal-head h2 {
  font-size: 16px;
}

.how-to-use-modal .modal-body {
  padding: 4px 18px 18px;
  overflow-y: auto;
  max-height: calc(82vh - 56px);
}

.how-to-use-modal h3 {
  font-size: 13px;
  margin-top: 16px;
  margin-bottom: 4px;
}

.how-to-use-modal p {
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text);
}

.how-to-use-modal a {
  color: var(--accent);
}

#record-count {
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  background: var(--surface-2);
  position: sticky;
  top: 0;
}

tr:hover td {
  background: #f8fafb;
}

.muted {
  color: var(--muted);
}

.link-button {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font-weight: 700;
  cursor: pointer;
  text-decoration: underline;
  font-size: 13px;
}

.app-footer {
  margin-top: 20px;
  text-align: center;
}

.app-footer a {
  color: var(--muted);
}

.app-footer .credit {
  margin-top: 6px;
  font-size: 12px;
  font-weight: 600;
}

@media (max-width: 980px) {
  .summary-grid,
  .content-grid {
    grid-template-columns: 1fr;
  }

  .content-grid {
    flex: none;
  }

  .detail-panel {
    min-height: 260px;
  }

  #map {
    min-height: 420px;
  }
}

@media (max-width: 640px) {
  .topbar-inner,
  .dashboard {
    padding-left: 14px;
    padding-right: 14px;
  }

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

  .toolbar {
    align-items: stretch;
  }

  label,
  select,
  button,
  .button-link,
  .ghost-button {
    width: 100%;
  }
}
