/* ========================================
   CDMX Observatorio de Seguridad
   Mobile-first responsive design
   ======================================== */

:root {
    --bg-base: #0f172a;
    --bg-surface: #1e293b;
    --bg-glass: rgba(30, 41, 59, 0.7);
    --bg-glass-strong: rgba(30, 41, 59, 0.92);
    --border-glass: rgba(255, 255, 255, 0.08);
    --border-glass-hover: rgba(255, 255, 255, 0.15);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent-cyan: #38bdf8;
    --accent-indigo: #818cf8;
    --accent-red: #ef4444;
    --accent-purple: #a855f7;
    --accent-yellow: #eab308;
    --accent-blue: #3b82f6;
    --accent-gray: #6b7280;
    --font-main: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --success: #10b981;
    --danger: #ef4444;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.15);
    --shadow-glow: 0 0 30px rgba(56, 189, 248, 0.08);
    --transition-base: 0.2s ease;
}

/* ── Reset ── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ── Body (mobile-first: scrollable) ── */
body.dark-theme {
    background-color: var(--bg-base);
    color: var(--text-primary);
    font-family: var(--font-main);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    line-height: 1.5;
}

/* ── Glassmorphism ── */
.glass-panel {
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
}

/* ========================================
   HEADER
   ======================================== */
.app-header {
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.95) 0%, rgba(15, 23, 42, 0.98) 100%);
    border-bottom: 1px solid var(--border-glass);
    padding: 16px 20px;
    position: sticky;
    top: 0;
    z-index: 50;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    max-width: 1600px;
    margin: 0 auto;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.header-shield {
    font-size: 1.75rem;
    flex-shrink: 0;
    filter: drop-shadow(0 0 8px rgba(56, 189, 248, 0.3));
}

.header-text {
    min-width: 0;
}

.app-title {
    font-size: 1.15rem;
    font-weight: 700;
    background: linear-gradient(90deg, var(--accent-cyan), var(--accent-indigo));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.2;
}

.app-subtitle {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-top: 2px;
    display: none;
}

.header-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.btn-action {
    background: rgba(56, 189, 248, 0.1);
    border: 1px solid rgba(56, 189, 248, 0.3);
    color: var(--accent-cyan);
    border-radius: var(--radius-sm);
    padding: 7px 12px;
    cursor: pointer;
    font-size: 0.8rem;
    font-family: var(--font-main);
    font-weight: 500;
    transition: all var(--transition-base);
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}

.btn-action:hover {
    background: rgba(56, 189, 248, 0.2);
    border-color: rgba(56, 189, 248, 0.5);
    box-shadow: 0 0 12px rgba(56, 189, 248, 0.15);
}

.btn-action .btn-label {
    display: none;
}

.btn-export-pdf {
    background: rgba(129, 140, 248, 0.1);
    border-color: rgba(129, 140, 248, 0.3);
    color: var(--accent-indigo);
}

.btn-export-pdf:hover {
    background: rgba(129, 140, 248, 0.2);
    border-color: rgba(129, 140, 248, 0.5);
    box-shadow: 0 0 12px rgba(129, 140, 248, 0.15);
}

/* ========================================
   LAYOUT CONTAINER (mobile: column)
   ======================================== */
.dashboard-container {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 60px);
    min-height: calc(100dvh - 60px);
}

/* ========================================
   SIDEBAR / FILTERS
   ======================================== */
.sidebar {
    padding: 16px;
    border-radius: 0;
    border: none;
    border-bottom: 1px solid var(--border-glass);
    background: var(--bg-glass-strong);
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-height: 50vh;
    overflow-y: auto;
}

/* Sidebar scrollbar */
.sidebar::-webkit-scrollbar {
    width: 5px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

.sidebar-header {
    display: none; /* title is now in the global header */
}

/* Primary filters: always visible */
.primary-filters {
    display: flex;
    flex-direction: column;
    gap: 14px;
    flex-shrink: 0;
}

/* Advanced filters: collapsible on mobile */
.advanced-filters {
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    overflow: hidden;
    flex-shrink: 0;
}

.advanced-filters summary {
    padding: 10px 14px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    list-style: none;
    transition: color var(--transition-base);
    user-select: none;
}

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

.advanced-filters summary::before {
    content: '▶';
    font-size: 0.65rem;
    transition: transform var(--transition-base);
    display: inline-block;
}

.advanced-filters[open] summary::before {
    transform: rotate(90deg);
}

.advanced-filters summary:hover {
    color: var(--text-primary);
}

.advanced-filters-body {
    padding: 0 14px 14px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

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

/* Form controls */
.control-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.control-group label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
    letter-spacing: 0.01em;
}

/* ========================================
   MAIN CONTENT (mobile: full-width column)
   ======================================== */
.main-content {
    flex: 1;
    padding: 16px;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.content-wrapper {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ── Section titles ── */
.section-heading {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.section-heading .section-icon {
    font-size: 1.1rem;
}

/* ========================================
   KPI GRID
   ======================================== */
.kpi-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.kpi-mode-toggle {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 10px;
}
.kpi-mode-toggle label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.kpi-card {
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: relative;
    overflow: hidden;
    transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.kpi-card:hover {
    border-color: var(--border-glass-hover);
    box-shadow: var(--shadow-glow);
}

.kpi-card h3 {
    font-size: 0.72rem;
    color: var(--text-secondary);
    font-weight: 500;
    line-height: 1.3;
    padding-right: 50px;
}

.kpi-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
}

.kpi-value-small {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.2;
}

.kpi-badge {
    position: absolute;
    top: 14px;
    right: 12px;
    padding: 3px 7px;
    border-radius: 6px;
    font-size: 0.68rem;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.08);
    white-space: nowrap;
}

.kpi-badge.up-bad {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
}

.kpi-badge.down-good {
    background: rgba(16, 185, 129, 0.15);
    color: #6ee7b7;
}

/* ========================================
   CHARTS & MAP
   ======================================== */
.charts-map-grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chart-container,
.map-container {
    padding: 16px;
    display: flex;
    flex-direction: column;
}

.chart-container h2,
.map-container h2 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.canvas-wrapper {
    position: relative;
    min-height: 260px;
    width: 100%;
}

.canvas-wrapper canvas {
    width: 100% !important;
    height: 100% !important;
}

#crimeMap {
    border-radius: var(--radius-sm);
    background: #e8eaed;
    z-index: 1;
    min-height: 350px;
    height: 350px;
}

/* ========================================
   CHECKBOXES
   ======================================== */
.checkbox-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.category-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-primary);
    transition: opacity var(--transition-base);
    padding: 2px 0;
}

.category-checkbox:hover {
    opacity: 0.8;
}

.cat-color-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.categories-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.toggle-all-label {
    font-size: 0.78rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--text-primary);
}

/* ========================================
   NEIGHBORS PANEL
   ======================================== */
.neighbors-toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
    transition: color var(--transition-base);
    padding: 2px 0;
}

.neighbors-toggle-label:hover {
    color: var(--text-primary);
}

.neighbors-toggle-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent-cyan);
    cursor: pointer;
    flex-shrink: 0;
}

.neighbors-panel {
    margin-top: 8px;
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    overflow: hidden;
    animation: fadeInUp 0.2s ease-out;
}

.neighbors-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-glass);
    background: rgba(15, 23, 42, 0.4);
}

.neighbors-title {
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.neighbors-checkboxes {
    max-height: 180px;
    overflow-y: auto;
    padding: 6px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* Custom scrollbar for neighbors list */
.neighbors-checkboxes::-webkit-scrollbar {
    width: 5px;
}

.neighbors-checkboxes::-webkit-scrollbar-track {
    background: transparent;
}

.neighbors-checkboxes::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}

.neighbors-checkboxes::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

.neighbor-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-primary);
    transition: opacity var(--transition-base);
    padding: 2px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.neighbor-checkbox:hover {
    opacity: 0.8;
}

.neighbor-checkbox input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: #fbbf24;
    cursor: pointer;
    flex-shrink: 0;
}

.neighbor-color-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #fbbf24;
    flex-shrink: 0;
}

.neighbor-alcaldia-tag {
    font-size: 0.65rem;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.06);
    padding: 1px 5px;
    border-radius: 3px;
    flex-shrink: 0;
    margin-left: auto;
}

/* ========================================
   TOMSELECT DARK THEME
   ======================================== */
.ts-control {
    background: rgba(15, 23, 42, 0.6) !important;
    border: 1px solid var(--border-glass) !important;
    color: var(--text-primary) !important;
    border-radius: var(--radius-sm) !important;
    font-size: 0.9rem !important;
    min-height: 38px !important;
}

.ts-control input {
    color: var(--text-primary) !important;
}

.ts-dropdown {
    background: var(--bg-surface) !important;
    border: 1px solid var(--border-glass) !important;
    color: var(--text-primary) !important;
    border-radius: var(--radius-sm) !important;
}

.ts-dropdown .option.active {
    background: rgba(56, 189, 248, 0.15) !important;
    color: var(--accent-cyan) !important;
}

.ts-dropdown .option:hover {
    background: rgba(56, 189, 248, 0.1) !important;
}

/* ========================================
   EMPTY STATE / LOADING
   ======================================== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--text-secondary);
    gap: 16px;
    padding: 60px 24px;
    flex: 1;
}

.icon-placeholder {
    font-size: 3.5rem;
    filter: drop-shadow(0 0 12px rgba(56, 189, 248, 0.2));
}

.empty-state h2 {
    font-size: 1.2rem;
    color: var(--text-primary);
}

.empty-state p {
    max-width: 320px;
    font-size: 0.9rem;
    line-height: 1.5;
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    visibility: hidden;
    opacity: 0;
    transition: visibility 0s 0.2s, opacity 0.2s;
}

.loading-overlay.active {
    visibility: visible;
    opacity: 1;
    transition: opacity 0.2s;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    border-top-color: var(--accent-cyan);
    animation: spin 0.8s ease-in-out infinite;
    margin-bottom: 12px;
}

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

/* ========================================
   FOOTER
   ======================================== */
.app-footer {
    background: rgba(15, 23, 42, 0.9);
    border-top: 1px solid var(--border-glass);
    padding: 20px 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.78rem;
    line-height: 1.6;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.footer-inner {
    max-width: 1600px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
}

.footer-source {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
}

.footer-links {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    justify-content: center;
}

.footer-links a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color var(--transition-base);
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.footer-links a:hover {
    color: var(--accent-cyan);
}

.footer-divider {
    width: 40px;
    height: 1px;
    background: var(--border-glass);
}

.footer-copy {
    font-size: 0.72rem;
    color: var(--text-muted);
}

/* ========================================
   MAP POPUPS DARK
   ======================================== */
.leaflet-popup-content-wrapper {
    background: var(--bg-base) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm) !important;
    box-shadow: var(--shadow-card) !important;
}

.leaflet-popup-tip {
    background: var(--bg-base) !important;
}

.leaflet-popup-content {
    font-family: var(--font-main) !important;
    font-size: 0.85rem !important;
    line-height: 1.4 !important;
}
/* ========================================
   COLONIA POLYGON LABELS (Leaflet tooltips)
   ======================================== */
.colonia-label {
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    font-family: var(--font-main) !important;
    font-size: 0.7rem !important;
    font-weight: 700 !important;
    color: #1e293b !important;
    text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 6px #fff !important;
    box-shadow: none !important;
    white-space: nowrap !important;
    pointer-events: none !important;
}

.colonia-label::before {
    display: none !important;
}

.colonia-label-selected {
    color: #0c4a6e !important;
}

.colonia-label-neighbor {
    color: #78350f !important;
}

/* ========================================
   MAP FULLSCREEN BUTTON
   ======================================== */
.map-fullscreen-btn {
    display: none; /* hidden on mobile */
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    color: var(--text-secondary);
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.map-fullscreen-btn:hover {
    background: var(--bg-glass-strong);
    color: var(--text-primary);
    border-color: var(--accent-cyan);
}

/* ========================================
   MAP FULLSCREEN MODAL
   ======================================== */
.map-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}

.map-modal-overlay.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.map-modal {
    width: 92vw;
    height: 88vh;
    background: var(--bg-base);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: scaleIn 0.25s ease;
}

.map-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-glass);
    flex-shrink: 0;
}

.map-modal-header h2 {
    font-size: 1.1rem;
    margin: 0;
}

.map-modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    color: var(--text-secondary);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.map-modal-close:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.3);
}

.map-modal-body {
    flex: 1;
    position: relative;
}

.map-modal-body #crimeMap {
    height: 100% !important;
    border-radius: 0;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

/* ========================================
   ANIMATIONS
   ======================================== */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.content-wrapper .kpi-grid,
.content-wrapper .charts-map-grid {
    animation: fadeInUp 0.4s ease-out;
}

/* ========================================
   RESPONSIVE — TABLET (≥ 768px)
   ======================================== */
@media (min-width: 768px) {
    .app-title {
        font-size: 1.3rem;
    }

    .app-subtitle {
        display: block;
    }

    .btn-action .btn-label {
        display: inline;
    }

    .header-shield {
        font-size: 2rem;
    }

    .kpi-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .kpi-card h3 {
        font-size: 0.78rem;
    }

    .kpi-value {
        font-size: 2rem;
    }

    .kpi-value-small {
        font-size: 1.15rem;
    }

    .primary-filters {
        flex-direction: row;
        gap: 16px;
    }

    .primary-filters .control-group {
        flex: 1;
    }

    #crimeMap {
        min-height: 400px;
        height: 400px;
    }
}

/* ========================================
   RESPONSIVE — DESKTOP (≥ 1024px)
   ======================================== */
@media (min-width: 1024px) {
    body.dark-theme {
        overflow: hidden;
    }

    .app-header {
        position: relative;
    }

    .dashboard-container {
        flex-direction: row;
        height: calc(100vh - 60px);
        min-height: unset;
    }

    .sidebar {
        width: 310px;
        min-width: 310px;
        height: 100%;
        max-height: unset;
        border-radius: 0;
        border-bottom: none;
        border-right: 1px solid var(--border-glass);
        overflow-y: auto;
        padding: 20px;
        gap: 16px;
    }

    .primary-filters {
        flex-direction: column;
        gap: 14px;
    }

    /* On desktop, show advanced filters expanded by default */
    .advanced-filters {
        border: none;
    }

    .advanced-filters summary {
        display: none;
    }

    .advanced-filters-body {
        padding: 0;
    }

    .map-fullscreen-btn {
        display: flex;
    }

    .main-content {
        height: 100%;
        overflow-y: auto;
        padding: 20px;
    }

    .kpi-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .charts-map-grid {
        flex-direction: row;
        flex: 1;
        min-height: 0;
    }

    .chart-container {
        flex: 1.5;
        min-width: 0;
    }

    .map-container {
        flex: 1;
        min-width: 0;
    }

    .canvas-wrapper {
        flex: 1;
        min-height: 280px;
    }

    #crimeMap {
        flex: 1;
        min-height: 300px;
        height: auto;
    }
}

/* ========================================
   RESPONSIVE — WIDE DESKTOP (≥ 1400px)
   ======================================== */
@media (min-width: 1400px) {
    .app-title {
        font-size: 1.4rem;
    }

    .sidebar {
        width: 340px;
        min-width: 340px;
        padding: 24px;
    }

    .kpi-value {
        font-size: 2.2rem;
    }
}

/* ========================================
   PRINT / PDF STYLES
   ======================================== */
@media print {
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    body.dark-theme {
        background: #ffffff !important;
        color: #1e293b !important;
        overflow: visible !important;
    }

    .app-header {
        position: relative;
        background: #ffffff !important;
        border-bottom: 2px solid #e2e8f0;
    }

    .app-title {
        -webkit-text-fill-color: #1e293b;
        background: none;
        color: #1e293b;
    }

    .header-actions,
    .sidebar,
    .loading-overlay,
    .empty-state {
        display: none !important;
    }

    .dashboard-container {
        display: block !important;
        height: auto !important;
    }

    .main-content {
        height: auto !important;
        overflow: visible !important;
        padding: 16px !important;
    }

    .glass-panel {
        background: #ffffff !important;
        border: 1px solid #e2e8f0 !important;
        box-shadow: none !important;
        backdrop-filter: none !important;
    }

    .kpi-card h3 { color: #64748b !important; }
    .kpi-value, .kpi-value-small { color: #1e293b !important; }
    .chart-container h2, .map-container h2 { color: #1e293b !important; }

    .kpi-grid,
    .chart-container,
    .map-container {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .app-footer {
        background: #ffffff !important;
        color: #64748b !important;
        border-top: 1px solid #e2e8f0;
    }

    .charts-map-grid {
        flex-direction: column !important;
    }

    #crimeMap {
        height: 400px !important;
        min-height: 400px !important;
    }
}

/* ========================================
   KPI BREAKDOWN TABLE
   ======================================== */
.kpi-table-section {
    padding: 16px;
}

.kpi-table-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.kpi-table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-sm);
}

/* Thin scrollbar */
.kpi-table-scroll::-webkit-scrollbar { height: 3px; }
.kpi-table-scroll::-webkit-scrollbar-track { background: transparent; }
.kpi-table-scroll::-webkit-scrollbar-thumb { background: var(--border-glass-hover); border-radius: 3px; }

.kpi-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
    min-width: 560px;
}

.kpi-table thead tr {
    border-bottom: 1px solid var(--border-glass-hover);
}

.kpi-table th {
    padding: 8px 12px;
    text-align: left;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.kpi-table th.col-num {
    text-align: right;
}

.kpi-table th .th-sub {
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    opacity: 0.75;
    font-size: 0.68rem;
}

.kpi-table tbody tr {
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    transition: background var(--transition-base);
}

.kpi-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

/* Total row */
.kpi-table tbody tr.row-total {
    border-bottom: 1px solid var(--border-glass-hover);
    background: rgba(56, 189, 248, 0.04);
}

.kpi-table tbody tr.row-total td {
    font-weight: 600;
    color: var(--text-primary);
}

.kpi-table td {
    padding: 9px 12px;
    color: var(--text-secondary);
    vertical-align: middle;
}

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

/* Category cell */
.kpi-table-cat {
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    color: var(--text-primary);
}

.kpi-table-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
    display: inline-block;
}

/* Inline badge inside table cells */
.kpi-tbl-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 5px;
    font-size: 0.68rem;
    font-weight: 600;
    margin-left: 6px;
    background: rgba(255, 255, 255, 0.07);
    color: var(--text-muted);
    white-space: nowrap;
    vertical-align: middle;
}

.kpi-tbl-badge.up-bad {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
}

.kpi-tbl-badge.down-good {
    background: rgba(16, 185, 129, 0.15);
    color: #6ee7b7;
}

.kpi-tbl-badge.na {
    background: transparent;
    color: var(--text-muted);
    font-style: italic;
}

/* No data state */
.kpi-table-empty {
    text-align: center;
    padding: 24px;
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.82rem;
}

@media print {
    .kpi-table-section {
        break-inside: avoid;
        page-break-inside: avoid;
    }
    .kpi-table-scroll {
        overflow: visible;
    }
    .kpi-table {
        min-width: unset;
        width: 100%;
    }
}

/* ========================================
   DOWNLOAD BAR
   ======================================== */
.download-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 18px;
    flex-wrap: wrap;
}

.download-bar-info {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-width: 0;
}

.download-bar-icon {
    font-size: 1.4rem;
    flex-shrink: 0;
    line-height: 1.3;
}

.download-bar-title {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 3px;
}

.download-bar-desc {
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.btn-download-csv {
    background: rgba(16, 185, 129, 0.08);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: var(--success);
    border-radius: var(--radius-sm);
    padding: 9px 16px;
    cursor: pointer;
    font-size: 0.82rem;
    font-family: var(--font-main);
    font-weight: 600;
    transition: all var(--transition-base);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    flex-shrink: 0;
}

.btn-download-csv:hover {
    background: rgba(16, 185, 129, 0.18);
    border-color: rgba(16, 185, 129, 0.5);
    box-shadow: 0 0 12px rgba(16, 185, 129, 0.15);
}

.btn-download-csv:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

@media (max-width: 480px) {
    .download-bar {
        flex-direction: column;
        align-items: flex-start;
    }
    .btn-download-csv {
        width: 100%;
        justify-content: center;
    }
}

@media print {
    .download-bar { display: none !important; }
}





/* ========================================
   INFO BUTTON (header variant)
   ======================================== */
.btn-info {
    background: rgba(129, 140, 248, 0.08);
    border-color: rgba(129, 140, 248, 0.25);
    color: var(--accent-indigo);
}

.btn-info:hover {
    background: rgba(129, 140, 248, 0.18);
    border-color: rgba(129, 140, 248, 0.5);
    box-shadow: 0 0 12px rgba(129, 140, 248, 0.15);
}

/* ========================================
   MAP INFO BUTTON (inline icon)
   ======================================== */
.map-info-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-muted);
    padding: 0 0 0 6px;
    vertical-align: middle;
    transition: color var(--transition-base), transform var(--transition-base);
    line-height: 1;
    display: inline-flex;
    align-items: center;
}

.map-info-btn:hover {
    color: var(--accent-cyan);
    transform: scale(1.2);
}

/* ========================================
   INFO MODAL
   ======================================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 500;
    background: rgba(9, 15, 29, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0s 0.25s;
}

.modal-overlay.is-open {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.25s ease;
}

.modal-panel {
    position: relative;
    width: 100%;
    max-width: 680px;
    max-height: calc(100dvh - 32px);
    display: flex;
    flex-direction: column;
    border-radius: var(--radius-lg);
    background: rgba(20, 30, 50, 0.97) !important;
    border: 1px solid rgba(129, 140, 248, 0.2);
    box-shadow: 0 8px 48px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(129, 140, 248, 0.1);
    animation: modalSlideIn 0.28s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes modalSlideIn {
    from { opacity: 0; transform: translateY(24px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-close {
    position: absolute;
    top: 14px;
    right: 14px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border-glass);
    color: var(--text-secondary);
    border-radius: 6px;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all var(--transition-base);
    z-index: 1;
}

.modal-close:hover {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.3);
    color: #fca5a5;
}

/* Modal header */
.modal-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 24px 24px 18px;
    border-bottom: 1px solid var(--border-glass);
    flex-shrink: 0;
}

.modal-icon {
    font-size: 2rem;
    filter: drop-shadow(0 0 10px rgba(129, 140, 248, 0.4));
    flex-shrink: 0;
}

.modal-header h2 {
    font-size: 1.15rem;
    font-weight: 700;
    background: linear-gradient(90deg, var(--accent-indigo), var(--accent-cyan));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.2;
    margin: 0;
}

.modal-subtitle {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 3px;
}

/* Modal body (scrollable) */
.modal-body {
    overflow-y: auto;
    padding: 20px 24px 24px;
    display: flex;
    flex-direction: column;
    gap: 0;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

/* Scrollbar styling */
.modal-body::-webkit-scrollbar { width: 4px; }
.modal-body::-webkit-scrollbar-track { background: transparent; }
.modal-body::-webkit-scrollbar-thumb { background: var(--border-glass-hover); border-radius: 4px; }

/* Modal section */
.modal-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px 0;
}

.modal-section p {
    font-size: 0.88rem;
    color: var(--text-secondary);
    line-height: 1.65;
    margin: 0;
}

.modal-section-title {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.modal-divider {
    height: 1px;
    background: var(--border-glass);
}

/* Links */
.modal-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--accent-cyan);
    background: rgba(56, 189, 248, 0.06);
    border: 1px solid rgba(56, 189, 248, 0.2);
    border-radius: var(--radius-sm);
    padding: 7px 12px;
    text-decoration: none;
    transition: all var(--transition-base);
    width: fit-content;
}

.modal-link:hover {
    background: rgba(56, 189, 248, 0.14);
    border-color: rgba(56, 189, 248, 0.4);
}

.modal-link-inline {
    color: var(--accent-cyan);
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-color: rgba(56, 189, 248, 0.4);
    transition: color var(--transition-base);
}

.modal-link-inline:hover {
    color: #7dd3fc;
}

/* Note */
.modal-note {
    font-size: 0.78rem !important;
    color: var(--text-muted) !important;
    font-style: italic;
    background: rgba(255, 255, 255, 0.03);
    border-left: 2px solid var(--border-glass-hover);
    padding: 8px 12px !important;
    border-radius: 0 4px 4px 0;
}

/* List */
.modal-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.modal-list li {
    font-size: 0.88rem;
    color: var(--text-secondary);
    padding-left: 18px;
    position: relative;
    line-height: 1.6;
}

.modal-list li::before {
    content: '•';
    position: absolute;
    left: 4px;
    color: var(--accent-cyan);
    font-size: 1rem;
    line-height: 1.5;
}

/* Blockquote */
.modal-quote {
    border-left: 3px solid rgba(129, 140, 248, 0.5);
    background: rgba(129, 140, 248, 0.05);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    padding: 14px 16px;
    margin: 0;
    font-size: 0.83rem;
    color: var(--text-secondary);
    line-height: 1.7;
    font-style: italic;
}

.modal-quote cite {
    display: block;
    margin-top: 10px;
    font-size: 0.76rem;
    color: var(--text-muted);
    font-style: normal;
}

/* Category grid */
.modal-cats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.modal-cat-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 0.82rem;
}

.modal-cat-item strong {
    display: block;
    color: var(--text-primary);
    font-size: 0.83rem;
    margin-bottom: 2px;
}

.modal-cat-item span {
    color: var(--text-muted);
    font-size: 0.76rem;
    line-height: 1.4;
}

.modal-cat-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 3px;
}

/* Quarter reference grid */
.modal-quarters-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.modal-quarter-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.modal-quarter-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--accent-cyan);
    background: rgba(56, 189, 248, 0.1);
    border: 1px solid rgba(56, 189, 248, 0.2);
    border-radius: 5px;
    padding: 2px 7px;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ── Responsive adjustments ── */
@media (max-width: 480px) {
    .modal-panel {
        max-height: calc(100dvh - 16px);
        border-radius: var(--radius-md);
    }

    .modal-header {
        padding: 18px 18px 14px;
        gap: 10px;
    }

    .modal-icon {
        font-size: 1.6rem;
    }

    .modal-header h2 {
        font-size: 1rem;
    }

    .modal-body {
        padding: 16px 18px 20px;
    }

    .modal-cats-grid {
        grid-template-columns: 1fr;
    }
}

@media (min-width: 768px) {
    .modal-header h2 {
        font-size: 1.25rem;
    }

    .modal-section p,
    .modal-list li {
        font-size: 0.9rem;
    }
}
