/*
 * Safe Eats — Task 9 (FR-403, FR-404, FR-408, NFR-13).
 *
 * Two rules drive the whole sheet:
 *
 * 1. The basemap is greyscale (CARTO Positron, DEC-008), so the pins own the
 *    only colour on the page. Nothing in the chrome may compete for that
 *    channel — the header, buttons and list are ink on paper, deliberately.
 * 2. Colour is never the only carrier of the signal. Each state also has a
 *    shape, and the list mirrors it as a word. That survives greyscale printing,
 *    colour-blindness, and a phone in bright sun.
 */

:root {
  --ink:        #1c1e21;
  --ink-soft:   #5b6169;
  --rule:       #d8dade;
  --paper:      #ffffff;
  --paper-soft: #f5f6f7;
  --focus:      #0b57d0;

  /* Signal colours are served by /api/meta and applied inline, so the palette
     has exactly one definition (src/signal.js). These are here only for the
     legend swatch borders, which need a neutral. */
  --swatch-edge: rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

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

body {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

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

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

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 1000;
  padding: .6rem 1rem;
  background: var(--paper);
  border: 2px solid var(--focus);
}
.skip-link:focus { left: .5rem; top: .5rem; }

/* ------------------------------------------------------------------ bar --- */

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: .25rem .75rem;
  padding: .6rem .9rem;
  border-bottom: 1px solid var(--rule);
}

.bar h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -.01em;
}

.bar__where {
  font-weight: 400;
  color: var(--ink-soft);
}

.bar__asof {
  margin: 0;
  margin-left: auto;
  font-size: .8rem;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

/* The caveat is chrome, not an alert: a red warning box every visit teaches
   people to stop reading it. Quiet and always present beats loud and dismissed. */
.disclaimer {
  margin: 0;
  padding: .5rem .9rem;
  background: var(--paper-soft);
  border-bottom: 1px solid var(--rule);
  font-size: .82rem;
  line-height: 1.35;
  color: var(--ink-soft);
}
.disclaimer strong { color: var(--ink); }

/* ------------------------------------------------------------------ map --- */

main {
  position: relative;
  flex: 1 1 auto;
  /* The map must be usable without scrolling on a 375x667 phone while the
     disclaimer above it stays visible. 55vh leaves both on screen. */
  min-height: 55vh;
}

#map {
  position: absolute;
  inset: 0;
  background: var(--paper-soft);
}

/* Positioned above Leaflet's own controls (z-index 400-1000). */
.search-area {
  position: absolute;
  z-index: 1001;
  left: 50%;
  transform: translateX(-50%);
  bottom: 1.25rem;
  padding: .7rem 1.1rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: .9rem;
  font-weight: 600;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .18);
  cursor: pointer;
}
.search-area:hover { background: var(--paper-soft); }

.status {
  position: absolute;
  z-index: 1001;
  left: .75rem;
  top: .75rem;
  max-width: min(22rem, calc(100% - 1.5rem));
  padding: .4rem .65rem;
  border: 1px solid var(--rule);
  border-radius: .35rem;
  background: rgba(255, 255, 255, .94);
  font-size: .8rem;
  color: var(--ink-soft);
}
.status:empty { display: none; }
.status[data-tone="error"] {
  border-color: #cf222e;
  color: #8a1119;
}

/* ---------------------------------------------------------------- pins ---- */

/* Leaflet wraps a divIcon in .leaflet-marker-icon; the SVG inside carries the
   shape and the fill. No background or border here — the shape IS the mark. */
.pin { display: block; }
/* The shadow is what keeps a pin readable over a colour basemap (DEC-013).
   On the old greyscale canvas the white stroke alone was enough; over a park
   or a highway it is not. */
.pin svg {
  display: block;
  overflow: visible;
  filter: drop-shadow(0 1px 1.5px rgba(0, 0, 0, .5));
}

.leaflet-marker-icon:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
}

/* Cluster bubbles stay neutral. Colouring a cluster by the worst signal inside
   it would state something the data does not: that the area is unsafe. */
.cluster {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .96);
  border: 2px solid #3a4046;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .45);
  color: var(--ink);
  font-size: .78rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------- popup ---- */

.card { min-width: 13rem; }
.card__name {
  margin: 0 0 .15rem;
  font-size: .95rem;
  font-weight: 700;
}
.card__addr {
  margin: 0 0 .5rem;
  font-size: .82rem;
  color: var(--ink-soft);
}
.card__signal {
  display: flex;
  align-items: center;
  gap: .4rem;
  margin: 0 0 .2rem;
  font-size: .87rem;
  font-weight: 600;
}
.card__plain {
  margin: .35rem 0 0;
  font-size: .8rem;
  color: var(--ink-soft);
}

/* -------------------------------------------------------------- results --- */

.results {
  padding: 1rem .9rem 1.5rem;
  border-top: 1px solid var(--rule);
}
.results h2 {
  margin: 0 0 .6rem;
  font-size: .95rem;
}
.results__list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: .1rem;
}
.results__list li { border-bottom: 1px solid var(--paper-soft); }
.results__list a {
  display: flex;
  align-items: baseline;
  gap: .5rem;
  padding: .5rem .1rem;
  color: inherit;
  text-decoration: none;
}
.results__list a:hover { background: var(--paper-soft); }
.results__name { font-weight: 600; font-size: .9rem; }
.results__meta {
  margin-left: auto;
  font-size: .78rem;
  color: var(--ink-soft);
  white-space: nowrap;
}

/* --------------------------------------------------------------- legend --- */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: .25rem .9rem;
  margin: .5rem 0 0;
  padding: 0;
  list-style: none;
  font-size: .78rem;
  color: var(--ink-soft);
}
.legend li { display: flex; align-items: center; gap: .35rem; }
.legend svg { display: block; }

/* ----------------------------------------------------------------- foot --- */

.foot {
  padding: .8rem .9rem calc(.8rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--rule);
  background: var(--paper-soft);
  font-size: .75rem;
  color: var(--ink-soft);
}
.foot p { margin: 0 0 .3rem; }
.foot__note { font-style: italic; }

/* -------------------------------------------------------------- wide ------ */

@media (min-width: 60rem) {
  main { min-height: 0; flex: 1 1 auto; }
  body { height: 100vh; }
  .results {
    max-height: 30vh;
    overflow-y: auto;
  }
}

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

/*
 * Establishment detail (E5). A bottom sheet on a phone, a side panel on a wide
 * screen — the map stays visible in both, because the pin's position is part of
 * the answer to "should I eat here".
 */
.panel {
  position: fixed;
  z-index: 1200;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 82vh;
  overflow-y: auto;
  padding: 1.1rem 1rem calc(1.4rem + env(safe-area-inset-bottom));
  background: var(--paper);
  border-top: 1px solid var(--rule);
  border-radius: .9rem .9rem 0 0;
  box-shadow: 0 -6px 28px rgba(0, 0, 0, .22);
  -webkit-overflow-scrolling: touch;
}

.panel__close {
  position: absolute;
  top: .55rem;
  right: .6rem;
  width: 2.1rem;
  height: 2.1rem;
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}
.panel__close:hover { background: var(--paper-soft); }

.panel h2 {
  margin: 0 2.2rem .15rem 0;
  font-size: 1.15rem;
  line-height: 1.25;
}

.panel__addr {
  margin: 0 0 .8rem;
  color: var(--ink-soft);
  font-size: .87rem;
}

/* The verdict line. Shape and colour both present, and the words carry the
   meaning on their own — FR-404, FR-503. */
.verdict {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .6rem .7rem;
  border: 1px solid var(--rule);
  border-radius: .45rem;
  background: var(--paper-soft);
  font-weight: 600;
  font-size: .95rem;
}
.verdict__when {
  display: block;
  margin-top: .1rem;
  font-weight: 400;
  font-size: .8rem;
  color: var(--ink-soft);
}

.panel__plain {
  margin: .6rem 0 1rem;
  font-size: .88rem;
  line-height: 1.45;
}

.panel h3 {
  margin: 1.2rem 0 .5rem;
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--ink-soft);
}

/* Tiered violation counts. The tier IS the plain language — DBPR's own
   severity words — because the underlying codes are bare numbers with no
   published descriptions (DEC-011, FR-503). */
.tiers {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(6.5rem, 1fr));
  gap: .4rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.tiers > li {
  padding: .5rem .6rem;
  border: 1px solid var(--rule);
  border-radius: .4rem;
}
.tiers dt, .tier__label {
  display: block;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--ink-soft);
}
.tier__n {
  display: block;
  font-size: 1.3rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.tier__gloss {
  display: block;
  margin-top: .15rem;
  font-size: .72rem;
  color: var(--ink-soft);
  line-height: 1.3;
}

/* Inspection history */
.visits { margin: 0; padding: 0; list-style: none; }
.visit {
  padding: .7rem 0;
  border-top: 1px solid var(--paper-soft);
}
.visit__head {
  display: flex;
  align-items: center;
  gap: .45rem;
  font-size: .88rem;
  font-weight: 600;
}
.visit__date { font-variant-numeric: tabular-nums; }
.visit__type {
  margin-left: auto;
  font-weight: 400;
  font-size: .76rem;
  color: var(--ink-soft);
}
.visit__disposition {
  margin: .2rem 0 .3rem;
  font-size: .82rem;
  color: var(--ink-soft);
}
.visit__counts {
  margin: 0;
  font-size: .8rem;
  font-variant-numeric: tabular-nums;
}

.panel__unverified {
  /* A caveat, not an alarm: the pin is probably right, it simply has not been
     checked. Amber-on-parchment reads as "note this", where red would read as
     "this restaurant is unsafe" — a meaning that belongs to the signal alone. */
  margin: .5rem 0 .8rem;
  padding: .5rem .6rem;
  border-left: 3px solid #c98a00;
  background: #fdf7e8;
  border-radius: .2rem;
  font-size: .82rem;
  line-height: 1.45;
  color: var(--ink-soft);
}
.panel__unverified a { color: inherit; }

.panel__note {
  margin: 1rem 0 0;
  padding-top: .8rem;
  border-top: 1px solid var(--rule);
  font-size: .78rem;
  line-height: 1.45;
  color: var(--ink-soft);
}

.panel__source {
  display: inline-block;
  margin-top: .5rem;
  font-size: .8rem;
}

@media (min-width: 60rem) {
  .panel {
    top: 0;
    bottom: 0;
    left: auto;
    width: min(27rem, 40vw);
    max-height: none;
    border-radius: 0;
    border-top: 0;
    border-left: 1px solid var(--rule);
    box-shadow: -6px 0 28px rgba(0, 0, 0, .14);
  }
}

.card__more {
  margin-top: .55rem;
  padding: .4rem .7rem;
  border: 1px solid var(--rule);
  border-radius: .3rem;
  background: var(--paper);
  color: var(--focus);
  font: inherit;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
}
.card__more:hover { background: var(--paper-soft); }

/* ---------------------------------------------------------- prose page ---- */

/* The methodology page (FR-601). Measured column, generous leading: this is the
   page someone reads when they want to know whether to believe the map. */
.prose-page { height: auto; }
.prose-page .bar h1 a { color: inherit; text-decoration: none; }

.prose {
  max-width: 42rem;
  margin: 0 auto;
  padding: 1.5rem 1.1rem 3rem;
  font-size: 1rem;
  line-height: 1.65;
}
.prose .lede {
  font-size: 1.1rem;
  line-height: 1.55;
  margin: 0 0 1.6rem;
}
.prose h2 {
  margin: 2.2rem 0 .6rem;
  font-size: 1.12rem;
  line-height: 1.3;
}
.prose p { margin: 0 0 1rem; }
.prose code {
  padding: .1rem .3rem;
  border-radius: .2rem;
  background: var(--paper-soft);
  font-size: .9em;
}
.prose dt { font-weight: 700; margin-top: 1rem; }
.prose dd { margin: .25rem 0 0; color: var(--ink-soft); }

.callout {
  padding: .85rem 1rem;
  border: 1px solid var(--rule);
  border-left: 4px solid var(--ink-soft);
  border-radius: .3rem;
  background: var(--paper-soft);
  font-size: .93rem;
}

.mapping {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 1rem;
  font-size: .88rem;
}
.mapping th, .mapping td {
  padding: .55rem .5rem;
  border-bottom: 1px solid var(--rule);
  text-align: left;
  vertical-align: top;
}
.mapping th {
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--ink-soft);
}
.mapping td:first-child { white-space: nowrap; font-weight: 600; }

/* The swatch is decoration here: the row is already labelled in words, so the
   colour adds recognition rather than carrying meaning on its own. */
.chip {
  display: inline-block;
  width: .7rem;
  height: .7rem;
  margin-right: .4rem;
  border-radius: .15rem;
  vertical-align: baseline;
}

.dispositions { margin: 0; padding-left: 1.1rem; }
.dispositions li { margin-bottom: .15rem; }

@media (max-width: 34rem) {
  .mapping, .mapping tbody, .mapping tr, .mapping td { display: block; width: 100%; }
  .mapping thead { display: none; }
  .mapping tr { padding: .6rem 0; border-bottom: 1px solid var(--rule); }
  .mapping td { border: 0; padding: .15rem 0; }
}

/* FR-604 — the affiliation disclaimer. Not a footnote: mistaking this for an
   official state service is the specific misreading it exists to prevent. */
.foot__affil {
  margin-top: .5rem;
  padding-top: .5rem;
  border-top: 1px solid var(--rule);
  max-width: 42rem;
}

/* The worked example is an illustration, not live data — the muted head keeps
   it from reading as a record of a real establishment. */
.worked td:first-child { white-space: nowrap; font-weight: 400; }
.worked tbody tr:last-child { font-weight: 600; }

/* --------------------------------------------------------------- search --- */

/*
 * Sits above the map in normal flow rather than floating over it: at 375px a
 * floating search bar covers the thing you are searching, and the disclaimer
 * above it has to stay visible without scrolling (Gate 2).
 */
.search {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: .55rem .7rem;
  padding: .7rem .9rem;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
}

.search__field {
  display: flex;
  flex-direction: column;
  gap: .18rem;
  min-width: 8.5rem;
}
.search__field--grow { flex: 1 1 14rem; }

.search label {
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.search input,
.search select {
  font: inherit;
  font-size: .92rem;
  padding: .45rem .55rem;
  border: 1px solid var(--rule);
  border-radius: .3rem;
  background: var(--paper);
  color: var(--ink);
  min-height: 2.4rem;
}
.search input { width: 100%; }

.search__actions {
  display: flex;
  gap: .4rem;
  margin-left: auto;
}

.btn {
  font: inherit;
  font-size: .88rem;
  font-weight: 600;
  padding: .5rem .95rem;
  min-height: 2.4rem;
  border: 1px solid var(--rule);
  border-radius: .3rem;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}
.btn:hover { background: var(--paper-soft); }
.btn--primary {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}
.btn--primary:hover { background: #33383d; }

/* Says what the current result set actually is, so the list below is never
   ambiguous about whether you are looking at a search or at the viewport. */
.scope {
  padding: .5rem .9rem;
  border-bottom: 1px solid var(--rule);
  background: var(--paper-soft);
  font-size: .82rem;
  color: var(--ink-soft);
}
.scope:empty { display: none; }
.scope b { color: var(--ink); font-variant-numeric: tabular-nums; }

@media (max-width: 34rem) {
  .search__actions { margin-left: 0; width: 100%; }
  .search__actions .btn { flex: 1; }
}

/* The result filter carries the same mark the map uses, so the dropdown and
   the pins share one vocabulary. Colour is never alone: each option also
   carries its shape as a character, which survives a native mobile picker
   that ignores option styling entirely (FR-404). */
.search__withmark {
  display: flex;
  align-items: center;
  gap: .4rem;
}
.search__withmark select { flex: 1; min-width: 0; }

.search__mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.35rem;
  flex: 0 0 auto;
}
.search__mark svg { display: block; }
.search__mark:empty { display: none; }

/* An establishment we hold a record for but cannot place. Said plainly in the
   list rather than dropped from it — the record is real even when the pin is
   not, and a silent omission is how a map tells someone a restaurant does not
   exist. */
.results__unmapped {
  font-style: italic;
  color: var(--ink-faint, var(--ink-soft));
}

/* The per-county accuracy table on the methodology page. 67 rows is a lot of
   page, so it scrolls in its own box rather than pushing everything below it
   out of reach. */
.gate-summary { margin: .6rem 0 .3rem; }
.gate-scroll {
  max-height: 22rem;
  overflow: auto;
  border: 1px solid var(--rule);
  border-radius: .3rem;
}
table.gate { border-collapse: collapse; width: 100%; font-size: .85rem; }
table.gate th, table.gate td { padding: .3rem .5rem; text-align: left; border-bottom: 1px solid var(--rule); }
table.gate thead th {
  position: sticky; top: 0; background: var(--paper-soft);
  font-size: .7rem; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-soft);
}
