:root {
  --bg: #ffffff;
  --panel: #fafaf9;
  --text: #1c1917;
  --muted: #78716c;
  --line: #e7e5e4;
  --accent: #0f766e;
  --hover: #f0fdfa;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body { display: flex; flex-direction: column; }

header {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--bg);
}
.brand { font-weight: 700; font-size: 16px; white-space: nowrap; }
.brand span { color: var(--accent); }
.search { flex: 1; max-width: 640px; }
.search input {
  width: 100%; padding: 9px 12px; font-size: 14px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel); outline: none;
}
.search input:focus { border-color: var(--accent); background: #fff; }
.stats { margin-left: auto; color: var(--muted); white-space: nowrap; font-size: 13px; }

main { flex: 1; display: flex; min-height: 0; }
aside {
  width: 380px; flex-shrink: 0; overflow-y: auto;
  border-right: 1px solid var(--line); background: var(--panel);
}
#map { flex: 1; position: relative; }

.empty { padding: 24px 20px; }
.muted { color: var(--muted); }

/* search results */
.result { padding: 10px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.result:hover { background: var(--hover); }
.result .addr { font-weight: 600; }
.result .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.results-head { padding: 8px 16px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); }

/* detail */
#detail { padding: 16px; }
.d-title { font-size: 17px; font-weight: 700; margin: 0 0 2px; }
.d-sub { color: var(--muted); margin-bottom: 12px; }
.chip {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px;
  font-weight: 600; color: #fff; margin-bottom: 12px;
}
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 10px; margin: 0 0 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 0 8px; }
details { border: 1px solid var(--line); border-radius: 8px; background: #fff; margin-bottom: 8px; }
details summary { padding: 8px 10px; cursor: pointer; font-weight: 600; }
details .kv { padding: 0 10px 10px; grid-template-columns: 110px 1fr; font-size: 12.5px; margin: 0; }
.back { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; margin-bottom: 10px; font-size: 13px; }

.zoomhint {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 2;
  background: rgba(28,25,23,.85); color: #fff; padding: 6px 12px; border-radius: 999px; font-size: 13px;
}
.legend {
  position: absolute; bottom: 28px; left: 12px; z-index: 2;
  background: rgba(255,255,255,.95); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; font-size: 12px; line-height: 1.7;
}
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }

@media (max-width: 760px) {
  main { flex-direction: column-reverse; }
  aside { width: 100%; height: 45%; border-right: 0; border-top: 1px solid var(--line); }
  .stats { display: none; }
}

/* ---------------------------------------------------------------- user menu */
.user { display: flex; align-items: center; gap: 12px; font-size: 13px; white-space: nowrap; }
.user-email { color: var(--muted); }
.user a { color: var(--accent); text-decoration: none; font-weight: 600; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; }
button.link.danger { color: #b91c1c; }

/* ---------------------------------------------------------------- sign-in */
.auth-overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(250,250,249,.97); padding: 16px;
}
.auth-overlay[hidden] { display: none; }
.auth-card {
  width: 100%; max-width: 380px; background: #fff; border: 1px solid var(--line);
  border-radius: 12px; padding: 28px; box-shadow: 0 10px 30px rgba(0,0,0,.06);
}
.auth-card .brand { margin-bottom: 18px; font-size: 18px; }
.auth-lead { font-weight: 600; font-size: 15px; margin: 0 0 12px; }
.auth-msg { color: #b91c1c; font-size: 13px; }
.auth-dev { background: #fef9c3; border: 1px solid #fde68a; border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.auth-card form { display: grid; gap: 10px; }
.auth-card input, .add-form input, .add-form select {
  padding: 9px 12px; font-size: 14px; border: 1px solid var(--line); border-radius: 8px; outline: none; background: #fff;
}
.auth-card input:focus, .add-form input:focus { border-color: var(--accent); }
.auth-card button:not(.link), .add-form button {
  padding: 9px 14px; font-size: 14px; font-weight: 600; border: 0; border-radius: 8px;
  background: var(--accent); color: #fff; cursor: pointer;
}
.auth-card button:disabled { opacity: .6; cursor: default; }
.auth-card button.link { margin-top: 12px; }

/* ---------------------------------------------------------------- admin */
body.admin { display: block; overflow-y: auto; }
.brand small { color: var(--muted); font-weight: 500; font-size: 13px; margin-left: 6px; }
body.admin header .user { margin-left: auto; }
.admin-main { max-width: 980px; margin: 0 auto; padding: 24px 16px 48px; }
.admin-main h1 { font-size: 20px; margin: 0 0 4px; }
.add-form { display: flex; gap: 8px; margin: 18px 0 10px; flex-wrap: wrap; }
.add-form input { flex: 1; min-width: 220px; }
.msg { padding: 8px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 10px; }
.msg.ok { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.msg.err { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
     background: var(--panel); padding: 10px 12px; border-bottom: 1px solid var(--line); }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr.inactive td { color: var(--muted); }
td.actions { white-space: nowrap; }
td.actions button + button { margin-left: 12px; }
td select { padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.tag { font-size: 11px; background: #e0f2f1; color: var(--accent); border-radius: 999px; padding: 1px 7px; margin-left: 4px; }
.small { font-size: 12px; }

/* ---------------------------------------------------------------- summary areas */
.metric {
  position: absolute; top: 12px; left: 12px; z-index: 3; display: flex;
  background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 3px; gap: 2px;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
.metric[hidden] { display: none; }
.metric button {
  border: 0; background: none; padding: 6px 10px; border-radius: 6px; cursor: pointer;
  font: inherit; font-size: 12.5px; color: var(--muted);
}
.metric button.on { background: var(--text); color: #fff; }
.zoomhint { top: auto; bottom: 28px; left: auto; right: 12px; transform: none; }
.legend-title { font-weight: 600; margin-bottom: 2px; }
.hover-tip .maplibregl-popup-content { padding: 8px 10px; border-radius: 8px; font-size: 12.5px; min-width: 150px; }
.tip-name { font-weight: 700; margin-bottom: 4px; }
.tip-row { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); }
.tip-row b { color: var(--text); font-weight: 600; }
.zoom-btn {
  margin: 4px 0 6px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; cursor: pointer; font: inherit; font-size: 13px; color: var(--accent); font-weight: 600;
}
.cat-bars { display: grid; gap: 8px; }
.cat-row { display: grid; grid-template-columns: 1fr auto; gap: 3px 8px; font-size: 13px; }
.cat-label i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.cat-val { text-align: right; }
.cat-track { grid-column: 1 / -1; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.cat-track span { display: block; height: 100%; border-radius: 3px; }

/* ---------------------------------------------------------------- map tools: filters + basemap */
.map-tools { position: absolute; top: 12px; left: 12px; z-index: 3; display: flex; gap: 8px; align-items: flex-start; }
.map-tools .metric { position: static; }
.tool-btn, .basemap {
  background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
.tool-btn { padding: 8px 12px; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--text); }
.tool-btn.on { border-color: var(--accent); color: var(--accent); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 999px;
         background: var(--accent); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
.badge[hidden] { display: none; }
.filters {
  position: absolute; top: 56px; left: 12px; z-index: 3; width: 280px; max-height: calc(100% - 120px); overflow-y: auto;
  background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.10); font-size: 13px;
}
.filters[hidden] { display: none; }
.f-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.f-group { margin-bottom: 12px; }
.f-label { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.f-cats { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 8px; }
.f-cats label { display: flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.f-cats i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.f-range { display: flex; align-items: center; gap: 6px; }
.f-range input { width: 100%; min-width: 0; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
.f-range input:focus { outline: none; border-color: var(--accent); }
.f-note { color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); padding-top: 8px; }
.basemap { position: absolute; top: 12px; right: 52px; z-index: 3; display: flex; padding: 3px; gap: 2px; }
.basemap button { border: 0; background: none; padding: 6px 10px; border-radius: 6px; cursor: pointer; font: inherit; font-size: 12.5px; color: var(--muted); }
.basemap button.on { background: var(--text); color: #fff; }
@media (max-width: 760px) { .filters { width: calc(100% - 24px); } .basemap { top: auto; bottom: 28px; right: 12px; } }

/* ---------------------------------------------------------------- detail links */
.links { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; }
.links a { color: var(--accent); font-weight: 600; text-decoration: none; }
.links a:hover { text-decoration: underline; }

.redacted { color: var(--muted); font-style: italic; cursor: help; }

/* ---------------------------------------------------------------- data coverage page */
.coverage-main { max-width: 1180px; }
.coverage-main h2 { font-size: 16px; margin: 28px 0 10px; }
.cov { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.cov.full { background: #dcfce7; color: #166534; }
.cov.partial { background: #fef3c7; color: #92400e; }
.cov.none { background: var(--panel); color: var(--muted); border: 1px solid var(--line); }
.cov-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; margin-top: 18px; }
.cov-card { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: #fff; }
.cov-card-head { font-size: 15px; margin-bottom: 2px; }
.cov-headline { display: flex; flex-wrap: wrap; gap: 4px; margin: 10px 0 2px; }
.cov-note { color: var(--muted); margin: 8px 0 0; line-height: 1.45; }
.cov-table th:not(:first-child), .cov-table td.cov-cell { text-align: center; }
.cov-table td { padding: 7px 10px; }
.cov-table td.cov-field { white-space: nowrap; position: sticky; left: 0; background: #fff; }
.cov-table td.cov-field code { color: var(--muted); font-size: 11px; margin-left: 4px; }
.cov-table tr.cov-group td { background: var(--panel); font-size: 12px; font-weight: 700; text-transform: uppercase;
                             letter-spacing: .04em; color: var(--muted); position: static; }
.cov-pct { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
@media (max-width: 760px) { .cov-table td.cov-field code { display: none; } }

/* ---------------------------------------------------------------- admin: users table + drawer */
table.users tbody tr { cursor: pointer; }
table.users tbody tr:hover td, table.users tbody tr:focus td { background: var(--hover); }
table.users tbody tr:focus { outline: none; }
td.chips { white-space: nowrap; }
.chip-s { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; margin: 0 4px 2px 0;
          border-radius: 999px; background: #e0f2f1; color: var(--accent); }
.muted-chip { background: var(--panel); color: var(--muted); border: 1px solid var(--line); }
.warn-chip { background: #fef3c7; color: #92400e; }

.drawer-backdrop { position: fixed; inset: 0; background: rgba(28,25,23,.25); z-index: 40; }
.drawer-backdrop[hidden], .drawer[hidden] { display: none; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 100%); z-index: 41;
  background: #fff; border-left: 1px solid var(--line); box-shadow: -12px 0 32px rgba(0,0,0,.10);
  display: flex; flex-direction: column; padding: 18px 20px; gap: 16px; overflow-y: auto;
}
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.drawer-title { font-size: 16px; font-weight: 700; word-break: break-all; }
.icon-btn { border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); padding: 0 4px; }
.drawer .field { display: grid; gap: 6px; }
.drawer .field > label, .drawer .label { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.drawer select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font: inherit; }
.drawer .radio { display: flex; gap: 8px; align-items: center; font-size: 13.5px; cursor: pointer; }
.toggle-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 0 24px; }
.toggle-chips.dim { opacity: .45; }
.tchip { border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: 999px;
         padding: 5px 12px; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.tchip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.tchip:disabled { cursor: default; }
.note { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13px; margin: 0; }
.warn { color: #92400e; margin: 4px 0 0 24px; }
.drawer-foot { margin-top: auto; display: flex; align-items: center; gap: 10px; padding-top: 12px; border-top: 1px solid var(--line); }
.drawer-foot .spacer { flex: 1; }
.btn-primary, .btn-secondary { padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; }
.btn-primary { background: var(--accent); color: #fff; border: 0; }
.btn-secondary { background: #fff; color: var(--text); border: 1px solid var(--line); }

/* ---------------------------------------------------------------- map: state switcher, no-access */
.state-switch { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel);
                font: inherit; font-size: 13px; color: var(--text); cursor: pointer; }
.state-switch[hidden] { display: none; }
.no-access { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 4;
             max-width: 340px; background: #fff; border: 1px solid var(--line); border-radius: 12px;
             padding: 18px 20px; box-shadow: 0 10px 30px rgba(0,0,0,.10); text-align: center; }
.no-access[hidden] { display: none; }
.no-access p { margin: 6px 0 0; color: var(--muted); font-size: 13.5px; }
@media (max-width: 760px) { .state-switch { max-width: 120px; } }
