/* PATH A: :root defaults — moved from index.html so all 14 pages get them.
   Without this, non-index pages render unstyled (browser default white bg). */
:root {
    --bg: #0a1410;
    --bg-elev: #0f1c17;
    --bg-elev-2: #14241d;
    --fg: #e6f3ec;
    --fg-dim: #9bb5a7;
    --fg-mute: #6b8077;
    --accent: #10b981; /* Emerald 500 — primary brand */
    --accent-dim: #047857; /* Emerald 700 — hover/active */
    --accent-fg: #04231a; /* dark text on emerald bg */
    --accent-soft: rgba(16, 185, 129, 0.14);
    --accent-border: rgba(16, 185, 129, 0.45);
    --accent-glow: rgba(52, 211, 153, 0.5);
    --warn: #facc15;
    --err: #dc2626;
    --info: #06b6d4;
    --pos: #34d399;
    --sev-low: #34d399;
    --sev-med: #facc15;
    --sev-high: #047857;
    --sev-alert: #ef4444;
    --live: #34d399;
    --live-bg: rgba(52, 211, 153, 0.12);
    --line: #1f352a;
    --tile-default: #0369a1;
    --tile-priority: #059669;
    --tile-priority-fill: #064e3b;
    --property: #10b981;
    --property-fill: #064e3b;
    --gbif-animalia: #facc15;
    --gbif-plantae: #34d399;
    --shadow: 0 4px 24px rgba(0,0,0,.25);
    --radius: 10px;
    --radius-lg: 14px;
    --forest: #4d7c0f;
    --forest-soft: rgba(77, 124, 15, 0.16);
    --forest-border: rgba(77, 124, 15, 0.40);
    --water: #0369a1;
    --water-soft: rgba(3, 105, 161, 0.16);
    --water-border: rgba(3, 105, 161, 0.40);
    --soil: #a16207;
    --soil-soft: rgba(161, 98, 7, 0.16);
    --soil-border: rgba(161, 98, 7, 0.40);
    --sand: #f5deb3;
    --paper: #faf6ef;
}

/* PATH A: Base body styles — moved from index.html so all 14 pages get them */
*, *::before, *::after { box-sizing: border-box; }
html { height: 100%; }
body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--fg);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    opacity: 0.04;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 200'><g fill='none' stroke='%2310b981' stroke-width='0.6'><path d='M-20,60 Q30,40 80,55 T200,50'/><path d='M-20,80 Q40,55 90,75 T200,70'/><path d='M-20,100 Q35,70 85,95 T200,90'/><path d='M-20,120 Q50,85 100,115 T200,110'/><path d='M-20,140 Q30,105 85,135 T200,130'/><path d='M-20,160 Q40,120 90,155 T200,150'/><path d='M-20,40 Q35,15 85,30 T200,30'/><path d='M-20,20 Q40,-5 90,10 T200,10'/><path d='M-20,180 Q35,145 85,175 T200,170'/></g></svg>");
    background-size: 240px 240px;
}

/* Light theme overrides — semantic vars already have light variants */
[data-theme="light"] {
    --bg: #f0fdf4;
    --bg-elev: #ffffff;
    --bg-elev-2: #ecfdf5;
    --fg: #052e16;
    --fg-dim: #475569;
    --fg-mute: #94a3b8;
    --line: #d1fae5;
    --line-strong: #a7f3d0;
    --accent: #059669; /* emerald 600 for light */
    --accent-dim: #064e3b;
    --accent-fg: #ffffff;
    --accent-soft: rgba(5, 150, 105, 0.10);
    --accent-border: rgba(5, 150, 105, 0.30);
    --accent-glow: rgba(16, 185, 129, 0.4);
    --warn: #ca8a04;
    --err: #dc2626;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}
[data-theme="light"] body::before {
    opacity: 0.06;
}
[data-theme="light"] .cmdk-overlay {
    background: rgba(250, 246, 239, 0.7);
}

/* Skeleton loaders */
.skeleton {
    background: linear-gradient(90deg, var(--bg-elev-2) 0%, var(--line) 50%, var(--bg-elev-2) 100%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.4s ease-in-out infinite;
    border-radius: 4px;
    color: transparent !important;
}
@keyframes skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
.skeleton-line {
    height: 12px;
    margin: 4px 0;
}
.skeleton-line.short { width: 40%; }
.skeleton-line.medium { width: 60%; }
.skeleton-line.long { width: 90%; }
.skeleton-circle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: inline-block;
}

/* === Mobile responsive pass === */
@media (max-width: 768px) {
    body { font-size: 14px; padding: 0; margin: 0; }
    body::before { opacity: 0.02; }  /* less prominent on small screens */

    /* Compact header: tighten padding, single-line nav, hide secondary chips */
    header {
        padding: 6px 10px !important;
        gap: 6px !important;
        flex-wrap: nowrap !important;
        align-items: center;
        min-height: 44px;
    }
    header h1 { font-size: 14px !important; flex: 0 0 auto; }
    header nav {
        flex: 1 1 0 !important;
        min-width: 0 !important;
        overflow-x: auto !important;
        overflow-y: hidden;
        white-space: nowrap !important;
        padding: 0 !important;
        margin-top: 0 !important;
        border-top: none !important;
        flex-basis: 0 !important;
        height: 32px;
        display: flex !important;
        align-items: center;
    }
    /* Hide secondary nav links on mobile to keep just primary actions */
    header nav a[href*="run-tracker"],
    header nav a[href*="barrios"],
    header nav a[href*="cde"],
    header nav a[href*="asuncion"] {
        display: none !important;
    }
    /* Hide chip strip on mobile (BCP, GitHub link, language picker are still visible
       in MÁS dropdown, so user can reach them). */
    header .freshness-badge,
    header .bcp-badge,
    header .lang-picker,
    header #mapTitle,
    header > a[href*="github"],
    header #newsTickerBtn,
    header #langSwitcher,
    header .repo-link,
    header #moreMenu,
    header .cmdk-trigger,
    .cmdk-trigger {
        display: none !important;
    }
    /* Compress share button on mobile */
    #btnShare { padding: 4px 6px !important; font-size: 0 !important; }
    #btnShare svg { margin: 0 !important; }
    /* Keep theme/install buttons but tighten */
    #btnTheme, #btnInstall { margin-left: 2px !important; }

    /* Map fills viewport below the compact header */
    #map { height: calc(100vh - 50px) !important; }

    /* Compress header chips */
    .cmdk-trigger { font-size: 11px !important; padding: 3px 8px !important; }
    .cmdk-trigger span:not(kbd) { display: none; }
    .cmdk-trigger kbd { display: inline; }

    /* Map: take full width, full height */
    #map, .leaflet-container {
        height: calc(100vh - 50px) !important;
        width: 100% !important;
    }
    
    /* Panels: stack vertically */
    .panel { padding: 12px !important; margin: 6px 0 !important; }
    section.full.panel { padding: 12px !important; }
    
    /* Tables: horizontal scroll */
    table { 
        font-size: 11px !important;
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
    
    /* Hide non-essential chips on small screens */
    .bcp-badge { font-size: 10px !important; padding: 2px 6px !important; }
    
    /* Navigation: collapsible */
    header nav {
        flex: 0 0 100%;
        overflow-x: auto;
        white-space: nowrap;
        padding: 4px 0;
        border-top: 1px solid var(--line);
        margin-top: 4px;
    }
    header nav a { 
        padding: 4px 8px !important; 
        font-size: 11px !important;
        flex-shrink: 0;
    }
    
    /* Cmd+K modal: full width on mobile */
    .cmdk-modal { width: 95vw !important; max-height: 80vh !important; }
    
    /* Chip strip: tighter */
    .mapbiomas-scrubber { padding: 10px !important; }
    .mapbiomas-scrubber-year { font-size: 16px !important; }
    
    /* Footer / lower widgets */
    .legend { font-size: 11px !important; }
    
    /* NL→SQL panel */
    .nl2sql-input-row { flex-wrap: wrap; }
    .nl2sql-input { font-size: 13px; min-width: 0; flex: 1 1 100%; }
    
    /* Cross-filter banner: smaller */
    #crossFilterBanner { font-size: 11px !important; padding: 6px 12px !important; }
}

@media (max-width: 480px) {
    header h1 { font-size: 16px !important; }
    /* Hide more elements on tiny screens */
    .map-title { display: none; }
    .freshness-badge { font-size: 10px !important; }
}

/* Inline kbd styling */
kbd {
    background: var(--bg-elev-2);
    border: 1px solid var(--line);
    border-radius: 3px;
    padding: 1px 5px;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 11px;
    color: var(--fg);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
}

/* Print stylesheet */
@media print {
    body { background: white !important; color: black !important; font-size: 11pt; }
    body::before { display: none !important; }
    header, footer, nav, .cmdk-trigger, .theme-toggle, .page-help-btn,
    #crossFilterBanner, .legend, .share-btn, .view-on-map-btn {
        display: none !important;
    }
    .panel, section { box-shadow: none !important; border: 1px solid #ccc !important; page-break-inside: avoid; }
    .cmdk-overlay, .kbd-overlay { display: none !important; }
    a { color: black !important; text-decoration: underline; }
    a[href]::after { content: " (" attr(href) ")"; font-size: 9pt; }
    h1 { font-size: 18pt; }
    h2 { font-size: 14pt; page-break-after: avoid; }
    table { border-collapse: collapse !important; width: 100% !important; }
    th, td { border: 1px solid #ccc !important; padding: 4px !important; color: black !important; background: white !important; }
    .mapbiomas-scrubber, .nl2sql-panel, .filter-chip {
        border: 1px solid #ccc !important;
    }
    [data-print-hide] { display: none !important; }
    [data-print-show] { display: block !important; }
    @page { margin: 1.5cm; }
}

/* === Micro-interactions & animations === */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes pulse-soft {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Smooth hover lift on cards / panels */
.panel:hover, .card:hover, .barrio-card:hover {
    transform: translateY(-1px);
    transition: transform 0.15s ease;
}

/* Active state for buttons */
button:active:not(:disabled), .btn:active {
    transform: scale(0.97);
    transition: transform 0.05s;
}

/* Focus ring (accessibility) */
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Live dot pulse */
.live-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    animation: pulse-soft 1.5s ease-in-out infinite;
    margin-right: 4px;
    vertical-align: middle;
}

/* Smooth transitions for all interactive elements */
button, a, .panel, .card, .chip, .filter-chip {
    transition: background-color 0.12s, color 0.12s, border-color 0.12s, box-shadow 0.12s;
}

/* Better scrollbar in Webkit */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
::-webkit-scrollbar-track {
    background: var(--bg);
}
::-webkit-scrollbar-thumb {
    background: var(--line-strong);
    border-radius: 5px;
    border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

/* Selection color */
::selection {
    background: var(--accent);
    color: var(--bg);
}

/* Spinner */
.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--line);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* Smooth fade-in for new content */
.fade-in {
    animation: fadeIn 0.3s ease-out;
}

/* Status badges */
.badge-live {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: rgba(194, 65, 12, 0.15);
    color: var(--accent);
    border-radius: 12px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.badge-live::before {
    content: '';
    display: inline-block;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--accent);
    animation: pulse-soft 1.5s ease-in-out infinite;
}

/* Skip to content link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 8px;
    background: var(--accent);
    color: var(--bg);
    padding: 8px 12px;
    border-radius: 4px;
    font-weight: 600;
    text-decoration: none;
    z-index: 9999;
    transition: top 0.15s;
}
.skip-link:focus {
    top: 8px;
}
.skip-link:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

/* Better focus indicators for all interactive elements */
*:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 2px;
}

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

/* ============================================================ */
/*  PATCH 2026-09-21 — UI/UX upgrade (markers / sidebar / nav / popup / buttons) */
/*  All new rules scoped under .pg-up- to avoid colliding with existing styles. */
/* ============================================================ */

/* ---------- #1 MARKERS: price-label density fade by zoom ---------- */
/* JS toggles .pg-up-labels-fade on the map container at zoom < 12 and */
/* .pg-up-labels-hide at zoom < 10. Below: price pills fade to invisible.   */
.leaflet-container.pg-up-labels-fade .py-price-label {
    opacity: 0.45;
    transition: opacity 0.2s ease;
}
.leaflet-container.pg-up-labels-hide .py-price-label {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

/* Price-band color ramp — green gradient. Low (mint) → mid (emerald) → high (deep forest). */
.pg-up-price-band-low  { background: #34d399 !important; color: #fff !important; border-color: rgba(0,0,0,0.06) !important; }
.pg-up-price-band-mid  { background: #059669 !important; color: #fff !important; border-color: rgba(0,0,0,0.06) !important; }
.pg-up-price-band-high { background: #064e3b !important; color: #d1fae5 !important; }

/* Selected marker ring — added by JS to the chosen CircleMarker via .pg-up-selected */
.leaflet-interactive.pg-up-selected {
    stroke: #fff !important;
    stroke-width: 3 !important;
    filter: drop-shadow(0 0 6px rgba(194,65,12,0.6));
}

/* Custom cluster bubble — replaces the inline badge. Smaller footprint, color by count. */
.pg-up-cluster-bubble {
    background: var(--bg-elev);
    color: var(--fg);
    border: 2px solid var(--accent);
    border-radius: 999px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.18);
    font: 600 11px/1 ui-sans-serif, system-ui, sans-serif;
    padding: 4px 8px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}
.pg-up-cluster-bubble.hot {
    background: var(--accent);
    color: var(--bg);
    border-color: rgba(255,255,255,0.4);
}

/* ---------- #4 POPUP: stronger surface + shadow + active z-index ---------- */
.leaflet-popup-content-wrapper.pg-up-active {
    border-radius: 12px !important;
    box-shadow: 0 12px 32px rgba(10, 14, 26, 0.22) !important;
    border: 1px solid var(--line) !important;
    background: var(--bg-elev) !important;
    z-index: 1000 !important;
}
.leaflet-popup-content-wrapper.pg-up-active h3 {
    font-family: Fraunces, Georgia, serif;
    font-weight: 600;
    margin: 0 0 6px 0;
    color: var(--fg);
}
.leaflet-popup-tip.pg-up-active {
    background: var(--bg-elev) !important;
    box-shadow: 0 4px 12px rgba(10, 14, 26, 0.12) !important;
}

/* Currency chip in popup top-right */
.pg-up-currency-chip {
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--bg-elev-2);
    color: var(--fg);
    border: 1px solid var(--line);
    border-radius: 999px;
    font: 600 10px/1 ui-sans-serif;
    padding: 3px 7px;
    cursor: pointer;
    user-select: none;
}
.pg-up-currency-chip:hover { color: var(--accent); border-color: var(--accent); }

/* ---------- #5 BUTTONS: Aplicar dominant, Limpiar ghost ---------- */
/* Apply to both desktop and mobile filter buttons (data-attr hook). */
button[data-pg-role="apply"], button[data-pg-role="clear"] {
    font-family: inherit;
    transition: background-color 0.15s, border-color 0.15s, transform 0.05s, box-shadow 0.15s;
}
button[data-pg-role="apply"]:hover { box-shadow: 0 4px 12px rgba(194,65,12,0.28); transform: translateY(-1px); }
button[data-pg-role="clear"]:hover { color: var(--accent); border-color: var(--accent); background: var(--bg-elev-2); }

/* ---------- #2 SIDEBAR: sticky tab bar at top of <aside> ---------- */
.pg-up-sidebar-tabs {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    gap: 4px;
    padding: 8px 10px;
    background: var(--bg-elev);
    border-bottom: 1px solid var(--line);
    margin: 0 0 8px 0;
    backdrop-filter: blur(6px);
}
.pg-up-sidebar-tab {
    flex: 1;
    text-align: center;
    padding: 6px 8px;
    border-radius: 6px;
    background: transparent;
    color: var(--fg-dim);
    border: 1px solid transparent;
    font: 500 12px/1 ui-sans-serif;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.12s, color 0.12s, border-color 0.12s;
}
.pg-up-sidebar-tab:hover { color: var(--fg); background: var(--bg-elev-2); }
.pg-up-sidebar-tab[aria-selected="true"] {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: var(--accent);
    font-weight: 600;
}

/* Hide sidebar sections that belong to a non-active tab */
.pg-up-tab-panel { display: none; }
.pg-up-tab-panel.pg-up-active { display: block; }

/* ---------- #3 NAV: active-state underline + ARIA hint ---------- */
header nav a[aria-current="page"] {
    box-shadow: inset 0 -2px 0 var(--accent);
    color: var(--accent);
    font-weight: 600;
}
header nav a {
    position: relative;
    padding-bottom: 4px;
}

/* "Más" dropdown button — already exists but make it feel like an icon */
#btnMoreMenu {
    transition: background-color 0.12s, transform 0.12s !important;
}
#btnMoreMenu:hover {
    background: var(--accent) !important;
    color: var(--bg) !important;
    transform: rotate(90deg);
}

/* Footer changelog drawer — collapsed by default */
.pg-up-changelog-drawer summary {
    cursor: pointer;
    color: var(--accent);
    font-weight: 500;
}
.pg-up-changelog-drawer[open] summary { margin-bottom: 6px; }

/* Active-filter chip shown above filter tab body */
.pg-up-active-filters {
    display: none;
    margin: 0 10px 8px 10px;
    padding: 6px 10px;
    background: var(--accent-soft);
    border: 1px solid var(--accent);
    border-radius: 6px;
    font: 500 11px/1.4 ui-sans-serif;
    color: var(--accent);
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.pg-up-active-filters.is-shown { display: flex; }
.pg-up-active-filters button {
    background: none; border: none; color: inherit; cursor: pointer;
    font: inherit; text-decoration: underline;
}

/* Filter form sections collapsible */
.pg-up-filter-section {
    margin-bottom: 8px;
}
.pg-up-filter-section > summary {
    cursor: pointer;
    font: 500 12px/1.4 ui-sans-serif;
    color: var(--fg);
    padding: 6px 10px;
    border-radius: 4px;
    list-style: none;
    user-select: none;
}
.pg-up-filter-section > summary::-webkit-details-marker { display: none; }
.pg-up-filter-section > summary::before {
    content: "▸ ";
    color: var(--fg-dim);
    margin-right: 4px;
    display: inline-block;
    transition: transform 0.15s;
}
.pg-up-filter-section[open] > summary::before { transform: rotate(90deg); }
.pg-up-filter-section > summary:hover { background: var(--bg-elev-2); }
.pg-up-filter-section > .pg-up-section-body {
    padding: 8px 10px 12px 10px;
}

/* ---------- Stage 2 fix: prevent duplicate filter UI on mobile/desktop ---------- */
/* Mobile filterSheet (bottom-sheet): only visible on mobile, hidden on desktop */
.pg-up-mobile-sheet { display: none; }
@media (max-width: 768px) {
    .pg-up-mobile-sheet { display: block; }
}
.pg-up-mobile-toggle { display: none; }
@media (max-width: 768px) {
    .pg-up-mobile-toggle { display: inline-flex; }
}

/* ---------- Wave 4.5 (3c) — Comparar preview ---------- */
.pg-up-compare-preview {
    position: absolute;
    left: 0;
    bottom: calc(100% + 8px);
    width: 320px;
    background: var(--bg-elev);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 12px 32px rgba(10, 14, 26, 0.18);
    padding: 12px 14px;
    font-size: 11px;
    color: var(--fg);
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transform: translateY(4px);
    transition: opacity 0.18s ease, transform 0.18s ease;
}
.pg-up-compare-preview.pg-up-shown {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}
.pg-up-compare-title {
    font: 600 12px/1.3 Fraunces, Inter, serif;
    margin-bottom: 8px;
    color: var(--accent);
}
.pg-up-compare-row {
    display: grid;
    grid-template-columns: 80px 1fr 80px;
    align-items: center;
    gap: 8px;
    padding: 3px 0;
}
.pg-up-bar {
    height: 6px;
    background: var(--bg-elev-2);
    border-radius: 3px;
    overflow: hidden;
}
.pg-up-fill {
    display: block;
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
}
.pg-up-num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}
.pg-up-compare-hint {
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid var(--line);
    font-size: 10px;
    color: var(--fg-dim);
    font-style: italic;
}

/* ---------- Wave 3: heat grid markers fade + legend ---------- */
.leaflet-container.pg-up-markers-faded .leaflet-pane.leaflet-marker-pane {
    opacity: 0.25;
    transition: opacity 0.3s ease;
}
.leaflet-container .leaflet-pane.leaflet-marker-pane {
    transition: opacity 0.3s ease;
}
.pg-up-heat-legend {
    position: fixed;
    bottom: 30px;
    left: 12px;
    z-index: 1000;
    background: var(--bg-elev, rgba(20, 20, 20, 0.92));
    color: var(--fg, #eee);
    border: 1px solid var(--line, rgba(255,255,255,0.15));
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 11px;
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    min-width: 180px;
}
.pg-up-heat-legend-title {
    font-weight: 600;
    margin-bottom: 5px;
    color: var(--fg, #eee);
}
.pg-up-heat-legend-row {
    display: flex;
    gap: 2px;
    height: 10px;
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 3px;
}
.pg-up-heat-sw {
    flex: 1;
    height: 100%;
    display: block;
}
.pg-up-heat-legend-axis {
    display: flex;
    justify-content: space-between;
    font-size: 9px;
    color: var(--fg-dim, #999);
    text-transform: lowercase;
    letter-spacing: 0.3px;
}
.pg-up-heat-legend-hint {
    margin-top: 6px;
    padding-top: 5px;
    border-top: 1px solid var(--line, rgba(255,255,255,0.1));
    font-size: 10px;
    color: var(--fg-dim, #999);
    font-style: italic;
}

/* Mobile: shrink legend, push above zoom controls to avoid overlap */
@media (max-width: 768px) {
    .pg-up-heat-legend {
        bottom: 90px;
        left: 8px;
        right: 8px;
        min-width: 0;
        font-size: 10px;
        padding: 6px 8px;
    }
    .pg-up-heat-legend-title { font-size: 10px; margin-bottom: 3px; }
}

/* ========== PR3 — UTILITY CLASSES (extracted from inline styles) ==========
   Goal: reduce 746 inline style attributes to ~300 by promoting the most
   repeated patterns into reusable classes. Only patterns with ≥6 occurrences
   were migrated (diminishing returns below that). */
.dropdown-link {
    display: block;
    padding: 8px 10px;
    color: var(--fg);
    text-decoration: none;
    border-radius: 3px;
    font-size: 13px;
}
.dropdown-link:hover { background: var(--bg-elev-2); }

.pill {
    width: 100%;
    padding: 6px;
    background: var(--bg-elev-2);
    color: var(--fg);
    border: 1px solid var(--line);
    border-radius: 4px;
}

.section-title {
    cursor: pointer;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--fg-dim);
    padding: 4px 0;
    border-top: 1px solid var(--line);
}

.panel-card {
    background: var(--bg-elev);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 12px;
}
.panel-card[hidden] { display: none; }

.row-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.row-between-gap4 {
    display: flex;
    justify-content: space-between;
    gap: 4px;
}

.grid-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.grid-2col > .filter-section-full {
    grid-column: 1 / -1;
    padding: 8px 10px;
    margin-bottom: 6px;
}

.text-dim-sm {
    font-size: 10px;
    color: var(--fg-dim);
}

.text-dim-sm-top4 {
    font-size: 10px;
    color: var(--fg-dim);
    margin-top: 4px;
}

.text-accent-bold {
    color: var(--accent);
    font-weight: 600;
}

.text-h2 {
    margin: 0;
    font-size: 14px;
}

.icon-3 {
    vertical-align: -3px;
}

.no-bullet { list-style: none; }

.divider-line {
    border: none;
    border-top: 1px solid var(--line);
    margin: 4px 0;
}

.tab-right {
    padding: 8px;
    border-bottom: 2px solid var(--accent);
    text-align: right;
}

/* Color helpers — single-property overrides for inline color */
.text-success { color: #10b981; }
.text-danger  { color: #ef4444; }
.text-err     { color: var(--err); }

/* Form control: chip-style toggle */
.toggle-chip {
    background: var(--bg-elev-2);
    color: var(--fg);
    border: 1px solid var(--line);
    padding: 4px 10px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 11px;
    font-family: inherit;
}

/* Sidebar / list-item card */
.list-item {
    padding: 8px;
    border-bottom: 2px solid var(--accent);
    text-align: right;
}

/* Spacing helpers */
.mb-2 { margin-bottom: 6px; }
.mb-3 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 12px; }
.mt-2 { margin-top: 6px; }
.m-0  { margin: 0; }
.m-vertical-6 { margin: 6px 0; }

/* Icon-only button (used in panel headers for refresh/close actions) */
.icon-btn {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 11px;
    padding: 4px;
    border-radius: 4px;
    transition: background 0.15s;
}
.icon-btn:hover { background: var(--bg-elev-2); }

/* CRITIQUE-FIX: Top-depto chip — was a <div> with onclick; now <button> */
.pg-up-top-depto {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    font-size: 10px;
    padding: 3px 6px;
    margin-bottom: 2px;
    border-radius: 3px;
    background: transparent;
    border: 1px solid transparent;
    color: inherit;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s;
}
.pg-up-top-depto:hover,
.pg-up-top-depto:focus-visible {
    background: var(--bg-elev-2);
    border-color: var(--accent-border);
}
.pg-up-top-depto:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Bottom tray — collapsible insight dock (replaces top-of-sidebar widgets) */
.bottom-tray {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 996;
    display: flex;
    gap: 8px;
    pointer-events: none;
    align-items: flex-end;
}
.bottom-tray > * { pointer-events: auto; }
.bottom-tray-tab {
    background: var(--bg-elev);
    color: var(--accent);
    border: 1px solid var(--accent-border);
    border-radius: 24px;
    padding: 8px 14px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    gap: 6px;
}
.bottom-tray-tab:hover { background: var(--bg-elev-2); }
.bottom-tray-content {
    position: fixed;
    bottom: 70px;
    left: 50%;
    transform: translateX(-50%);
    width: min(680px, 90vw);
    max-height: 50vh;
    overflow-y: auto;
    background: var(--bg-elev);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 8px 28px rgba(0,0,0,0.6);
    z-index: 995;
    display: none;
}
.bottom-tray-content.open { display: block; }
@media (max-width: 768px) {
    .bottom-tray-content {
        left: 8px; right: 8px; width: auto; transform: none;
        bottom: 80px;
    }
}


/* ============================================
   UTILITY CLASSES (extracted from inline styles)
   Replaces the most common inline patterns.
   ============================================ */

/* Text colors */
.text-fg-dim { color: var(--fg-dim); }
.text-fg { color: var(--fg); }
.text-accent { color: var(--accent); }
.text-err { color: var(--err); }
.text-warn { color: var(--warn); }
.text-mute { color: var(--fg-mute); }
.text-green { color: #10b981; }
.text-red { color: #ef4444; }

/* Font sizes */
.fs-9 { font-size: 9px; }
.fs-10 { font-size: 10px; }
.fs-11 { font-size: 11px; }
.fs-12 { font-size: 12px; }
.fs-13 { font-size: 13px; }

/* Font weights */
.fw-600 { font-weight: 600; }
.fw-500 { font-weight: 500; }
.fw-700 { font-weight: 700; }

/* Margins */
.m-0 { margin: 0; }
.mt-2 { margin-top: 2px; }
.mt-4 { margin-top: 4px; }
.mt-6 { margin-top: 6px; }
.mb-2 { margin-bottom: 2px; }
.mb-4 { margin-bottom: 4px; }
.mb-6 { margin-bottom: 6px; }
.mb-8 { margin-bottom: 8px; }
.m-6-0 { margin: 6px 0; }

/* Padding */
.p-4 { padding: 4px; }
.p-5 { padding: 5px; }
.p-6 { padding: 6px; }
.p-8 { padding: 8px; }

/* Display */
.d-none { display: none; }
.d-inline { display: inline; }
.d-block { display: block; }
.d-flex { display: flex; }
.d-grid { display: grid; }

/* Width */
.w-100 { width: 100%; }
.w-auto { width: auto; }

/* Borders */
.border-line { border: 1px solid var(--line); }
.border-accent { border: 1px solid var(--accent); }
.border-bottom-accent { border-bottom: 2px solid var(--accent); }

/* Backgrounds */
.bg-elev { background: var(--bg-elev); }
.bg-elev-2 { background: var(--bg-elev-2); }
.bg-accent-soft { background: var(--accent-soft); }

/* Flex utilities */
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-center { display: flex; justify-content: center; align-items: center; }
.flex-col { display: flex; flex-direction: column; }
.gap-2 { gap: 2px; }
.gap-4 { gap: 4px; }
.gap-6 { gap: 6px; }

/* Vertical alignment */
.va-bottom { vertical-align: bottom; }
.va-3 { vertical-align: -3px; }

/* Common input style */
.input-base {
    width: 100%;
    padding: 6px;
    background: var(--bg-elev-2);
    color: var(--fg);
    border: 1px solid var(--line);
    border-radius: 4px;
    font-family: inherit;
    font-size: 12px;
}

/* Card grid */
.grid-cols-full { grid-column: 1 / -1; }

/* Text alignment */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-left { text-align: left; }

/* HR with theme color */
.hr-line { border: none; border-top: 1px solid var(--line); margin: 6px 0; }


/* ============================================
   EMPTY STATES + LOADING
   ============================================ */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px 16px;
    color: var(--fg-dim);
    text-align: center;
    min-height: 120px;
}

.empty-state-icon {
    font-size: 32px;
    margin-bottom: 12px;
    opacity: 0.5;
}

.empty-state-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--fg);
    margin-bottom: 4px;
}

.empty-state-message {
    font-size: 12px;
    color: var(--fg-dim);
    max-width: 240px;
    line-height: 1.5;
}

.empty-state-action {
    margin-top: 12px;
    padding: 6px 12px;
    background: var(--accent-soft);
    color: var(--accent);
    border: 1px solid var(--accent-border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 12px;
    font-family: inherit;
}

.empty-state-action:hover {
    background: var(--accent);
    color: var(--accent-fg);
}

.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--line);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.error-state {
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.30);
    color: var(--err);
    padding: 12px;
    border-radius: var(--radius);
    font-size: 12px;
    margin: 8px 0;
}

.error-state-title {
    font-weight: 600;
    margin-bottom: 4px;
}

.success-state {
    background: var(--accent-soft);
    border: 1px solid var(--accent-border);
    color: var(--accent);
    padding: 12px;
    border-radius: var(--radius);
    font-size: 12px;
    margin: 8px 0;
}
