/* v1.5 "Winter": the 301 palette, used ONLY by the new winter parts (town picker, winter card, banners, chips, layer
   legend / toggles). Everything else keeps the v1.4 dark look (Seth's D1). Functional and professional: white panels,
   1 px hairlines, a subtle grid. No glows, neon, drop-shadow halos or pulsing. Color always comes with a word + icon.
   Contrast (WCAG AA): white on rust 5.2:1, ink on amber 5.3:1, white on green 11.8:1, slate on white 5.8:1.
   Amber is never used for text on white (2.9:1); amber fills always carry ink text. Tap targets >= 44 px, body >= 16 px. */
:root {
  --w-slate: #5C6670;
  --w-rust: #B84A27;
  --w-amber: #D9822B;
  --w-green: #1E3F20;
  --w-white: #FFFFFF;
  --w-line: #DDE1E4;
  --w-page: #F5F6F7;
  --w-ink: #1F2428;
  --w-grid: #EEF0F2;
  --w-font: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

.w-panel, .w-sheet, .w-banner, .w-chip, .w-legend, .w-layers, .w-chip-town, .w-menu-pop, .w-preview {
  font-family: var(--w-font); font-size: 16px; line-height: 1.45; color: var(--w-ink); box-shadow: none; text-shadow: none;
}
.w-panel *, .w-sheet *, .w-banner *, .w-legend *, .w-layers *, .w-menu-pop * { text-shadow: none; box-shadow: none; }

/* ---------- header chip "<Town> ▾" + menu ---------- */
.w-chip-town {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 12px; border: 1px solid var(--w-line);
  border-radius: 8px; background: var(--w-white); color: var(--w-ink); font-weight: 600; cursor: pointer; white-space: nowrap;
}
.w-chip-town:focus-visible, .w-btn:focus-visible, .w-town:focus-visible, .w-layer:focus-visible, .w-input:focus-visible, .w-menu summary:focus-visible { outline: 3px solid var(--w-ink); outline-offset: 2px; }
.w-chip-pin { width: 10px; height: 10px; border: 2px solid var(--w-slate); border-radius: 50% 50% 50% 0; transform: rotate(-45deg); display: inline-block; }
.w-menu { position: relative; }
.w-menu summary { list-style: none; display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; padding: 0 12px; box-sizing: border-box; border: 1px solid var(--w-line); border-radius: 8px; background: var(--w-white); color: var(--w-ink); cursor: pointer; font: 600 16px var(--w-font); }
.w-menu summary::-webkit-details-marker { display: none; }
.w-menu-pop { position: absolute; right: 0; top: calc(100% + 6px); z-index: 60; width: 260px; padding: 12px; background: var(--w-white); border: 1px solid var(--w-line); border-radius: 10px; }
.w-menu-pop fieldset { border: 0; margin: 0; padding: 0; }
.w-menu-pop legend { font-weight: 700; margin-bottom: 6px; }
.w-seg { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--w-line); border-radius: 8px; overflow: hidden; }
.w-seg label { display: flex; align-items: center; justify-content: center; min-height: 44px; cursor: pointer; border-left: 1px solid var(--w-line); color: var(--w-ink); }
.w-seg label:first-child { border-left: 0; }
.w-seg input { position: absolute; opacity: 0; pointer-events: none; }
.w-seg input:checked + span { font-weight: 700; text-decoration: underline; text-underline-offset: 4px; }
.w-seg label:has(input:checked) { background: var(--w-page); }
.w-seg label:has(input:focus-visible) { outline: 3px solid var(--w-ink); outline-offset: -3px; }
.w-menu-pop .w-small { margin: 8px 0 0; }

/* ---------- picker sheet ---------- */
.w-sheet {
  width: min(560px, 100vw); max-width: 100vw; max-height: 92vh; margin: auto auto 0; padding: 16px 16px 20px; border: 1px solid var(--w-line);
  border-radius: 14px 14px 0 0; background: var(--w-white);
  background-image: linear-gradient(var(--w-grid) 1px, transparent 1px), linear-gradient(90deg, var(--w-grid) 1px, transparent 1px);
  background-size: 24px 24px; background-position: -1px -1px; overflow: auto;
}
@media (min-width: 700px) { .w-sheet { margin: auto; border-radius: 14px; } }
.w-sheet::backdrop { background: rgba(31, 36, 40, 0.55); }
.w-sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.w-sheet h2 { margin: 0; font: 800 1.5rem/1.2 var(--w-font); color: var(--w-ink); letter-spacing: 0; text-transform: none; }
.w-sub { margin: 6px 0 12px; color: var(--w-slate); }
.w-label { display: block; font-weight: 600; margin-bottom: 4px; }
.w-input { width: 100%; box-sizing: border-box; min-height: 48px; padding: 10px 12px; font: 16px var(--w-font); color: var(--w-ink); background: var(--w-white); border: 1px solid var(--w-slate); border-radius: 8px; }
.w-results { margin-top: 6px; }
.w-county { margin: 14px 0 6px; font: 700 0.95rem var(--w-font); color: var(--w-slate); text-transform: uppercase; letter-spacing: 0.04em; }
.w-towns { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.w-town { width: 100%; min-height: 44px; padding: 8px 12px; text-align: left; font: 16px var(--w-font); color: var(--w-ink); background: var(--w-white); border: 1px solid var(--w-line); border-radius: 8px; cursor: pointer; }
.w-town:hover { border-color: var(--w-slate); }
.w-town.is-current { border-color: var(--w-ink); font-weight: 700; }
.w-cur { font-size: 0.8rem; color: var(--w-slate); font-weight: 600; }
.w-hint { margin: 8px 0; color: var(--w-slate); }
.w-btn { min-height: 44px; padding: 0 16px; font: 600 16px var(--w-font); border-radius: 8px; border: 1px solid var(--w-ink); background: var(--w-ink); color: var(--w-white); cursor: pointer; }
.w-btn-quiet { background: var(--w-white); color: var(--w-ink); border-color: var(--w-line); }
.w-unofficial { margin: 14px 0 0; padding-top: 10px; border-top: 1px solid var(--w-line); font-size: 0.875rem; color: var(--w-slate); }

/* ---------- banners (Snow Emergency, school, preview) ---------- */
.w-banners { display: grid; gap: 8px; margin: 0 0 12px; }
.w-banner { display: grid; grid-template-columns: 28px 1fr; gap: 10px; align-items: start; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--w-line); background: var(--w-white); }
.w-banner .w-ic { width: 24px; height: 24px; }
.w-banner h2, .w-banner h3 { margin: 0 0 2px; font: 800 1.05rem/1.3 var(--w-font); letter-spacing: 0; text-transform: none; color: inherit; }
.w-banner p { margin: 2px 0 0; }
.w-banner a { color: inherit; text-decoration: underline; text-underline-offset: 3px; font-weight: 600; }
.w-banner ul { margin: 4px 0 0; padding-left: 18px; }
.w-banner.w-rust { background: var(--w-rust); border-color: var(--w-rust); color: var(--w-white); }
.w-banner.w-amber { background: var(--w-amber); border-color: var(--w-amber); color: var(--w-ink); }
.w-banner .w-fine { font-size: 0.875rem; opacity: 1; }
.w-preview { position: fixed; left: 0; right: 0; top: var(--top-h, 56px); z-index: 19; display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 6px 12px;
  background: var(--w-ink); color: var(--w-white); font-weight: 700; border-bottom: 3px solid var(--w-amber); text-align: center; }
.w-preview .w-ic { width: 20px; height: 20px; }

/* ---------- winter card ---------- */
.w-panel { margin: 0 0 12px; padding: 14px; border: 1px solid var(--w-line); border-radius: 12px; background: var(--w-white);
  background-image: linear-gradient(var(--w-grid) 1px, transparent 1px), linear-gradient(90deg, var(--w-grid) 1px, transparent 1px);
  background-size: 24px 24px; background-position: -1px -1px; }
.w-panel h2 { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font: 800 1.2rem/1.25 var(--w-font); color: var(--w-ink); letter-spacing: 0; text-transform: none; }
.w-panel h2 .w-ic { width: 22px; height: 22px; color: var(--w-slate); }
.w-panel h3 { margin: 12px 0 6px; font: 700 1rem var(--w-font); color: var(--w-ink); letter-spacing: 0; text-transform: none; }
.w-panel p { margin: 4px 0; }
.w-snow { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; padding: 10px 12px; background: var(--w-page); border: 1px solid var(--w-line); border-radius: 8px; }
.w-snow b { font-size: 1.35rem; }
.w-slate-t { color: var(--w-slate); }
.w-small { font-size: 0.875rem; color: var(--w-slate); }
.w-reasons { margin: 6px 0 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 6px; }
.w-reasons li { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 2px 10px; border: 1px solid var(--w-line); border-radius: 999px; background: var(--w-white); font-size: 0.9rem; }
.w-trucks { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border: 1px solid var(--w-line); border-radius: 8px; background: var(--w-white); }
.w-trucks .w-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--w-amber); border: 1px solid var(--w-ink); flex: none; }
.w-src { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--w-line); }
.w-src a, .w-panel a, .w-legend a { color: var(--w-ink); text-decoration: underline; text-underline-offset: 3px; }
/* v1.7: "Who plows my road?" + Frederick official road status in the winter card (public/road-contacts.js) */
.w-rc { margin-top: 10px; padding: 10px 12px; border: 1px solid var(--w-line); border-radius: 8px; background: var(--w-white); }
.w-panel .w-rc .rc-h { margin: 0 0 6px; }
.w-rc .rc-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.w-rc .rc-small { margin: 8px 0 0; font-size: 0.875rem; color: var(--w-slate); }
.w-near { display: inline-block; margin: 0 6px 4px 0; padding: 1px 8px; font: 700 0.75rem/1.6 var(--w-font); color: var(--w-white); background: var(--w-green); border-radius: 999px; letter-spacing: 0.02em; }
.w-toggle-link { min-height: 44px; padding: 0 4px; background: none; border: 0; color: inherit; font: inherit; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

/* ---------- pavement chips ---------- */
.w-chips { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.w-chip { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--w-line); background: var(--w-white); color: var(--w-slate); }
.w-chip .w-ic { width: 20px; height: 20px; flex: none; }
.w-chip.is-ice { background: var(--w-rust); border-color: var(--w-rust); color: var(--w-white); font-weight: 600; }
.w-chip .w-tag { margin-left: auto; font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
.w-chip.is-old { border-style: dashed; }

/* ---------- map: layer toggles (one-thumb row) + legend ---------- */
.w-layers { display: flex; gap: 6px; padding: 8px; background: var(--w-white); border: 1px solid var(--w-line); border-radius: 10px; margin: 0 0 8px; overflow-x: auto; }
.w-layer { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; border: 1px solid var(--w-line); border-radius: 999px; background: var(--w-white); color: var(--w-ink); font: 600 16px var(--w-font); cursor: pointer; white-space: nowrap; }
.w-layer[aria-pressed="true"] { border-color: var(--w-ink); background: var(--w-page); }
.w-layer[aria-pressed="true"]::before { content: "✓"; font-weight: 800; }
.w-layer[aria-pressed="false"]::before { content: "○"; color: var(--w-slate); }
.w-legend { margin: 8px 0 0; padding: 10px 12px; background: var(--w-white); border: 1px solid var(--w-line); border-radius: 10px; font-size: 0.95rem; }
.w-legend p { margin: 4px 0; display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; }
.w-sw-truck { width: 10px; height: 10px; border-radius: 50%; background: var(--w-amber); border: 1px solid var(--w-ink); position: relative; flex: none; }
.w-sw-truck::after { content: ""; position: absolute; left: 50%; top: -6px; width: 2px; height: 5px; margin-left: -1px; background: var(--w-ink); }
.w-sw-trail { width: 10px; height: 10px; flex: none; background: none; position: relative; }
.w-sw-trail::before { content: '\2744'; position: absolute; inset: -3px 0 0 -1px; font-size: 11px; line-height: 1; color: #9ed8ff; }
.w-sw-ice { width: 12px; height: 12px; border-radius: 50%; background: var(--w-rust); border: 2px solid var(--w-white); outline: 1px solid var(--w-rust); flex: none; }
.w-sw-ok { width: 12px; height: 12px; border-radius: 50%; background: var(--w-white); border: 2px solid var(--w-slate); flex: none; }
.w-hide-closures .mk-closure { display: none !important; }

/* preview notice: fixed under the top bar on every view; the page and the map move down to make room */
body.w-has-preview main { padding-top: 52px; }
body.w-has-preview #view-map { top: calc(var(--top-h, 56px) + 40px); }

/* map view: toggles at the bottom (one-thumb row), winter legend just above them */
#view-map .w-layers { position: absolute; left: 10px; bottom: 10px; z-index: 6; margin: 0; max-width: calc(100% - 64px); }
#view-map .w-legend { position: absolute; left: 10px; bottom: 76px; z-index: 6; margin: 0; max-width: min(430px, calc(100% - 64px)); }
.w-pop { font: 15px/1.4 var(--w-font); color: var(--w-ink); }
.w-pop small { color: var(--w-slate); }
.w-panel .w-maplink { font-weight: 700; }
.w-menu-pop { color: var(--w-ink); }
.topbar .w-chip-town, .topbar .w-menu { flex: none; }

@media (prefers-reduced-motion: reduce) {
  .w-panel *, .w-sheet *, .w-banner *, .w-layers *, .w-legend * { transition: none !important; animation: none !important; }
}
.w-menu-label { margin-left: 6px; font-size: 15px; }
@media (max-width: 600px) {
  /* phones: the top bar has no room, so the town chip + Winter menu sit in a light strip just under it */
  :root { --w-strip: 56px; }
  .topbar::after { content: ""; position: absolute; left: 0; right: 0; top: 100%; height: var(--w-strip); background: var(--w-page); border-bottom: 1px solid var(--w-line); pointer-events: none; }
  .topbar .w-chip-town { position: absolute; left: 10px; top: calc(100% + 6px); z-index: 2; max-width: calc(100vw - 150px); overflow: hidden; text-overflow: ellipsis; }
  .topbar .w-menu { position: absolute; right: 10px; top: calc(100% + 6px); z-index: 2; }
  main { padding-top: calc(var(--w-strip) + 12px); }
  #view-map { top: calc(var(--top-h) + var(--w-strip)); }
  .w-preview { top: calc(var(--top-h) + var(--w-strip)); }
  body.w-has-preview main { padding-top: calc(var(--w-strip) + 52px); }
  body.w-has-preview #view-map { top: calc(var(--top-h) + var(--w-strip) + 40px); }
  .w-towns { grid-template-columns: repeat(2, 1fr); }
  #view-map .w-legend { bottom: 70px; font-size: 0.9rem; max-width: calc(100% - 20px); }
  #view-map .w-layers { max-width: calc(100% - 20px); }
  #view-map .w-layer { padding: 0 10px; font-size: 15px; gap: 5px; }
  #view-map .w-layers { gap: 4px; padding: 6px; }
  /* v1.8: on phones the full-width layer row used to sit on top of the MapLibre attribution (i). While the row is shown
     (app.js sets .w-row-on), the bottom-right control stack moves up to sit 6 px above the row (row: 10 px from the
     bottom + 58 px tall = 68 px; the (i) has its own 10 px margin, so the stack's bottom is 64 px) and stays above the
     legend; the winter legend keeps clear of that right-hand column the way it already does on desktop. The row keeps its
     full width (the v1.7 M4 narrower row, reverted in M6, is not used). Row hidden = the (i) stays where it always was. */
  #view-map.w-row-on .maplibregl-ctrl-bottom-right { bottom: 64px; z-index: 7; }
  #view-map.w-row-on .w-legend { max-width: calc(100% - 64px); }
}

/* v1.5 CHANGE-01: Recent truck passes legend swatches (deep green solid < 10 min, slate dashed 10-30 min) */
.w-sw-pass { display: inline-block; width: 22px; height: 0; border-top: 5px solid #1E3F20; vertical-align: middle; margin: 0 6px 0 0; border-radius: 2px; }
.w-sw-pass.is-older { border-top: 5px dashed #5C6670; }
.w-lg-passes { border-top: 1px solid #E3E6E8; margin-top: 6px; padding-top: 6px; }
/* v1.7 "Storm depth": time since a truck passed (same weights / dashes as the map lines; never colour alone):
   under 1 h = deep green solid, thickest · 1-3 h = slate dashed · more than 3 h = light slate dotted, thinnest.
   The swatch sits on a dark chip so it looks like the line on the dark map. */
.w-sw-hist { display: inline-block; flex: none; width: 30px; height: 14px; margin: 0 6px 0 0; border-radius: 3px; background: #1F2428; vertical-align: middle; position: relative; }
.w-sw-hist::before, .w-sw-hist::after { content: ""; position: absolute; left: 4px; right: 4px; top: 50%; transform: translateY(-50%); border-radius: 3px; }
.w-sw-hist.is-h1::before { height: 9px; background: rgba(232, 236, 239, 0.9); }   /* light casing */
.w-sw-hist.is-h1::after { left: 5px; right: 5px; border-top: 5px solid #1E3F20; }
.w-sw-hist.is-h3::before { height: 8px; background: rgba(232, 236, 239, 0.55); }
.w-sw-hist.is-h3::after { left: 5px; right: 5px; border-top: 4px dashed #5C6670; border-radius: 0; }
.w-sw-hist.is-h24::after { border-top: 3px dotted #AEB7BF; border-radius: 0; }
.w-trucks .w-sw-hist { margin: 0; }
@media (prefers-contrast: more) {
  .w-sw-hist.is-h1::before { background: #E8ECEF; }
  .w-sw-hist.is-h3::before { background: rgba(232, 236, 239, 0.9); }
  .w-sw-hist.is-h24::after { border-top-color: #FFFFFF; }
}
@media (forced-colors: active) {
  .w-sw-hist { forced-color-adjust: none; background: Canvas; border: 1px solid CanvasText; }
  .w-sw-hist::before { display: none; }
  .w-sw-hist.is-h1::after, .w-sw-hist.is-h3::after, .w-sw-hist.is-h24::after { border-top-color: CanvasText; }
}
.w-lg-h { font-weight: 700; margin: 0 0 2px; }
/* CHANGE-01: foldable map legend (44 px summary target) */
.w-lg-box > summary { min-height: 44px; display: flex; align-items: center; font-weight: 700; cursor: pointer; list-style: none; }
.w-lg-box > summary::-webkit-details-marker { display: none; }
.w-lg-box > summary::after { content: "▾"; margin-left: auto; padding-left: 12px; color: var(--w-slate); }
.w-lg-box[open] > summary::after { content: "▴"; }
.w-lg-box > summary:focus-visible { outline: 3px solid var(--w-ink); outline-offset: 2px; }
#view-map .w-legend { padding-top: 0; padding-bottom: 0; }
#view-map .w-lg-box[open] { padding-bottom: 8px; }
/* winter popups (sensor, closure, recent pass) use the white 301 panel, not the dark map popup */
.w-popup .maplibregl-popup-content { background: var(--w-white) !important; color: var(--w-ink); border: 1px solid var(--w-line); }
.w-popup.maplibregl-popup-anchor-bottom .maplibregl-popup-tip, .w-popup.maplibregl-popup-anchor-bottom-left .maplibregl-popup-tip, .w-popup.maplibregl-popup-anchor-bottom-right .maplibregl-popup-tip { border-top-color: var(--w-white) !important; }
.w-popup.maplibregl-popup-anchor-top .maplibregl-popup-tip, .w-popup.maplibregl-popup-anchor-top-left .maplibregl-popup-tip, .w-popup.maplibregl-popup-anchor-top-right .maplibregl-popup-tip { border-bottom-color: var(--w-white) !important; }
.w-popup .maplibregl-popup-close-button { color: var(--w-slate); min-width: 44px; min-height: 44px; }
