/* nearmiss accessible map UI — framework-free.
   Risk and significance are never conveyed by color alone; contrast targets
   WCAG 2.2 AA (>= 4.5:1 text), focus is always visible, and interactive targets
   are at least 24x24 px (WCAG 2.5.8). */

:root {
  --fg: #15202b;
  --bg: #ffffff;
  --muted: #4a5560;
  --accent: #0b4f9c; /* >= 4.5:1 on white */
  --hot: #8a1c1c; /* paired ALWAYS with text/pattern, never color alone */
  --line: #c3ccd6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
  padding: 0 1rem 3rem;
}

header,
main,
footer {
  max-width: 64rem;
  margin: 0 auto;
}

h1 {
  font-size: 1.6rem;
  margin: 1rem 0 0.25rem;
}

.lede {
  color: var(--fg);
  max-width: 48rem;
}

/* Plain-language "bottom line" for a hurried reader (council member / neighbor).
   Prominent but not alarming; the words carry the meaning, not color alone. */
.bottom-line {
  max-width: 48rem;
  margin: 1rem 0;
  padding: 0.6rem 0.85rem;
  background: #eef3f9;
  border: 1px solid var(--accent);
  border-radius: 6px;
  font-size: 1.02rem;
}

.lang-switch {
  display: flex;
  gap: 0.25rem;
  justify-content: flex-end;
  margin-top: 0.5rem;
}

.lang-switch button {
  font: inherit;
  cursor: pointer;
  padding: 0.25rem 0.6rem;
  min-height: 24px;
  min-width: 24px;
  border: 1px solid var(--accent);
  background: var(--bg);
  color: var(--accent);
  border-radius: 4px;
}

.lang-switch button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--bg);
  font-weight: 700;
}

.demo-note,
.real-note {
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.95rem;
  max-width: 48rem;
}

.national-cta {
  max-width: 48rem;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--accent);
  border-inline-start-width: 5px;
  border-radius: 6px;
  background: #eef3f9;
}

.national-cta strong {
  display: block;
}

/* Amber: synthetic / demo data. */
.demo-note {
  background: #fff4e5;
  border: 1px solid #8a4b00;
  color: #5a2e00; /* >= 4.5:1 on the light background */
}

/* Green: real data. A distinct palette from the demo warning, never the only
   signal — the words "real data" carry the meaning. Text >= 4.5:1 on the bg. */
.real-note {
  background: #e7f4ea;
  border: 1px solid #1b5e20;
  color: #14401a;
}

a {
  color: var(--accent);
}

a:focus-visible,
button:focus-visible,
.table-wrap:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  inset-inline-start: -999px;
  top: 0;
  background: var(--bg);
  padding: 0.5rem 0.75rem;
  border: 2px solid var(--accent);
}

.skip-link:focus {
  inset-inline-start: 0.5rem;
  top: 0.5rem;
  z-index: 10;
}

figure {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.5rem;
}

/* Two real maps side by side; stack on narrow screens / at high zoom. */
.map-split {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

/* R10: single-map toggle. When one view is selected, the other figure collapses
   and the shown map spans the full width. */
.map-split[data-view="reports"] {
  grid-template-columns: 1fr;
}
.map-split[data-view="reports"] .map-fig:nth-of-type(2) {
  display: none;
}
.map-split[data-view="rate"] {
  grid-template-columns: 1fr;
}
.map-split[data-view="rate"] .map-fig:nth-of-type(1) {
  display: none;
}

/* R11/R27: stack the two maps sooner so each stays usable on phones / at 200%. */
@media (max-width: 60rem) {
  .map-split[data-view="both"] {
    grid-template-columns: 1fr;
  }
}

.map-toggle {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.map-toggle button {
  font: inherit;
  cursor: pointer;
  padding: 0.25rem 0.6rem;
  min-height: 24px;
  border: 1px solid var(--accent);
  background: var(--bg);
  color: var(--accent);
  border-radius: 4px;
}

.map-toggle button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--bg);
  font-weight: 700;
}

.table-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 0.5rem 0;
}

.table-controls input[type="search"] {
  font: inherit;
  padding: 0.3rem 0.5rem;
  min-height: 24px;
  border: 1px solid var(--muted);
  border-radius: 4px;
}

.filter-status {
  color: var(--muted);
  font-size: 0.9rem;
}

/* Briefly highlight a segment row when deep-linked (#seg-…) from the summary. */
tbody th[scope="row"]:target {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

.map-fig {
  margin: 0;
  display: flex;
  flex-direction: column;
}

.map-title {
  font-weight: 700;
  color: var(--fg);
  font-size: 1rem;
  margin: 0 0 0.5rem;
}

.leaflet-map {
  width: 100%;
  height: 22rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #f5f7fa;
}

/* Permanent call-out labels on the protagonist segments (the most-reported
   street on the left, the significant hotspots on the right). High-contrast
   text on white, so the label never relies on color. */
.map-label {
  font: 700 0.78rem/1.2 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: #fff;
  border: 1px solid var(--fg);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  white-space: nowrap;
}

figcaption {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

.map-cap {
  margin-top: 0.5rem;
}

/* Text equivalent of the map's headline finding (significant hotspots). Visible
   to everyone and announced to screen readers via aria-live. */
.hotspot-summary {
  margin: 0 0 1rem;
  padding: 0.5rem 0.75rem;
  border-inline-start: 4px solid var(--accent);
  background: #f3f7fc;
  max-width: 48rem;
}

.downloads {
  margin: 0.75rem 0 0;
  font-size: 0.95rem;
}

#download-meta {
  color: var(--muted);
}

.share-card-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

#share-card-btn {
  font: inherit;
  cursor: pointer;
  padding: 0.3rem 0.7rem;
  min-height: 24px;
  border: 1px solid var(--accent);
  background: var(--bg);
  color: var(--accent);
  border-radius: 4px;
}

#share-card-btn:hover:not(:disabled) {
  background: var(--accent);
  color: var(--bg);
}

#share-card-btn:disabled {
  cursor: default;
  opacity: 0.6;
}

.faq {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.25rem 0.75rem;
  margin-bottom: 0.5rem;
  max-width: 48rem;
}

.faq > summary {
  cursor: pointer;
  font-weight: 700;
  padding: 0.5rem 0;
  min-height: 24px;
}

.faq[open] > summary {
  border-bottom: 1px solid var(--line);
  margin-bottom: 0.5rem;
}

.faq > p {
  margin: 0 0 0.75rem;
  max-width: 44rem;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

table {
  border-collapse: collapse;
  width: 100%;
  /* Kept modest so the table still reflows usably at 200% zoom / narrow widths;
     the .table-wrap scrolls horizontally only when truly necessary. */
  min-width: 30rem;
}

caption {
  text-align: start;
  padding: 0.5rem 0.75rem;
  color: var(--muted);
}

th,
td {
  text-align: start;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--bg);
  border-bottom: 2px solid var(--fg);
  z-index: 1;
}

/* Keep the segment name (the row header) visible when the table must scroll
   horizontally at 200% zoom / narrow widths. */
th[scope="row"] {
  position: sticky;
  inset-inline-start: 0;
  background: var(--bg);
  z-index: 1;
}

thead th:first-child {
  z-index: 2; /* the top-left corner sits above both sticky axes */
}

th button {
  font: inherit;
  font-weight: 700;
  color: var(--accent);
  background: none;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  min-height: 24px;
  min-width: 24px;
  padding: 0.15rem 0.35rem;
}

th button:hover {
  text-decoration: underline;
}

/* A significant hotspot row gets a thick inline-start border (a PATTERN, not color
   alone) AND an explicit text marker rendered in the cell. */
tr.is-hotspot td {
  border-inline-start: 6px solid var(--hot);
  background: #fbeeee;
}

.tag {
  display: inline-block;
  border: 1px solid var(--fg);
  border-radius: 999px;
  padding: 0 0.4rem;
  font-size: 0.85rem;
}

.tag-hot {
  border-color: var(--hot);
  color: var(--hot);
  font-weight: 700;
}

.uncertain {
  font-style: italic;
  color: var(--muted);
}

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

footer {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}

/* R23: council-ready "Print / save as PDF". A print stylesheet plus a button —
   no external PDF library. The print-only blocks carry the caveats and metadata
   into the packet; interactive chrome is hidden and both maps are forced visible
   so the printed page is the honest, self-contained equivalent of the screen. */

/* Print-only blocks are hidden on screen. */
.print-only {
  display: none;
}

.print-control {
  margin: 0 0 0.75rem;
}

.print-control button {
  font: inherit;
  cursor: pointer;
  padding: 0.3rem 0.75rem;
  min-height: 24px;
  min-width: 24px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--bg);
  border-radius: 4px;
  font-weight: 700;
}

.print-control button:hover {
  text-decoration: underline;
}

@media print {
  /* Make map tiles and hotspot colors actually print. */
  * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    color-adjust: exact;
  }

  body {
    padding: 0;
    color: #000;
  }

  /* Hide interactive chrome: language switch, map toggle, the print button
     itself, the table filter, and Leaflet's own zoom/attribution controls. */
  .lang-switch,
  .map-toggle,
  .print-control,
  .table-controls,
  .report-cta,
  .skip-link,
  .leaflet-control-container {
    display: none !important;
  }

  /* Show the print-only header and footer. */
  .print-only {
    display: block;
  }

  .print-header {
    margin-bottom: 0.75rem;
    border-bottom: 2px solid #000;
    padding-bottom: 0.4rem;
  }

  .print-title {
    font-size: 1.3rem;
    font-weight: 700;
    margin: 0 0 0.25rem;
  }

  .print-meta {
    margin: 0 0 0.35rem;
    font-size: 0.95rem;
  }

  .print-caveat {
    margin: 0;
    font-size: 0.9rem;
    font-style: italic;
  }

  .print-footer {
    margin-top: 1rem;
    padding-top: 0.4rem;
    border-top: 1px solid #000;
    font-size: 0.8rem;
    color: #000;
  }

  /* Force BOTH maps visible regardless of the on-screen data-view state. */
  .map-split[data-view] {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.5rem;
  }

  .map-split[data-view] .map-fig {
    display: flex !important;
  }

  /* Fixed, print-friendly map heights and keep each figure/table on one page. */
  .leaflet-map {
    height: 9cm !important;
  }

  figure,
  .map-fig,
  #data-table,
  tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  /* Show every table row: undo any name-filter hiding and let the table print
     in full, including the Significance/CI columns. */
  #data-table {
    width: 100%;
    min-width: 0;
    font-size: 0.8rem;
  }

  .table-wrap {
    overflow: visible !important;
    border: none;
  }

  thead th,
  th[scope="row"] {
    position: static !important;
  }

  /* Hotspot rows keep their pattern marker but print with a plain background. */
  tr.is-hotspot td {
    background: transparent;
  }

  a {
    color: #000;
    text-decoration: none;
  }

  details.faq {
    break-inside: avoid;
  }

  details.faq > p {
    display: block !important;
  }
}

/* ---------------------------------------------------------------------------
 * Public submission form (submit.html). Accessible, native controls, generous
 * target sizes (>= 24px), clear focus and labels — the same WCAG 2.2 AA bar as
 * the rest of the site (docs/INTAKE-AND-ABUSE.md A1).
 * ------------------------------------------------------------------------- */
.privacy-note {
  border: 1px solid var(--line);
  border-inline-start: 4px solid var(--accent);
  border-radius: 6px;
  padding: 0.6rem 0.9rem;
  margin: 1rem 0;
  background: var(--bg);
}
.privacy-note ul {
  margin: 0.4rem 0 0.2rem;
  padding-inline-start: 1.2rem;
}
.privacy-note li {
  margin: 0.3rem 0;
}

#report-form fieldset {
  border: 1px solid var(--line);
  border-radius: 6px;
  margin: 1rem 0;
  padding: 0.75rem 1rem 1rem;
}
#report-form legend {
  font-weight: 600;
  padding: 0 0.4rem;
}
#report-form .req {
  font-weight: 400;
  color: var(--muted, #555);
  font-size: 0.85em;
}
.field {
  margin: 0.6rem 0;
}
.field label {
  display: block;
  margin-bottom: 0.25rem;
  font-weight: 500;
}
.field input[type="text"],
.field input[type="number"],
.field select,
.field textarea {
  width: 100%;
  max-width: 32rem;
  min-height: 2.5rem;
  padding: 0.4rem 0.55rem;
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 5px;
}
.field textarea {
  min-height: 4.5rem;
  resize: vertical;
}
.field-help {
  font-size: 0.9rem;
  color: var(--muted, #555);
  margin: 0.3rem 0 0;
  max-width: 38rem;
}
.field-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin: 0.4rem 0;
}
.field-inline-status,
.form-status {
  font-size: 0.92rem;
}
.form-status {
  display: block;
  min-height: 1.3em;
  margin: 0.5rem 0;
  font-weight: 500;
}
.form-status.is-error {
  color: #8a1c1c;
}
.radio-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.35rem;
}
@media (min-width: 32rem) {
  .radio-grid {
    grid-template-columns: 1fr 1fr;
  }
}
.radio-grid label {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.35rem 0.4rem;
  min-height: 2.5rem;
}
.radio-grid input[type="radio"] {
  width: 1.15rem;
  height: 1.15rem;
  margin-top: 0.1rem;
}
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 1rem 0;
}
.form-actions button,
.field-row button {
  min-height: 2.75rem;
  padding: 0.5rem 1rem;
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
}
.field-row button {
  background: var(--bg);
  color: var(--accent);
}
.result {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.75rem 1rem 1rem;
  margin: 1rem 0;
}
#submission-json {
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0.5rem;
}
