/* ═══════════════════════════════════════════════════════
   JobApp — map.html only. REVISION 3 (C.1d).
   Uses the tokens already defined in style.css :root.
   Nothing here overrides a shared class.

   R2 changes: the map shell is wider than the site's --max-width (a map is the
   one element that earns the extra width), the canvas is taller, and every
   surface is lifted a step off near-black. The v1 palette was correct on paper
   and unreadable on a screen.

   R3 (C.1d) adds exactly three things and changes nothing else, because the
   constraint on this pass is refinement rather than redesign:
     · a search field in the toolbar
     · a browse list in the sidebar — the affordance that makes a 2-pixel state,
       a scattered Alaskan region and a grey cell under a lit one all reachable
     · a `code · state` meta line under every name (ZIP3-STATE-1)
   The palette, the layout, the tier switcher and the card language are UNTOUCHED.
   ═══════════════════════════════════════════════════════ */

.map-page {
    padding-top: calc(var(--nav-height) + 2.5rem);
    padding-bottom: 4rem;
}

/* R2: the map gets its own width. --max-width (1140) is a reading measure and a
   map is not text. */
:root {
    --map-max-width: 1560px;
    --map-height: 760px;
    --map-side-width: 348px;
}

/* ── Head ───────────────────────────────────────── */
.map-head {
    max-width: 900px;
    margin: 0 auto 2rem;
    padding: 0 1.5rem;
    text-align: center;
}
.map-title {
    font-size: clamp(2rem, 5vw, 3.25rem);
    font-weight: 800;
    letter-spacing: -0.02em;
    margin: 0.75rem 0 0.85rem;
}
.map-sub {
    max-width: 720px;
    margin: 0 auto;
    color: var(--text-secondary);
    font-size: 1.02rem;
}
.map-sub em { color: var(--text); font-style: normal; }

/* ── Shell ──────────────────────────────────────── */
.map-shell {
    max-width: var(--map-max-width);
    margin: 0 auto;
    padding: 0 1.5rem;
}

.map-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 0.85rem;
}
.tier-group { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

/* ── Search (C.1d) ──────────────────────────────── */
.map-search { position: relative; flex: 1 1 260px; max-width: 380px; }
.map-search input {
    width: 100%;
    font-family: var(--font-mono);
    font-size: 0.76rem;
    color: var(--text);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.52rem 2rem 0.52rem 0.8rem;
    transition: border-color 0.25s var(--ease-out), box-shadow 0.25s var(--ease-out);
}
.map-search input::placeholder { color: var(--text-muted); }
.map-search input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 14px var(--accent-glow);
}
/* The browser's own clear affordance is inconsistent across engines and
   invisible on a dark field. One control, ours, always in the same place. */
.map-search input::-webkit-search-cancel-button { display: none; }
.search-clear {
    position: absolute; right: 0.45rem; top: 50%;
    transform: translateY(-50%);
    background: none; border: none; cursor: pointer;
    color: var(--text-muted); font-size: 0.72rem; line-height: 1;
    padding: 0.25rem;
}
.search-clear:hover { color: var(--text); }
.tier-btn {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.95rem;
    cursor: pointer;
    transition: all 0.25s var(--ease-out);
}
.tier-btn:hover { border-color: var(--border-hover); color: var(--text); }
.tier-btn.is-active {
    color: #fff;
    border-color: var(--accent);
    background: linear-gradient(135deg, rgba(124,77,255,0.28), rgba(20,184,166,0.18));
    box-shadow: 0 0 18px var(--accent-glow);
}
.map-reset {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-muted);
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.8rem;
    cursor: pointer;
    margin-left: 0.35rem;
    transition: all 0.25s var(--ease-out);
}
.map-reset:hover { color: var(--text); border-color: var(--border-hover); }
.map-tier-note {
    font-family: var(--font-mono);
    font-size: 0.74rem;
    color: var(--text-secondary);
    margin-left: auto;
}

.map-body {
    display: grid;
    grid-template-columns: 1fr var(--map-side-width);
    gap: 1rem;
    align-items: start;
}
@media (max-width: 1040px) {
    .map-body { grid-template-columns: 1fr; }
    .map-side { position: static; }
}

/* ── Canvas ─────────────────────────────────────── */
.map-canvas-wrap {
    position: relative;
    border: 1px solid var(--border-hover);
    border-radius: var(--radius-lg);
    overflow: hidden;
    /* R2: lifted off --bg-alt (#060D16). The country needs something to sit on. */
    background: #0B1727;
}
.map-canvas {
    width: 100%;
    height: var(--map-height);
    background: #0B1727;
}
@media (max-width: 1040px) { .map-canvas { height: 560px; } }
@media (max-width: 620px)  { .map-canvas { height: 440px; } }

/* Leaflet chrome, restyled to the site's language. */
.leaflet-container {
    background: #0B1727;
    font-family: var(--font-display);
    outline: none;
}
.leaflet-control-zoom a {
    background: var(--bg-card);
    color: var(--text);
    border-color: var(--border);
}
.leaflet-control-zoom a:hover { background: var(--bg-card-hover); color: #fff; }
.leaflet-control-attribution {
    background: rgba(6,13,22,0.82);
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.62rem;
}
.leaflet-control-attribution a { color: var(--text-secondary); }

.leaflet-popup-content-wrapper {
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--border-hover);
    border-radius: var(--radius);
    box-shadow: 0 18px 40px rgba(0,0,0,0.55);
}
.leaflet-popup-tip { background: var(--bg-card); border: 1px solid var(--border-hover); }
.leaflet-popup-content { margin: 0.85rem 1rem; min-width: 220px; }
.leaflet-popup-close-button { color: var(--text-muted) !important; }

.pop-tier {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
    display: block;
}
.pop-name {
    font-size: 1.02rem;
    font-weight: 700;
    margin: 0.15rem 0 0.6rem;
    line-height: 1.25;
    word-break: break-word;
}
.pop-rows { display: grid; grid-template-columns: 1fr auto; gap: 0.28rem 0.9rem; }
.pop-rows dt { font-size: 0.79rem; color: var(--text-secondary); }
.pop-rows dd { font-family: var(--font-mono); font-size: 0.82rem; text-align: right; }
.pop-rows dd.is-absent { color: var(--text-muted); }
.pop-note {
    margin-top: 0.65rem;
    padding-top: 0.6rem;
    border-top: 1px solid var(--border);
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.5;
}

/* ── Legend ─────────────────────────────────────── */
.map-legend {
    position: absolute;
    left: 14px;
    bottom: 14px;
    background: rgba(10,22,40,0.93);
    border: 1px solid var(--border-hover);
    border-radius: var(--radius);
    padding: 0.7rem 0.85rem;
    max-width: 250px;
    backdrop-filter: blur(6px);
    z-index: 500;
}
.legend-title {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
}
.legend-scale { display: flex; gap: 3px; margin: 0.45rem 0 0.55rem; }
.legend-scale span { height: 9px; flex: 1; border-radius: 2px; }
.legend-row {
    display: flex; align-items: center; gap: 0.5rem;
    font-size: 0.72rem; color: var(--text-secondary);
}
/* R2: matches map.js's GREY_FILL / GREY_STROKE. If you change one, change both. */
.legend-swatch { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.legend-swatch-grey { background: #33475F; border: 1px solid #5B7A9E; }
.legend-foot {
    margin-top: 0.5rem;
    font-size: 0.67rem;
    color: var(--text-muted);
    line-height: 1.45;
}

.map-status {
    position: absolute;
    top: 14px; left: 50%;
    transform: translateX(-50%);
    background: rgba(10,22,40,0.94);
    border: 1px solid var(--border-hover);
    border-radius: 999px;
    padding: 0.35rem 0.95rem;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-secondary);
    z-index: 500;
    transition: opacity 0.3s var(--ease-out);
}
.map-status[hidden] { display: none; }
.map-status.is-error { border-color: var(--red); color: var(--red-soft); }

/* ── Sidebar ────────────────────────────────────── */
.map-side {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    position: sticky;
    top: calc(var(--nav-height) + 1rem);
    max-height: calc(100vh - var(--nav-height) - 2rem);
    overflow-y: auto;
    padding-right: 2px;
}
.map-side::-webkit-scrollbar { width: 6px; }
.map-side::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: 3px; }

.side-empty, .side-cell, .side-block {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.05rem;
    flex: none;
}
.side-empty h3, .side-block h4 { font-size: 0.92rem; margin-bottom: 0.4rem; }
.side-block h4 {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.6rem;
}
.side-empty p, .side-muted { font-size: 0.82rem; color: var(--text-secondary); }

.side-cell { position: relative; }
.side-close {
    position: absolute; top: 0.6rem; right: 0.7rem;
    background: none; border: none; color: var(--text-muted);
    cursor: pointer; font-size: 0.85rem;
}
.side-tier {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
}
.side-name { font-size: 1.15rem; font-weight: 700; margin: 0.15rem 0 0.2rem; word-break: break-word; }

/* ZIP3-STATE-1. The identity line: code first, because 435 of 918 region labels
   are STILL ambiguous once the state is added and only the code is unique. */
.side-meta {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-secondary);
    margin-bottom: 0.7rem;
}
.pop-meta {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin: -0.35rem 0 0.55rem;
}

.side-metrics { display: grid; grid-template-columns: 1fr auto; gap: 0.3rem 0.8rem; }
.side-metrics dt { font-size: 0.8rem; color: var(--text-secondary); }
.side-metrics dd { font-family: var(--font-mono); font-size: 0.82rem; text-align: right; }
.side-metrics dd.is-absent { color: var(--text-muted); }
.side-metrics dt.is-pending, .side-metrics dd.is-pending { color: var(--text-muted); font-style: italic; }

.side-note, .side-fine {
    margin-top: 0.7rem;
    font-size: 0.74rem;
    color: var(--text-muted);
    line-height: 1.55;
}

/* ── Browse list (C.1d) ─────────────────────────── */
.side-browse { display: flex; flex-direction: column; min-height: 0; }
.browse-count {
    font-family: var(--font-mono);
    font-size: 0.66rem;
    color: var(--text-muted);
    margin-bottom: 0.45rem;
}
.browse-list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 260px;
    overflow-y: auto;
    border-top: 1px solid var(--border);
}
.browse-list::-webkit-scrollbar { width: 6px; }
.browse-list::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: 3px; }

.browse-row {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: baseline;
    column-gap: 0.6rem;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    border-bottom: 1px solid var(--border);
    padding: 0.42rem 0.15rem;
    cursor: pointer;
    transition: background 0.18s var(--ease-out);
}
.browse-row:hover  { background: var(--bg-card-hover); }
.browse-row:focus-visible { outline: 1px solid var(--accent); outline-offset: -1px; }
.browse-name {
    grid-column: 1;
    font-size: 0.82rem;
    color: var(--text-secondary);
    word-break: break-word;
}
.browse-row.is-lit .browse-name { color: var(--text); }
.browse-meta {
    grid-column: 1;
    font-family: var(--font-mono);
    font-size: 0.63rem;
    color: var(--text-muted);
}
.browse-val {
    grid-column: 2;
    grid-row: 1 / span 2;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--teal, #14B8A6);
    align-self: center;
}
.browse-val.is-absent { color: var(--text-muted); }
/* A published cell with nowhere to draw — 'remote', the armed-forces codes.
   Listed, never dropped: a published cell that renders nowhere is silent data
   loss, and this badge is the only place a visitor can find it. */
.browse-badge {
    grid-column: 1 / -1;
    font-family: var(--font-mono);
    font-size: 0.58rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    border: 1px dashed var(--border-hover);
    border-radius: 999px;
    padding: 0.05rem 0.4rem;
    justify-self: start;
    margin-top: 0.2rem;
}

/* R2: the members' block is now a promotion, not a second login form. */
.side-member-cta {
    display: block;
    text-align: center;
    margin-top: 0.75rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, var(--accent) 0%, var(--teal) 100%);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.8rem;
    transition: filter 0.25s var(--ease-out);
}
.side-member-cta:hover { filter: brightness(1.12); }

.member-msg { font-size: 0.74rem; color: var(--text-muted); min-height: 1.1em; }
.member-msg.is-ok { color: var(--green); }
.member-msg.is-err { color: var(--red-soft); }

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

/* ── Explainers ─────────────────────────────────── */
.map-explain { margin-top: 3rem; }
.map-explain-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1.5rem;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1rem;
}
.explain-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.2rem 1.25rem;
}
.explain-card h4 { font-size: 0.95rem; margin-bottom: 0.45rem; }
.explain-card p { font-size: 0.84rem; color: var(--text-secondary); line-height: 1.65; }
.explain-card em { color: var(--text); font-style: normal; }

.nav-active { color: var(--accent-soft) !important; }