/*
 * Public data explorer. Standalone from style.css on purpose: the staff site's
 * global rules (header, containers, tables) are not meant for this page, and
 * keeping them apart lets either change without breaking the other.
 */

:root {
    --green: #6b8e3d;
    --green-dark: #2d4a15;
    --green-tint: #eef3e6;
    --brown: #8d6e63;
    --ink: #1f2419;
    --ink-2: #4a4d44;
    --muted: #6f716a;
    --line: #dfe2d8;
    --surface: #f6f6f2;
    --card: #ffffff;
    --shadow: 0 1px 2px rgba(20, 30, 10, 0.06), 0 2px 10px rgba(20, 30, 10, 0.05);
    --radius: 10px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    margin: 0;
    font-family: 'Roboto', system-ui, -apple-system, sans-serif;
    color: var(--ink);
    background: var(--surface);
    line-height: 1.5;
    font-size: 15px;
}

h1, h2, h3, h4 { line-height: 1.25; margin: 0; }

button { font: inherit; }

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); border: 0;
}

.pub-wrap {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
}

.muted { color: var(--muted); }

/* --- header ------------------------------------------------------------- */

.pub-header {
    background: var(--card);
    border-bottom: 1px solid var(--line);
}

.pub-header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 68px;
}

.pub-brand img { height: 44px; display: block; }

.pub-header-links { display: flex; gap: 20px; align-items: center; }

.pub-header-links a {
    color: var(--ink-2);
    text-decoration: none;
    font-weight: 500;
}

.pub-header-links a:hover { color: var(--green-dark); }

.pub-staff {
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 6px 14px;
    font-size: 14px;
}

/* --- hero --------------------------------------------------------------- */

.pub-hero {
    background: linear-gradient(180deg, #ffffff 0%, var(--green-tint) 100%);
    border-bottom: 1px solid var(--line);
    padding: 34px 0 26px;
}

.pub-hero h1 {
    font-size: clamp(26px, 3.4vw, 38px);
    color: var(--green-dark);
    letter-spacing: -0.01em;
}

.pub-lede {
    max-width: 760px;
    margin: 10px 0 18px;
    color: var(--ink-2);
    font-size: 17px;
}

.pub-headline {
    list-style: none;
    padding: 0;
    margin: 0 0 18px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px 28px;
    color: var(--ink-2);
}

.pub-headline strong {
    color: var(--ink);
    font-size: 20px;
    font-variant-numeric: tabular-nums;
}

.pub-questions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.pub-questions-label { color: var(--muted); font-size: 14px; margin-right: 4px; }

.pub-chip {
    border: 1px solid #c9d4b8;
    background: #fff;
    color: var(--green-dark);
    border-radius: 999px;
    padding: 6px 14px;
    font-size: 14px;
    cursor: pointer;
}

.pub-chip:hover { background: var(--green-dark); color: #fff; border-color: var(--green-dark); }

/* --- filters ------------------------------------------------------------ */

.pub-filters {
    position: sticky;
    top: 0;
    z-index: 1100;            /* above Leaflet's panes and controls */
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(6px);
    border-bottom: 1px solid var(--line);
    padding: 12px 0 8px;
}

.pub-filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 14px;
    align-items: flex-end;
}

.pub-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }

.pub-field-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.pub-field-reset { margin-left: auto; }

/* multi-select dropdown built on <details> */
.msel { position: relative; }

.msel summary {
    list-style: none;
    cursor: pointer;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 8px;
    padding: 7px 30px 7px 11px;
    min-width: 150px;
    max-width: 220px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    position: relative;
}

.msel summary::-webkit-details-marker { display: none; }

.msel summary::after {
    content: '';
    position: absolute;
    right: 12px;
    top: 50%;
    width: 7px;
    height: 7px;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    transform: translateY(-70%) rotate(45deg);
}

.msel.is-set summary {
    border-color: var(--green);
    background: var(--green-tint);
    color: var(--green-dark);
    font-weight: 600;
}

.msel-list {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 20;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(20, 30, 10, 0.14);
    padding: 6px;
    min-width: 240px;
    max-height: 320px;
    overflow: auto;
}

.msel-list label {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
}

.msel-list label:hover { background: var(--surface); }

.msel-list input { accent-color: var(--green-dark); }

.msel-count { margin-left: auto; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

.msel-empty { margin: 6px 8px; color: var(--muted); }

.pub-years { display: flex; align-items: center; gap: 6px; color: var(--muted); }

.pub-years select {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 7px 8px;
    background: #fff;
    font: inherit;
}

.pub-seg {
    display: inline-flex;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
}

.pub-seg label { cursor: pointer; }

.pub-seg input { position: absolute; opacity: 0; pointer-events: none; }

.pub-seg span { display: block; padding: 7px 12px; }

.pub-seg input:checked + span { background: var(--green-dark); color: #fff; }

.pub-seg input:focus-visible + span { outline: 2px solid var(--green); outline-offset: -2px; }

.pub-selection {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 14px;
    margin-top: 10px;
    font-size: 14px;
    color: var(--ink-2);
}

.pub-selection > i { color: var(--green); }

.pub-link {
    border: 0;
    background: none;
    color: var(--green-dark);
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
    padding: 0;
}

/* --- buttons ------------------------------------------------------------ */

.pub-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    border-radius: 8px;
    padding: 8px 13px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
}

.pub-btn:hover { border-color: var(--green); color: var(--green-dark); }

.pub-btn.is-on { background: var(--green-dark); border-color: var(--green-dark); color: #fff; }

.pub-btn-primary { background: var(--green-dark); border-color: var(--green-dark); color: #fff; }

.pub-btn-primary:hover { background: var(--green); border-color: var(--green); color: #fff; }

.pub-btn-ghost { background: transparent; }

.icon-btn {
    border: 0;
    background: none;
    color: var(--muted);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
}

.icon-btn:hover { color: var(--green-dark); background: var(--green-tint); }

button:focus-visible, a:focus-visible, summary:focus-visible, input:focus-visible, select:focus-visible {
    outline: 2px solid var(--green);
    outline-offset: 2px;
}

/* --- tabs --------------------------------------------------------------- */

.pub-tabs {
    display: flex;
    gap: 4px;
    margin: 20px 0 16px;
    border-bottom: 1px solid var(--line);
    scroll-margin-top: 160px;
}

.pub-tabs [role=tab] {
    border: 0;
    background: none;
    padding: 12px 18px;
    font-size: 16px;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    margin-bottom: -1px;
}

.pub-tabs [role=tab]:hover { color: var(--ink); }

.pub-tabs [role=tab][aria-selected=true] {
    color: var(--green-dark);
    border-bottom-color: var(--green-dark);
}

.pub-panel { padding-bottom: 40px; }

/* --- map ---------------------------------------------------------------- */

.map-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 16px;
    align-items: start;
}

.map-frame {
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 1px solid var(--line);
}

#map { height: min(72vh, 720px); min-height: 420px; background: #e8e8e2; }

#map.is-drawing { cursor: crosshair; }

.map-hint {
    position: absolute;
    left: 50%;
    bottom: 18px;
    transform: translateX(-50%);
    z-index: 1000;
    background: rgba(29, 40, 18, 0.92);
    color: #fff;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 14px;
    max-width: 90%;
    text-align: center;
}

.map-side { display: flex; flex-direction: column; gap: 12px; }

.side-block {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
    box-shadow: var(--shadow);
}

.side-title { font-size: 16px; color: var(--ink); }

.side-sub { font-size: 13px; color: var(--muted); font-weight: 400; }

.side-h3 { font-size: 13px; margin: 14px 0 6px; color: var(--ink-2); }

.side-note { font-size: 13px; color: var(--muted); margin: 10px 0 0; }

.tool-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 10px;
}

.legend { list-style: none; margin: 8px 0 0; padding: 0; }

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    border: 1px solid transparent;
    background: none;
    padding: 5px 6px;
    border-radius: 6px;
    text-align: left;
    cursor: pointer;
    color: var(--ink);
}

.legend-item:hover:not([disabled]) { background: var(--surface); }

.legend-item.is-on { border-color: var(--green); background: var(--green-tint); }

.legend-item[disabled] { cursor: default; }

.legend-label { flex: 1; font-size: 14px; }

.legend-count { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

.swatch {
    display: inline-block;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    flex: none;
    margin-right: 6px;
    vertical-align: -1px;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.12);
}

.legend .swatch { margin-right: 0; }

.detail-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }

#plotActions { margin: 10px 0 4px; }

#plotActions .pub-btn { width: 100%; }

.facts { margin: 10px 0 0; display: grid; gap: 4px; }

.facts div { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }

.facts dt { color: var(--muted); }

.facts dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.comp-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) 70px 38px;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    margin-bottom: 4px;
}

.comp-row .swatch { margin-right: 0; }

.comp-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.comp-bar { height: 8px; background: var(--surface); border-radius: 4px; overflow: hidden; }

.comp-bar span { display: block; height: 100%; border-radius: 4px; }

.comp-val { text-align: right; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* Leaflet tooltips in the page font */
.leaflet-container { font-family: inherit; }

.leaflet-tooltip { font-size: 13px; line-height: 1.4; }

/* --- reports ------------------------------------------------------------ */

.report-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.report-title { font-size: 22px; color: var(--green-dark); }

.report-scope { margin: 4px 0 0; color: var(--ink-2); }

.report-filters { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.pub-loading, .pub-empty {
    padding: 50px 20px;
    text-align: center;
    color: var(--muted);
    background: var(--card);
    border: 1px dashed var(--line);
    border-radius: var(--radius);
}

.kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 14px;
}

.kpi {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px 16px;
    box-shadow: var(--shadow);
}

.kpi-value { font-size: 26px; font-weight: 700; color: var(--green-dark); font-variant-numeric: tabular-nums; }

.kpi-label { font-size: 13px; color: var(--muted); }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
    margin-bottom: 14px;
}

.card h3 { font-size: 17px; }

.card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

.card-answer { font-size: 17px; margin: 8px 0 2px; }

.card-note { font-size: 14px; color: var(--muted); margin: 4px 0 12px; }

.card-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.card-grid .card { margin-bottom: 14px; }

.chart-box { position: relative; height: 320px; }

.pub-search {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 7px 11px;
    min-width: 260px;
    font: inherit;
}

/* --- tables ------------------------------------------------------------- */

.table-scroll { overflow-x: auto; }

.table-tall { max-height: 560px; overflow-y: auto; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table th, .data-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

.data-table thead th {
    position: sticky;
    top: 0;
    background: #fafaf7;
    font-size: 12px;
    font-weight: 600;
    color: var(--ink-2);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    vertical-align: bottom;
    z-index: 1;
}

.data-table thead small { text-transform: none; font-weight: 400; color: var(--muted); letter-spacing: 0; }

.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.data-table tbody tr:hover { background: #fafaf7; }

.data-table td.mix { font-size: 13px; color: var(--ink-2); }

.data-table.compact th, .data-table.compact td { padding: 5px 6px; font-size: 12.5px; }

.data-table tr.is-out td { color: #a5a7a0; }

.data-table button.sort {
    border: 0;
    background: none;
    padding: 0;
    font: inherit;
    color: inherit;
    text-transform: inherit;
    letter-spacing: inherit;
    cursor: pointer;
}

/* --- downloads ---------------------------------------------------------- */

.dl-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 14px;
    margin-bottom: 14px;
}

.dl-card { display: flex; flex-direction: column; margin: 0; }

.dl-card p { color: var(--ink-2); font-size: 14px; flex: 1; margin: 6px 0 14px; }

.dictionary summary { cursor: pointer; list-style: none; }

.dictionary summary::-webkit-details-marker { display: none; }

.dictionary summary h3::before { content: '\25B8  '; color: var(--muted); }

.dictionary[open] summary h3::before { content: '\25BE  '; }

.dictionary h4 { margin: 18px 0 6px; font-size: 14px; }

.dict-table th { width: 220px; font-weight: 400; }

.dict-table code { font-size: 13px; color: var(--green-dark); }

/* --- about / footer ----------------------------------------------------- */

.pub-about {
    background: var(--card);
    border-top: 1px solid var(--line);
    padding: 36px 0;
}

.pub-about h2 { font-size: 22px; color: var(--green-dark); margin-bottom: 16px; }

.about-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 28px;
}

.about-grid h3 { font-size: 15px; margin-bottom: 6px; }

.about-grid p, .about-grid li { color: var(--ink-2); font-size: 14px; }

.about-grid ul { padding-left: 18px; margin: 0; }

.pub-footer {
    background: var(--green-dark);
    color: #dfe8d2;
    font-size: 13px;
    padding: 18px 0;
}

/* --- responsive --------------------------------------------------------- */

@media (max-width: 1000px) {
    .map-layout { grid-template-columns: 1fr; }
    .card-grid { grid-template-columns: 1fr; }
    .about-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
    .pub-wrap { padding: 0 16px; }
    .pub-filters { position: static; }
    .pub-header-links a:not(.pub-staff) { display: none; }
    .pub-brand img { height: 36px; }
    .msel summary { min-width: 0; max-width: none; }
    .pub-field { flex: 1 1 140px; }
    .pub-field-reset { margin-left: 0; }
    .pub-tabs [role=tab] { padding: 10px 12px; font-size: 15px; }
    .pub-search { min-width: 0; width: 100%; }
    #map { height: 60vh; }
}

/* --- print: the report only ---------------------------------------------- */

@media print {
    body { background: #fff; font-size: 12px; }
    .pub-header-links, .pub-hero, .pub-filters, .pub-tabs, #tab-map, #tab-downloads,
    .pub-about, .pub-footer, #printReport, .pub-search, .icon-btn { display: none !important; }
    #tab-analytics { display: block !important; }
    .card, .kpi { box-shadow: none; break-inside: avoid; }
    .card-grid { grid-template-columns: 1fr 1fr; }
    .table-tall { max-height: none; overflow: visible; }
    .data-table thead th { position: static; }
}

/* Page-level notice, e.g. a shared link that no longer exists */
.pub-notice {
    margin: 12px 0 0;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-left: 4px solid var(--brown);
    border-radius: var(--radius);
    background: var(--card);
    color: var(--ink);
    font-size: 14px;
}

/* What the map selection does to the other tabs */
.sel-panel {
    margin: 0 0 14px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    font-size: 14px;
    color: var(--ink-2);
}
.sel-panel p { margin: 0; }
.sel-panel .fa-circle-info { color: var(--muted); margin-right: 4px; }
.sel-panel.is-active { border-color: var(--green); background: var(--green-tint); color: var(--ink); }
.sel-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }
.sel-note {
    margin: 8px 0 0;
    padding: 6px 10px;
    border-left: 3px solid var(--green);
    background: var(--green-tint);
    border-radius: 0 6px 6px 0;
    font-size: 14px;
    color: var(--ink);
}
.sel-note .fa-draw-polygon { color: var(--green-dark); margin-right: 4px; }
@media print { .sel-note .pub-link { display: none; } }
