:root {
  --navy: #12263f;
  --navy-2: #1c3a5e;
  --accent: #c62828;
  --bg: #f4f6f9;
  --border: #d5dbe3;
  --text: #1d2733;
  --muted: #64748b;
  --ok: #2e7d32;
  --sidebar-w: 340px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; color: var(--text); background: var(--bg); font-size: 14px; }
button, input, select, textarea { font: inherit; }

/* ---------- Header ---------- */
#topbar {
  height: 52px; background: var(--navy); color: #fff; display: flex; align-items: center;
  padding: 0 12px; gap: 12px; position: relative; z-index: 1001; box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
#topbar .brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
#topbar .badge { width: 34px; height: 34px; border-radius: 6px; background: var(--accent); display: grid; place-items: center; font-weight: 800; font-size: 13px; }
#topbar h1 { font-size: 16px; margin: 0; font-weight: 600; line-height: 1.1; }
#topbar h1 small { display: block; font-weight: 400; font-size: 11px; opacity: .75; }
#menuBtn { display: none; background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; }

#searchWrap { flex: 1; max-width: 560px; position: relative; margin-left: 12px; }
#searchBox {
  width: 100%; padding: 8px 12px 8px 34px; border-radius: 6px; border: 0; outline: none; font-size: 14px;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat 10px center;
}
#searchResults {
  position: absolute; top: 40px; left: 0; right: 0; background: #fff; color: var(--text); border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25); max-height: 60vh; overflow: auto; display: none;
}
#searchResults .grp { padding: 6px 12px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: #f1f5f9; }
#searchResults .item { padding: 8px 12px; cursor: pointer; border-bottom: 1px solid #eef2f6; }
#searchResults .item:hover, #searchResults .item.active { background: #e8f0fe; }
#searchResults .item small { color: var(--muted); display: block; }
#searchResults .empty { padding: 10px 12px; color: var(--muted); }

#topbar .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.tb-btn { background: var(--navy-2); color: #fff; border: 1px solid rgba(255,255,255,.2); border-radius: 6px; padding: 7px 12px; cursor: pointer; white-space: nowrap; }
.tb-btn:hover { background: #24507f; }
.tb-btn.on { background: var(--accent); border-color: var(--accent); }

/* ---------- Layout ---------- */
#main { position: absolute; top: 52px; left: 0; right: 0; bottom: 0; display: flex; }
#sidebar { width: var(--sidebar-w); background: #fff; border-right: 1px solid var(--border); display: flex; flex-direction: column; z-index: 1000; }
#map { flex: 1; }

.tabs { display: flex; border-bottom: 1px solid var(--border); }
.tabs button { flex: 1; padding: 10px 4px; border: 0; background: none; cursor: pointer; color: var(--muted); border-bottom: 3px solid transparent; font-weight: 600; }
.tabs button.active { color: var(--navy); border-bottom-color: var(--accent); }
.tab { display: none; overflow: auto; flex: 1; padding: 10px 12px 20px; }
.tab.active { display: block; }

h3.sect { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 16px 0 6px; display: flex; align-items: center; justify-content: space-between; }
h3.sect:first-child { margin-top: 4px; }

.lyr { display: flex; align-items: center; gap: 8px; padding: 6px 4px; border-radius: 6px; }
.lyr:hover { background: #f5f7fa; }
.lyr input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--navy); }
.lyr .sw { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 10px; font-weight: 700; flex: none; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.25); }
.lyr .sw.sq { border-radius: 3px; }
.lyr .name { flex: 1; }
.lyr .name small { display: block; color: var(--muted); font-size: 11px; }
.lyr .cnt { font-size: 11px; background: #eef2f6; color: var(--muted); border-radius: 10px; padding: 1px 7px; }
.lyr .acts { display: flex; gap: 2px; }
.icon-btn { border: 0; background: none; cursor: pointer; padding: 4px 6px; border-radius: 4px; color: var(--muted); font-size: 13px; }
.icon-btn:hover { background: #e2e8f0; color: var(--text); }

.basemaps { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.basemaps label { border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; cursor: pointer; display: flex; gap: 6px; align-items: center; font-size: 13px; }
.basemaps label:has(input:checked) { border-color: var(--navy); background: #eef3fb; }

.btn { border: 1px solid var(--border); background: #fff; border-radius: 6px; padding: 7px 12px; cursor: pointer; }
.btn:hover { background: #f1f5f9; }
.btn.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn.primary:hover { background: var(--navy-2); }
.btn.danger { color: #b71c1c; border-color: #f0b4b4; }
.btn.danger:hover { background: #fdecec; }
.btn.block { width: 100%; }
.btn.sm { padding: 4px 8px; font-size: 12px; }
.row { display: flex; gap: 6px; align-items: center; }
.row > * { flex: 1; }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0 8px; }
.note { background: #fff8e1; border: 1px solid #ffe082; border-radius: 6px; padding: 8px 10px; font-size: 12px; }

.field { margin-bottom: 9px; }
.field label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 3px; color: #334155; }
.field input, .field select, .field textarea { width: 100%; padding: 7px 8px; border: 1px solid var(--border); border-radius: 5px; background: #fff; }
.field textarea { min-height: 60px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid #93c5fd; border-color: #60a5fa; }

/* ---------- Nearby results ---------- */
.near-item { padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; margin-bottom: 5px; cursor: pointer; display: flex; gap: 8px; align-items: center; }
.near-item:hover { background: #f5f7fa; }
.near-item .d { margin-left: auto; font-weight: 600; font-size: 12px; white-space: nowrap; }

/* ---------- Status bar ---------- */
#statusbar {
  position: absolute; bottom: 0; left: var(--sidebar-w); right: 0; height: 26px; background: rgba(18,38,63,.88); color: #fff;
  font-size: 12px; display: flex; align-items: center; gap: 18px; padding: 0 10px; z-index: 999; font-family: Consolas, monospace;
}
#statusbar .zoomwarn { margin-left: auto; color: #ffd54f; font-family: inherit; }
.leaflet-bottom.leaflet-right { bottom: 26px; }
.leaflet-bottom.leaflet-left { bottom: 26px; }

/* ---------- Map markers ---------- */
.cf-marker { display: grid; place-items: center; border-radius: 50%; color: #fff; font-weight: 800; font-size: 11px; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.5); font-family: Arial, sans-serif; line-height: 1; }
.cf-marker.oos { outline: 3px dashed #000; outline-offset: 1px; opacity: .75; }
.addr-label { background: rgba(255,255,255,.85); border: 0; box-shadow: none; padding: 0 3px; font-size: 11px; font-weight: 700; color: #0d47a1; }
.addr-label::before { display: none; }
.map-hide-addr-labels .addr-label { display: none; }
.pick-mode, .pick-mode .leaflet-interactive { cursor: crosshair !important; }
.measure-label { background: #12263f; color: #fff; border: 0; font-weight: 600; }
.measure-label::before { display: none; }

/* ---------- Popups ---------- */
.leaflet-popup-content { margin: 10px 12px; min-width: 230px; }
.pop h4 { margin: 0 0 2px; font-size: 14px; }
.pop .sub { color: var(--muted); font-size: 11px; margin-bottom: 6px; }
.pop table { border-collapse: collapse; width: 100%; font-size: 12px; }
.pop td { padding: 2px 4px; border-bottom: 1px solid #eef2f6; vertical-align: top; }
.pop td:first-child { color: var(--muted); white-space: nowrap; padding-right: 8px; }
.pop .acts { margin-top: 8px; display: flex; gap: 4px; flex-wrap: wrap; }
.pop .acts a, .pop .acts button { font-size: 12px; }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.55); z-index: 2000; display: none; align-items: center; justify-content: center; padding: 16px; }
.modal-bg.open { display: flex; }
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 560px; max-height: 92vh; display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.modal header { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.modal header h2 { font-size: 16px; margin: 0; flex: 1; }
.modal .body { padding: 14px 16px; overflow: auto; }
.modal footer { padding: 10px 16px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
.modal footer .left { margin-right: auto; }

.fld-row { display: grid; grid-template-columns: 1.3fr 1fr auto; gap: 6px; margin-bottom: 6px; align-items: start; }
.fld-row input, .fld-row select { padding: 6px; border: 1px solid var(--border); border-radius: 5px; width: 100%; }
.fld-row .opts { grid-column: 1 / 3; }

#toast { position: fixed; left: 50%; bottom: 44px; transform: translateX(-50%); background: #12263f; color: #fff; padding: 9px 16px; border-radius: 6px; z-index: 3000; display: none; box-shadow: 0 6px 20px rgba(0,0,0,.3); }
#toast.err { background: #b71c1c; }

#pickBanner { position: absolute; top: 62px; left: 50%; transform: translateX(-50%); background: var(--accent); color: #fff; padding: 8px 14px; border-radius: 6px; z-index: 1002; display: none; box-shadow: 0 4px 12px rgba(0,0,0,.3); }
#pickBanner button { margin-left: 10px; background: #fff; color: var(--accent); border: 0; border-radius: 4px; padding: 3px 8px; cursor: pointer; font-weight: 600; }

/* ---------- Legend ---------- */
.legend-sub { margin: 2px 0 6px 34px; font-size: 11px; color: var(--muted); }
.legend-sub span { display: inline-flex; align-items: center; gap: 4px; margin-right: 8px; }
.legend-sub i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  :root { --sidebar-w: 0px; }
  #menuBtn { display: block; }
  #topbar h1 small, #topbar .right .lbl { display: none; }
  #sidebar { position: absolute; top: 0; bottom: 0; left: 0; width: 320px; transform: translateX(-100%); transition: transform .2s; box-shadow: 4px 0 16px rgba(0,0,0,.25); }
  #sidebar.open { transform: none; }
  #statusbar { left: 0; }
  #statusbar .dms { display: none; }
  #searchWrap { margin-left: 0; }
}
@media print {
  #topbar, #sidebar, #statusbar, .leaflet-control-container { display: none !important; }
  #main { top: 0; }
}

/* ---------- Response districts ---------- */
.district-label { background: rgba(255,255,255,.82); border: 1px solid rgba(0,0,0,.25); border-radius: 4px; box-shadow: none;
  font-weight: 700; font-size: 11px; color: #111; padding: 1px 5px; white-space: nowrap; }
.district-label::before { display: none; }
.map-hide-district-labels .district-label { display: none; }
.dleg { cursor: pointer; padding: 3px 4px; }
.dleg .sw { width: 18px; height: 18px; }
.sw-inline { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: middle; border: 1px solid rgba(0,0,0,.3); }
#districtOpacity { accent-color: var(--navy); }
.dm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 6px; }
.dm-actions .btn:disabled { opacity: .5; cursor: default; }
.qs-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.qs-table th { text-align: left; font-size: 11px; color: var(--muted); padding: 4px; border-bottom: 1px solid var(--border); }
.qs-table td { padding: 3px 4px; border-bottom: 1px solid #eef2f6; vertical-align: middle; }
.qs-table input { width: 100%; padding: 5px 6px; border: 1px solid var(--border); border-radius: 4px; }
.esn-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px; margin-top: 6px; }
.esn-grid label { display: flex; align-items: center; gap: 4px; font-size: 12px; padding: 3px 5px; border: 1px solid var(--border); border-radius: 4px; cursor: pointer; }
.esn-grid label:has(input:checked) { background: #eef3fb; border-color: var(--navy); }
.esn-grid small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
details summary { cursor: pointer; margin: 4px 0; }
#drawBanner { position: absolute; top: 62px; left: 50%; transform: translateX(-50%); background: #12263f; color: #fff; padding: 8px 14px;
  border-radius: 6px; z-index: 1002; display: none; box-shadow: 0 4px 12px rgba(0,0,0,.3); max-width: 92vw; }
#drawBanner button { margin-left: 8px; background: #fff; color: #12263f; border: 0; border-radius: 4px; padding: 3px 9px; cursor: pointer; font-weight: 600; }

/* ---- boundary editor panel ---- */
#bndPanel { position: absolute; top: 62px; right: 12px; width: 330px; max-width: calc(100vw - 24px); background: #fff; border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.25); z-index: 1003; display: none; padding: 10px 12px; font-size: 13px; }
#bndPanel .bp-head { display: flex; align-items: center; gap: 8px; margin: -10px -12px 8px; padding: 8px 12px; background: var(--navy); color: #fff; border-radius: 8px 8px 0 0; }
#bndPanel .bp-count { margin-left: auto; background: #ffb300; color: #222; border-radius: 10px; padding: 1px 8px; font-size: 11px; font-weight: 600; }
#bndPanel .bp-count:empty { display: none; }
#bndPanel .bp-row { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
#bndPanel .bp-row label { font-size: 12px; color: var(--muted); min-width: 70px; }
#bndPanel .bp-row select { flex: 1; min-width: 0; padding: 4px; }
#bndPanel .bp-tools .btn { flex: 1 1 45%; }
#bndPanel .bp-hint { font-size: 12px; color: #334; background: #f4f6f9; border-radius: 6px; padding: 6px 8px; margin-bottom: 8px; line-height: 1.4; }
#bndPanel .bp-acres { display: inline-block; margin-left: 4px; font-weight: 600; color: var(--navy-2); }
#bndPanel .bp-foot { margin-bottom: 0; border-top: 1px solid var(--border); padding-top: 8px; }
.btn.on { background: var(--navy); color: #fff; border-color: var(--navy); }
@media (max-width: 820px) { #bndPanel { top: auto; bottom: 10px; right: 10px; left: 10px; width: auto; } }
