/* D5 cannabis map demo. County of San Luis Obispo identity first (Open Sans, five-colour palette),
   house style second (Plex Mono for data, 2px radius, 1.5px rules, double neatline, no shadows). */

/* ---------- Tokens ---------- */
:root {
  color-scheme: light dark;
  /* the five */
  --navy: #01426A;
  --teal: #00B2A9;
  --green: #6CC24A;
  --gold: #B9975B;
  --stone: #83786F;
  /* County greys and black tints */
  --grey: #888B8D;
  --grey-2: #D0D3D4;
  --grey-3: #D9E1E2;
  --ink: #15181A;

  --ground: #FFFFFF;
  --surface: #FFFFFF;
  --tint: #D9E1E2;          /* hover / active wash */
  --text: #15181A;
  --muted: #5C5F61;         /* stone is 4.3:1 on white, so a black tint carries muted text */
  --rule: #D0D3D4;
  --frame: var(--navy);     /* neatlines */
  --link: var(--navy);
  --focus: var(--navy);
  --line: #01426A;          /* map strokes: VRL, 5-mile ring, parcel outline */
  --site-ring: #FFFFFF;
  --band: var(--navy);
  --on-band: #FFFFFF;
  --tiles: grayscale(1) contrast(0.92) brightness(1.04);

  --sans: "Open Sans", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --r: 2px;
  --bw: 1.5px;
  --gutter: 16px;
  --tap: 44px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #15181A;
    --surface: #1F2427;
    --tint: #2C3337;
    --text: #D9E1E2;
    --muted: #A7AAAC;
    --rule: #3A4247;
    --frame: #888B8D;
    --link: #D9E1E2;
    --focus: var(--teal);
    --line: #D9E1E2;
    --site-ring: #15181A;
    --tiles: grayscale(1) invert(1) brightness(0.88) contrast(0.86);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --ground: #15181A;
  --surface: #1F2427;
  --tint: #2C3337;
  --text: #D9E1E2;
  --muted: #A7AAAC;
  --rule: #3A4247;
  --frame: #888B8D;
  --link: #D9E1E2;
  --focus: var(--teal);
  --line: #D9E1E2;
  --site-ring: #15181A;
  --tiles: grayscale(1) invert(1) brightness(0.88) contrast(0.86);
}
:root[data-theme="light"] { color-scheme: light; }

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--ground);
  color: var(--text);
  font: 400 16px/1.5 var(--sans);
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
}
main { position: fixed; inset: 0; }
#map { position: absolute; inset: 0; z-index: 0; background: var(--ground); } /* own stacking context: Leaflet controls stay under the cards */
h1, h2 { font-weight: 800; line-height: 1.2; margin: 0; }
p { margin: 0; }
.mono { font-family: var(--mono); }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap); padding: 0 16px;
  font: 700 15px/1 var(--sans);
  color: var(--on-band); background: var(--navy);
  border: var(--bw) solid var(--navy); border-radius: var(--r);
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--teal); border-color: var(--teal); color: var(--ink); }

/* ---------- Title card ---------- */
/* Double-rule neatline: a 1.5px outer rule, 3px gap, a 1px inner rule. The band sits flush inside the inner rule. */
.title-card {
  position: absolute; z-index: 1000;
  top: var(--gutter); right: var(--gutter);
  width: 424px; max-width: calc(100% - 2 * var(--gutter));
  padding: 3px;
  background: var(--surface);
  border: var(--bw) solid var(--frame); border-radius: var(--r);
}
.title-in { border: 1px solid var(--frame); padding-bottom: 16px; }
.title-card .eyebrow {
  padding: 8px 16px 7px;
  background: var(--band); color: var(--on-band);
  font-size: 13px; font-weight: 600; letter-spacing: 0.02em;
}
.title-card h1 {
  margin: 14px 16px 14px;
  font-size: 22px; font-weight: 800; color: var(--text);
}
/* stamp and button share one height and fill the row edge to edge */
.title-card .row { display: grid; grid-template-columns: auto 1fr; gap: 10px; margin: 0 16px; }
.title-card .row .btn { width: 100%; }
.stamp {
  display: inline-flex; align-items: center;
  min-height: var(--tap); margin: 0;
  font: 500 12px/1 var(--mono); letter-spacing: 0.06em;
  color: var(--ink); background: var(--gold);
  border-radius: var(--r);
  padding: 0 10px;
  white-space: nowrap;
}

/* ---------- Legend ---------- */
.legend {
  position: absolute; z-index: 1000;
  right: var(--gutter); bottom: calc(var(--foot-h, 28px) + 12px);
  width: 300px; max-width: calc(100% - 2 * var(--gutter));
  background: var(--surface);
  border: var(--bw) solid var(--frame); border-radius: var(--r);
}
.legend-toggle {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  min-height: var(--tap); padding: 0 12px;
  font: 700 14px/1 var(--sans); letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--on-band); background: var(--band);
  border: 0; border-radius: 0; cursor: pointer;
}
.legend-toggle::after {
  content: ""; width: 8px; height: 8px;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: translateY(2px) rotate(-135deg);
}
.legend-toggle[aria-expanded="false"]::after { transform: translateY(-2px) rotate(45deg); }
.legend ul { list-style: none; margin: 0; padding: 4px 0; }
.legend ul[hidden] { display: none; }
.legend li + li { border-top: 1px solid var(--rule); }
.legend li button {
  display: flex; align-items: center; gap: 12px; width: 100%;
  min-height: var(--tap); padding: 0 12px;
  font: 400 14px/1.25 var(--sans); text-align: left;
  color: var(--text); background: none; border: 0; cursor: pointer;
}
.legend li button:hover { background: var(--tint); }
.legend li button::after {
  content: ""; margin-left: auto; flex: none;
  width: 16px; height: 16px; border: var(--bw) solid var(--muted); border-radius: var(--r);
}
.legend li button[aria-pressed="true"]::after {
  background: var(--line); border-color: var(--line);
  box-shadow: inset 0 0 0 3px var(--surface); /* a filled box, not a drop shadow */
}
.legend li button[aria-pressed="false"] { color: var(--muted); }
.legend li button[aria-pressed="false"] .sw { opacity: 0.45; }

/* swatches: shape as well as colour */
.sw { flex: none; width: 24px; height: 18px; display: inline-block; position: relative; }
.sw-app { background: color-mix(in srgb, var(--teal) 75%, transparent); border: 1px solid var(--navy); border-radius: 1px; width: 22px; height: 16px; }
.sw-site::before {
  content: ""; position: absolute; left: 3px; top: 0; width: 18px; height: 18px; border-radius: 50%;
  background: var(--green); border: 2px solid var(--site-ring); outline: 1px solid var(--grey);
}
.sw-district { background: rgba(136, 139, 141, 0.5); border: 1.5px solid rgba(0, 0, 0, 0.5); width: 22px; height: 16px; }
/* lines and rings are masks filled with the token colour, so the dash pattern matches the map */
.sw-vrl, .sw-ring { background: var(--c); -webkit-mask: var(--m) center / contain no-repeat; mask: var(--m) center / contain no-repeat; }
.sw-vrl  { --c: var(--line); --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 18'%3E%3Cpath d='M0 9h24' stroke='%23000' stroke-width='2.5' stroke-dasharray='6 3' stroke-linecap='round'/%3E%3C/svg%3E"); }
.sw-ring-1 { --c: var(--gold); --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 18'%3E%3Ccircle cx='12' cy='9' r='7.5' fill='none' stroke='%23000' stroke-width='2'/%3E%3C/svg%3E"); }
.sw-ring-3 { --c: var(--teal); --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 18'%3E%3Ccircle cx='12' cy='9' r='7.5' fill='none' stroke='%23000' stroke-width='2' stroke-dasharray='4 2.5'/%3E%3C/svg%3E"); }
.sw-ring-5 { --c: var(--line); --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 18'%3E%3Ccircle cx='12' cy='9' r='7.5' fill='none' stroke='%23000' stroke-width='2' stroke-dasharray='5 2.5 1.5 2.5'/%3E%3C/svg%3E"); }

/* ---------- About dialog ---------- */
dialog#about {
  width: min(560px, calc(100% - 2 * var(--gutter)));
  max-height: calc(100% - 2 * var(--gutter));
  padding: 0; margin: auto;
  color: var(--text); background: var(--surface);
  border: var(--bw) solid var(--frame); border-radius: var(--r);
  padding: 3px;
}
dialog#about::backdrop { background: rgba(21, 24, 26, 0.55); }
.dialog-in { border: 1px solid var(--frame); padding-bottom: 20px; }
.dialog-in h2 {
  padding: 12px 16px 11px; margin-bottom: 16px;
  background: var(--band); color: var(--on-band);
  font-size: 20px; font-weight: 800;
}
.dialog-in p { margin: 0 16px 14px; font-size: 16px; }
.dialog-in .btn { margin: 6px 16px 0; }

/* ---------- Leaflet overrides ---------- */
.leaflet-container { font: 400 14px/1.4 var(--sans); background: var(--ground); }
.leaflet-tile-pane { filter: var(--tiles); }

.leaflet-bar { border: var(--bw) solid var(--frame) !important; border-radius: var(--r) !important; box-shadow: none !important; }
.leaflet-bar a, .leaflet-bar a:hover {
  width: var(--tap); height: var(--tap); line-height: var(--tap);
  font: 400 22px/var(--tap) var(--sans);
  color: var(--text); background: var(--surface); border-bottom-color: var(--rule);
}
.leaflet-bar a:hover { background: var(--tint); }
.leaflet-bar a:first-child, .leaflet-bar a:last-child { border-radius: 0; }
.leaflet-bar a.leaflet-disabled { color: var(--grey); background: var(--surface); }
.leaflet-left .leaflet-control, .leaflet-right .leaflet-control { margin-left: var(--gutter); }
.leaflet-bottom .leaflet-control { margin-bottom: 12px; }

/* Popups: house shapes, no shadow */
.leaflet-popup-content-wrapper {
  padding: 0; border-radius: var(--r);
  background: var(--surface); color: var(--text);
  border: var(--bw) solid var(--frame);
  box-shadow: none;
}
.leaflet-popup-content { margin: 0; width: 280px; font-size: 14px; line-height: 1.45; }
.leaflet-popup-tip-container { margin-top: -1.5px; }
.leaflet-popup-tip { background: var(--surface); border: var(--bw) solid var(--frame); box-shadow: none; }
.leaflet-container a.leaflet-popup-close-button {
  width: var(--tap); height: var(--tap); top: 0; right: 0;
  font: 400 24px/var(--tap) var(--sans); color: var(--on-band);
}
.leaflet-container a.leaflet-popup-close-button:hover { color: var(--on-band); background: rgba(255, 255, 255, 0.12); }

.pop-head { background: var(--band); color: var(--on-band); padding: 10px 48px 9px 14px; }
.pop-title { font: 500 18px/1.25 var(--mono); }
.pop-title.sans { font: 800 18px/1.25 var(--sans); }
.pop-sub { font-size: 13px; opacity: 0.85; margin-top: 2px; }
.pop-body { position: relative; padding: 10px 14px 12px; }
.pop-body dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; }
.pop-body dt { color: var(--muted); font-size: 13px; padding-top: 1px; }
.pop-body dd { margin: 0; }
.pop-body .num { font-family: var(--mono); font-size: 13.5px; }
.pop-sect {
  margin: 12px 0 6px; padding-top: 10px; border-top: 1px solid var(--rule);
  font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
}
.pop-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.pop-list li { position: relative; }
.pop-note { margin-top: 12px; font-size: 12px; color: var(--muted); }

/* Inert stand-ins: look like links, are not links. Highlight at once, explain after 1s. */
.inert {
  display: inline-block; min-height: 28px; padding: 2px 4px; margin-left: -4px;
  color: var(--link); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px;
  border-radius: var(--r); cursor: default;
  transition: background-color 0s, text-decoration-thickness 0s;
}
.inert.num { font-family: var(--mono); font-size: 14px; font-weight: 500; }
.inert:hover, .inert:focus-visible, .inert.tip-on { background: var(--tint); text-decoration-thickness: 2.5px; }
.tip {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 4px); z-index: 2;
  padding: 7px 9px 8px;
  font-size: 13px; line-height: 1.4; color: var(--text);
  background: var(--surface); border: var(--bw) solid var(--frame); border-radius: var(--r);
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity 0.15s ease 0s, visibility 0s linear 0.15s;
}
.tip b { display: block; font: 500 11px/1.2 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-bottom: 3px; }
@media (hover: hover) {
  .inert:hover + .tip { opacity: 1; visibility: visible; transition: opacity 0.15s ease 1s, visibility 0s linear 1s; }
}
.inert:focus-visible + .tip { opacity: 1; visibility: visible; transition: opacity 0.15s ease 1s, visibility 0s linear 1s; }
.inert.tip-on + .tip { opacity: 1; visibility: visible; transition: none; }

/* Clusters (MarkerCluster.Default.css is not loaded) */
.marker-cluster {
  display: flex; align-items: center; justify-content: center;
  background: var(--green); color: var(--ink);
  border: 2px solid var(--site-ring); outline: 1px solid var(--grey); border-radius: 50%;
  font: 500 14px/1 var(--mono);
}

/* Attribution / footer */
.leaflet-control-attribution.leaflet-control {
  margin: 0; padding: 0; background: none; font-size: 13px; line-height: 1.4;
}
.foot {
  display: flex; flex-wrap: wrap; align-items: center; gap: 2px 0;
  padding: 3px 8px 3px 10px; margin: 0;
  color: var(--text); background: var(--surface);
  border-top: var(--bw) solid var(--frame); border-left: var(--bw) solid var(--frame);
  border-top-left-radius: var(--r);
  font-size: 13px;
}
.foot > * + *::before { content: "·"; display: inline-block; margin: 0 7px; color: var(--muted); } /* inline-block: keeps the link underline off the dot */
.foot a, .leaflet-container .foot a { color: var(--link); text-decoration: underline; text-underline-offset: 2px; }
.foot a:hover { text-decoration-thickness: 2px; }
.theme-dot {
  width: 28px; height: 28px; padding: 0; margin: 0 0 0 4px;
  background: none; border: 0; cursor: pointer; position: relative;
}
.theme-dot::before { display: none; }
.theme-dot::after {
  content: ""; position: absolute; inset: 7px; border-radius: 50%;
  border: var(--bw) solid var(--text);
  background: linear-gradient(90deg, var(--text) 50%, transparent 50%);
}

/* Narrow: footer wraps, so no separators and the theme dot is pinned top-right */
@media (max-width: 900px) {
  .foot { position: relative; column-gap: 14px; padding-right: 40px; }
  .foot > * + *::before { display: none; }
  .theme-dot { position: absolute; top: 0; right: 4px; margin: 0; }
}

/* ---------- Phones ---------- */
@media (max-width: 640px) {
  :root { --gutter: 12px; }
  .title-card {
    top: 0; right: 0; left: 0; width: auto; max-width: none;
    padding: env(safe-area-inset-top) 0 0; border-width: 0 0 var(--bw); border-radius: 0;
  }
  .title-in { border: 0; padding-bottom: 10px; }
  .title-card .eyebrow { padding: 6px var(--gutter); font-size: 12px; }
  .title-card h1 { margin: 8px var(--gutter); font-size: 17px; }
  .title-card .row { margin: 0 var(--gutter); gap: 8px; }
  .stamp { min-height: 40px; padding: 0 8px; letter-spacing: 0.03em; }
  .title-card .btn { min-height: 40px; font-size: 14px; padding: 0 10px; }
  .legend { right: var(--gutter); width: auto; min-width: 140px; }
  .leaflet-bottom.leaflet-left { bottom: var(--foot-h, 0px); }
  .legend ul { max-height: calc(100dvh - var(--title-h, 120px) - var(--foot-h, 40px) - 80px); overflow: auto; }
  .legend:has(ul:not([hidden])) { left: var(--gutter); }
  .leaflet-top .leaflet-control { margin-top: 0; }
  .foot { font-size: 12px; padding: 3px 6px 3px 8px; border-left: 0; border-radius: 0; }
  .foot a:nth-of-type(2) { margin-right: 30px; } /* leaves room for the pinned theme dot on the first row */
  .leaflet-bottom.leaflet-right { left: 0; }
  .leaflet-bottom.leaflet-right .leaflet-control-attribution { float: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; }
  .tip { transition-property: visibility !important; transition-duration: 0s !important; }
  .leaflet-fade-anim .leaflet-popup, .leaflet-fade-anim .leaflet-tile { transition: none !important; }
}
