/* Trade Area Demographics — commercial redesign (branch redesign/commercial-ux).
   Token system: drafting-paper canvas, near-black ink, one survey-red signature,
   Archivo/Archivo Expanded display + IBM Plex Mono instrument voice.
   Every classname app.js generates (report tables, chips, legend, dialog, tips)
   is styled here — keep those selectors when editing. */

:root {
  --ink: #17191E; --ink-2: #3D424D; --muted: #6E7480;
  --paper: #F1F1EC; --surface: #FFFFFF; --surface-2: #FBFAF6;
  --line: #E3E2D9; --line-2: #D2D1C6;
  --brand: #BE3A20; --brand-press: #9A2C14; --brand-tint: #F6E8E2;
  --teal: #11626B; --teal-tint: #E4EFF0;
  --green: #2C7049; --amber: #B7821E; --red: #B63528;
  --green-bg: #EAF0EB; --amber-bg: #F8F1E1; --red-bg: #F6E8E5;
  --custom: #6C3FA0; --custom-tint: #F0E9F8;
  --shadow: 0 1px 2px rgba(20,22,28,.05), 0 3px 12px rgba(20,22,28,.05);
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Archivo", system-ui, sans-serif;
  color: var(--ink); background: var(--paper);
  font-size: 13.5px; line-height: 1.5; -webkit-font-smoothing: antialiased;
  background-image: radial-gradient(circle at 1px 1px, rgba(23,25,30,.02) 1px, transparent 0);
  background-size: 26px 26px;
}
.mono { font-family: "IBM Plex Mono", ui-monospace, monospace; }
button { font-family: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }
.hidden { display: none !important; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ───────── top bar ───────── */
.appbar {
  display: flex; align-items: center; gap: 16px; height: 56px; padding: 0 18px;
  background: rgba(247,246,242,.9); backdrop-filter: blur(10px) saturate(1.4);
  -webkit-backdrop-filter: blur(10px) saturate(1.4);
  border-bottom: 1px solid var(--line); position: relative; z-index: 1300;
}
.brand-lock { display: flex; align-items: center; gap: 11px; flex: none; }
.mark { width: 28px; height: 28px; flex: none; display: block; }
.wordmark { display: flex; flex-direction: column; line-height: 1; margin: 0; font-size: inherit; }
.wordmark .name {
  font-family: "Archivo Expanded", "Archivo", sans-serif; font-weight: 800;
  font-size: 13.5px; letter-spacing: .01em; color: var(--ink); text-transform: uppercase;
}
.wordmark .kicker {
  font-family: "IBM Plex Mono", monospace; font-size: 9px; font-weight: 500;
  letter-spacing: .22em; color: var(--muted); margin-top: 3px;
}
.bar-spacer { flex: 1 1 auto; }
/* account area (populated by app.js from /api/auth/me; hidden when auth is off) */
.account { display: inline-flex; align-items: center; gap: 10px; flex: none; }
#account-email { font-family: "IBM Plex Mono", monospace; font-size: 11px; color: var(--ink-2); }
/* plan chip — quiet by design: it states a fact, it is not a call to action */
.plan-chip {
  font-family: "IBM Plex Mono", monospace; font-size: 10px; font-weight: 500;
  letter-spacing: .06em; text-transform: uppercase; color: var(--teal);
  background: var(--teal-tint); border: 1px solid #C5DCDF;
  padding: 3px 8px; border-radius: 999px; white-space: nowrap;
}
.banner {
  font-size: 12px; font-weight: 600; color: #7A5A12; background: var(--amber-bg);
  border: 1px solid #E8D9B4; padding: 4px 12px; border-radius: 8px;
}

/* ───────── layout ───────── */
#layout { display: grid; grid-template-columns: 336px 1fr; height: calc(100vh - 56px); }
#controls {
  overflow-y: auto; background: var(--surface); border-right: 1px solid var(--line);
  padding: 4px 0 26px;
}
#workspace { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
main { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
#map { flex: 1 1 auto; min-height: 200px; background: #F4F2EA; }
#report-wrap { flex: 0 0 auto; max-height: 60%; overflow: auto; padding: 16px 22px 30px; }
#workspace.has-report main { flex: 0 0 46%; }
#workspace.has-report #report-wrap { flex: 1 1 auto; }

/* ───────── left rail: build-flow steps ───────── */
.step { padding: 16px 20px 15px; border-bottom: 1px solid var(--line); }
.step-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.step-num {
  width: 23px; height: 23px; flex: none; border-radius: 7px; display: grid; place-items: center;
  font-family: "IBM Plex Mono", monospace; font-weight: 600; font-size: 11.5px;
  color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--line-2);
}
.step-title { font-weight: 700; font-size: 13px; letter-spacing: .01em; }
.hint { font-size: 11px; color: var(--muted); margin: 6px 0 4px; line-height: 1.5; }

/* inputs */
input[type=text], input[type=number], select {
  font-family: inherit; font-size: 13px; color: var(--ink);
  border: 1px solid var(--line-2); border-radius: 9px; background: var(--surface);
  padding: 7px 10px;
}
input[type=text]:focus, input[type=number]:focus, select:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-tint);
}
input[type=checkbox] { accent-color: var(--brand); width: 15px; height: 15px; }

.add-row { display: flex; gap: 8px; margin-bottom: 8px; }
.stepper-input {
  display: flex; align-items: center; flex: 1 1 auto; min-width: 0;
  border: 1px solid var(--line-2); border-radius: 9px; background: var(--surface); overflow: hidden;
}
.stepper-input:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-tint); }
.stepper-input input {
  width: 52px; flex: none; border: 0; border-radius: 0; padding: 8px 0 8px 12px;
  font-family: "IBM Plex Mono", monospace; font-size: 13.5px; font-weight: 600; background: none;
}
.stepper-input input:focus { outline: none; box-shadow: none; }
.stepper-input .unit {
  flex: 1 1 auto; color: var(--muted); font-family: "IBM Plex Mono", monospace;
  font-size: 10.5px; padding: 0 10px 0 6px; white-space: nowrap;
}
.add-btn {
  flex: none; padding: 0 13px; border-radius: 9px; border: 1px solid var(--ink);
  background: var(--ink); color: #fff; font-weight: 600; font-size: 12.5px;
}
.add-btn:hover { background: #000; }
.ghost-btn {
  padding: 7px 13px; border-radius: 9px; border: 1px solid var(--line-2);
  background: var(--surface); color: var(--ink-2); font-size: 12.5px; font-weight: 600;
}
.ghost-btn:hover { background: var(--surface-2); border-color: var(--muted); color: var(--ink); }
.ghost-btn.grow { flex: 1 1 auto; }
.draw-row { margin-top: 10px; }
button[disabled] { opacity: .55; cursor: progress; }
button[data-add][disabled] { cursor: not-allowed; }

/* trade-area chips (JS-created: .chip / .chip.custom) */
.chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 11px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 4px 7px 4px 11px;
  border-radius: 9px; font-size: 12px; font-weight: 600;
  background: var(--brand-tint); color: var(--brand-press); border: 1px solid #E8C6B8;
}
.chip button {
  border: none; background: none; padding: 0 2px; color: inherit; opacity: .55;
  font-size: 15px; line-height: 1; font-weight: 700;
}
.chip button:hover { opacity: 1; }
.chip.custom { background: var(--custom-tint); color: var(--custom); border-color: #DECBF2; }
/* Crosshair while drawing a custom area (overrides Leaflet's grab cursor). */
.leaflet-container.drawing,
.leaflet-container.drawing .leaflet-interactive { cursor: crosshair !important; }

/* metric search + groups */
.metric-search-row { display: flex; gap: 8px; margin-bottom: 10px; }
.metric-search-row input { flex: 1 1 auto; min-width: 0; }
.metric-group { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; overflow: hidden; background: var(--surface); }
.metric-group > summary {
  cursor: pointer; padding: 8px 12px; font-size: 12.5px; font-weight: 700;
  background: var(--surface-2); display: flex; align-items: center; gap: 9px; list-style: none;
}
.metric-group > summary::-webkit-details-marker { display: none; }
.metric-group > summary::before {
  content: "▸"; color: var(--muted); font-size: 10px; transition: transform .12s ease;
}
.metric-group[open] > summary::before { transform: rotate(90deg); }
.metric-group > summary .group-toggle { flex: none; margin: 0; cursor: pointer; }
.metric-group > summary .group-title { flex: 1 1 auto; }
.metric-item {
  display: flex; align-items: center; gap: 9px; padding: 6px 12px; font-size: 12.5px;
  border-top: 1px solid var(--line); cursor: pointer;
}
.metric-group .metric-item:first-of-type { border-top: none; }
.metric-item input { flex: none; }
.metric-item .metric-name { flex: 1 1 auto; }
/* Non-invasive source marker — the Census table is in its tooltip (req #2). */
.src-mark { color: #B4B9C0; font-size: 10.5px; cursor: help; margin-left: 3px; }
.src-mark:hover, .src-mark:focus { color: var(--brand); outline: none; }
.search-results { max-height: 170px; overflow-y: auto; border-radius: 10px; }
.search-results .metric-item { border-top: none; border-bottom: 1px solid var(--line); }
.search-results code {
  font-family: "IBM Plex Mono", monospace; font-size: 10px; color: var(--muted);
}
.src { font-size: 11px; color: var(--muted); }

/* options */
.field { margin-bottom: 12px; }
.field-label { display: block; font-size: 11.5px; font-weight: 600; color: var(--muted); margin-bottom: 7px; }
.year-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.year-chip {
  font-family: "IBM Plex Mono", monospace; font-size: 12px; font-weight: 500;
  padding: 5px 11px; border-radius: 8px; border: 1px solid var(--line-2);
  background: var(--surface); color: var(--ink-2);
}
.year-chip:hover { border-color: var(--muted); }
.year-chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.sel { width: 100%; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%236E7480' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}

/* compute */
.compute-wrap { padding: 16px 20px; border-bottom: 1px solid var(--line); }
.compute {
  width: 100%; height: 44px; border: 0; border-radius: 10px;
  background: var(--brand); color: #fff; font-weight: 700; font-size: 14px;
  letter-spacing: .01em; box-shadow: 0 1px 2px rgba(20,22,28,.16);
}
.compute:hover { background: var(--brand-press); }
.export-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ───────── floating origin search over the map ───────── */
#origin-float {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  z-index: 1100; width: min(500px, calc(100% - 104px));
  background: rgba(255,255,255,.82); backdrop-filter: blur(12px) saturate(1.5);
  -webkit-backdrop-filter: blur(12px) saturate(1.5);
  border: 1px solid rgba(255,255,255,.7); border-radius: 12px;
  box-shadow: 0 6px 20px rgba(20,30,45,.12); padding: 9px 11px;
}
#origin-float .row { display: flex; gap: 8px; align-items: center; }
#origin-float .search-ic { flex: none; color: var(--muted); margin-left: 2px; }
#origin-float input[type=text] { flex: 1 1 auto; min-width: 0; background: rgba(255,255,255,.92); }
#origin-float #geocode-btn {
  flex: none; padding: 7px 14px; border-radius: 9px; border: 1px solid var(--ink);
  background: var(--ink); color: #fff; font-size: 12.5px; font-weight: 600;
}
#origin-float #geocode-btn:hover { background: #000; }
#origin-float .hint { margin: 5px 2px 0; }
.origin-info {
  font-family: "IBM Plex Mono", monospace; font-size: 11px; color: var(--teal);
  margin: 6px 2px 0;
}
.origin-info:empty { display: none; }

/* address autocomplete dropdown */
.autocomplete { position: relative; }
.suggest {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 1200;
  margin: 0; padding: 4px; list-style: none; background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; max-height: 230px; overflow-y: auto;
  box-shadow: var(--shadow);
}
.suggest li { padding: 7px 9px; font-size: 12px; border-radius: 6px; cursor: pointer; line-height: 1.35; }
.suggest li:hover, .suggest li.active { background: var(--brand-tint); }
.suggest li.empty { color: var(--muted); cursor: default; }

/* Leaflet controls — match the system (light touch) */
.leaflet-container { font-family: "Archivo", system-ui, sans-serif; }
.leaflet-bar { border: 1px solid var(--line-2) !important; box-shadow: var(--shadow) !important; border-radius: 9px !important; overflow: hidden; }
.leaflet-bar a { color: var(--ink-2) !important; }
.leaflet-control-layers { border: 1px solid var(--line-2) !important; box-shadow: var(--shadow) !important; border-radius: 10px !important; }

/* ───────── progress / status ───────── */
.progress { height: 3px; width: 100%; background: var(--line); border-radius: 3px; overflow: hidden; margin-bottom: 10px; }
.progress-bar {
  height: 100%; width: 40%; border-radius: 3px; background: var(--brand);
  animation: progress-slide 1.1s ease-in-out infinite;
}
@keyframes progress-slide { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }
.status { font-family: "IBM Plex Mono", monospace; font-size: 11.5px; color: var(--muted); margin-bottom: 10px; min-height: 17px; }
.status.error { color: var(--red); }
.spinner {
  display: inline-block; width: 12px; height: 12px; vertical-align: -2px;
  border: 2px solid var(--line-2); border-top-color: var(--brand); border-radius: 50%;
  animation: spin .7s linear infinite; margin-right: 7px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ───────── report (all JS-generated) ───────── */
#report { max-width: 1160px; }
.report-head { margin-bottom: 16px; }
.eyebrow {
  font-family: "IBM Plex Mono", monospace; font-size: 10px; font-weight: 500;
  letter-spacing: .16em; text-transform: uppercase; color: var(--muted); margin-bottom: 7px;
}
.report-head h2 {
  font-family: "Archivo Expanded", "Archivo", sans-serif; font-weight: 700;
  font-size: 21px; letter-spacing: -.01em; margin: 0;
}
.report-head .sub { font-family: "IBM Plex Mono", monospace; font-size: 11px; color: var(--muted); margin-top: 5px; }

/* headline stat cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 13px; margin-bottom: 20px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px 13px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 2px; background: var(--brand); }
.card .clbl {
  font-family: "IBM Plex Mono", monospace; font-size: 9.5px; font-weight: 500;
  letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
}
.card .cnum {
  font-family: "Archivo Expanded", "Archivo", sans-serif; font-weight: 800;
  font-size: 26px; line-height: 1.05; margin-top: 10px; letter-spacing: -.015em;
  font-variant-numeric: tabular-nums;
}
.card .cfoot { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 11px; color: var(--ink-2); }
.card .delta {
  font-family: "IBM Plex Mono", monospace; font-size: 10.5px; font-weight: 600;
  padding: 2px 7px; border-radius: 6px;
}
.card .delta.up { color: var(--green); background: var(--green-bg); }
.card .delta.down { color: var(--red); background: var(--red-bg); }
.card .since { color: var(--muted); font-size: 11px; }

/* data table */
table.report {
  border-collapse: separate; border-spacing: 0; width: 100%; font-size: 12.5px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow);
}
table.report th, table.report td { padding: 9px 14px; text-align: right; border-bottom: 1px solid var(--line); }
table.report th:first-child, table.report td:first-child { text-align: left; }
table.report tbody tr:last-child td { border-bottom: none; }
table.report thead th {
  font-family: "IBM Plex Mono", monospace; font-size: 9.5px; font-weight: 500;
  letter-spacing: .1em; text-transform: uppercase; color: var(--muted);
  background: var(--surface-2); position: sticky; top: 0; z-index: 3;
}
table.report tbody td { font-variant-numeric: tabular-nums; }
table.report tbody td:first-child { color: var(--ink-2); }
table.report tbody td .val { font-weight: 700; font-family: "IBM Plex Mono", monospace; font-size: 12px; }
table.report tbody td .moe { display: block; font-size: 10px; color: #A6ABB3; font-family: "IBM Plex Mono", monospace; margin-top: 1px; }
/* reliability marker: a small square, not a tinted cell — the number stays the hero */
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-left: 7px; vertical-align: 1px; }
.dot.green { background: var(--green); } .dot.amber { background: var(--amber); } .dot.red { background: var(--red); }
.dot.na { background: none; border: 1px solid var(--line-2); }
.flag {
  color: var(--teal); font-size: 9px; vertical-align: super;
  font-family: "IBM Plex Mono", monospace; margin-left: 3px;
}
table.report.multiyear th { white-space: nowrap; }
table.report td.delta { font-weight: 600; font-family: "IBM Plex Mono", monospace; font-size: 11.5px; color: var(--muted); }
table.report td.delta.up { color: var(--green); }
table.report td.delta.down { color: var(--red); }
.catch-title {
  font-family: "IBM Plex Mono", monospace; font-size: 11px; font-weight: 600;
  letter-spacing: .12em; text-transform: uppercase; color: var(--ink-2);
  margin: 20px 0 8px;
}
.catch-title:first-of-type { margin-top: 4px; }
.report td .notemark { color: var(--amber); font-size: 10px; vertical-align: super; cursor: help; margin-left: 2px; }
.report td.has-note { position: relative; }

/* legend / footnotes */
.legend {
  margin-top: 14px; padding: 12px 15px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); font-size: 11.5px;
  color: var(--ink); line-height: 1.55;
}
.legend h3 {
  margin: 0 0 8px; font-family: "IBM Plex Mono", monospace; font-size: 10px;
  font-weight: 600; letter-spacing: .13em; text-transform: uppercase; color: var(--muted);
}
.legend .legend-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); gap: 4px 18px; }
.legend .li { display: flex; align-items: baseline; gap: 7px; }
.legend .swatch { flex: none; width: 9px; height: 9px; border-radius: 2px; margin-top: 4px; }
.legend .swatch.green { background: var(--green); }
.legend .swatch.amber { background: var(--amber); }
.legend .swatch.red { background: var(--red); }
.legend .tag { flex: none; font-family: "IBM Plex Mono", monospace; font-size: 11px; }
.legend .muted { color: var(--muted); }
.legend .notes { margin-top: 9px; padding-top: 9px; border-top: 1px solid var(--line); color: var(--muted); }
.change-legend .notes { border-top: none; padding-top: 0; margin-top: 0; }
.provenance { font-family: "IBM Plex Mono", monospace; font-size: 10.5px; color: var(--muted); margin-top: 12px; line-height: 1.7; }

/* ───────── info tooltips (shared floating bubble, positioned by app.js) ───────── */
.info {
  display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; margin-left: 2px; border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--line-2); color: var(--muted);
  font-size: 10px; font-weight: 700; cursor: help; vertical-align: middle; user-select: none;
}
.info:hover, .info:focus { background: var(--ink); border-color: var(--ink); color: #fff; outline: none; }
.info-tip {
  position: fixed; top: 0; left: 0; z-index: 9999;
  max-width: min(290px, calc(100vw - 24px)); white-space: pre-wrap;
  max-height: calc(100vh - 16px); overflow-y: auto;
  background: var(--ink); color: #F3F3EF; padding: 10px 12px; border-radius: 9px;
  font-size: 11.5px; font-weight: 400; line-height: 1.5; letter-spacing: 0;
  text-transform: none; text-align: left; box-shadow: 0 8px 26px rgba(15,20,30,.3);
  opacity: 0; visibility: hidden; transition: opacity .12s ease; pointer-events: none;
}
.info-tip.show { opacity: 1; visibility: visible; }
.info-tip .info-tip-arrow { position: absolute; width: 0; height: 0; border: 6px solid transparent; }
.info-tip.below .info-tip-arrow { top: -12px; border-bottom-color: var(--ink); }
.info-tip.above .info-tip-arrow { bottom: -12px; border-top-color: var(--ink); }

/* ───────── report defaults ("save as my defaults") ───────── */
.prefs-row { display: flex; gap: 7px; margin-top: 14px; }
#prefs-note { margin-top: 7px; }
#prefs-note.error { color: var(--red); }

/* ───────── history drawer ───────── */
/* A right-side drawer rather than a modal dialog: rerun edits the controls on
   the way out, so the panel sits over the report, not over the whole app. */
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(23,25,30,.35); z-index: 1400;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 380px;
  max-width: calc(100vw - 24px); z-index: 1401;
  background: var(--surface); border-left: 1px solid var(--line);
  box-shadow: -12px 0 40px rgba(15,25,40,.16);
  display: flex; flex-direction: column;
  animation: drawer-in .18s ease-out;
}
@keyframes drawer-in { from { transform: translateX(16px); opacity: 0; } }
.drawer .dialog-head { flex: none; }
.drawer > .hint { padding: 10px 18px 0; margin: 0; flex: none; }
.drawer #history-close {
  border: none; background: none; font-size: 24px; line-height: 1;
  color: var(--muted); padding: 0 6px;
}
.drawer #history-close:hover { color: var(--ink); }
#history-body { padding: 12px 18px 18px; overflow-y: auto; flex: 1 1 auto; }
.hist-item {
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 8px; background: var(--surface-2);
}
.hist-title {
  font-weight: 600; font-size: 12.5px; line-height: 1.35;
  overflow-wrap: anywhere;   /* a long geocoded address must not widen the drawer */
}
.hist-meta {
  font-family: "IBM Plex Mono", monospace; font-size: 10.5px; color: var(--muted);
  margin-top: 3px; overflow-wrap: anywhere;
}
.hist-badge {
  font-family: "Archivo", sans-serif; font-size: 9.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--red); background: var(--red-bg);
  border-radius: 5px; padding: 1px 5px;
}
.hist-actions { display: flex; gap: 6px; margin-top: 9px; }
.hist-actions .ghost-btn { padding: 4px 10px; font-size: 11.5px; }
.hist-actions .ghost-btn:disabled { opacity: .45; cursor: not-allowed; }
@media (max-width: 720px) { .drawer { width: 100%; max-width: 100%; } }

/* ───────── cached-geographies dialog ───────── */
dialog#cache-dialog {
  border: none; border-radius: 14px; padding: 0; color: var(--ink);
  max-width: 580px; width: calc(100vw - 32px);
  box-shadow: 0 24px 70px rgba(15,25,40,.3);
}
dialog#cache-dialog::backdrop { background: rgba(23,25,30,.45); }
.dialog-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.dialog-head h2 { margin: 0; font-size: 14.5px; font-weight: 700; }
#cache-dialog .hint { padding: 10px 18px 0; margin: 0; }
#cache-dialog-close {
  border: none; background: none; font-size: 24px; line-height: 1;
  color: var(--muted); padding: 0 6px;
}
#cache-dialog-close:hover { color: var(--ink); }
#cache-dialog-body { padding: 10px 18px 18px; max-height: 62vh; overflow-y: auto; }
table.geo-table { border-collapse: collapse; width: 100%; font-size: 12px; }
.geo-table th, .geo-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.geo-table th {
  font-family: "IBM Plex Mono", monospace; font-size: 9.5px; font-weight: 500;
  letter-spacing: .1em; text-transform: uppercase; color: var(--muted);
}
.geo-table td.num, .geo-table th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.geo-state-row td {
  background: var(--surface-2); font-family: "IBM Plex Mono", monospace; font-weight: 600;
  color: var(--ink-2); text-transform: uppercase; font-size: 10px; letter-spacing: .1em;
}
.geo-badge {
  display: inline-block; font-size: 10px; padding: 1px 7px; border-radius: 7px;
  background: var(--teal-tint); color: var(--teal); border: 1px solid #C9DEE0;
  font-family: "IBM Plex Mono", monospace;
}
.geo-badge.muted { background: var(--surface-2); color: var(--muted); border-color: var(--line); }

/* ───────── upgrade prompt (opened only by a 402; dormant while plans are
   unlimited — PUBLIC_LAUNCH_PLAN §4) ───────── */
.upgrade-prompt {
  position: fixed; inset: 0; z-index: 2000; display: flex;
  align-items: center; justify-content: center; padding: 20px;
  background: rgba(23,25,30,.45);
}
.upgrade-card {
  background: var(--surface); border-radius: 14px; padding: 22px;
  max-width: 420px; width: 100%; box-shadow: 0 24px 70px rgba(15,25,40,.3);
}
.upgrade-card h2 { margin: 0 0 8px; font-size: 15px; font-weight: 700; }
.upgrade-card p { margin: 0 0 10px; color: var(--ink-2); }
.upgrade-note { font-size: 12px; color: var(--muted); }
#upgrade-close { margin-top: 4px; }

/* ───────── mobile / small screens ─────────
   Stack the rail above the map+report, let the page scroll naturally, and bump
   control font-size to 16px so iOS doesn't zoom on focus. Map-first flow:
   #workspace is display:contents so map / controls / report reorder freely. */
@media (max-width: 760px) {
  .appbar { height: auto; min-height: 52px; flex-wrap: wrap; padding: 9px 14px; gap: 8px 14px; }
  .banner { flex-basis: 100%; text-align: center; }

  #layout { display: flex; flex-direction: column; height: auto; }
  #workspace { display: contents; }
  main { order: 1; }
  #controls { order: 2; overflow: visible; border-right: none;
    border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
  #report-wrap { order: 3; flex: none; max-height: none; }
  #map { flex: none; height: 58vh; min-height: 280px; }
  #workspace.has-report #map { flex: none; height: 42vh; }

  /* 16px = iOS Safari's no-zoom threshold for focused form fields */
  input[type=text], input[type=number], select, .stepper-input input { font-size: 16px; }
  .add-btn, .ghost-btn, #origin-float #geocode-btn { font-size: 14px; padding: 9px 14px; }
  .compute { height: 48px; }
  .chip, .chip button { font-size: 13px; }
  .metric-item { padding-top: 8px; padding-bottom: 8px; }
  .year-chip { padding: 7px 12px; font-size: 13px; }
  #cache-dialog-body { max-height: 70vh; }

  /* Keep the floating origin search comfortably inside a phone viewport. */
  #origin-float { top: 8px; width: calc(100% - 20px); padding: 8px; }
  .report-head h2 { font-size: 18px; }
  .cards { grid-template-columns: 1fr 1fr; }
  #report-wrap { padding: 14px 14px 26px; }
}
@media (max-width: 430px) { .cards { grid-template-columns: 1fr; } }
