#map, #preview-map { background: #e8f0fa; isolation: isolate; }
.dark :is(#map, #preview-map) { background: #0d1f3c; }
.home-map-frame { position: relative; margin: 0; overflow: hidden; border: 1px solid #5a84ba; border-radius: 1rem; background: #152d55; box-shadow: 0 16px 40px #080f1f52; }
.home-map-heading, .home-map-caption { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .6rem .85rem; }
.home-map-heading { min-height: 52px; padding-block: .2rem; font-size: .875rem; font-weight: 700; }
.home-map-motion { min-height: 44px; padding-inline: .4rem; flex-shrink: 0; color: #dce6f5; font-size: .75rem; text-decoration: underline; text-underline-offset: .2em; }
.home-map-motion:hover { color: #fff; }
.home-map-motion:focus-visible { outline-color: #bacde8; }
.home-map-caption { font-size: .75rem; color: #dce6f5; }
.home-map-caption a { display: inline-flex; align-items: center; min-height: 32px; text-decoration: underline; white-space: nowrap; }
#preview-map { height: clamp(13.5rem, 31vw, 24rem); pointer-events: none; }
#preview-map .preview-marker-ring { transform-box: fill-box; transform-origin: center; opacity: 0; }
@media (prefers-reduced-motion: no-preference) {
  #preview-map .preview-incident-dot {
    transform-box: fill-box;
    transform-origin: center;
    animation: preview-marker-appear .44s cubic-bezier(.25, .7, .32, 1) var(--marker-delay, 0ms) both;
  }
  #preview-map.preview-paused .preview-incident-dot { animation-play-state: paused; }
  @keyframes preview-marker-appear {
    0% { opacity: 0; transform: scale(.2); }
    65% { opacity: 1; transform: scale(1.27); }
    100% { opacity: 1; transform: scale(1); }
  }
}
.home-map-status, .map-feedback { position: absolute; z-index: 2; top: 50%; left: 50%; width: max-content; max-width: calc(100% - 2rem); transform: translate(-50%, -50%); text-align: center; border-radius: .55rem; padding: .55rem .85rem; font-size: .875rem; background: #fff; color: #152d55; box-shadow: 0 2px 10px #080f1f26; pointer-events: none; }
.dark :is(.home-map-status, .map-feedback) { background: #152d55; color: #f0f4fa; }

.incident-map-page { display: flex; flex-direction: column; min-height: calc(100vh - 65px); min-height: calc(100svh - 65px); }
.map-toolbar { position: relative; padding: .3rem clamp(.75rem, 2.5vw, 1.75rem); border-bottom: 1px solid #dce6f5; }
.dark .map-toolbar { border-color: #1e3d70; }
.map-toolbar-title { position: absolute; inset-block-start: .3rem; inset-inline-start: clamp(.75rem, 2.5vw, 1.75rem); display: inline-flex; align-items: center; min-height: 44px; gap: .5rem; font-size: clamp(1.05rem, 2.5vw, 1.35rem); font-weight: 800; letter-spacing: -.025em; }
@media (prefers-reduced-motion: no-preference) {
  .map-toolbar-title > svg { animation: public-art-enter .42s ease-out both; }
}
.map-tools-toggle { display: flex; width: max-content; margin-inline-start: auto; cursor: pointer; list-style: none; font-weight: 750; }
.map-tools-toggle::-webkit-details-marker { display: none; }
.map-tools-summary-copy { display: grid; text-align: left; line-height: 1.1; }
.map-tools-summary-copy small { margin-top: .2rem; color: #52657d; font-size: .68rem; font-weight: 550; }
.dark .map-tools-summary-copy small { color: #bacde8; }
.map-tools-chevron { transition: transform .15s; }
.map-tools[open] .map-tools-chevron { transform: rotate(180deg); }
@media (prefers-reduced-motion: no-preference) {
  .map-tools.map-tools-nudge:not([open]) > summary { animation: map-tools-nudge 5s ease-in-out both; }
  @keyframes map-tools-nudge {
    0%, 100% { box-shadow: 0 0 0 0 transparent; background-color: transparent; }
    8%, 24%, 40% { box-shadow: 0 0 0 4px rgb(56 102 165 / 22%); background-color: #dce6f5; }
    16%, 32%, 48% { box-shadow: 0 0 0 0 transparent; background-color: transparent; }
  }
}
.dark .map-tools.map-tools-nudge:not([open]) > summary { color: #f0f4fa; }
@media (prefers-reduced-motion: no-preference) {
  .dark .map-tools.map-tools-nudge:not([open]) > summary { animation-name: map-tools-nudge-dark; }
  @keyframes map-tools-nudge-dark {
    0%, 100% { box-shadow: 0 0 0 0 transparent; background-color: transparent; }
    8%, 24%, 40% { box-shadow: 0 0 0 4px rgb(138 171 211 / 24%); background-color: #1e3d70; }
    16%, 32%, 48% { box-shadow: 0 0 0 0 transparent; background-color: transparent; }
  }
}
.map-tools-panel { border-top: 1px solid #dce6f5; }
.dark .map-tools-panel { border-color: #1e3d70; }
.map-toolbar-options, .map-result-line, .map-record-links { display: flex; flex-wrap: wrap; align-items: center; gap: 0 .65rem; }
.map-toolbar-options, .map-result-line { justify-content: space-between; }
.map-result-line { margin-top: .15rem; }
.map-record-context { display: flex; flex-wrap: wrap; align-items: center; gap: 0 .65rem; }
.map-record-context > p { padding-block: .25rem; font-size: .8125rem; color: #475569; font-weight: 650; }
.dark .map-record-context > p { color: #dce6f5; }
.map-result-line .page-filter-chips { margin-block: .15rem; }
.map-filters { width: 100%; }
.map-filters summary { display: inline-flex; }
.map-filter-count { min-width: 1.25rem; border-radius: 2rem; padding: 0 .3rem; color: #152d55; background: #dce6f5; text-align: center; }
.map-filter-form { display: grid; gap: .7rem; padding: .4rem 0 .65rem; }
.map-filter-basics, .map-custom-date-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .55rem; }
.map-filter-control { min-width: 0; }
.map-date-filter { min-width: 0; margin: 0; padding: .55rem .65rem .65rem; border: 1px solid #dce6f5; border-radius: .7rem; }
.dark .map-date-filter { border-color: #355780; }
.map-date-filter > legend { padding-inline: .25rem; color: #152d55; font-size: .8125rem; font-weight: 750; }
.dark .map-date-filter > legend { color: #f0f4fa; }
.map-date-presets { display: flex; flex-wrap: wrap; gap: .35rem; }
.map-date-presets button { min-height: 44px; padding: .4rem .65rem; border: 1px solid #9bb3d1; border-radius: .55rem; background: #fff; color: #1e3d70; font-size: .8125rem; font-weight: 700; transition: background-color .15s, border-color .15s, color .15s; }
.map-date-presets button:hover, .map-date-presets button[aria-pressed="true"] { border-color: #5a84ba; background: #dce6f5; color: #152d55; }
.map-date-presets button:focus-visible, .map-custom-date summary:focus-visible { outline: 2px solid #3866a5; outline-offset: 2px; }
.dark .map-date-presets button { border-color: #5a84ba; background: #0d1f3c; color: #dce6f5; }
.dark .map-date-presets button:hover, .dark .map-date-presets button[aria-pressed="true"] { background: #1e3d70; color: #fff; }
.map-custom-date { margin-top: .45rem; }
.map-custom-date summary { width: max-content; min-height: 40px; display: flex; align-items: center; cursor: pointer; color: #1e3d70; font-size: .8125rem; font-weight: 650; text-decoration: underline; text-underline-offset: .15em; }
.dark .map-custom-date summary { color: #dce6f5; }
.map-custom-date-fields { padding-top: .4rem; }
.map-filter-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .65rem; }
.map-filter-field { min-height: 44px; max-width: 100%; padding: .35rem .6rem; border: 1px solid #94a3b8; border-radius: .5rem; background: #fff; color: #152d55; font-size: .875rem; }
.dark .map-filter-field { background: #0d1f3c; border-color: #5a84ba; color: #f0f4fa; color-scheme: dark; }
.map-views { display: grid; gap: .3rem; width: min(100%, 23rem); min-width: 0; margin: 0; padding: 0; border: 0; }
.map-view-title { padding: 0; font-size: .875rem; font-weight: 750; color: #152d55; }
.dark .map-view-title { color: #f0f4fa; }
.map-mode-buttons { position: relative; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .2rem; width: min(100%, 23rem); padding: .2rem; border: 1px solid #cbd8e9; border-radius: .75rem; background: #f0f4fa; isolation: isolate; }
.dark .map-mode-buttons { border-color: #355780; background: #0d1f3c; }
.map-mode-indicator { position: absolute; z-index: 0; top: .2rem; bottom: .2rem; left: 0; width: 0; border: 1px solid #9bb3d1; border-radius: .55rem; background: #fff; box-shadow: 0 1px 3px #080f1f20; transform: translateX(0); transition: transform .24s cubic-bezier(.2,.75,.25,1); pointer-events: none; }
.dark .map-mode-indicator { border-color: #5a84ba; background: #1e3d70; }
.map-mode-buttons button { position: relative; z-index: 1; display: inline-flex; align-items: center; justify-content: center; gap: .3rem; min-width: 0; min-height: 44px; padding: .35rem .3rem; border: 1px solid transparent; border-radius: .55rem; background: transparent; font-size: .75rem; font-weight: 700; color: #1e3d70; transition: color .16s; white-space: nowrap; }
.map-mode-buttons button:enabled:hover { color: #152d55; }
.map-mode-buttons button[aria-pressed="true"] { color: #152d55; }
.map-mode-buttons button:focus-visible { outline: 2px solid #3866a5; outline-offset: 2px; }
.dark .map-mode-buttons button { color: #dce6f5; }
.dark .map-mode-buttons button:enabled:hover, .dark .map-mode-buttons button[aria-pressed="true"] { color: #fff; }
.map-view-hint { max-width: 34rem; min-height: 1.2em; margin: 0; color: #52657d; font-size: .72rem; line-height: 1.35; }
.dark .map-view-hint { color: #bacde8; }
.map-mode-buttons button:disabled { opacity: .6; }
.map-workspace { position: relative; display: flex; flex-direction: column; flex: 1; }
#map { min-height: 24rem; flex: 1; }
.map-legend { position: absolute; z-index: 1; inset-inline-start: .65rem; inset-block-end: 1.45rem; width: max-content; max-width: min(17rem, calc(100% - 1.3rem)); padding: .55rem .7rem; border: 1px solid #bacde8; border-radius: .65rem; box-shadow: 0 3px 12px #080f1f29; background: #ffffffed; color: #334155; font-size: .75rem; pointer-events: none; }
.dark .map-legend { background: #0d1f3cf5; border-color: #2a508a; color: #dce6f5; }
.map-legend-items { display: flex; flex-wrap: wrap; gap: .35rem .85rem; }
/* Sized like the marker it stands for, so the legend can be compared with the
   map rather than merely read. The digit colour comes from app/severity.py,
   where it is chosen per step for >= 4.5:1 against its own fill. */
.map-severity-dot { width: 1.25rem; height: 1.25rem; display: inline-grid; place-items: center; border-radius: 50%; background: var(--severity-color, #94a3b8); color: var(--severity-digit, #111827); border: 1.5px solid var(--severity-outline, #1e293b); font-size: .66rem; font-weight: 800; }
/* The outline, not the fill, is what separates the symbol from the map: a ramp
   running light to dark must pass close to a pale background at one end and a
   dark one at the other, so no fill can clear 3:1 against both. Measured:
   10.2:1 against the light country fill, 9.1:1 against the dark one. */
.map-event-marker { display: grid; place-items: center; border: 2px solid var(--severity-outline, #1e293b); border-radius: 50%; box-shadow: 0 1px 4px #080f1f66; font-size: .75rem; font-weight: 800; }
.map-cluster-marker, .map-legend-cluster { display: inline-grid; place-items: center; border-radius: 50%; background: #1e3d70; color: #fff; border: 3px solid #bacde8; font-size: .8rem; font-weight: 800; }
.map-legend-cluster { width: 1.55rem; height: 1.55rem; border-width: 2px; font-size: .68rem; }
/* The same direction as the severity ramp, so the two readings of the map
   agree. The old strip ran blue-cyan-green-yellow-red, which is neither
   sequential nor free of the red/green pair. */
.map-density-strip { width: min(100%, 15rem); height: .5rem; border-radius: 1rem; background: linear-gradient(to right, #fcd34d, #fb923c, #ef4444, #b91c1c, #6b0f1a); }
[data-heatmap-legend] { width: min(100%, 15rem); }
.map-popup-meta { color: #475569; margin-block: .25rem; }
.leaflet-container a.map-popup-link { color: #1e3d70; text-decoration: underline; font-weight: 700; }
@media (min-width: 1024px) {
  .map-filters { width: auto; flex: 1; }
  .map-filter-form { padding-bottom: .1rem; }
  .map-views { align-self: flex-start; padding-top: .125rem; }
}
@media (prefers-reduced-motion: reduce) {
  .map-mode-indicator { transition: none; }
  .map-tools-chevron { transition: none; }
}

/* The marker and legend outline follows the theme, because its job is to
   contrast with the map behind it. */
:root { --severity-outline: #1e293b; }
.dark { --severity-outline: #f8fafc; }
