/* ==========================================================================
   Leadspanic — AI-native Linear-style theme
   Single stylesheet, mobile-first, dark-default with light toggle.
   Every class name used by app.js is defined here.
   ========================================================================== */

/* ---------- 1. Design tokens ---------- */
:root {
    /* Brand */
    --brand-500: #7c5cff;
    --brand-400: #9b85ff;
    --brand-600: #5a3cd9;
    --brand-grad: linear-gradient(135deg, #7c5cff 0%, #22d3ee 100%);
    --accent-grad: linear-gradient(135deg, #f472b6 0%, #7c5cff 100%);

    /* Semantic */
    --success: #10b981;
    --warning: #f59e0b;
    --danger:  #ef4444;
    --info:    #22d3ee;

    /* Light surface */
    --bg-page:       #f7f8fb;
    --bg-surface:    #ffffff;
    --bg-surface-2:  #f1f2f7;
    --bg-input:      #ffffff;
    --text-primary:  #0f172a;
    --text-secondary:#475569;
    --text-muted:    #94a3b8;
    --border:        #e5e7eb;
    --border-strong: #cbd5e1;
    --shadow-sm: 0 1px 2px rgba(15,23,42,0.06);
    --shadow-md: 0 4px 16px rgba(15,23,42,0.08);
    --shadow-lg: 0 12px 40px rgba(15,23,42,0.12);
    --glass:     rgba(255,255,255,0.72);
    --glass-stroke: rgba(15,23,42,0.06);

    --nav-bg: rgba(255,255,255,0.85);
    --nav-text: #475569;
    --sheet-bg: #ffffff;

    --radius-xs: 6px;
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-xl: 28px;

    --ease: cubic-bezier(.2,.7,.2,1);

    color-scheme: light;
}

[data-theme="dark"] {
    --bg-page:       #0b0d12;
    --bg-surface:    #11141b;
    --bg-surface-2:  #161a23;
    --bg-input:      #1a1f2a;
    --text-primary:  #f3f4f6;
    --text-secondary:#a1a8b6;
    --text-muted:    #6b7280;
    --border:        #222835;
    --border-strong: #2f3646;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.5);
    --shadow-md: 0 6px 24px rgba(0,0,0,0.5);
    --shadow-lg: 0 16px 50px rgba(0,0,0,0.6);
    --glass:     rgba(17,20,27,0.72);
    --glass-stroke: rgba(255,255,255,0.06);
    --nav-bg: rgba(11,13,18,0.85);
    --nav-text: #a1a8b6;
    --sheet-bg: #11141b;
    color-scheme: dark;
}

/* ---------- 2. Reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
html {
    /* Prevent iOS rubber-band / scroll-chaining from revealing adjacent
       tab content underneath. Body-only overflow:hidden isn't enough on
       Safari. */
    overflow: hidden;
    overscroll-behavior: none;
}
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-feature-settings: "cv02","cv03","cv04","cv11";
    -webkit-font-smoothing: antialiased;
    background: var(--bg-page);
    color: var(--text-primary);
    line-height: 1.5;
    overflow: hidden; /* tab content manages its own scroll */
    overscroll-behavior: none;
    /* NOTE: intentionally NOT using position:fixed on body — it creates a
       new stacking context that makes z-index comparisons with Leaflet
       internals unreliable. html{overflow:hidden} handles iOS rubber-band. */
}
img, svg { display: block; max-width: 100%; }
button { font: inherit; cursor: pointer; border: 0; background: transparent; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand-500); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Ambient aurora background (subtle) */
body::before {
    content: "";
    position: fixed; inset: 0; z-index: -1;
    background:
        radial-gradient(1200px 600px at 10% -10%, rgba(124,92,255,0.12), transparent 60%),
        radial-gradient(1000px 500px at 110% 10%, rgba(34,211,238,0.10), transparent 60%);
    pointer-events: none;
}

/* ---------- 3. Header ---------- */
header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.7rem 1.25rem;
    background: var(--glass);
    backdrop-filter: saturate(140%) blur(16px);
    -webkit-backdrop-filter: saturate(140%) blur(16px);
    border-bottom: 1px solid var(--glass-stroke);
    position: sticky; top: 0; z-index: 50;
}
header .brand { display: flex; align-items: center; gap: 0.6rem; }
header .brand-mark {
    width: 34px; height: 34px; border-radius: 10px;
    background: var(--brand-grad);
    display: grid; place-items: center;
    box-shadow: 0 6px 18px rgba(124,92,255,0.35);
    color: white; font-weight: 800;
}
header h1 {
    font-size: 1.05rem; font-weight: 700; letter-spacing: -0.01em;
    background: var(--brand-grad); -webkit-background-clip: text; background-clip: text; color: transparent;
}
header p { display: none; }

header .header-actions { display: flex; align-items: center; gap: 0.4rem; }
.icon-btn {
    width: 36px; height: 36px; border-radius: 10px;
    display: grid; place-items: center;
    color: var(--text-secondary);
    transition: background .18s var(--ease), color .18s var(--ease), transform .18s var(--ease);
}
.icon-btn:hover { background: var(--bg-surface-2); color: var(--text-primary); }
.icon-btn:active { transform: scale(.96); }
#darkModeIcon { width: 18px; height: 18px; }

/* ---------- 4. Desktop tab bar ---------- */
.tabs {
    display: flex;
    align-items: stretch;
    gap: 0.15rem;
    padding: 0.4rem 0.75rem 0;
    background: var(--bg-page);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tabs-primary,
.tabs-secondary { display: flex; align-items: stretch; gap: 0.15rem; }

.tabs-divider {
    width: 1px;
    background: var(--border);
    margin: 0.45rem 0.6rem 0;
    flex-shrink: 0;
}

.tab-btn {
    position: relative;
    display: inline-flex; align-items: center; gap: 0.45rem;
    padding: 0.65rem 0.85rem;
    font-size: 0.86rem; font-weight: 500;
    color: var(--text-secondary);
    border-radius: 10px 10px 0 0;
    white-space: nowrap;
    transition: color .18s var(--ease), background .18s var(--ease);
}
.tab-btn .tab-ic { width: 15px; height: 15px; stroke: currentColor; fill: none; flex-shrink: 0; }
.tab-btn:hover { color: var(--text-primary); background: var(--bg-surface-2); }
.tab-btn.active { color: var(--text-primary); }
.tab-btn.active::after {
    content: ""; position: absolute; left: 10%; right: 10%; bottom: -1px;
    height: 2px; border-radius: 2px; background: var(--brand-grad);
}

.tab-btn--sec {
    padding: 0.42rem 0.7rem;
    margin: 0.2rem 0 0.18rem;
    font-size: 0.82rem; border-radius: 8px;
    color: var(--text-muted);
}
.tab-btn--sec .tab-ic { width: 13px; height: 13px; }
.tab-btn--sec:hover { background: var(--bg-surface-2); color: var(--text-primary); }
.tab-btn--sec.active { background: rgba(124, 92, 255, 0.1); color: var(--text-primary); }
.tab-btn--sec.active::after { display: none; }


/* ---------- 4b. Mobile sub-nav (chip row) ---------- */
.mobile-subnav {
    display: none;
    gap: 6px;
    padding: 7px 12px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}
.mobile-subnav::-webkit-scrollbar { display: none; }

.msn-chip {
    flex-shrink: 0;
    padding: 5px 12px;
    font-size: 12px; font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-surface-2);
    border-radius: 999px;
    border: 0; cursor: pointer;
    transition: background .15s var(--ease), color .15s var(--ease);
    font-family: inherit;
}
.msn-chip:active { transform: scale(.97); }
.msn-chip.active {
    background: var(--brand-500);
    color: #fff;
}


/* ---------- 4c. Mobile bottom nav (3 groups) ---------- */
.mobile-bottom-nav {
    display: none;
    position: fixed; left: 0; right: 0; bottom: 0;
    background: var(--nav-bg);
    backdrop-filter: saturate(140%) blur(10px);
    -webkit-backdrop-filter: saturate(140%) blur(10px);
    border-top: 1px solid var(--border);
    z-index: 40;
    padding-bottom: env(safe-area-inset-bottom);
}
.mobile-bottom-nav { display: none; align-items: stretch; }

.mobile-nav-btn {
    flex: 1;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 2px;
    padding: 8px 4px 10px;
    color: var(--nav-text);
    position: relative;
    background: none; border: 0; cursor: pointer;
    font-family: inherit;
    transition: color .15s var(--ease);
}
.mobile-nav-btn svg { width: 20px; height: 20px; stroke: currentColor; fill: none; }
.mobile-nav-label { font-size: 10.5px; font-weight: 600; letter-spacing: 0.01em; }
.mobile-nav-btn.active { color: var(--brand-500); }
.mobile-nav-btn.active::before {
    content: ""; position: absolute; top: 0; left: 22%; right: 22%;
    height: 2px; border-radius: 0 0 3px 3px; background: var(--brand-grad);
}

/* ---------- 5. Tab content shells ---------- */
.tab-content { display: none; height: calc(100dvh - 56px - 46px); position: relative; overflow: hidden; }
.tab-content.active { display: flex; animation: fade .22s var(--ease); }
/* Belt-and-suspenders: if anything ever tries to show an inactive tab
   (overridden display via JS error, stacking context issues, etc.), this
   keeps it hidden so siblings can't bleed through. */
.tab-content:not(.active) { display: none !important; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- 6. Shared components ---------- */
.container, .score-container, .compare-container, .ask-container { display: flex; width: 100%; height: 100%; }

.sidebar, .score-sidebar, .ask-sidebar, .compare-inputs, .library-list-pane {
    width: 360px;
    max-width: 100%;
    flex-shrink: 0;
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 1rem 1.1rem 2rem;
}

h3 {
    font-size: 0.95rem; font-weight: 700; letter-spacing: -0.01em;
    margin-bottom: 0.5rem; color: var(--text-primary);
}
h4 {
    font-size: 0.8rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.06em;
    color: var(--text-muted); margin: 0.6rem 0 0.4rem;
}
label {
    display: block;
    font-size: 0.78rem; font-weight: 600;
    color: var(--text-secondary);
    margin-top: 0.55rem; margin-bottom: 0.3rem;
}

input[type="text"], input[type="number"], input[type="search"], input[type="email"], select, textarea {
    width: 100%;
    padding: 0.6rem 0.75rem;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    transition: border-color .18s var(--ease), box-shadow .18s var(--ease), background .18s var(--ease);
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--brand-500);
    box-shadow: 0 0 0 3px rgba(124,92,255,0.18);
}
input::placeholder { color: var(--text-muted); }

select[multiple] {
    padding: 0.3rem;
    min-height: 100px;
}
select[multiple] option { padding: 0.35rem 0.5rem; border-radius: 6px; }

input[type="range"] {
    -webkit-appearance: none; appearance: none;
    width: 100%; height: 4px;
    background: var(--border); border-radius: 2px;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 18px; height: 18px; border-radius: 50%;
    background: var(--brand-500); cursor: pointer;
    box-shadow: 0 0 0 4px rgba(124,92,255,0.2);
}
input[type="range"]::-moz-range-thumb {
    width: 18px; height: 18px; border-radius: 50%;
    background: var(--brand-500); cursor: pointer; border: 0;
}

input[type="file"] { display: none; }
.file-label {
    display: inline-block;
    padding: 0.5rem 0.8rem;
    background: var(--bg-surface-2);
    border: 1px dashed var(--border-strong);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    cursor: pointer;
    transition: border-color .18s var(--ease), color .18s var(--ease);
}
.file-label:hover { border-color: var(--brand-500); color: var(--brand-500); }

/* ---------- 7. Buttons ---------- */
button:not(.tab-btn):not(.icon-btn):not(.mobile-nav-btn):not(.bm-btn):not(.ask-example):not(.close-btn):not(.pwa-install-dismiss):not(.lib-seg-btn):not(.find-similar-btn):not(.li-tool-btn):not(.li-panel-close):not(.mc-mobile-tabs button):not(.layer-toggle-item button):not(.wh-profile-btn):not(.collapsible-toggle) {
    padding: 0.62rem 0.95rem;
    background: var(--brand-grad);
    color: white; font-weight: 600; font-size: 0.88rem;
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 14px rgba(124,92,255,0.28);
    transition: transform .14s var(--ease), box-shadow .14s var(--ease), opacity .14s var(--ease);
}
button:not(.tab-btn):not(.icon-btn):not(.mobile-nav-btn):not(.bm-btn):not(.ask-example):not(.close-btn):not(.pwa-install-dismiss):not(.lib-seg-btn):not(.find-similar-btn):not(.li-tool-btn):not(.li-panel-close):not(.mc-mobile-tabs button):not(.layer-toggle-item button):not(.wh-profile-btn):not(.collapsible-toggle):hover { transform: translateY(-1px); box-shadow: 0 8px 22px rgba(124,92,255,0.35); }
button:not(.tab-btn):not(.icon-btn):not(.mobile-nav-btn):not(.bm-btn):not(.ask-example):not(.close-btn):not(.pwa-install-dismiss):not(.lib-seg-btn):not(.find-similar-btn):not(.li-tool-btn):not(.li-panel-close):not(.mc-mobile-tabs button):not(.layer-toggle-item button):not(.wh-profile-btn):not(.collapsible-toggle):active { transform: scale(.98); }
button:disabled { opacity: .55; cursor: not-allowed; }

.gps-btn, .wh-locate-btn, .compare-btn, .run-btn, .wh-go-btn, .li-run-btn {
    width: 100%;
    margin-top: 0.4rem;
}

/* Secondary style for Leaf/small buttons */
.btn-secondary {
    background: var(--bg-surface-2) !important;
    color: var(--text-primary) !important;
    box-shadow: none !important;
    border: 1px solid var(--border) !important;
}

/* ---------- 8. Map tab ---------- */
.search-section, .whos-here-section, .upload-section {
    padding: 0.9rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 0.8rem;
    background: var(--bg-surface);
}
.search-section { background: linear-gradient(180deg, rgba(124,92,255,0.06), transparent 80%); }

.search-bar { display: flex; gap: 0.4rem; margin-top: 0.35rem; }
.search-bar input { flex: 1; }
.search-bar button { flex-shrink: 0; }
.search-hint, .whos-here-hint, .csv-format-hint {
    margin-top: 0.4rem;
    font-size: 0.72rem;
    color: var(--text-muted);
}
.section-divider {
    text-align: center;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin: 0.6rem 0;
    position: relative;
}
.section-divider::before, .section-divider::after {
    content: ""; position: absolute; top: 50%; width: 25%; height: 1px; background: var(--border);
}
.section-divider::before { left: 0; }
.section-divider::after { right: 0; }

.whos-here-coords {
    font-size: 0.72rem; color: var(--text-muted); margin-top: 0.3rem;
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
}
.wh-radius-row { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.5rem; }
.wh-radius-row label { margin: 0; font-size: 0.75rem; }
.wh-radius-row input[type="range"] { flex: 1; }
.wh-radius-val { font-size: 0.75rem; font-weight: 600; color: var(--brand-500); min-width: 40px; text-align: right; }

.wh-results { margin-top: 0.6rem; }

/* Summary stat row */
.summary-bar {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem;
    margin: 0.6rem 0;
}
.summary-stat {
    padding: 0.55rem 0.4rem;
    background: var(--bg-surface-2);
    border-radius: var(--radius-sm);
    text-align: center;
    font-size: 0.66rem; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.06em;
}
.summary-stat .num {
    font-size: 1.1rem; font-weight: 700; color: var(--text-primary);
    letter-spacing: -0.02em;
}

.customer-list { margin-top: 0.5rem; }
.customer-item {
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 0.35rem;
    background: var(--bg-surface);
    cursor: pointer;
    transition: border-color .16s var(--ease), transform .16s var(--ease);
}
.customer-item:hover { border-color: var(--brand-500); transform: translateX(2px); }
.customer-name { font-size: 0.82rem; font-weight: 600; }
.customer-address { font-size: 0.72rem; color: var(--text-muted); }
.customer-persona { font-size: 0.72rem; color: var(--brand-500); margin-top: 0.2rem; font-weight: 500; }

#map, .li-map, .score-map, .ask-map, .compare-map-pane {
    flex: 1;
    height: 100%;
    min-height: 300px;
    background: var(--bg-surface-2);
}

.legend {
    position: absolute;
    right: 16px;
    bottom: 16px;
    background: var(--glass);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid var(--glass-stroke);
    border-radius: var(--radius-md);
    padding: 0.7rem 0.9rem;
    box-shadow: var(--shadow-md);
    max-width: 240px;
    max-height: 55vh;
    overflow-y: auto;
    font-size: 0.78rem;
    z-index: 500;
}
.legend h4 { margin: 0 0 0.4rem; }
.legend-item { display: flex; align-items: center; gap: 0.5rem; padding: 0.18rem 0; }
.legend-color { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }

/* Layer toggle */
.layer-toggle-item {
    display: flex; align-items: center; gap: 0.55rem;
    padding: 0.5rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 0.35rem;
    background: var(--bg-surface);
    cursor: pointer;
    transition: border-color .16s var(--ease);
}
.layer-toggle-item:hover { border-color: var(--brand-500); }
.layer-toggle-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--brand-500); }

/* Status / error / loading */
.status {
    padding: 0.55rem 0.75rem;
    background: var(--bg-surface-2);
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    margin: 0.45rem 0;
    color: var(--text-secondary);
    display: none;
}
.status:not(:empty) { display: block; }
.error-message {
    padding: 0.55rem 0.75rem;
    background: rgba(239,68,68,0.12);
    color: var(--danger);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    margin: 0.45rem 0;
    display: none;
    border: 1px solid rgba(239,68,68,0.3);
}
.error-message:not(:empty) { display: block; }

/* Who's Here summary cards */
.wh-summary-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem; margin-top: 0.5rem; }
.wh-summary-card {
    padding: 0.55rem;
    background: var(--bg-surface-2);
    border-radius: var(--radius-sm);
    text-align: center;
}
.wh-summary-card .label { font-size: 0.66rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.wh-summary-card .value { font-size: 1.05rem; font-weight: 700; color: var(--text-primary); }
.wh-persona-list { margin-top: 0.5rem; }
.wh-persona-item {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.4rem 0.55rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 0.3rem;
}
.wh-persona-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.wh-persona-info { flex: 1; min-width: 0; }
.wh-persona-name { font-size: 0.8rem; font-weight: 600; color: var(--text-primary); }
.wh-persona-count { font-size: 0.7rem; color: var(--text-muted); }
.wh-profile-btn {
    padding: 0.25rem 0.55rem;
    background: var(--bg-surface-2);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    border-radius: 6px;
    font-size: 0.7rem;
    transition: border-color .14s var(--ease), color .14s var(--ease);
}
.wh-profile-btn:hover { border-color: var(--brand-500); color: var(--brand-500); }

/* ---------- 9. Lead Score tab ---------- */
.business-model-seg {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.3rem;
    margin: 0.3rem 0 0.5rem;
}
.bm-btn {
    padding: 0.45rem 0.3rem;
    background: var(--bg-surface-2);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.78rem; font-weight: 600;
    transition: all .14s var(--ease);
}
.bm-btn:hover { border-color: var(--brand-500); color: var(--brand-500); }
.bm-btn.active {
    background: var(--brand-grad);
    color: white;
    border-color: transparent;
    box-shadow: 0 4px 12px rgba(124,92,255,0.35);
}

.lead-score-summary-card {
    padding: 0.75rem;
    background: var(--bg-surface-2);
    border-radius: var(--radius-md);
    margin-top: 0.6rem;
    font-size: 0.82rem;
}
.lead-score-summary-card .big {
    font-size: 1.8rem; font-weight: 800; letter-spacing: -0.02em;
    background: var(--brand-grad); -webkit-background-clip: text; background-clip: text; color: transparent;
}

.lead-tract-row {
    padding: 0.5rem 0.65rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 0.3rem;
    display: flex; align-items: center; gap: 0.5rem;
    font-size: 0.78rem;
    cursor: pointer;
    transition: border-color .14s var(--ease);
}
.lead-tract-row:hover { border-color: var(--brand-500); }
.lead-tract-badge {
    padding: 0.18rem 0.45rem;
    border-radius: 999px;
    font-size: 0.66rem;
    font-weight: 700;
    background: var(--brand-grad);
    color: white;
}

.lead-component-bar {
    margin-top: 0.3rem;
}
.lcb-label { font-size: 0.7rem; color: var(--text-muted); margin-bottom: 0.15rem; display: flex; justify-content: space-between; }
.lcb-track { height: 5px; background: var(--bg-surface-2); border-radius: 3px; overflow: hidden; }
.lcb-fill { height: 100%; background: var(--brand-grad); border-radius: 3px; transition: width .3s var(--ease); }
.lcb-val { font-weight: 600; color: var(--text-primary); }

/* ---------- 10. Market Comparison tab ---------- */
.compare-container { flex-direction: column; }
.compare-inputs {
    width: 100%;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 0.8rem 1rem;
    display: flex; flex-wrap: wrap; gap: 0.6rem;
    align-items: flex-end;
    overflow-y: visible;
}
.compare-input-group { flex: 1; min-width: 180px; display: flex; flex-direction: column; gap: 0.3rem; }
.compare-input-group label { margin: 0; }
.compare-input-group input, .compare-input-group select { width: 100%; }

.compare-btn { flex: 0 0 auto; align-self: stretch; }

.mc-mobile-tabs { display: none; }
.compare-maps {
    flex: 1;
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 1px;
    background: var(--border);
    min-height: 300px;
}
.compare-map-pane { display: block; width: 100%; height: 100%; }
.compare-results {
    padding: 0.8rem 1rem;
    border-top: 1px solid var(--border);
    background: var(--bg-surface);
}
.compare-chart-container {
    max-width: 520px; margin: 0 auto 0.8rem;
}
.compare-table {
    font-size: 0.82rem;
}
.compare-table table { width: 100%; border-collapse: collapse; }
.compare-table th, .compare-table td { padding: 0.4rem 0.6rem; text-align: left; border-bottom: 1px solid var(--border); }
.compare-table th { font-size: 0.72rem; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.06em; }

#mc-recommendation {
    background: linear-gradient(135deg, rgba(124,92,255,0.12), rgba(34,211,238,0.12));
    border: 1px solid var(--glass-stroke);
    color: var(--text-primary);
}

/* ---------- 11. Lead Intelligence tab ---------- */
.li-layout { flex-direction: row; }
.li-map { position: absolute; inset: 0; z-index: 1; }

.li-top-banner {
    position: absolute;
    top: 12px; left: 50%; transform: translateX(-50%);
    display: flex; gap: 0.3rem;
    padding: 0.3rem;
    background: var(--glass);
    backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    border: 1px solid var(--glass-stroke);
    border-radius: 999px;
    box-shadow: var(--shadow-md);
    z-index: 20;
    max-width: calc(100% - 24px);
}
.li-tool-btn {
    padding: 0.5rem 0.9rem;
    font-size: 0.82rem; font-weight: 600;
    color: var(--text-secondary);
    border-radius: 999px;
    transition: all .16s var(--ease);
    white-space: nowrap;
}
.li-tool-btn:hover { background: var(--bg-surface-2); color: var(--text-primary); }
.li-tool-btn.active { background: var(--brand-grad); color: white; box-shadow: 0 4px 14px rgba(124,92,255,0.3); }
.li-label-short { display: none; }

.li-panel {
    position: absolute;
    top: 0; right: 0; bottom: 0;
    width: 380px;
    max-width: 100%;
    background: var(--bg-surface);
    border-left: 1px solid var(--border);
    box-shadow: -10px 0 30px rgba(0,0,0,0.1);
    transform: translateX(100%);
    transition: transform .28s var(--ease);
    z-index: 15;
    display: flex; flex-direction: column;
}
.li-panel.open { transform: translateX(0); }
.li-panel-header {
    padding: 0.9rem 1rem;
    display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid var(--border);
    background: var(--bg-surface);
    position: sticky; top: 0; z-index: 1;
}
.li-panel-close {
    width: 32px; height: 32px; border-radius: 8px;
    font-size: 1.4rem; color: var(--text-secondary);
}
.li-panel-close:hover { background: var(--bg-surface-2); color: var(--text-primary); }
.li-panel-body { padding: 1rem; overflow-y: auto; flex: 1; }
.li-section { margin-bottom: 0.75rem; padding-bottom: 0.75rem; border-bottom: 1px solid var(--border); }
.li-section:last-child { border-bottom: 0; }
.li-results { margin-top: 0.8rem; }

/* ---------- 12. Report tab ---------- */
.report-layout { display: none; flex-direction: column; overflow-y: auto; }
.report-layout.active { display: flex; }
.report-form {
    max-width: 720px;
    margin: 1.5rem auto;
    padding: 1.4rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    width: calc(100% - 2rem);
}
.report-form h3 { font-size: 1.1rem; margin-bottom: 0.3rem; }
#report-output {
    max-width: 900px;
    margin: 0 auto 3rem;
    padding: 0 1rem;
    width: 100%;
}
.report-output, .report-metric-row {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.9rem 1rem;
    margin-bottom: 0.7rem;
}
.report-metric {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.35rem 0;
    font-size: 0.88rem;
}
.report-metric .label { color: var(--text-secondary); }
.report-metric .value { font-weight: 700; color: var(--text-primary); }

/* ---------- 13. Ask tab ---------- */
.ask-container { flex-direction: row; }
.ask-input-group { display: flex; gap: 0.4rem; margin-top: 0.5rem; }
.ask-input-group input { flex: 1; }
.ask-examples h4 { margin-top: 1rem; }
.ask-example {
    display: block; width: 100%; text-align: left;
    padding: 0.55rem 0.7rem;
    background: var(--bg-surface-2);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 0.8rem;
    border-radius: var(--radius-sm);
    margin-bottom: 0.35rem;
    transition: border-color .14s var(--ease), transform .14s var(--ease);
}
.ask-example:hover { border-color: var(--brand-500); transform: translateX(2px); }
.ask-results {
    margin-top: 0.8rem;
    padding: 0.75rem;
    background: var(--bg-surface-2);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    min-height: 80px;
}

/* ---------- 14. Library tab ---------- */
.library-layout { flex-direction: row; }
.library-list-pane { padding: 0.8rem 0.9rem 2rem; }
.library-seg {
    display: grid; grid-template-columns: repeat(3, 1fr);
    gap: 0.25rem;
    padding: 0.25rem;
    background: var(--bg-surface-2);
    border-radius: 10px;
    margin-bottom: 0.6rem;
}
.lib-seg-btn {
    padding: 0.45rem 0.3rem;
    font-size: 0.76rem; font-weight: 600;
    color: var(--text-secondary);
    border-radius: 7px;
    white-space: nowrap;
    transition: background .14s var(--ease), color .14s var(--ease);
}
.lib-seg-btn:hover { color: var(--text-primary); }
.lib-seg-btn.active { background: var(--bg-surface); color: var(--text-primary); box-shadow: var(--shadow-sm); }

#library-search { margin-bottom: 0.6rem; }
.library-cards { list-style: none; }
.library-card {
    padding: 0.7rem 0.85rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 0.45rem;
    cursor: pointer;
    transition: border-color .14s var(--ease), transform .14s var(--ease);
}
.library-card:hover { border-color: var(--brand-500); transform: translateY(-1px); }
.library-card.active { border-color: var(--brand-500); box-shadow: 0 0 0 3px rgba(124,92,255,0.18); }
.library-card-title { font-size: 0.88rem; font-weight: 700; color: var(--text-primary); }
.library-card-sub { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.15rem; }
.library-chip {
    display: inline-block;
    padding: 0.18rem 0.5rem;
    background: var(--bg-surface-2);
    color: var(--text-secondary);
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 600;
    margin-right: 0.3rem;
    margin-top: 0.3rem;
}
.library-empty {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.88rem;
}
.library-detail {
    flex: 1;
    overflow-y: auto;
    padding: 1.4rem 1.8rem 3rem;
    background: var(--bg-page);
}
.library-bars { margin-top: 0.6rem; }
.library-bar-row { margin-bottom: 0.4rem; }
.library-bar-label {
    font-size: 0.75rem;
    display: flex; justify-content: space-between;
    color: var(--text-secondary); margin-bottom: 0.2rem;
}
.library-bar-pct { font-weight: 700; color: var(--text-primary); }
.library-bar-inner { height: 6px; background: var(--bg-surface-2); border-radius: 3px; overflow: hidden; }
.library-bar-fill { height: 100%; background: var(--brand-grad); border-radius: 3px; }

.profile-section {
    padding: 1rem 1.1rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 0.8rem;
}
.profile-section h3 { font-size: 0.88rem; margin-bottom: 0.5rem; }

.tag-cloud { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.tag {
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
}
.tag-good { background: rgba(16,185,129,0.12); color: #059669; border: 1px solid rgba(16,185,129,0.2); }
.tag-bad  { background: rgba(239,68,68,0.12); color: #dc2626; border: 1px solid rgba(239,68,68,0.2); }
[data-theme="dark"] .tag-good { color: #34d399; }
[data-theme="dark"] .tag-bad  { color: #f87171; }

.do-item, .dont-item, .channel-item, .headline-item {
    padding: 0.5rem 0.7rem;
    background: var(--bg-surface-2);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    margin-bottom: 0.35rem;
}
.do-item::before { content: "✓  "; color: var(--success); font-weight: 700; }
.dont-item::before { content: "✕  "; color: var(--danger); font-weight: 700; }

.collapsible-toggle {
    width: 100%; text-align: left;
    padding: 0.6rem 0.8rem;
    background: var(--bg-surface-2);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    font-weight: 600; font-size: 0.85rem;
    margin-top: 0.5rem;
    display: flex; justify-content: space-between; align-items: center;
}
.collapsible-toggle::after { content: "▾"; color: var(--text-muted); }
.collapsible-toggle.active::after { content: "▴"; }
.collapsible-content { display: none; padding: 0.8rem 0.1rem; }
.collapsible-content.open { display: block; }

/* ---------- 15. Group badges ---------- */
.group-badges { display: flex; gap: 0.4rem; margin-top: 0.3rem; flex-wrap: wrap; }
.group-badge {
    padding: 0.2rem 0.55rem;
    background: var(--bg-surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-secondary);
}

/* ---------- 16. Find similar ---------- */
.find-similar-section {
    padding: 0.8rem;
    background: var(--bg-surface-2);
    border-radius: var(--radius-md);
    margin-top: 0.7rem;
}
.find-similar-btn {
    width: 100%;
    padding: 0.5rem 0.8rem;
    background: var(--brand-grad);
    color: white;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.82rem;
    margin-top: 0.45rem;
}

/* ---------- 17. Profile slide-in ---------- */
.profile-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.45);
    opacity: 0;
    visibility: hidden;
    transition: opacity .22s var(--ease), visibility .22s var(--ease);
    /* Sit just below the profile panel itself (9500) but above Leaflet (1000) */
    z-index: 9499;
}
.profile-overlay.open,
.profile-overlay.visible { opacity: 1; visibility: visible; }
.profile-panel {
    position: fixed; top: 0; right: 0; bottom: 0;
    width: 480px; max-width: 100vw;
    background: var(--bg-surface);
    border-left: 1px solid var(--border);
    box-shadow: -20px 0 60px rgba(0,0,0,0.25);
    transform: translateX(100%);
    transition: transform .3s var(--ease);
    /* Above Leaflet (1000) and the More sheet (9000+) — profile panel must
       always be top-most so opening it from any tab works. */
    z-index: 9500;
    display: flex; flex-direction: column;
    /* Respect the right safe-area (notch / rounded corner) on landscape iOS */
    padding-right: env(safe-area-inset-right);
    padding-top: env(safe-area-inset-top);
}
.profile-panel.open,
.profile-panel.visible { transform: translateX(0); }
.profile-panel-header {
    padding: 1.2rem 1.2rem 0.8rem;
    border-bottom: 1px solid var(--border);
    position: relative;
    background: linear-gradient(180deg, rgba(124,92,255,0.10), transparent 80%);
}
.profile-panel-header h2 {
    font-size: 1.25rem; font-weight: 700; letter-spacing: -0.01em;
    padding-right: 2rem;
}
.profile-panel-body { padding: 1.2rem; overflow-y: auto; flex: 1; }
.close-btn {
    position: absolute; top: 0.9rem; right: 0.9rem;
    width: 36px; height: 36px; border-radius: 10px;
    font-size: 1.3rem; color: var(--text-primary);
    background: var(--bg-surface-2);
    border: 1px solid var(--border);
}
.close-btn:hover { color: var(--brand-500); border-color: var(--brand-500); }
@media (hover: none) and (pointer: coarse) {
    .close-btn { width: 44px; height: 44px; }
}

/* ---------- 18. Loading overlay ---------- */
.loading-overlay {
    position: fixed; inset: 0;
    background: rgba(11,13,18,0.65);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: none;
    align-items: center; justify-content: center;
    flex-direction: column; gap: 1rem;
    z-index: 9999;
    color: white;
}
.loading-overlay.active { display: flex; }
.spinner {
    width: 40px; height: 40px;
    border: 3px solid rgba(255,255,255,0.2);
    border-top-color: var(--brand-400);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 0.88rem; font-weight: 500; }

/* ---------- 19. Mobile bottom nav — 3-group version ---------- */
.mobile-bottom-nav {
    display: none;
    position: fixed; left: 0; right: 0; bottom: 0;
    background: var(--nav-bg);
    backdrop-filter: saturate(140%) blur(10px);
    -webkit-backdrop-filter: saturate(140%) blur(10px);
    border-top: 1px solid var(--border);
    z-index: 40;
    padding-bottom: env(safe-area-inset-bottom);
}

/* Chip row sits ABOVE the 3 group buttons, inside the same nav. */
.mobile-group-chips {
    display: flex;
    gap: 4px;
    padding: 8px 10px 6px;
    overflow-x: auto;
    scrollbar-width: none;
    border-bottom: 1px solid var(--border);
}
.mobile-group-chips::-webkit-scrollbar { display: none; }

.mgc-chip {
    flex-shrink: 0;
    padding: 5px 11px;
    font-size: 12px; font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-surface-2);
    border-radius: 999px;
    transition: background .15s var(--ease), color .15s var(--ease);
}
.mgc-chip:active { transform: scale(.97); }
.mgc-chip.active {
    background: var(--brand-500);
    color: #fff;
}

/* The 3 group buttons (Explore / Analyze / Deliver). */
.mobile-group-row {
    display: flex;
    align-items: stretch;
}
.mobile-nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 8px 4px 10px;
    color: var(--nav-text);
    position: relative;
    transition: color .15s var(--ease);
}
.mobile-nav-btn svg {
    width: 20px; height: 20px;
    stroke: currentColor; fill: none;
}
.mobile-nav-label {
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.01em;
}
.mobile-nav-btn.active { color: var(--brand-500); }
.mobile-nav-btn.active::before {
    content: "";
    position: absolute; top: 0; left: 22%; right: 22%;
    height: 2px; border-radius: 0 0 3px 3px;
    background: var(--brand-grad);
}

/* Mobile "More" sheet */
/* Host element injected by openMoreMenu() — needs its own stacking
   context ABOVE Leaflet's internal UI layers. Leaflet uses:
     .leaflet-pane        z-index: 400
     .leaflet-tile-pane   z-index: 200
     .leaflet-overlay-pane z-index: 400
     .leaflet-control     z-index: 800
     .leaflet-top/.leaflet-bottom z-index: 1000
   So we must sit above 1000. We park at 9000 to stay clear of everything. */
#mobileMoreMenu {
    position: fixed;
    inset: 0;
    z-index: 9000;
    display: none;
    pointer-events: none;
}
#mobileMoreMenu.open {
    display: block;
    pointer-events: auto;
}
.mobile-more-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 9001;
    animation: fade .22s var(--ease);
}
.mobile-more-panel {
    position: fixed; left: 0; right: 0; bottom: 0;
    background: var(--sheet-bg);
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    padding: 0.6rem 1rem max(1rem, env(safe-area-inset-bottom));
    z-index: 9002;
    animation: sheetUp .28s var(--ease);
    box-shadow: 0 -18px 60px rgba(0,0,0,0.35);
}
.mobile-more-panel::before {
    content: "";
    display: block;
    width: 40px; height: 4px;
    background: var(--border-strong);
    border-radius: 2px;
    margin: 0 auto 0.7rem;
}
.mobile-more-title {
    font-size: 0.72rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.08em;
    color: var(--text-muted);
    padding: 0.3rem 0;
}
.mobile-more-panel > button {
    display: flex; align-items: center;
    width: 100%;
    padding: 0.9rem 1rem;
    margin-top: 0.4rem;
    background: var(--bg-surface-2);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    text-align: left;
    min-height: 48px;
    transition: border-color .14s var(--ease), color .14s var(--ease);
}
.mobile-more-panel > button:hover { border-color: var(--brand-500); color: var(--brand-500); }
.mobile-more-panel > button:active { transform: scale(0.99); }
.mobile-more-cancel {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg-surface-2);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    font-weight: 600;
    margin-top: 0.9rem !important;
    justify-content: center !important;
    text-align: center !important;
}
.mobile-more-soon {
    font-size: 0.78rem;
    color: var(--text-muted);
    padding: 0.65rem 0.85rem;
    margin-top: 0.3rem;
    background: var(--bg-surface-2);
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    text-align: center;
    font-style: italic;
}

/* PWA install */
.pwa-install-banner {
    position: fixed; left: 12px; right: 12px;
    /* Sit above the mobile bottom nav (~64px + safe-area) so it doesn't
       overlap or get covered; on desktop bottom nav is hidden so 16px is fine. */
    bottom: calc(72px + env(safe-area-inset-bottom));
    display: flex; align-items: center; gap: 0.8rem;
    padding: 0.7rem 0.9rem;
    background: var(--glass);
    backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    border: 1px solid var(--glass-stroke);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    z-index: 60;
}
.pwa-install-banner[hidden] { display: none !important; }
@media (min-width: 901px) {
    .pwa-install-banner { bottom: 16px; }
}
.pwa-install-text { flex: 1; font-size: 0.8rem; }
.pwa-install-text strong { display: block; margin-bottom: 0.1rem; }
.pwa-install-actions { display: flex; gap: 0.3rem; align-items: center; }
#pwaInstallBtn { padding: 0.45rem 0.8rem; font-size: 0.82rem; }
.pwa-install-dismiss {
    width: 32px; height: 32px; border-radius: 8px;
    color: var(--text-secondary);
    font-size: 1.2rem;
    background: transparent;
    border: 0;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color .15s var(--ease), background .15s var(--ease);
    flex-shrink: 0;
}
.pwa-install-dismiss:hover { color: var(--text-primary); background: var(--bg-surface-2); }
.pwa-install-dismiss:active { transform: scale(.95); }

/* ---------- 20. Skeletons ---------- */
.skeleton {
    background: linear-gradient(90deg, var(--bg-surface-2) 0%, var(--border) 50%, var(--bg-surface-2) 100%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
    border-radius: 6px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.skeleton-heading { height: 14px; width: 60%; margin-bottom: 0.5rem; }
.skeleton-text { height: 10px; width: 100%; margin-bottom: 0.35rem; }
.skeleton-avatar { width: 36px; height: 36px; border-radius: 50%; }
.skeleton-card { padding: 0.7rem; background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 0.4rem; }
.skeleton-row { display: flex; align-items: center; gap: 0.6rem; }

/* ---------- 21. Toast notifications ---------- */
.toast-container {
    position: fixed;
    top: 80px; right: 16px;
    display: flex; flex-direction: column; gap: 0.4rem;
    z-index: 9998;
    pointer-events: none;
}
.toast {
    pointer-events: auto;
    padding: 0.7rem 0.95rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: 0.82rem;
    min-width: 240px; max-width: 340px;
    animation: toastIn .28s var(--ease);
    display: flex; align-items: flex-start; gap: 0.55rem;
}
.toast.success { border-color: rgba(16,185,129,0.4); }
.toast.error   { border-color: rgba(239,68,68,0.4); }
.toast.info    { border-color: rgba(34,211,238,0.4); }
@keyframes toastIn { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }

/* ---------- 22. Onboarding tour ---------- */
.tour-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 9000;
    display: flex; align-items: center; justify-content: center;
    animation: fade .25s var(--ease);
}
.tour-card {
    width: min(460px, calc(100% - 2rem));
    padding: 1.4rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}
.tour-card h3 { font-size: 1.1rem; margin-bottom: 0.4rem; }
.tour-card p { font-size: 0.9rem; color: var(--text-secondary); line-height: 1.55; }
.tour-dots { display: flex; gap: 0.3rem; margin: 1rem 0 0.8rem; }
.tour-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--border); }
.tour-dot.active { background: var(--brand-500); width: 18px; border-radius: 4px; }
.tour-footer { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.tour-skip {
    padding: 0.5rem 0.8rem;
    color: var(--text-muted);
    font-size: 0.82rem;
}

/* ---------- 23. Utility ---------- */
.hidden { display: none !important; }
.flex { display: flex; }
.grid { display: grid; }

/* Geocode confirm modal dynamic injection */
.geocode-confirm {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 8000;
    display: flex; align-items: center; justify-content: center;
    animation: fade .2s var(--ease);
}
.geocode-confirm .gcc-card {
    width: min(440px, calc(100% - 2rem));
    padding: 1.2rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

/* Mobile sheet host */
.mobile-sheet-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 65;
    animation: fade .22s var(--ease);
}

/* ---------- 24. Responsive breakpoints ---------- */
@media (max-width: 900px) {
    :root {
        --mobile-header-h: 52px;
        --mobile-subnav-h: 40px;
        --mobile-bottomnav-h: 64px;
        --mobile-sidebar-maxh: 27vh;
    }

    .tabs { display: none; }
    .mobile-subnav { display: flex; }
    .mobile-bottom-nav {
        display: flex;
        position: fixed; bottom: 0; left: 0; right: 0;
        /* Must beat Leaflet (.leaflet-top/.leaflet-bottom = z-index 1000).
           Otherwise map controls/tiles render on top of the nav. */
        z-index: 1001;
        /* Solid background — blur makes map tiles bleed through on iOS */
        background: var(--bg-surface);
    }
    .tab-content { height: calc(100dvh - var(--mobile-header-h) - var(--mobile-subnav-h) - var(--mobile-bottomnav-h) - env(safe-area-inset-bottom)); }
    body.has-pwa-banner .mobile-bottom-nav { box-shadow: 0 -2px 16px rgba(0,0,0,0.12); }

    /* Hide the floating persona legend on mobile — takes too much space
       and duplicates info already shown in the sidebar persona panel. */
    .legend { display: none !important; }

    /* Keep Leaflet's bottom-corner controls (attribution, zoom) above the
       map tiles but clearly BELOW the bottom nav */
    .leaflet-bottom { z-index: 500 !important; }

    .compare-maps { grid-template-columns: 1fr; }
    .compare-map-pane { display: none; }
    .compare-map-pane.active { display: block; }
    .mc-mobile-tabs {
        display: flex;
        padding: 0.3rem 0.8rem;
        background: var(--bg-surface);
        border-bottom: 1px solid var(--border);
        gap: 0.3rem;
    }
    .mc-mobile-tabs button {
        flex: 1;
        padding: 0.5rem;
        background: var(--bg-surface-2);
        color: var(--text-secondary);
        border-radius: var(--radius-sm);
        font-weight: 600;
        font-size: 0.82rem;
    }
    .mc-mobile-tabs button.active {
        background: var(--brand-grad);
        color: white;
    }

    .container, .score-container, .ask-container, .library-layout {
        flex-direction: column;
    }
    .sidebar, .score-sidebar, .ask-sidebar, .library-list-pane {
        width: 100%;
        max-height: 55%;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }
    #map, .score-map, .ask-map, .library-detail {
        min-height: 45%;
    }

    .li-panel { width: 100%; }
    .li-label-full { display: none; }
    .li-label-short { display: inline; }

    .legend {
        right: max(10px, env(safe-area-inset-right));
        bottom: calc(80px + env(safe-area-inset-bottom));
        max-width: min(200px, calc(100vw - 40px));
    }
}

@media (max-width: 520px) {
    header { padding: 0.6rem 0.9rem; }
    header h1 { font-size: 0.95rem; }
    .mobile-nav-btn { font-size: 0.62rem; padding: 0.35rem 0.4rem; }
    .mobile-nav-btn svg { width: 18px; height: 18px; }
    .report-form { padding: 1rem; margin: 0.8rem auto; }
    .tab-content { height: calc(100dvh - var(--mobile-header-h) - var(--mobile-subnav-h) - var(--mobile-bottomnav-h)); }
}

/* Touch targets on mobile — WCAG 2.5.5 target size is 44×44px */
@media (hover: none) and (pointer: coarse) {
    button, .tab-btn, .mobile-nav-btn, .lib-seg-btn, .bm-btn, .icon-btn, .ask-example, .li-tool-btn, .file-label, .wh-profile-btn, .pwa-install-dismiss {
        min-height: 44px;
    }
    .icon-btn, .pwa-install-dismiss {
        min-width: 44px;
    }
    /* Keyboard / switch-control focus indicator — critical for a11y */
    :focus-visible {
        outline: 2px solid var(--brand-500);
        outline-offset: 2px;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ==========================================================================
   MOBILE LAYOUT HARDENING (controls-first, bounded maps)
   These rules override earlier ones only on mobile viewports so that
   every tab behaves the same: controls visible at top, map/content
   below with a firm height cap.  Root cause this fixes:
     - Maps were carrying min-height:300px on mobile which squeezed sidebars.
     - .compare-inputs could wrap unbounded and steal all vertical space.
     - .library-detail was being treated as a "map" via the shared rule.
     - data-sheet-state was present in HTML but had no CSS.
   ========================================================================== */
@media (max-width: 900px) {
    /* 1. Make every tab a simple top-to-bottom column with guaranteed stacking */
    .container,
    .score-container,
    .ask-container,
    .library-layout,
    .compare-container,
    .li-layout {
        display: flex;
        flex-direction: column;
        height: 100%;
        width: 100%;
        overflow: hidden;
    }

    /* 2. Kill the 300px map floor on mobile — the biggest culprit */
    #map,
    .li-map,
    .score-map,
    .ask-map,
    .compare-map-pane {
        min-height: 0 !important;
        height: auto;
    }

    /* 3. Force sidebars FIRST (order 1) with hard size caps,
          force maps SECOND (order 2) to fill remaining space. */
    .sidebar,
    .score-sidebar,
    .ask-sidebar,
    .library-list-pane,
    .compare-inputs {
        order: 1;
        flex: 0 1 auto;
        width: 100%;
        max-height: var(--mobile-sidebar-maxh);
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        border-right: 0;
        border-bottom: 1px solid var(--border);
        padding: 0.6rem 0.85rem;
        position: relative;
    }

    /* Scroll indicator — sticky chevron badge pinned at bottom of the
       scroll viewport so users know there's more content below the fold. */
    .sidebar::after,
    .score-sidebar::after,
    .ask-sidebar::after,
    .library-list-pane::after,
    .compare-inputs::after {
        content: 'Scroll ↓';
        position: sticky;
        bottom: 6px;
        left: 50%;
        display: block;
        width: max-content;
        margin: 6px auto -4px;
        padding: 4px 10px;
        font-size: 0.68rem;
        font-weight: 600;
        letter-spacing: 0.02em;
        color: #fff;
        background: var(--accent, #4f46e5);
        border-radius: 999px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.25);
        pointer-events: none;
        opacity: 0.92;
        animation: lp-scroll-hint 1.4s ease-in-out infinite;
    }

    @keyframes lp-scroll-hint {
        0%,100% { transform: translateY(0); opacity: 0.85; }
        50%     { transform: translateY(3px); opacity: 1; }
    }

    .sidebar h3,
    .score-sidebar h3,
    .ask-sidebar h3,
    .library-list-pane h3 {
        font-size: 0.85rem;
        margin-bottom: 0.4rem;
    }

    .sidebar input,
    .sidebar button,
    .score-sidebar input,
    .score-sidebar button,
    .ask-sidebar input,
    .ask-sidebar button,
    .library-list-pane input,
    .library-list-pane button,
    .compare-inputs input,
    .compare-inputs button {
        height: 34px;
        font-size: 0.82rem;
    }

    .sidebar p,
    .score-sidebar p,
    .ask-sidebar p,
    .library-list-pane p {
        font-size: 0.74rem;
        line-height: 1.4;
    }

    #map,
    .score-map,
    .ask-map,
    .li-map,
    .compare-maps {
        order: 2;
        flex: 1 1 auto;
        width: 100%;
        height: auto;
        max-height: none;
        min-height: 240px;
    }

    /* 4. Library detail is NOT a map — treat it like a result pane */
    .library-detail {
        order: 2;
        flex: 1 1 auto;
        width: 100%;
        min-height: 40vh;
        max-height: 55vh;
        overflow-y: auto;
    }

    /* 5. Compare tab specifics: inputs stay at top, A/B switcher visible,
          maps sit below the switcher, results scroll. */
    .compare-inputs {
        padding: 0.7rem 0.9rem;
        gap: 0.5rem;
    }
    .compare-input-group { flex: 1 1 46%; min-width: 0; }
    .compare-input-group[style*="120px"],
    .compare-input-group[style*="140px"],
    .compare-input-group[style*="240px"] {
        flex: 1 1 46% !important;
    }
    .compare-btn { flex: 1 1 100%; align-self: stretch; }
    .mc-mobile-tabs { order: 2; flex: 0 0 auto; }
    .compare-maps {
        order: 3;
        display: block;              /* override grid from desktop */
        height: 42vh;
    }
    .compare-map-pane { width: 100%; height: 100%; }
    .compare-map-pane.active { display: block; }
    .compare-map-pane:not(.active) { display: none; }
    .compare-results { order: 4; }

    /* 6. Lead Intelligence (analyze) on mobile:
          the banner + panel are absolutely positioned over the map on desktop.
          On mobile we need the banner to be reachable and the panel to be a sheet. */
    #analyze-tab .li-map {
        position: relative;          /* override inset: 0 absolute on mobile */
        inset: auto;
        order: 2;
        height: 42vh;
    }
    .li-top-banner {
        position: static;            /* no longer overlay */
        transform: none;
        order: 1;
        align-self: center;
        margin: 0.5rem auto;
        max-width: calc(100% - 18px);
    }
    .li-panel {
        position: fixed;             /* bottom sheet on mobile */
        left: 0; right: 0; top: auto; bottom: 0;
        width: 100%;
        max-height: 75vh;
        transform: translateY(100%);
        border-left: 0;
        border-top: 1px solid var(--border);
        border-top-left-radius: 20px;
        border-top-right-radius: 20px;
        box-shadow: 0 -18px 60px rgba(0,0,0,0.35);
    }
    .li-panel.open { transform: translateY(0); }

    /* 7. Ensure the mobile-sheet-host marker never collapses to zero
          (defensive — in case JS toggles data-sheet-state before CSS loads) */
    .mobile-sheet-host[data-sheet-state="closed"] { display: block; }
}

/* ==========================================================================
   Short-phone tweak: viewports under 520px are tight, so we trade a bit
   of map height for sidebar breathing room.
   ========================================================================== */
@media (max-width: 520px) {
    .sidebar,
    .score-sidebar,
    .ask-sidebar,
    .library-list-pane,
    .compare-inputs {
        max-height: var(--mobile-sidebar-maxh);
    }
    #map, .score-map, .ask-map, .li-map, .compare-maps,
    .compare-map-pane, .library-detail {
        height: auto;
        flex: 1 1 auto;
        min-height: 240px;
        max-height: none;
    }
    .compare-input-group { flex: 1 1 100%; }
}
