/* Census Map - site\census\assets\census.css
   Colour tokens on :root, dark mode redefined for BOTH the OS setting and the
   in-page toggle (the toggle must win either way). The choropleth ramps live in
   census.js, not here, because Leaflet paints them as inline SVG/canvas fills. */

:root {
  color-scheme: light;
  --bg: #f4f3f0;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #dddcd7;
  --text: #1b1b1a;
  --text-2: #52514e;
  --text-3: #7a7974;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #e3eefb;
  --warn-bg: #fff4dc;
  --warn-border: #eda100;
  --err-bg: #fde9e8;
  --err-border: #d03b3b;
  --info-bg: #e7f0fb;
  --info-border: #2a78d6;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #34332f;
    --text: #f3f2ee;
    --text-2: #c3c2b7;
    --text-3: #93928a;
    --accent: #5598e7;
    --accent-ink: #0b0b0b;
    --accent-soft: #1b2c42;
    --warn-bg: #33290f;
    --warn-border: #c98500;
    --err-bg: #3a1c1b;
    --err-border: #e66767;
    --info-bg: #17263a;
    --info-border: #3987e5;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211;
  --surface: #1a1a19;
  --surface-2: #232321;
  --border: #34332f;
  --text: #f3f2ee;
  --text-2: #c3c2b7;
  --text-3: #93928a;
  --accent: #5598e7;
  --accent-ink: #0b0b0b;
  --accent-soft: #1b2c42;
  --warn-bg: #33290f;
  --warn-border: #c98500;
  --err-bg: #3a1c1b;
  --err-border: #e66767;
  --info-bg: #17263a;
  --info-border: #3987e5;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
/* Author display rules (.busy is flex) beat the UA's [hidden] rule - without
   this the loading pill never goes away. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}
button, input, select { font: inherit; color: inherit; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 26px; height: 26px; color: var(--accent); flex: none; }
.brand h1 { margin: 0; font-size: 17px; letter-spacing: -.01em; }
.brand .sub { margin: 0; font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.build { color: var(--text-3); font-family: var(--mono); font-size: 11px; margin-left: 6px; white-space: nowrap; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.linkbtn { color: var(--text-2); text-decoration: none; padding: 6px 10px; border-radius: 8px; }
.linkbtn:hover { background: var(--surface-2); color: var(--text); }
.iconbtn { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); display: grid; place-items: center; cursor: pointer; }
.iconbtn svg { width: 18px; height: 18px; color: var(--text-2); }
.iconbtn:hover { background: var(--surface-2); }

/* ---------- layout ---------- */
.layout { flex: 1; display: flex; min-height: 0; }
.panel {
  width: 380px; flex: none; overflow-y: auto;
  padding: 12px; display: flex; flex-direction: column; gap: 12px;
  border-right: 1px solid var(--border);
}
.mapwrap { position: relative; flex: 1; min-width: 0; }
#map { position: absolute; inset: 0; background: var(--surface-2); }

@media (max-width: 820px) {
  .layout { flex-direction: column-reverse; }
  .panel { width: auto; border-right: 0; border-top: 1px solid var(--border); overflow: visible; padding: 12px 16px; }
  .mapwrap { flex: none; height: 58vh; }
  body { display: block; }
  .brand .sub { white-space: normal; }
}

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.card.small { font-size: 13px; }
.lbl { display: block; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-2); margin-bottom: 6px; }
.hint { margin: 8px 0 0; font-size: 12.5px; color: var(--text-2); }
.hint:empty { display: none; }
h2 { margin: 0; font-size: 16px; line-height: 1.3; }

.search-row { display: flex; gap: 6px; }
input[type=text], select {
  width: 100%; min-width: 0; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2);
}
input[type=text]:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
button {
  padding: 7px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; white-space: nowrap;
}
button:hover { background: var(--surface-2); }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.primary:hover { filter: brightness(1.06); background: var(--accent); }
.btnrow { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; border-right: 1px solid var(--border); background: var(--surface-2); padding: 8px 4px; }
.seg button:last-child { border-right: 0; }
.seg button[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* ---------- banners ---------- */
.banner { border-radius: var(--radius); padding: 10px 12px; border: 1px solid; border-left-width: 4px; font-size: 13px; }
.banner > b { display: block; margin-bottom: 2px; }
.banner a { color: var(--accent); }
.banner p { margin: 4px 0 0; }
.banner ol { margin: 6px 0 0; padding-left: 18px; }
.banner code { font-family: var(--mono); font-size: 12px; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; word-break: break-all; }
.banner.warn { background: var(--warn-bg); border-color: var(--warn-border); }
.banner.err { background: var(--err-bg); border-color: var(--err-border); }
.banner.info { background: var(--info-bg); border-color: var(--info-border); }
.banner .x { float: right; border: 0; background: transparent; padding: 0 2px; font-size: 16px; line-height: 1; color: var(--text-2); }
.keyform { margin-top: 8px; }
.keyform input[type=text] { font-family: var(--mono); font-size: 12.5px; background: var(--surface); }
.keymsg { margin: 6px 0 0; font-size: 12.5px; color: var(--text-2); }
.keymsg:empty { display: none; }
.keymsg.err { color: var(--text); font-weight: 600; }
.keymsg.err::before { content: "\2715  "; color: var(--err-border); }
.keymsg.good { color: var(--text); font-weight: 600; }
.keymsg.good::before { content: "\2713  "; color: #0ca30c; }
#banners { display: flex; flex-direction: column; gap: 8px; }
#banners:empty { display: none; }

/* ---------- legend ---------- */
.legend { display: flex; flex-direction: column; gap: 4px; }
.legend-row { display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: 8px; font-size: 13px; }
.swatch { width: 22px; height: 14px; border-radius: 3px; border: 1px solid rgba(0,0,0,.08); }
.swatch.none {
  background: repeating-linear-gradient(135deg, transparent 0 3px, var(--text-3) 3px 4px);
  border-color: var(--text-3); opacity: .7;
}
.legend-row .n { color: var(--text-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.legend-row .rng { font-variant-numeric: tabular-nums; }
.legend-note { font-size: 12.5px; color: var(--text-2); margin-top: 6px; }

/* ---------- profile ---------- */
.profile-head { display: flex; justify-content: space-between; gap: 8px; }
.ptable { width: 100%; table-layout: fixed; border-collapse: collapse; margin-top: 10px; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.ptable col.c-m { width: 34%; }
.ptable col.c-v { width: 17.5%; }
.ptable col.c-c { width: 16%; }
.ptable th { text-align: right; font-weight: 600; font-size: 11px; color: var(--text-2); padding: 4px 0 4px 4px; white-space: nowrap; overflow: hidden; }
.ptable th:first-child { text-align: left; padding-left: 0; }
.ptable td { padding: 4px 0 4px 4px; text-align: right; border-top: 1px solid var(--border); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ptable td:first-child { text-align: left; padding-left: 0; white-space: normal; color: var(--text); }
.ptable td.cmp { color: var(--text-2); }
.ptable tr.cat td { border-top: 0; padding-top: 12px; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-2); text-align: left; }
.ptable tr.active td { background: var(--accent-soft); }
.ptable tr.active td:first-child { box-shadow: inset 3px 0 0 var(--accent); padding-left: 6px; }
.ptable tr.metric-row { cursor: pointer; }
.ptable tr.metric-row:hover td { background: var(--surface-2); }
.ptable .na { color: var(--text-3); }
.ptable .refused { color: var(--text-3); font-style: italic; text-align: left; white-space: normal; }
.arrow { font-size: 10px; color: var(--text-3); margin-left: 3px; }

details summary { cursor: pointer; font-weight: 600; color: var(--text-2); padding: 2px 0; }
details + details { margin-top: 8px; }
details p { margin: 8px 0 0; color: var(--text-2); }
.diag { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 12px; }
.diag td, .diag th { border-top: 1px solid var(--border); padding: 4px 4px 4px 0; vertical-align: top; text-align: left; }
.diag .ok { color: var(--text); font-weight: 600; }
.diag code { font-family: var(--mono); font-size: 11px; word-break: break-all; color: var(--text-2); }

/* ---------- map overlays ---------- */
.busy {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 800;
  display: flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); font-size: 13px;
  max-width: calc(100% - 32px);
}
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.hovertip {
  position: absolute; z-index: 790; pointer-events: none;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 9px; box-shadow: var(--shadow); font-size: 12.5px; max-width: 260px;
}
.hovertip .v { font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; }
.hovertip .k { color: var(--text-2); }

.leaflet-container { font: inherit; background: var(--surface-2); }
.leaflet-control-attribution { font-size: 10.5px; }
:root[data-theme="dark"] .leaflet-control-attribution,
:root[data-theme="dark"] .leaflet-bar a { background: #232321cc; color: #c3c2b7; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .leaflet-control-attribution,
  :root:not([data-theme="light"]) .leaflet-bar a { background: #232321cc; color: #c3c2b7; }
}
.leaflet-control-attribution a { color: var(--accent); }
/* Dark mode: the light OpenStreetMap tiles are inverted on the tile pane only (shapes, pins and controls keep their colours). */
:root[data-theme="dark"] #map .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.9); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) #map .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.9); } }
.home-pin { background: none; border: 0; }

.fatal { position: fixed; left: 16px; right: 16px; bottom: 16px; z-index: 2000; background: #d03b3b; color: #fff; padding: 12px 14px; border-radius: 10px; font: 600 14px system-ui, sans-serif; }
