* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #f1f5f9;
    color: #1e293b;
    line-height: 1.5;
}

.navbar {
    background: #1e293b;
    color: #fff;
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 2rem;
}
.nav-brand {
    font-weight: 700;
    font-size: 1.1rem;
}
.nav-links { display: flex; gap: 1rem; }
.nav-links a {
    color: #94a3b8;
    text-decoration: none;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.9rem;
}
.nav-links a:hover, .nav-links a.active {
    color: #fff;
    background: #334155;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem;
}

h1 { margin-bottom: 0.5rem; font-size: 1.5rem; }
h2 { margin: 1.5rem 0 0.75rem; font-size: 1.2rem; }
.subtitle { color: #64748b; margin-bottom: 1rem; }

.cards {
    display: flex;
    gap: 1rem;
    margin: 1rem 0;
}
.card {
    background: #fff;
    border-radius: 8px;
    padding: 1.25rem 1.5rem;
    flex: 1;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.card-highlight { background: #1e40af; color: #fff; }
.card-label { font-size: 0.85rem; color: #64748b; margin-bottom: 0.25rem; }
.card-highlight .card-label { color: #bfdbfe; }
.card-value { font-size: 2rem; font-weight: 700; }

table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    font-size: 0.85rem;
}
th, td { padding: 0.5rem 0.75rem; text-align: left; }
th {
    background: #f8fafc;
    font-weight: 600;
    color: #475569;
    border-bottom: 2px solid #e2e8f0;
    position: sticky;
    top: 0;
}
td { border-bottom: 1px solid #f1f5f9; }
tr:hover td { background: #f8fafc; }
.row-total td { font-weight: 700; background: #f0f9ff; border-top: 2px solid #e2e8f0; }
.empty { text-align: center; padding: 2rem; color: #94a3b8; }

.voted-row { background: #f0fdf4; }

.badge-yes {
    background: #16a34a;
    color: #fff;
    padding: 0.15rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-no {
    background: #e2e8f0;
    color: #64748b;
    padding: 0.15rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
}

.filters {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.filters input, .filters select {
    padding: 0.5rem;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.9rem;
}
.filters input { min-width: 200px; }

.btn {
    display: inline-block;
    background: #2563eb;
    color: #fff;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    text-decoration: none;
    font-size: 0.9rem;
}
.btn:hover { background: #1d4ed8; }

.pagination {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
    justify-content: center;
}
.pagination a {
    color: #2563eb;
    text-decoration: none;
    font-weight: 600;
}

.form-add {
    background: #fff;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    max-width: 700px;
}
.form-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.form-row label {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 150px;
    font-size: 0.85rem;
    color: #475569;
    font-weight: 600;
}
.form-row input, .form-row select, .form-row textarea {
    margin-top: 0.25rem;
    padding: 0.5rem;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.9rem;
}

.actions { margin: 1rem 0; }

.chart-container {
    background: #fff;
    border-radius: 8px;
    padding: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.note { color: #64748b; font-size: 0.85rem; margin-top: 0.5rem; }

code {
    background: #e2e8f0;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.85rem;
}

/* Exception badges */
.badge-exc {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
}
.badge-name_match { background: #f59e0b; }
.badge-household { background: #8b5cf6; }
.badge-near_miss { background: #06b6d4; }

/* Small buttons for exception actions */
.btn-sm {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    color: #fff;
    text-decoration: none;
}
.btn-success { background: #16a34a; }
.btn-success:hover { background: #15803d; }
.btn-muted { background: #94a3b8; }
.btn-muted:hover { background: #64748b; }

.detail-cell { font-size: 0.8rem; color: #475569; max-width: 300px; }
.actions-cell { white-space: nowrap; }

/* Checkbox column */
.col-check { width: 2rem; text-align: center; }
.col-check input { cursor: pointer; }

/* Bulk action bar */
.bulk-bar {
    background: #1e40af;
    color: #fff;
    padding: 0.6rem 1rem;
    border-radius: 6px;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.9rem;
    position: sticky;
    top: 0;
    z-index: 10;
}
.bulk-bar .btn-sm { font-size: 0.8rem; }

/* Related voter link in exception detail */
.related-voter {
    margin-top: 0.25rem;
    font-size: 0.75rem;
    color: #2563eb;
}
.related-voter a { color: #2563eb; text-decoration: underline; }

/* Excluded voters section (Republican ballots) */
.excluded-heading { margin-top: 2rem; color: #991b1b; font-size: 1.1rem; }
.excluded-note { color: #6b7280; font-size: 0.85rem; margin: 0.25rem 0 0.75rem; }
.excluded-table { opacity: 0.7; }
.excluded-table tr { background: #fef2f2; }
.excluded-table thead tr { background: #fecaca; }

/* Sortable column headers */
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { background: #e2e8f0; }

/* ============================================================
   Metrics page
   ============================================================ */

/* Sticky filter bar */
.metrics-filter-bar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: #fff;
    padding: 0.65rem 1rem;
    margin: 1rem -1.5rem 0;
    border-bottom: 2px solid #e2e8f0;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
    box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}
.metrics-filter-bar label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}
.metrics-filter-bar select {
    padding: 0.35rem 0.5rem;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.85rem;
    background: #f8fafc;
}

/* Section nav links in sticky bar */
.metrics-nav {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.metrics-nav a {
    color: #475569;
    text-decoration: none;
    font-size: 0.8rem;
    padding: 0.25rem 0.6rem;
    border-radius: 9999px;
    background: #f1f5f9;
    transition: background 0.15s, color 0.15s;
}
.metrics-nav a:hover {
    background: #2563eb;
    color: #fff;
}

/* Section spacing */
.metrics-section {
    margin-top: 2rem;
    scroll-margin-top: 5rem;
}

/* Side-by-side chart + table layout */
.metrics-grid {
    display: flex;
    gap: 1.5rem;
    margin-top: 0.75rem;
    align-items: flex-start;
    flex-wrap: wrap;
}
.metrics-grid > * {
    flex: 1;
    min-width: 280px;
}
.metrics-grid .chart-container {
    min-width: 320px;
}

/* Count badges in section headers */
.metrics-count {
    font-size: 0.8rem;
    font-weight: 400;
    color: #94a3b8;
    margin-left: 0.35rem;
}

/* ============================================================
   City Data page
   ============================================================ */
.city-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}
.city-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.city-select {
    padding: 0.5rem 0.75rem;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.9rem;
    background: #fff;
    min-width: 280px;
    max-width: 400px;
}
.btn-print {
    background: #475569;
    color: #fff;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    white-space: nowrap;
}
.btn-print:hover { background: #334155; }

.city-empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #94a3b8;
}
.empty-icon {
    font-size: 3rem;
    margin-bottom: 0.75rem;
    opacity: 0.5;
}
.section-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: #1e293b;
}

/* ============================================================
   Voter Detail page
   ============================================================ */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1rem;
}
.detail-card {
    background: #fff;
    border-radius: 8px;
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.detail-card-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #e2e8f0;
}
.detail-rows { display: flex; flex-direction: column; gap: 0.4rem; }
.detail-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    padding: 0.2rem 0;
}
.detail-label { color: #64748b; font-weight: 500; }

/* ============================================================
   Map page
   ============================================================ */
.map-container {
    position: relative;
    height: calc(100vh - 60px);
    margin: -1.5rem;
}
.map-container #map {
    width: 100%;
    height: 100%;
}
.map-overlay {
    position: absolute;
    z-index: 1000;
    background: rgba(255,255,255,0.95);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    padding: 0.75rem;
    max-width: 320px;
}
.map-overlay-left {
    top: 0.75rem;
    left: 0.75rem;
}
.map-overlay-right {
    top: 0.75rem;
    right: 0.75rem;
    max-width: 280px;
}
.map-search {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
}
.map-city-select {
    width: 100%;
    padding: 0.4rem 0.6rem;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
}
.map-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
    font-size: 0.8rem;
}
.map-stat {
    background: #f8fafc;
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
    text-align: center;
}
.map-stat-value { font-size: 1.1rem; font-weight: 700; }
.map-stat-label { color: #64748b; font-size: 0.7rem; }
.map-toggles {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}
.map-toggle {
    flex: 1;
    padding: 0.35rem 0.5rem;
    border: 2px solid #e2e8f0;
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 600;
    text-align: center;
    transition: all 0.15s;
}
.map-toggle.active { border-color: currentColor; background: #f0f9ff; }
.map-toggle-voted { color: #16a34a; }
.map-toggle-voted.active { border-color: #16a34a; background: #f0fdf4; }
.map-toggle-not { color: #dc2626; }
.map-toggle-not.active { border-color: #dc2626; background: #fef2f2; }
.map-voter-card {
    font-size: 0.85rem;
}
.map-voter-card h4 {
    margin: 0 0 0.35rem;
    font-size: 0.95rem;
}
.map-voter-card p {
    margin: 0.15rem 0;
    color: #475569;
}
.search-results {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    margin-bottom: 0.5rem;
}
.search-result {
    padding: 0.4rem 0.6rem;
    cursor: pointer;
    font-size: 0.8rem;
    border-bottom: 1px solid #f1f5f9;
}
.search-result:hover { background: #f0f9ff; }
.search-result:last-child { border-bottom: none; }
.map-bottom-controls {
    position: absolute;
    z-index: 1000;
    bottom: 0.75rem;
    right: 0.75rem;
    display: flex;
    gap: 0.5rem;
}
.map-btn {
    background: rgba(255,255,255,0.95);
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 0.4rem 0.75rem;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}
.map-btn:hover { background: #f8fafc; }
.map-btn.active { background: #2563eb; color: #fff; border-color: #2563eb; }
.map-legend {
    position: absolute;
    z-index: 1000;
    bottom: 0.75rem;
    left: 0.75rem;
    background: rgba(255,255,255,0.95);
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    font-size: 0.75rem;
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
    display: flex;
    gap: 0.75rem;
}
.map-legend-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}
.map-legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 1.5px solid #fff;
    box-shadow: 0 0 2px rgba(0,0,0,0.3);
}

/* Print-only header */
.print-header { display: none; }

/* ============================================================
   Print styles
   ============================================================ */
@media print {
    .navbar, .btn-print, .city-controls, #city-empty, .nav-toggle { display: none !important; }
    .city-header { justify-content: center; }
    .print-header {
        display: block !important;
        text-align: center;
        margin-bottom: 1rem;
        padding-bottom: 0.75rem;
        border-bottom: 2px solid #e2e8f0;
    }
    .print-header h2 { font-size: 1.4rem; margin: 0; }
    .print-header p { color: #64748b; font-size: 0.85rem; margin: 0.25rem 0 0; }

    body { background: #fff; }
    .container { max-width: 100%; padding: 0.5rem; }
    .card, .chart-container, .table-wrap { box-shadow: none; border: 1px solid #e2e8f0; }
    table { box-shadow: none; }
    .cards, .chart-container, .table-wrap { page-break-inside: avoid; }
    canvas { max-width: 100% !important; height: auto !important; }
}

/* ============================================================
   Responsive: table wrapper & mobile utilities
   ============================================================ */

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.table-wrap table {
    box-shadow: none;       /* shadow lives on wrapper now */
    border-radius: 0;
}

/* Hamburger toggle — hidden on desktop */
.nav-toggle {
    display: none;
    background: none;
    border: none;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    line-height: 1;
}

/* ============================================================
   Tablet breakpoint (≤ 768px)
   ============================================================ */
@media (max-width: 768px) {
    /* --- Navigation hamburger --- */
    .nav-toggle { display: block; }
    .navbar {
        flex-wrap: wrap;
        gap: 0.5rem;
        padding: 0.6rem 1rem;
    }
    .nav-brand { flex: 1; }
    .nav-links {
        display: none;
        width: 100%;
        flex-direction: column;
        gap: 0.25rem;
        padding: 0.5rem 0;
    }
    .nav-links a {
        padding: 0.6rem 0.75rem;
        font-size: 1rem;
    }
    .navbar.nav-open .nav-links {
        display: flex;
    }
    .nav-user {
        display: none;
        width: 100%;
        padding: 0.25rem 0;
        border-top: 1px solid #334155;
        margin-top: 0.25rem;
    }
    .navbar.nav-open .nav-user {
        display: flex;
        align-items: center;
        gap: 0.75rem;
    }

    /* --- Container & typography --- */
    .container { padding: 0.75rem; }
    h1 { font-size: 1.25rem; }
    h2 { font-size: 1.05rem; margin: 1rem 0 0.5rem; }
    .subtitle { font-size: 0.85rem; }

    /* --- Cards: 2 per row --- */
    .cards { flex-wrap: wrap; }
    .cards .card {
        min-width: calc(50% - 0.5rem);
        padding: 0.75rem 1rem;
    }
    .card-value { font-size: 1.5rem; }

    /* --- Tables --- */
    table { font-size: 0.78rem; }
    th, td { padding: 0.35rem 0.5rem; }
    .hide-mobile { display: none; }

    /* --- Filters: stack vertically --- */
    .filters {
        flex-direction: column;
        gap: 0.5rem;
    }
    .filters input, .filters select {
        width: 100%;
        min-width: 0;
    }

    /* --- Buttons: 44px touch targets --- */
    .btn {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    .btn-sm {
        min-height: 36px;
        padding: 0.35rem 0.6rem;
    }

    /* --- Pagination --- */
    .pagination { gap: 0.5rem; flex-wrap: wrap; }
    .pagination a {
        padding: 0.5rem 0.75rem;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }

    /* --- Bulk action bar --- */
    .bulk-bar {
        flex-wrap: wrap;
        font-size: 0.8rem;
        gap: 0.5rem;
    }

    /* --- Metrics page --- */
    .metrics-filter-bar {
        margin: 0.5rem -0.75rem 0;
        padding: 0.5rem 0.75rem;
        gap: 0.75rem;
    }
    .metrics-grid { flex-direction: column; }
    .metrics-grid > * { min-width: 100%; }
    .metrics-grid .chart-container { min-width: 100%; }

    /* --- Form --- */
    .form-add { padding: 1rem; }

    /* --- City Data page --- */
    .city-header { flex-direction: column; align-items: stretch; }
    .city-controls { flex-direction: column; }
    .city-select { min-width: 100%; max-width: 100%; }
    .btn-print { justify-content: center; min-height: 44px; }
}

/* ============================================================
   Phone breakpoint (≤ 480px)
   ============================================================ */
@media (max-width: 480px) {
    .cards .card { min-width: 100%; }
    .card-value { font-size: 1.3rem; }
    .nav-brand { font-size: 0.95rem; }
    table { font-size: 0.72rem; }
    th, td { padding: 0.3rem 0.4rem; }
}
