/* CSS Variables */
:root {
    /* Premium palette */
    --primary-color: #7c3aed; /* violet-600 */
    --primary-dark: #6d28d9; /* violet-700 */
    --secondary-color: #0ea5e9; /* sky-500 */
    --accent-color: #22d3ee; /* cyan-400 */
    --success-color: #059669;
    --warning-color: #d97706;
    --error-color: #dc2626;
    --background-color: #f8fafc;
    --surface-color: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px 0 rgba(15, 23, 42, 0.08), 0 4px 6px -1px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 24px 38px rgba(124, 58, 237, 0.15), 0 12px 16px rgba(2, 132, 199, 0.08);
    --glass-bg: rgba(255, 255, 255, 0.65);
    --glass-border: rgba(255, 255, 255, 0.45);

    /* Gradients */
    --gradient-primary: linear-gradient(135deg, #7c3aed, #06b6d4);
    --gradient-secondary: linear-gradient(135deg, #0ea5e9, #22d3ee);
}

/* Reset and Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--background-color);
    background-image:
        radial-gradient(1000px 300px at 15% -10%, rgba(124,58,237,0.08), transparent),
        radial-gradient(900px 280px at 85% -8%, rgba(34,211,238,0.10), transparent);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* Header */
.header {
    background: linear-gradient(180deg, rgba(255,255,255,0.75), rgba(255,255,255,0.45));
    backdrop-filter: saturate(180%) blur(8px);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
    padding-top: env(safe-area-inset-top);
}

.header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--primary-color);
}

.logo i {
    font-size: 1.5rem;
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

.logo h1::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    margin-left: 6px;
    border-radius: 50%;
    background: var(--accent-color);
    box-shadow: 0 0 0 6px rgba(34, 211, 238, 0.18);
}

.nav {
    display: flex;
    gap: 0.5rem;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.85rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 0.375rem;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.2s ease, color 0.2s ease;
    font-weight: 500;
    position: relative;
}

/* Mobile nav */
.menu-toggle {
    display: none;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 0.35rem 0.6rem;
    color: var(--text-primary);
}

@media (max-width: 900px) {
    .header .container {
        flex-wrap: wrap;
    }

    .menu-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        margin-left: auto;
    }

    .nav {
        width: 100%;
        display: none;
        flex-wrap: wrap;
        gap: 0.5rem;
        margin-top: 0.75rem;
    }

    .nav.open {
        display: flex;
    }

    .nav-btn {
        flex: 1 1 calc(50% - 0.5rem);
        justify-content: center;
        background: var(--background-color);
    }
}

.nav-btn:hover {
    background: linear-gradient(180deg, #f8fafc, #eef2f7);
    color: var(--text-primary);
    transform: translateY(-2px);
}

.nav-btn.active {
    background: var(--gradient-primary);
    color: white;
    box-shadow: 0 10px 18px rgba(124,58,237,0.25);
}

.nav-btn.active::after {
    content: '';
    position: absolute;
    left: 50%;
    bottom: -6px;
    transform: translateX(-50%);
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-color);
    box-shadow: 0 8px 12px rgba(34, 211, 238, 0.35);
}

/* Main Content */
.main {
    min-height: calc(100vh - 120px);
    padding: 2rem 0;
}

.section {
    display: none;
}

.section.active {
    display: block;
}

.section-header {
    text-align: center;
    margin-bottom: 2rem;
}

.section-header h2 {
    font-size: clamp(1.25rem, 4.5vw, 2rem);
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.section-header p {
    color: var(--text-secondary);
    font-size: 1.125rem;
}

/* Tools Grid (Home) */
.tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
}

.tool-card {
    background: var(--glass-bg);
    border-radius: 0.75rem;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    padding: 1.25rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.tool-card-header {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-areas:
        'icon title'
        'icon desc';
    column-gap: 0.75rem;
}

.tool-icon {
    grid-area: icon;
    width: 48px;
    height: 48px;
    border-radius: 10px;
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.tool-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 26px 40px rgba(124,58,237,0.14), 0 14px 18px rgba(2,132,199,0.08);
}

.tool-card-header h3 {
    grid-area: title;
    margin: 0;
    font-size: 1.125rem;
}

.tool-card-header p {
    grid-area: desc;
    margin-top: 0.25rem;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.tool-card-actions {
    margin-top: 1rem;
    display: flex;
    gap: 0.5rem;
}

/* Hero */
.home-hero {
    position: relative;
    margin: 1rem 0 2rem 0;
    background: radial-gradient(1200px 420px at 10% 0%, rgba(124,58,237,0.12), transparent),
                radial-gradient(1200px 420px at 90% 0%, rgba(34,211,238,0.12), transparent),
                linear-gradient(120deg, rgba(124,58,237,0.05), rgba(34,211,238,0.05));
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    overflow: hidden;
}

.home-hero::before {
    content: '';
    position: absolute;
    top: -40%;
    right: -10%;
    width: 60%;
    height: 180%;
    background: radial-gradient(closest-side, rgba(124,58,237,0.10), transparent);
    transform: rotate(12deg);
}

.home-hero-content {
    position: relative;
    padding: 2rem;
}

.home-hero-content h1 {
    font-size: clamp(1.5rem, 4.5vw, 2.25rem);
    line-height: 1.2;
    margin-bottom: 0.5rem;
}

.home-hero-content p {
    color: var(--text-secondary);
}

.hero-actions {
    margin-top: 1rem;
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

/* Quick Links */
.quick-links-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1rem;
}

.link-card {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 0.75rem;
    align-items: center;
    padding: 0.9rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    background: var(--surface-color);
    text-decoration: none;
    color: inherit;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.link-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
    border-color: #dbe3ef;
}

.link-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(99,102,241,0.08);
    color: #6366f1;
    font-size: 1rem;
}

.link-content h3 {
    font-size: 1rem;
    margin: 0;
}

.link-content p {
    margin: 0.15rem 0 0 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.link-cta {
    color: var(--primary-color);
    font-weight: 600;
}

/* Data Controls */
.data-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: 1rem;
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: var(--surface-color);
    border-radius: 0.75rem;
    box-shadow: var(--shadow);
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.control-group label {
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.875rem;
}

.control-group select {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    font-size: 0.875rem;
    min-width: 150px;
}

.data-info {
    display: flex;
    align-items: center;
    margin-left: auto;
}

.data-info span {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 3rem;
}

.stat-card {
    background: var(--surface-color);
    padding: 1.5rem;
    border-radius: 0.75rem;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.5rem;
}

.stat-content h3 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.stat-content p {
    color: var(--text-secondary);
    font-weight: 500;
}

/* Charts Grid */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 2rem;
}

/* Allow charts to fit narrow screens */
@media (max-width: 420px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }
}

.chart-container {
    background: var(--glass-bg);
    padding: 1.5rem;
    border-radius: 0.75rem;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--glass-border);
}

.chart-container h3 {
    margin-bottom: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Filters */
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: var(--surface-color);
    border-radius: 0.75rem;
    box-shadow: var(--shadow);
}

/* Make inputs/buttons larger and easier to tap on mobile */
@media (max-width: 480px) {
    input, select, button {
        min-height: 44px;
    }
    .btn {
        padding: 0.65rem 1rem;
        font-size: 1rem;
    }
}

.map-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: var(--surface-color);
    border-radius: 0.75rem;
    box-shadow: var(--shadow);
}

/* Segmented control */
.segmented {
    display: inline-flex;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    overflow: hidden;
    background: var(--background-color);
}
.segmented-btn {
    appearance: none;
    border: none;
    background: transparent;
    padding: 0.4rem 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
}
.segmented-btn.active,
.segmented-btn[aria-pressed="true"] {
    background: var(--gradient-primary);
    color: #fff;
}
.segmented-btn + .segmented-btn {
    border-left: 1px solid var(--border-color);
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.filter-group label {
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.875rem;
}

.filter-group input,
.filter-group select {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    font-size: 0.875rem;
    min-width: 150px;
}

.filter-group input:focus,
.filter-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Buttons */
.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.375rem;
    font-weight: 500;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease;
    font-size: 0.875rem;
    position: relative;
    overflow: hidden;
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
    box-shadow: 0 10px 22px rgba(124,58,237,0.28), 0 6px 12px rgba(2,132,199,0.18);
}

.btn-primary:hover {
    background: var(--gradient-primary);
    transform: translateY(-1px) scale(1.01);
    filter: drop-shadow(0 10px 24px rgba(124,58,237,0.32));
}

.btn-secondary {
    background: var(--gradient-secondary);
    color: white;
}

.btn-secondary:hover {
    background: var(--gradient-secondary);
    transform: translateY(-1px) scale(1.005);
}

/* Ripple effect */
.btn .ripple {
    position: absolute;
    left: 0;
    top: 0;
    width: 20px;
    height: 20px;
    background: radial-gradient(circle, rgba(255,255,255,0.5) 0%, rgba(255,255,255,0.35) 40%, rgba(255,255,255,0) 70%);
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0);
    pointer-events: none;
    mix-blend-mode: soft-light;
    animation: ripple 650ms ease-out forwards;
}

@keyframes ripple {
    to { transform: translate(-50%, -50%) scale(14); opacity: 0; }
}

/* Falling clone animation */
.fall-clone {
    position: fixed;
    z-index: 2000;
    border-radius: 0.375rem;
    box-shadow: 0 10px 22px rgba(124,58,237,0.28), 0 6px 12px rgba(2,132,199,0.18);
    animation: fall-away 900ms cubic-bezier(.2,.85,.3,1) forwards;
    will-change: transform, opacity;
}

@keyframes fall-away {
    0% { transform: translate3d(0,0,0) rotate(0deg) scale(1); opacity: 1; }
    60% { transform: translate3d(10px, 65vh, 0) rotate(12deg) scale(0.98); opacity: 0.9; }
    100% { transform: translate3d(-6px, 120vh, 0) rotate(-16deg) scale(0.96); opacity: 0; }
}

.btn:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.35);
    outline-offset: 2px;
}

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

/* Table */
.table-container {
    background: var(--glass-bg);
    border-radius: 0.75rem;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--glass-border);
    overflow: hidden;
}

.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--background-color);
}

.table-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
}

.table-controls select {
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 0.25rem;
}

.quick-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    background: #f7fafc;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.6rem;
    border-radius: 999px;
    border: 1px solid #e5e7eb;
    background: white;
    color: #334155;
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
}

.chip:hover {
    background: #f3f4f6;
    transform: translateY(-1px);
}

.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Mobile stackable table treatment */
@media (max-width: 640px) {
    .table-wrapper table.stackable thead,
    .table-wrapper table.stackable tfoot {
        display: none;
    }
    .table-wrapper table.stackable,
    .table-wrapper table.stackable tbody,
    .table-wrapper table.stackable tr,
    .table-wrapper table.stackable td,
    .table-wrapper table.stackable th {
        display: block;
        width: 100%;
    }
    .table-wrapper table.stackable tbody tr {
        border-bottom: 1px solid var(--border-color);
        padding: 0.5rem 0.75rem;
        background: var(--surface-color);
    }
    .table-wrapper table.stackable td {
        border: none;
        padding: 0.45rem 0;
        display: grid;
        grid-template-columns: 9.5rem 1fr;
        gap: 0.75rem;
    }
    .table-wrapper table.stackable td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary);
    }
    .table-wrapper table.stackable td.numeric {
        text-align: right;
    }
}

/* Mobile-first visibility: hide less-critical columns on very small screens */
@media (max-width: 420px) {
    #data-table th:nth-child(4),
    #data-table td:nth-child(4),
    #data-table th:nth-child(6),
    #data-table td:nth-child(6) {
        display: none;
    }
    /* Hide Stage on tiny screens in Flows */
    #flows-table th:nth-child(3),
    #flows-table td:nth-child(3) {
        display: none;
    }
    #traffic-table th:nth-child(3),
    #traffic-table td:nth-child(3),
    #permits-table th:nth-child(5),
    #permits-table td:nth-child(5),
    #crime-table th:nth-child(3),
    #crime-table td:nth-child(3) {
        display: none;
    }
}

#data-table {
    width: 100%;
    border-collapse: collapse;
}

/* Enhanced tables */
.table-container.compact #data-table th,
.table-container.compact #data-table td,
.table-container.compact table th,
.table-container.compact table td {
    padding: 0.55rem 0.75rem;
}

.subtable {
    margin: 0.25rem 0 0.75rem 0;
    width: 100%;
    border-collapse: collapse;
}
.subtable th, .subtable td {
    padding: 0.35rem 0.5rem;
    border-bottom: 1px dashed var(--border-color);
}
.subtable th {
    background: var(--background-color);
}

/* Score badge */
.score-badge {
    display: inline-block;
    min-width: 2rem;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    background: rgba(37,99,235,0.12);
    color: #1e3a8a;
    font-weight: 700;
}

/* Inspections master/detail on mobile */
.master-row {
    cursor: pointer;
}
.master-row .toggle-cell {
    position: relative;
}
.master-row .toggle-cell .caret {
    display: inline-block;
    width: 0.7rem;
    height: 0.7rem;
    margin-right: 0.35rem;
    border-right: 2px solid #64748b;
    border-bottom: 2px solid #64748b;
    transform: rotate(-45deg);
    transition: transform 0.2s ease;
}
.master-row.open .toggle-cell .caret {
    transform: rotate(45deg);
}

.subtable-wrapper[hidden] { display: none; }

/* Improve focus states for keyboard access */
.master-row:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.35);
    outline-offset: 2px;
}

/* Denser spacing for stacked mobile rows inside inspections */
@media (max-width: 640px) {
    #inspections-container .subtable-root.stackable tbody tr,
    #inspections-container .subtable.stackable tbody tr {
        padding: 0.35rem 0.5rem;
    }
    #inspections-container .subtable-root.stackable td,
    #inspections-container .subtable.stackable td {
        grid-template-columns: 8.5rem 1fr;
        padding: 0.35rem 0;
    }
}

@media (max-width: 768px) {
    /* Stack master row content a bit closer on mobile */
    .table-container.compact table th,
    .table-container.compact table td {
        padding: 0.5rem;
    }
    .truncate { max-width: 22ch; }
}

.table-wrapper thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--background-color);
}

tbody tr:nth-child(even) {
    background: #f9fbfd;
}

td.numeric {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.truncate {
    display: inline-block;
    max-width: 28ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Flow badge coloring */
.flow-badge {
    display: inline-block;
    min-width: 3.25rem;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    font-variant-numeric: tabular-nums;
}
.flow-low { background: rgba(34,197,94,0.12); color: #166534; }
.flow-med { background: rgba(59,130,246,0.12); color: #1e3a8a; }
.flow-high { background: rgba(245,158,11,0.12); color: #7c2d12; }
.flow-extreme { background: rgba(239,68,68,0.12); color: #7f1d1d; }

#data-table th,
#data-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

#data-table th {
    background: var(--background-color);
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    user-select: none;
}

#data-table th:hover {
    background: #e2e8f0;
}

#data-table tbody tr:hover {
    background: var(--background-color);
}

.status-badge {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    background: rgba(100,116,139,0.12);
}

.loading {
    text-align: center;
    color: var(--text-secondary);
    font-style: italic;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    background: var(--background-color);
}

/* Map */
#map-container {
    height: 600px;
    background: var(--glass-bg);
    border-radius: 0.75rem;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--glass-border);
    overflow: hidden;
}

/* Traffic */
.traffic-layout {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 1.5rem;
}

/* Ensure map/table stacks on small screens (fallback if other media rule misses) */
@media (max-width: 600px) {
    .traffic-layout {
        grid-template-columns: 1fr;
    }
}

#traffic-map {
    height: 600px;
    background: var(--glass-bg);
    border-radius: 0.75rem;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--glass-border);
    overflow: hidden;
}

#permits-map {
    height: 600px;
    background: var(--glass-bg);
    border-radius: 0.75rem;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--glass-border);
    overflow: hidden;
}

/* Mobile optimizations */
@media (max-width: 600px) {
    #map-container,
    #traffic-map,
    #permits-map,
    #inspections-map,
    #crime-map {
        height: 360px;
    }

    /* Tables as cards for small screens */
    .table-wrapper table.stackable tbody tr {
        border: 1px solid var(--border-color);
        border-radius: 0.75rem;
        margin: 0.5rem;
        padding: 0.5rem 0.75rem;
        box-shadow: var(--shadow);
        background: #fff;
    }
}

#inspections-map {
    height: 600px;
    background: var(--glass-bg);
    border-radius: 0.75rem;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--glass-border);
    overflow: hidden;
}

#crime-map {
    height: 600px;
    background: var(--glass-bg);
    border-radius: 0.75rem;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--glass-border);
    overflow: hidden;
}

/* Footer */
.footer {
    background: linear-gradient(180deg, rgba(255,255,255,0.8), rgba(255,255,255,0.6));
    border-top: 1px solid var(--border-color);
    padding: 1rem 0;
    text-align: center;
    color: var(--text-secondary);
}

/* Floating Action Button */
.fab {
    position: fixed;
    right: 16px;
    bottom: 16px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--gradient-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
    text-decoration: none;
    z-index: 1100;
    transition: transform 0.15s ease, background 0.2s ease;
    /* keep away from home bar */
    margin-bottom: env(safe-area-inset-bottom);
}

.fab:hover {
    background: var(--gradient-primary);
    transform: translateY(-2px);
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

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

.loading-spinner {
    background: var(--glass-bg);
    padding: 2rem;
    border-radius: 0.75rem;
    text-align: center;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--glass-border);
}

.loading-spinner i {
    font-size: 2rem;
    color: var(--primary-color);
    margin-bottom: 1rem;
}

/* Section header accent */
.section-header h2::after {
    content: '';
    display: block;
    width: 64px;
    height: 4px;
    margin: 10px auto 0;
    border-radius: 999px;
    background: var(--gradient-primary);
    box-shadow: 0 12px 24px rgba(124,58,237,0.22);
}

/* Responsive Design */
@media (max-width: 768px) {
    .header .container {
        flex-direction: column;
        gap: 1rem;
    }

    .logo h1 {
        font-size: 1.25rem;
    }

    .nav {
        width: 100%;
        justify-content: center;
    }

    .nav-btn {
        flex: 1;
        justify-content: center;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .charts-grid {
        grid-template-columns: 1fr;
    }

    .filters {
        flex-direction: column;
    }

    .table-header {
        flex-direction: column;
        gap: 1rem;
        align-items: flex-start;
    }

    .pagination {
        flex-direction: column;
        gap: 1rem;
    }

    .map-filters {
        flex-direction: column;
    }

    .home-hero-content {
        padding: 1.5rem;
    }

    .home-hero-content h1 {
        font-size: 1.5rem;
    }

    .tool-card {
        padding: 1rem;
    }

    .link-card {
        padding: 0.85rem 0.9rem;
    }

    .data-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .data-controls .control-group {
        margin-bottom: 0.5rem;
    }

    .data-info {
        margin-left: 0;
        margin-top: 1rem;
    }

    #map-container {
        height: 400px;
    }

    .traffic-layout {
        grid-template-columns: 1fr;
    }

    #traffic-map {
        height: 400px;
    }

    #permits-map {
        height: 400px;
    }

    #inspections-map {
        height: 400px;
    }

    #crime-map {
        height: 400px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0 0.5rem;
    }

    .main {
        padding: 1rem 0;
    }

    .section-header h2 {
        font-size: 1.5rem;
    }

    .stat-card {
        padding: 1rem;
    }

    .chart-container {
        padding: 1rem;
    }

    .filters {
        padding: 1rem;
    }

    .map-filters {
        padding: 1rem;
    }

    .hero-actions {
        flex-direction: column;
    }

    .hero-actions .btn {
        width: 100%;
    }

    .link-card {
        grid-template-columns: auto 1fr;
        align-items: start;
    }

    .link-cta {
        display: none;
    }
}

/* Chart.js responsive adjustments */
.chart-container canvas {
    max-height: 300px !important;
    width: 100% !important;
}

/* Prevent media overflow on small screens */
img, video, svg {
    max-width: 100%;
    height: auto;
}

/* Leaflet map adjustments */
.leaflet-container {
    font-family: inherit;
}

.leaflet-popup-content-wrapper {
    border-radius: 0.375rem;
}

/* Custom scrollbar */
.table-wrapper::-webkit-scrollbar {
    height: 6px;
}

.table-wrapper::-webkit-scrollbar-track {
    background: var(--background-color);
}

.table-wrapper::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.table-wrapper::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
} 

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
    }
}