:root {
  --bg: #f6f6f3;
  --panel: #ffffff;
  --ink: #1f2a24;
  --muted: #5d6a62;
  --line: #d9ddd6;
  --accent: #2f6b4f;
  --accent-ink: #ffffff;
  --accent-soft: #e4efe8;
  --warn-bg: #fff4d6;
  --warn-ink: #6b4e00;
  --err-bg: #fde8e6;
  --err-ink: #8a1c12;
  --ok-bg: #e4efe8;
  --ok-ink: #1f4d36;
  --radius: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 var(--font); color: var(--ink); background: var(--bg); }
a { color: var(--accent); }
h1 { font-size: 20px; margin: 0 0 12px; }
h2 { font-size: 16px; margin: 20px 0 8px; }
h3 { font-size: 14px; margin: 16px 0 6px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 16px; padding: 0 16px; height: 48px;
  background: var(--accent); color: var(--accent-ink); }
.topbar .brand { font-weight: 600; white-space: nowrap; color: var(--accent-ink); text-decoration: none; }
.topbar nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; }
.topbar nav a { color: #dcebe2; text-decoration: none; padding: 6px 10px; border-radius: var(--radius); white-space: nowrap; }
.topbar nav a:hover { background: rgba(255,255,255,.12); color: #fff; }
.topbar nav a.active { background: rgba(255,255,255,.2); color: #fff; }
.topbar .who { display: flex; align-items: center; gap: 8px; white-space: nowrap; font-size: 13px; }
.topbar .who button { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.5); }

main.page { max-width: 1280px; margin: 0 auto; padding: 20px 16px 48px; }
main.full { height: calc(100vh - 48px); display: flex; }

/* ---------- controls ---------- */
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 6px 12px; border-radius: var(--radius); cursor: pointer; text-decoration: none; display: inline-block; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--err-ink); border-color: #e5b4ae; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; padding: 5px 8px; border: 1px solid #c4cac1; border-radius: var(--radius);
  background: #fff; color: var(--ink); min-width: 0; }
input[type=checkbox] { width: 16px; height: 16px; }
textarea { width: 100%; min-height: 70px; }
label { font-size: 13px; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 3px; }
.field input, .field select { width: 100%; }
.field input[type=checkbox], .field input[type=radio] { width: 16px; flex: none; }
.field .check { justify-content: flex-start; }
.field .err { color: var(--err-ink); font-size: 12px; }
.field.invalid input, .field.invalid select { border-color: var(--err-ink); }
.field .hint { font-size: 12px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 6px; color: var(--ink); }

.flash { padding: 8px 12px; border-radius: var(--radius); margin-bottom: 12px; }
.flash.ok { background: var(--ok-bg); color: var(--ok-ink); }
.flash.error { background: var(--err-bg); color: var(--err-ink); }
.note { background: var(--warn-bg); color: var(--warn-ink); padding: 8px 12px; border-radius: var(--radius); margin: 8px 0 12px; }
.muted { color: var(--muted); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.grid { display: grid; gap: 12px; }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 860px) { .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 520px) { .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; } }

/* ---------- tables ---------- */
.table-wrap { overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; }
table.data th, table.data td { padding: 6px 8px; border-bottom: 1px solid #eceee9; text-align: left; vertical-align: top; }
table.data th { position: sticky; top: 0; background: #f0f2ee; font-weight: 600; white-space: nowrap; z-index: 1; }
table.data th a { color: var(--ink); text-decoration: none; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover td { background: #f5f8f4; }
table.data tr.selected td { background: var(--accent-soft); }
table.data tfoot td { font-weight: 600; background: #f0f2ee; }

.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; white-space: nowrap; }
.pill.hroa { background: #e0efe6; color: #1f5c3d; }
.pill.review { background: #fde6dc; color: #8a2f0d; }
.pill.county { background: #ece4f6; color: #4b2a7a; }
.pill.csd { background: #e0ebf7; color: #1d4677; }
.pill.private { background: #f1e9df; color: #6a4520; }
.pill.not_started { background: #eceeea; color: #4a524d; }
.pill.scheduled { background: #dfeafa; color: #1d4677; }
.pill.in_progress { background: #fff1cf; color: #6b4e00; }
.pill.complete { background: #dcefe3; color: #1f5c3d; }
.pill.good { background: #dcefe3; color: #1f5c3d; }
.pill.fair { background: #fbf2c9; color: #6b5800; }
.pill.poor { background: #fde3cf; color: #8a3d0d; }
.pill.failed { background: #f9d9d5; color: #8a1c12; }
.pill.open { background: #fde6dc; color: #8a2f0d; }
.pill.resolved { background: #dcefe3; color: #1f5c3d; }
.pill.dismissed { background: #eceeea; color: #4a524d; }

/* ---------- map page ---------- */
.sidebar { width: 300px; flex: none; background: var(--panel); border-right: 1px solid var(--line);
  overflow-y: auto; padding: 12px 14px; }
.sidebar h2 { font-size: 13px; text-transform: none; color: var(--muted); margin: 14px 0 6px; }
.sidebar .layer { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.map { flex: 1; min-width: 0; position: relative; }
.legend { margin-top: 6px; }
.legend .row { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 1px 0; }
.legend .swatch { width: 22px; height: 5px; border-radius: 2px; flex: none; }
.maplibregl-popup-content { font: 13px/1.4 var(--font); padding: 10px 12px; max-width: 280px; }
.popup h4 { margin: 0 0 4px; font-size: 14px; }
.popup dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 1px 10px; }
.popup dt { color: var(--muted); }
.popup dd { margin: 0; }
@media (max-width: 760px) {
  main.full { flex-direction: column-reverse; height: auto; }
  .sidebar { width: 100%; border-right: 0; border-top: 1px solid var(--line); }
  .map { height: 62vh; }
}

/* ---------- inventory ---------- */
.split { display: grid; grid-template-columns: minmax(0, 3fr) minmax(320px, 2fr); gap: 12px; align-items: start; }
.split .mini-map { position: sticky; top: 12px; height: 520px; border: 1px solid var(--line); border-radius: var(--radius); }
@media (max-width: 1000px) { .split { grid-template-columns: 1fr; } .split .mini-map { position: static; height: 320px; } }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; margin-bottom: 10px; }
.filters .field { min-width: 120px; }
.filters .field.grow { flex: 1; min-width: 180px; }
.bulk { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; padding: 10px; margin: 10px 0; }
.summary { margin: 6px 0; color: var(--muted); }
.table-scroll { max-height: 560px; }
td.fromto { min-width: 190px; }
table.data td.mono { white-space: nowrap; }

/* ---------- segment form ---------- */
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 14px; }
.form-grid .wide { grid-column: span 3; }
@media (max-width: 760px) { .form-grid { grid-template-columns: 1fr; } .form-grid .wide { grid-column: span 1; } }
.readonly { background: #f3f4f1; padding: 5px 8px; border-radius: var(--radius); min-height: 31px; }
.seg-head { display: flex; justify-content: space-between; align-items: start; gap: 12px; flex-wrap: wrap; }
.seg-map { height: 260px; border: 1px solid var(--line); border-radius: var(--radius); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 360px; }
.login h1 { margin-bottom: 4px; }
.login form { display: grid; gap: 10px; margin-top: 14px; }

/* layer legend swatches and parcel editing */
.swatch { display: inline-block; vertical-align: middle; }
.sidebar .layer .swatch { width: 18px; height: 4px; flex: none; }
.swatch.area { height: 12px; border: 2px solid; border-radius: 2px; background: transparent; }
.swatch.dot { width: 8px; height: 8px; border-radius: 50%; margin: 0 7px; }
.sidebar .layer .swatch { width: 18px; }
.parcel-edit { margin-top: 8px; display: grid; gap: 4px; font-size: 12.5px; }
.parcel-edit button { padding: 2px 8px; font-size: 12px; margin-left: 4px; }
.sidebar .basemaps label { display: flex; gap: 6px; align-items: center; }
.sidebar .layer .swatch.area { height: 12px; width: 18px; }
.sidebar .layer .swatch.dot { width: 8px; height: 8px; margin: 0 5px; }

/* ---------- accounts ---------- */
fieldset.plain { border: 0; margin: 0; padding: 0; min-width: 0; }
.topbar .who a { color: #fff; text-decoration: none; }
.topbar .who a.active, .topbar .who a:hover { text-decoration: underline; }
.login .links { font-size: 13px; margin-top: 10px; }
.policy { font-size: 12px; color: var(--muted, #666); }
.secret { font-family: ui-monospace, Menlo, monospace; font-size: 15px; letter-spacing: .04em; }
.codes { font-family: ui-monospace, Menlo, monospace; font-size: 16px; columns: 2; list-style: none; padding: 0; }
.codes li { padding: 4px 0; }
.link-box { width: 100%; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.account-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; align-items: start; }
.qr svg { width: 240px; height: 240px; display: block; }
.copy-row { display: flex; gap: 8px; margin: 4px 0 8px; }
.copy-row .link-box { flex: 1; min-width: 0; }
