/* AfterWell — water-point maintenance tracker (demo).
   Restyle only: every class name, the HTML and the JavaScript are unchanged.
   System fonts (no downloads — works on slow field connections), high contrast,
   44px touch targets. Status is always carried by label + shape, never colour alone.
   Optional: data-theme="light" | "dark" on any element forces a theme. */

/* ---------- tokens ---------- */

:root,
[data-theme="light"] {
  --bg: #eef2f2;
  --surface: #ffffff;
  --surface-2: #f6f8f8;
  --text: #11212a;
  --muted: #4c5c66;
  --border: #d3dcdf;
  --border-strong: #a9b8be;
  --focus: #1f6fd6;

  --primary: #0b5f8f;
  --primary-hover: #084a70;
  --primary-text: #ffffff;
  --primary-soft: #e2eff6;

  --ok: #15703a;
  --ok-bg: #e3f3e8;
  --fault: #b42318;
  --fault-bg: #fdebe8;
  --repair: #8a4a00;
  --repair-bg: #fcefd9;
  --overdue: #693d9e;
  --overdue-bg: #f0e8f8;

  /* Solid alert fill — white text on it in both themes (>= 5.5:1). */
  --alert-solid: #b42318;
  --alert-solid-deep: #8f1a11;

  --banner-bg: #fff1bd;
  --banner-text: #453400;
  --banner-edge: #e3c45a;

  --shadow-sm: 0 1px 2px rgba(17, 33, 42, 0.06);
  --shadow: 0 1px 2px rgba(17, 33, 42, 0.06), 0 4px 14px rgba(17, 33, 42, 0.06);
  --radius: 10px;
  --radius-sm: 6px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c1215;
    --surface: #151d21;
    --surface-2: #1a2429;
    --text: #e7eef0;
    --muted: #a0b1b9;
    --border: #2a383e;
    --border-strong: #42545c;
    --focus: #84b8ff;
    --primary: #62b4e6;
    --primary-hover: #8dc9ef;
    --primary-text: #04121b;
    --primary-soft: #122e3d;
    --ok: #6fd292;
    --ok-bg: #12301e;
    --fault: #ff9187;
    --fault-bg: #3b1613;
    --repair: #ffc266;
    --repair-bg: #352610;
    --overdue: #c9a6f5;
    --overdue-bg: #2a1f3d;
    --alert-solid: #c42a1e;
    --alert-solid-deep: #ff9187;
    --banner-bg: #393110;
    --banner-text: #fbe9a0;
    --banner-edge: #6b5a1c;
    --shadow-sm: none;
    --shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
    color-scheme: dark;
  }
}

[data-theme="dark"] {
  --bg: #0c1215;
  --surface: #151d21;
  --surface-2: #1a2429;
  --text: #e7eef0;
  --muted: #a0b1b9;
  --border: #2a383e;
  --border-strong: #42545c;
  --focus: #84b8ff;
  --primary: #62b4e6;
  --primary-hover: #8dc9ef;
  --primary-text: #04121b;
  --primary-soft: #122e3d;
  --ok: #6fd292;
  --ok-bg: #12301e;
  --fault: #ff9187;
  --fault-bg: #3b1613;
  --repair: #ffc266;
  --repair-bg: #352610;
  --overdue: #c9a6f5;
  --overdue-bg: #2a1f3d;
  --alert-solid: #c42a1e;
  --alert-solid-deep: #ff9187;
  --banner-bg: #393110;
  --banner-text: #fbe9a0;
  --banner-edge: #6b5a1c;
  --shadow-sm: none;
  --shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
  color-scheme: dark;
}

/* ---------- base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-padding-top: 56px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans", "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
}

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
h2:focus { outline: none; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- demo banner (always on screen) ---------- */

.demo-banner {
  position: sticky; top: 0; z-index: 1200;
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap;
  gap: 4px 10px;
  margin: 0;
  padding: 7px 16px;
  background: var(--banner-bg);
  color: var(--banner-text);
  border-bottom: 1px solid var(--banner-edge);
  font-size: 0.875rem; font-weight: 500;
  text-align: center;
}
.demo-banner::before {
  content: "Fictional demo data";
  padding: 1px 8px;
  border: 1.5px solid currentColor; border-radius: 999px;
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  white-space: nowrap;
}

/* ---------- header & AfterWell mark ---------- */

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

/* The <h1> keeps its text; the mark and "AfterWell" wordmark are drawn in front of it,
   and the original title becomes the product line underneath. */
.app-header h1 {
  display: flex; flex-wrap: wrap; align-items: center;
  column-gap: 6px; row-gap: 0;
  margin: 0;
  padding-left: 52px;
  min-height: 44px;
  position: relative;
  font-size: 0.875rem; font-weight: 500; line-height: 1.3;
  color: var(--muted);
}
/* Size the title by its real width, not its unwrapped width, so the controls stay on one row. */
.app-header h1 { flex: 0 1 320px; }
.app-header h1 .brand .tag { margin-left: 6px; vertical-align: 3px; letter-spacing: 0.06em; }
.app-header h1 .brand {
  flex-basis: 100%;
  font-size: 1.375rem; font-weight: 800; line-height: 1.15; letter-spacing: -0.02em;
  color: var(--text);
}
.app-header h1::after {
  content: "";
  position: absolute; left: 0; top: 50%;
  width: 42px; height: 42px; margin-top: -21px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' rx='15' fill='%230b5f8f'/%3E%3Cpath d='M0 46c8 0 8-4 16-4s8 4 16 4 8-4 16-4 8 4 16 4v18H0z' fill='%23094d74'/%3E%3Cpath d='M32 9c0 0-15 16.5-15 27.5a15 15 0 0 0 30 0C47 25.5 32 9 32 9z' fill='%23ffffff'/%3E%3Cpath d='M24.5 37.5l5.2 5.2 10.3-11' fill='none' stroke='%230b5f8f' stroke-width='4.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
}

.tag {
  display: inline-block; padding: 0 7px;
  font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  line-height: 1.6;
  background: var(--banner-bg); color: var(--banner-text);
  border: 1px solid var(--banner-edge); border-radius: 999px;
}

.header-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.actor { display: flex; align-items: center; gap: 8px; font-size: 0.875rem; color: var(--muted); font-weight: 600; }
.actor select { max-width: 100%; width: auto; color: var(--text); font-weight: 500; }

.notices { padding: 0 16px; }
.notice {
  margin: 10px 0 0; padding: 10px 14px;
  background: var(--repair-bg); color: var(--text);
  border: 1px solid var(--repair); border-radius: var(--radius-sm);
  font-size: 0.9rem;
}
.notice::before { content: "Note · "; font-weight: 700; color: var(--repair); }

/* ---------- page order: map first, then the summary, then the list ----------
   No HTML change: <main> steps aside (display: contents) so the map, the summary
   strip and the register can be ordered as one column. */

body { display: flex; flex-direction: column; min-height: 100vh; }
.demo-banner { order: 0; }
.app-header { order: 1; }
.notices { order: 2; }
.layout { display: contents; }
.map-area { order: 3; }
.counts { order: 4; }
.panel { order: 5; }

.notices, .map-area, .counts {
  width: 100%; max-width: 1280px; margin-inline: auto;
  padding-left: 16px; padding-right: 16px;
}

/* ---------- map: the centre of the page ---------- */

.map-area { min-width: 0; padding-top: 14px; }
.map {
  height: clamp(380px, 62vh, 760px);
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2);
  overflow: hidden;
}
.map--unavailable {
  display: flex; align-items: center; justify-content: center;
  padding: 16px; text-align: center; color: var(--muted);
  background: repeating-linear-gradient(135deg, var(--surface-2) 0 14px, var(--surface) 14px 28px);
}

/* ---------- summary strip: one chip per status, same icons as the map ---------- */

.counts {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 8px;
  padding-top: 18px; padding-bottom: 14px;
}
.counts::before {
  content: "Water points by status \00B7  select one to list them";
  order: -2; flex-basis: 100%;
  font-size: 0.8rem; font-weight: 700; color: var(--muted);
}
.count {
  display: inline-flex; align-items: center; gap: 8px;
  min-width: 0; min-height: 44px;
  padding: 6px 14px 6px 8px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 999px;
  font: inherit; text-align: left; cursor: pointer;
  transition: border-color 0.12s, background-color 0.12s;
}
.count:hover { border-color: var(--border-strong); background: var(--surface-2); }
.count__n { font-size: 1.1rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.count__label { font-size: 0.875rem; font-weight: 500; color: var(--muted); line-height: 1.2; }
.count[data-filter="all"] { padding-left: 14px; }

/* Icons drawn in CSS from the filter key, matching the map markers. */
.count::before {
  flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px;
  color: #ffffff; font-size: 0.8rem; font-weight: 900; line-height: 1;
}
.count[data-filter="all"]::before { display: none; }
.count[data-filter="operational"]::before { content: "\2713"; background: #15703a; border-radius: 50%; }
.count[data-filter="open"]::before { content: "!"; background: #b42318; clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); width: 28px; height: 28px; }
.count[data-filter="awaiting_parts"]::before { content: "\2699\FE0E"; background: #93500a; border-radius: 5px; }
.count[data-filter="overdue"]::before { content: "\25F7"; color: var(--overdue); background: var(--overdue-bg); border: 2px dashed var(--overdue); border-radius: 50%; }
.count[data-filter="unassigned"]::before { content: "!"; background: var(--alert-solid); border-radius: 6px; }

.count--active {
  border-color: var(--text);
  box-shadow: inset 0 0 0 1px var(--text);
}
.count--active .count__label { color: var(--text); font-weight: 700; }

/* The one chip nobody should miss. */
.count--alert {
  background: var(--fault-bg);
  border: 2px solid var(--alert-solid);
}
.count--alert .count__n, .count--alert .count__label { color: var(--fault); font-weight: 800; }
.count--alert:hover { background: var(--fault-bg); border-color: var(--alert-solid-deep); }
.count--alert.count--active { box-shadow: inset 0 0 0 1px var(--alert-solid); }

/* ---------- register / detail panel ---------- */

.panel {
  width: calc(100% - 32px); max-width: 1248px;
  margin: 0 auto 28px;
  min-width: 0;
  padding: 18px 20px 28px;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
}

@media (min-width: 901px) {
  .filters { grid-template-columns: 2fr 1fr 1fr; }
  .filters .field:first-child { grid-column: auto; }
  .register { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
  .panel .facts { max-width: 760px; }
  .panel .case, .panel .history { max-width: 900px; }
}

@media (max-width: 900px) {
  /* Unassigned faults jump to the front of the summary, full width. */
  .count--alert { order: -1; flex-basis: 100%; }
}

/* ---------- Leaflet chrome ---------- */

.leaflet-container { font: inherit; background: var(--surface-2); }
.leaflet-bar { border: 1px solid var(--border-strong) !important; border-radius: 8px !important; box-shadow: var(--shadow) !important; overflow: hidden; }
.leaflet-bar a { width: 36px !important; height: 36px !important; line-height: 36px !important; background: var(--surface) !important; color: var(--text) !important; border-color: var(--border) !important; }
.leaflet-bar a:hover { background: var(--surface-2) !important; }
.leaflet-control-attribution { background: color-mix(in srgb, var(--surface) 85%, transparent) !important; color: var(--muted); }
.leaflet-control-attribution a { color: var(--primary); }

/* ---------- legend & markers ---------- */

.legend {
  display: flex; flex-wrap: wrap; gap: 2px 16px;
  margin: 6px 0 0; padding: 0 4px; list-style: none;
  font-size: 0.8rem; color: var(--muted);
}
.legend li { display: flex; align-items: center; gap: 4px; }
.legend .marker { width: 18px; height: 18px; font-size: 0.65rem; margin: 4px; border-width: 1.5px; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4); }
.legend .marker--unassigned { margin: 6px; box-shadow: 0 0 0 2px #ffffff, 0 0 0 4px #b42318; }
.legend .marker--unassigned::after { display: none; }

.marker-host { background: none; border: none; }
.marker {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.55), 0 2px 5px rgba(0, 0, 0, 0.3);
  color: #ffffff; font-weight: 800; font-size: 0.95rem; line-height: 1;
}
.marker--operational { background: #15703a; border-radius: 50%; }
.marker--fault { background: #b42318; transform: rotate(45deg); border-radius: 4px; }
.marker--fault .marker__glyph { transform: rotate(-45deg); }
.marker--repair { background: #93500a; border-radius: 4px; }
.marker--overdue { background: #693d9e; border-radius: 50%; border-style: dashed; }

.marker--unassigned {
  box-shadow: 0 0 0 3px #ffffff, 0 0 0 6px #b42318, 0 4px 12px rgba(0, 0, 0, 0.45);
}
.marker--unassigned::after {
  content: "";
  position: absolute; inset: -11px;
  border: 3px solid #b42318; border-radius: inherit;
  opacity: 0;
  animation: aw-pulse 2s ease-out 4;
  pointer-events: none;
}
@keyframes aw-pulse {
  0% { transform: scale(0.8); opacity: 0.9; }
  100% { transform: scale(1.5); opacity: 0; }
}
.marker--selected { outline: 3px solid #1f6fd6; outline-offset: 4px; }

.leaflet-tooltip.tooltip-unassigned {
  padding: 5px 10px;
  background: #b42318; color: #ffffff;
  border: 2px solid #ffffff; border-radius: 6px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
  font: inherit; font-size: 0.85rem; font-weight: 800;
}
.leaflet-tooltip-right.tooltip-unassigned::before { border-right-color: #ffffff; margin-left: -14px; }

/* ---------- panel content ---------- */

.panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; }
.panel h2 { margin: 4px 0; font-size: 1.35rem; font-weight: 800; letter-spacing: -0.01em; line-height: 1.25; }
.section-title { margin: 22px 0 8px; font-size: 1rem; font-weight: 800; }
.muted { color: var(--muted); }
.text-warn { color: var(--overdue); }
.text-alert { color: var(--fault); }

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 9px 16px; min-height: 44px;
  font: inherit; font-size: 0.95rem; font-weight: 700; line-height: 1.2;
  border-radius: 8px;
  border: 1px solid transparent; cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s;
}
.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary-hover); }
/* Dark mode: a deeper button fill so the main action doesn't glare (white text, 5.8:1). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn-primary { background: #1b6796; color: #ffffff; }
  :root:not([data-theme="light"]) .btn-primary:hover { background: #237bb0; }
}
[data-theme="dark"] .btn-primary { background: #1b6796; color: #ffffff; }
[data-theme="dark"] .btn-primary:hover { background: #237bb0; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); border-color: var(--primary); }
.btn-link {
  padding: 4px 0; min-height: 44px;
  background: none; color: var(--primary);
  text-decoration: underline; text-underline-offset: 3px; font-weight: 600;
}
.btn-link:hover { color: var(--primary-hover); }

.flash {
  margin: 0 0 10px; padding: 10px 14px;
  background: var(--ok-bg); color: var(--text);
  border: 1px solid var(--ok); border-radius: var(--radius-sm);
  font-weight: 600;
}
.flash::before { content: "✓ "; color: var(--ok); font-weight: 800; }

.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
.filters .field:first-child { grid-column: 1 / -1; }
.register-note { margin: 10px 0; font-size: 0.85rem; }

/* ---------- register rows ---------- */

/* Folded sections (filters, map key, water point details, healthy points). */
.fold { margin: 8px 0; }
.fold > summary { min-height: 40px; font-size: 0.9rem; }
.fold__note { font-weight: 600; color: var(--primary); }
.fold .filters { margin-top: 0; }
.fold .facts { margin-top: 0; }
.legend-fold .legend { margin: 0; padding: 0; }
.filters .field__label {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
#register-list > li:has(> .fold) { grid-column: 1 / -1; }
.row--ok { flex-direction: row; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; padding: 10px 14px; }
.row__ok { font-size: 0.8rem; font-weight: 600; color: var(--ok); }

.register { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.register .empty {
  padding: 16px; color: var(--muted); text-align: center;
  border: 1px dashed var(--border-strong); border-radius: var(--radius);
}
.row {
  display: flex; flex-direction: column; gap: 6px; width: 100%;
  padding: 12px 14px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  font: inherit; text-align: left; cursor: pointer;
  transition: border-color 0.12s, background-color 0.12s;
}
.row:hover { border-color: var(--border-strong); background: var(--surface-2); }

/* Unassigned: the only row with a fill and a thick edge; the solid flag inside carries the words. */
.row--unassigned,
.row--unassigned:hover {
  padding: 14px;
  background: var(--fault-bg);
  border: 2px solid var(--alert-solid);
}
.row--unassigned:hover { border-color: var(--alert-solid-deep); }
.row--unassigned .row__name { font-size: 1.1rem; }
.row--unassigned .badge { background: transparent; padding-left: 0; }

.row__title { display: flex; flex-wrap: wrap; gap: 2px 8px; align-items: baseline; }
.row__name { font-weight: 700; }
.row__id {
  font-size: 0.8rem; color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-weight: 500;
}
.row__meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 0.85rem; }
.row__cat { color: var(--muted); }
.row__age { font-size: 0.85rem; color: var(--muted); }

/* ---------- badges & flags ---------- */

.badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 1px 8px 1px 6px; border-radius: 999px; border: none;
  font-size: 0.8rem; font-weight: 700; white-space: nowrap; line-height: 1.6;
}
.badge__glyph {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.1em; font-weight: 900;
}
/* Glyph + label carry the meaning; a light tint only, no outlines. */
.badge--operational { color: var(--ok); background: var(--ok-bg); }
.badge--fault { color: var(--fault); background: var(--fault-bg); }
.badge--repair { color: var(--repair); background: var(--repair-bg); }
.badge--overdue { color: var(--overdue); background: var(--overdue-bg); }

.flag-unassigned {
  display: inline-flex; align-items: center; gap: 8px; align-self: flex-start;
  padding: 4px 12px 4px 8px;
  background: var(--alert-solid); color: #ffffff;
  border-radius: 6px; font-weight: 800; font-size: 0.875rem; line-height: 1.4;
  box-shadow: 0 2px 6px rgba(180, 35, 24, 0.3);
}
.flag-unassigned--big { font-size: 1.15rem; padding: 8px 16px 8px 10px; }
.flag-icon {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 1.35em; height: 1.35em;
  border: 2.5px solid currentColor; border-radius: 4px;
  font-size: 0.85em; font-weight: 900; line-height: 1;
}

/* ---------- detail ---------- */

.facts {
  display: grid; grid-template-columns: max-content minmax(0, 1fr);
  gap: 6px 14px; margin: 10px 0;
  font-size: 0.925rem;
}
.facts dt { color: var(--muted); font-weight: 600; }
.facts dd { margin: 0; overflow-wrap: anywhere; }

.case {
  margin-top: 18px; padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.case h3 { margin: 10px 0 4px; font-size: 1.1rem; font-weight: 800; }
.case--unassigned {
  border: 2px solid var(--alert-solid);
  background: var(--fault-bg);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--alert-solid) 14%, transparent);
}
.case--unassigned > p:first-child { margin-top: 0; }
.case__warning { margin: 8px 0 0; font-weight: 700; color: var(--fault); font-size: 1rem; }
.case__age { margin: 0; font-weight: 600; }

.severity { text-transform: capitalize; font-weight: 700; }
.severity--critical, .severity--high { color: var(--fault); }
.severity--critical::before { content: "▲ "; font-size: 0.8em; }

.recording-as {
  display: inline-block;
  margin: 0 0 8px; padding: 3px 10px;
  font-size: 0.85rem; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
}
.recording-as strong { color: var(--text); }

/* ---------- action drawers ---------- */

.action {
  margin: 0 0 8px; padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px;
}
.action[open] { border-color: var(--border-strong); padding-bottom: 12px; }
.action summary {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 46px; padding: 6px 0;
  cursor: pointer; font-weight: 700; list-style: none;
}
.action summary::-webkit-details-marker { display: none; }
.action summary::after {
  content: ""; flex: none;
  width: 9px; height: 9px; margin-right: 4px;
  border-right: 2.5px solid currentColor; border-bottom: 2.5px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
  transition: transform 0.15s;
}
.action[open] summary::after { transform: rotate(-135deg) translateY(-2px); }
.action summary:hover { color: var(--primary); }
.action form { padding-top: 6px; display: grid; gap: 12px; border-top: 1px solid var(--border); padding-top: 12px; }
.stack { display: grid; gap: 12px; margin-top: 8px; }

/* ---------- form controls ---------- */

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field__label { font-size: 0.85rem; font-weight: 700; }
.field__hint { font-size: 0.8rem; color: var(--muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
input, select, textarea {
  width: 100%; max-width: 100%;
  padding: 9px 11px; min-height: 44px;
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 8px;
  transition: border-color 0.12s, box-shadow 0.12s;
}
input:hover, select:hover, textarea:hover { border-color: var(--muted); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 30%, transparent);
}
input::placeholder { color: var(--muted); opacity: 0.85; }
textarea { resize: vertical; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 700; min-height: 44px; }
.check input { width: 22px; height: 22px; min-height: 0; accent-color: var(--primary); }

.form-errors:empty { display: none; }
.form-errors {
  padding: 10px 14px; background: var(--fault-bg); color: var(--fault);
  border: 2px solid var(--fault); border-radius: 8px; font-size: 0.9rem;
}
.form-errors p { margin: 0; font-weight: 800; }
.form-errors p::before { content: "! "; }
.form-errors ul { margin: 4px 0 0; padding-left: 18px; }

/* ---------- history timeline ---------- */

.history {
  margin-bottom: 14px; padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.history h4 { margin: 0 0 6px; font-size: 0.95rem; font-weight: 800; }
.history__summary { margin: 4px 0 10px; font-size: 0.9rem; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 16px; border-left: 2px solid var(--border-strong); }
.event { position: relative; padding: 2px 0 12px 10px; }
.event:last-child { padding-bottom: 2px; }
.event::before {
  content: ""; position: absolute; left: -24px; top: 6px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--surface); border: 3px solid var(--muted);
}
.event--resolved::before { border-color: var(--ok); background: var(--ok); }
.event--reported::before { border-color: var(--fault); border-radius: 3px; transform: rotate(45deg); }
.event--note::before { border-style: dotted; }
.event p { margin: 0; }
.event__transition { font-size: 0.85rem; color: var(--muted); }
.event__meta { font-size: 0.8rem; color: var(--muted); }
.event__note { margin-top: 3px !important; font-size: 0.9rem; }
.event__details {
  display: grid; grid-template-columns: max-content minmax(0, 1fr);
  gap: 2px 10px; margin: 6px 0 0; padding: 8px 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  font-size: 0.85rem;
}
.event__details dt { color: var(--muted); font-weight: 600; }
.event__details dd { margin: 0; overflow-wrap: anywhere; }

/* ---------- phone ---------- */

@media (max-width: 600px) {
  .app-header { padding: 10px 16px; }
  .header-controls { width: 100%; }
  .actor { flex: 1 1 100%; }
  .actor select { flex: 1; min-width: 0; }
  .header-controls .btn { flex: 1 1 100%; }
  .map { height: 56vh; min-height: 340px; max-height: 520px; }
  .panel { width: calc(100% - 32px); }
  /* Banner sits at the top of the page here (sticky would eat a 3-line strip of screen). */
  .demo-banner { position: static; }
  html { scroll-padding-top: 12px; }
  .leaflet-tooltip.tooltip-unassigned { white-space: normal; width: max-content; max-width: 132px; line-height: 1.3; }
  .panel { padding: 14px 14px 24px; }
  .panel-head .btn-row { width: 100%; }
  .panel-head .btn-row .btn { flex: 1 1 0; }
}

@media (max-width: 420px) {
  .filters, .field-row { grid-template-columns: minmax(0, 1fr); }
  .facts, .event__details { grid-template-columns: minmax(0, 1fr); row-gap: 0; }
  .facts dd, .event__details dd { margin-bottom: 6px; }
  .flag-unassigned--big { font-size: 1.05rem; }
  .demo-banner { font-size: 0.8rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
  .marker--unassigned::after { animation: none; opacity: 0.7; transform: scale(1.15); }
}
