:root {
  --text: #222;
  --muted: #666;
  --line: #ddd;
  --bg: #fff;
  --soft: #f4f6f8;
  --brand: #2f5680;
  --brand-dark: #24466a;
  --danger: #b3261e;
  --warn: #8a5a00;
  --map-bg: #fff;
  --map-fill: #6a8caf;
  --map-fill-hover: #5a7ea4;
  --map-fill-sel: #2f5680;
  --map-line: #fff;
  --map-county: rgba(255, 255, 255, 0.25);
  --map-empty: #b9c8d8;
  --hatch: #8ea6bf;
  --font: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.5; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.vh { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.page { max-width: 1280px; margin: 0 auto; padding-inline: 16px; padding-block: 24px 40px; }
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 12px; }
.page-head h1 { margin: 0; font-size: 26px; font-weight: 700; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.admin-entry { display: flex; gap: 8px; flex-wrap: wrap; }
.admin-entry form { margin: 0; }

.finder { position: relative; display: flex; gap: 8px; max-width: 560px; margin: 18px 0 20px; }
.finder input { flex: 1; min-width: 0; height: 40px; padding: 0 10px; border: 1px solid #bbb; border-radius: 3px; background: #fff; }
.finder input:focus { border-color: var(--brand); outline: none; }
.suggest { position: absolute; z-index: 20; left: 0; right: 0; top: 100%; margin: 2px 0 0; padding: 0; list-style: none; background: #fff; border: 1px solid #bbb; max-height: 300px; overflow-y: auto; }
.suggest li { padding: 7px 10px; cursor: pointer; display: flex; justify-content: space-between; gap: 12px; }
.suggest li[aria-selected="true"], .suggest li:hover { background: var(--soft); }
.suggest .muted { color: var(--muted); font-size: 13px; white-space: nowrap; }

.btn { height: 40px; padding: 0 16px; border: 1px solid #bbb; border-radius: 3px; background: #fff; white-space: nowrap; }
.btn:hover { background: var(--soft); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 14px; }
.btn-link { border: 0; background: none; padding: 0; height: auto; color: var(--brand); text-decoration: underline; }
.btn-link:hover { background: none; }
.btn-danger { color: var(--danger); }
.btn[aria-pressed="true"] { background: var(--soft); border-color: var(--brand); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 32px; align-items: start; }
@media (max-width: 900px) { .layout { grid-template-columns: minmax(0, 1fr); gap: 20px; } }

.map-box { position: relative; aspect-ratio: 975 / 610; max-height: 78vh; width: 100%; max-width: 100%; background: var(--map-bg); touch-action: none; }
.map-box svg { display: block; width: 100%; height: 100%; }
.map-box.paint svg { cursor: crosshair; }
.map-status { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }

.county { fill: var(--map-fill); stroke: var(--map-county); stroke-linejoin: round; }
.county.un { fill: url(#hatch); }
.county.no-data { fill: var(--map-empty); }
.county.in { fill: var(--map-fill-sel); }
.county.hover { fill: var(--map-fill-hover); }
.county.in.hover { fill: var(--map-fill-sel); }
.county.picked { stroke: var(--map-line); }
.b-territory { fill: none; stroke: var(--map-line); stroke-linejoin: round; stroke-linecap: round; pointer-events: none; }
.b-selected { fill: none; stroke: var(--map-line); stroke-linejoin: round; stroke-linecap: round; pointer-events: none; }
.hatch-bg { fill: var(--map-empty); }
.hatch-line { stroke: var(--hatch); stroke-width: 1.4; }
.lbl { font-family: var(--font); font-weight: 700; fill: #fff; paint-order: stroke; stroke: rgba(24, 44, 68, .7); stroke-linejoin: round; pointer-events: none; text-anchor: middle; dominant-baseline: central; }

.map-tools { position: absolute; left: 0; top: 0; display: flex; flex-direction: column; gap: 4px; }
.map-tools button { width: 30px; height: 30px; border: 1px solid #bbb; border-radius: 3px; background: #fff; font-size: 17px; line-height: 1; display: grid; place-items: center; }
.map-tools button:hover { background: var(--soft); }
.map-wrap { position: relative; min-width: 0; }
.chips { position: absolute; right: 0; top: 30%; display: grid; grid-template-columns: repeat(2, 44px); gap: 7px; }
.chips button { height: 28px; border: 0; border-radius: 6px; background: var(--map-fill); color: #fff; font-weight: 700; font-size: 13px; }
.chips button:hover, .chips button[aria-pressed="true"] { background: var(--map-fill-sel); }
.city-dot { fill: #1b2a3a; stroke: #fff; pointer-events: none; }
.city-lbl { font-family: var(--font); font-weight: 600; fill: #fff; paint-order: stroke; stroke: rgba(24, 44, 68, .7); stroke-linejoin: round; dominant-baseline: central; pointer-events: none; }
.paint-banner { position: absolute; left: 40px; top: 0; right: 100px; padding: 6px 10px; background: var(--brand); color: #fff; font-size: 14px; }

.tip { position: fixed; z-index: 30; pointer-events: none; padding: 6px 9px; background: #fff; border: 1px solid #bbb; font-size: 13px; max-width: 260px; box-shadow: 0 2px 6px rgba(0, 0, 0, .12); }
.tip b { display: block; }

.side { display: grid; gap: 24px; min-width: 0; }
.side h2 { margin: 0 0 4px; font-size: 20px; }
.side h3 { margin: 16px 0 6px; font-size: 15px; }
.side p { margin: 0 0 8px; }
.where { color: var(--muted); font-size: 14px; }
.rep { padding: 10px 0; border-top: 1px solid var(--line); line-height: 1.6; }
.rep:first-of-type, .rep-label + .rep { border-top: 0; padding-top: 2px; }
.rep > span { display: block; color: var(--muted); font-size: 15px; }
.rep > .rep-name { color: var(--brand); font-size: 16px; }
.rep a { text-decoration: none; overflow-wrap: anywhere; }
.rep a:hover { text-decoration: underline; }
.rep-label { margin: 18px 0 6px; font-size: 14px; font-weight: 700; color: var(--muted); letter-spacing: .02em; }
.browse { border-top: 1px solid var(--line); padding-top: 16px; display: grid; gap: 6px; }
.browse label { font-size: 14px; color: var(--muted); }
.browse select, .field input, .field select { width: 100%; height: 36px; padding: 0 8px; border: 1px solid #bbb; border-radius: 3px; background: #fff; min-width: 0; }

.admin { display: grid; gap: 20px; border-top: 2px solid var(--brand); padding-top: 16px; }
.admin section { display: grid; gap: 10px; }
.admin section + section { border-top: 1px solid var(--line); padding-top: 16px; }
.admin h3 { margin: 0; }
.admin .hint { color: var(--muted); font-size: 14px; margin: 0; }
.field { display: grid; gap: 3px; }
.field label { font-size: 13px; color: var(--muted); }
.field input[aria-invalid="true"] { border-color: var(--danger); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (max-width: 420px) { .grid2 { grid-template-columns: 1fr; } }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.rep-edit { display: grid; gap: 8px; padding: 10px; background: var(--soft); }
.county-list { display: flex; flex-wrap: wrap; gap: 4px; max-height: 170px; overflow-y: auto; }
.county-list button { border: 1px solid var(--line); background: #fff; border-radius: 3px; padding: 1px 7px; font-size: 13px; }
.county-list button:hover { border-color: var(--brand); }

.savebar { position: sticky; bottom: 0; z-index: 15; margin-top: 24px; display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; justify-content: space-between; padding: 10px 0; padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); background: #fff; border-top: 1px solid var(--line); }
.save-state.dirty { color: var(--warn); font-weight: 700; }
.toast { position: fixed; left: 50%; bottom: calc(72px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 40; background: #333; color: #fff; padding: 8px 14px; border-radius: 3px; max-width: calc(100% - 32px); }

.login { min-height: 100vh; display: grid; place-items: center; padding-inline: 16px; padding-block: 32px; }
.login-card { width: 100%; max-width: 340px; display: grid; gap: 12px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card .btn { width: 100%; }
.notice { margin: 0; padding: 8px 10px; background: #fdf1e0; color: var(--warn); font-size: 14px; }
.suggest li.group { font-weight: 700; }
.rep .btn-link { font-size: 16px; font-weight: 700; text-align: left; }
.hint { color: var(--muted); font-size: 14px; margin: 0; }

@media (max-width: 600px) {
  body { font-size: 17px; }
  .page { padding-block: 16px 32px; }
  .page-head h1 { font-size: 23px; line-height: 1.25; }
  .page-head p { font-size: 16px; }
  .finder { margin: 14px 0 16px; }
  .finder input, .finder .btn { height: 48px; font-size: 17px; }
  .suggest li { padding: 12px 10px; font-size: 16px; }
  .suggest .muted { font-size: 14px; }
  .map-box { margin-bottom: 42px; }
  .map-tools { top: auto; left: auto; right: 0; bottom: -40px; flex-direction: row; gap: 5px; }
  .map-tools button { width: 34px; height: 34px; font-size: 18px; }
  .chips { position: static; display: flex; flex-wrap: nowrap; justify-content: space-between; gap: 5px; margin-top: 2px; }
  .chips button { flex: 0 1 38px; min-width: 34px; height: 28px; font-size: 12px; border-radius: 5px; }
  .side h2 { font-size: 23px; }
  .side h3 { font-size: 17px; }
  .where { font-size: 16px; }
  .rep-label { font-size: 15px; }
  .rep > span { font-size: 17px; }
  .rep > .rep-name { font-size: 19px; }
  .rep a { display: inline-block; padding-block: 4px; }
  .rep .btn-link { font-size: 18px; }
  .browse label { font-size: 16px; }
  .browse select, .field input, .field select { height: 46px; font-size: 16px; }
  .btn { height: 46px; }
  .btn-sm { height: 40px; font-size: 15px; }
  .savebar .row { width: 100%; }
  .savebar .btn { flex: 1; }
  .tip { display: none; }
}
