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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f0f2f5;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Header ── */
header {
    background: #0f172a;
    color: white;
    padding: 14px 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

header .logo {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px rgba(255,255,255,0.15);
}

header h1 {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0.2px;
}

header p {
    font-size: 0.72rem;
    opacity: 0.55;
    margin-top: 2px;
}

/* ── Layout ── */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

#map {
    flex: 1;
    min-height: 0;
}

/* ── Sidebar ── */
#sidebar {
    width: 380px;
    background: white;
    display: flex;
    flex-direction: column;
    border-left: 1px solid #e2e8f0;
    overflow: hidden;
    flex-shrink: 0;
}

.sidebar-top {
    padding: 14px 16px;
    border-bottom: 1px solid #e2e8f0;
    background: white;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-top .search-wrap {
    flex: 1;
}

#sidebar-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #f8fafc;
    cursor: pointer;
    color: #64748b;
}

#sidebar-toggle svg {
    width: 16px;
    height: 16px;
    transition: transform 0.2s;
}

.search-wrap {
    position: relative;
}

.search-wrap svg {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    width: 16px;
    height: 16px;
    pointer-events: none;
}

.search-wrap input {
    width: 100%;
    padding: 9px 12px 9px 34px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.875rem;
    color: #1e293b;
    background: #f8fafc;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.search-wrap input:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
    background: white;
}

.search-wrap input::placeholder {
    color: #94a3b8;
}

.sidebar-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    scroll-behavior: smooth;
}

/* ── Tab bar ── */
.tab-bar {
    display: flex;
    border-bottom: 1px solid #e2e8f0;
    background: white;
    flex-shrink: 0;
}

.tab-btn {
    flex: 1;
    padding: 8px 6px 7px;
    border: none;
    border-bottom: 2px solid transparent;
    background: none;
    color: #94a3b8;
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    transition: color 0.15s, border-color 0.15s;
    margin-bottom: -1px;
}

.tab-btn svg {
    width: 16px;
    height: 16px;
}

.tab-btn.active {
    color: #3b82f6;
    border-bottom-color: #3b82f6;
}

.tab-btn[data-tab="worst"].active {
    color: #dc2626;
    border-bottom-color: #dc2626;
}

.tab-badge {
    display: inline-block;
    background: #3b82f6;
    color: white;
    font-size: 0.6rem;
    font-weight: 700;
    padding: 0 4px;
    border-radius: 99px;
    line-height: 1.6;
    margin-left: 2px;
}

.tab-badge[hidden] {
    display: none;
}

/* ── Filters panel ── */
#filters-panel {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

#filters-panel[hidden] {
    display: none;
}

#about-panel {
    display: block;
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

#about-panel[hidden] {
    display: none !important;
}

.about-content h2 {
    font-size: 1rem;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 8px;
}

.about-content h3 {
    font-size: 0.82rem;
    font-weight: 700;
    color: #1e293b;
    margin-top: 16px;
    margin-bottom: 6px;
}

.about-content p {
    font-size: 0.8rem;
    color: #475569;
    line-height: 1.5;
    margin-bottom: 6px;
}

.about-content ul {
    font-size: 0.8rem;
    color: #475569;
    line-height: 1.6;
    padding-left: 18px;
    margin-bottom: 6px;
}

.about-content a {
    color: #3b82f6;
    text-decoration: none;
}

.about-content a:hover {
    text-decoration: underline;
}

.about-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    margin: 8px 0;
}

.about-table th {
    text-align: left;
    color: #64748b;
    font-weight: 600;
    padding: 4px 8px;
    border-bottom: 1px solid #e2e8f0;
}

.about-table td {
    padding: 4px 8px;
    color: #475569;
    border-bottom: 1px solid #f1f5f9;
}

.about-table td:first-child {
    white-space: nowrap;
}

.dot-inline {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 5px;
    vertical-align: middle;
}

/* ── List view ── */
.list-title {
    font-size: 0.78rem;
    font-weight: 700;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    padding: 10px 0 6px;
}

.list-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid #f1f5f9;
    cursor: pointer;
}

.list-item:hover {
    background: #f8fafc;
    margin: 0 -16px;
    padding: 10px 16px;
}

.list-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 2px solid white;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.15);
}

.list-info {
    flex: 1;
    min-width: 0;
}

.list-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: #1e293b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-address {
    font-size: 0.75rem;
    color: #94a3b8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-meta {
    font-size: 0.7rem;
    color: #cbd5e1;
    margin-top: 1px;
}

/* ── Sort bar ── */
.sort-bar {
    display: flex;
    gap: 5px;
    padding: 8px 0 4px;
}

.sort-btn {
    padding: 3px 9px;
    border: 1px solid #e2e8f0;
    border-radius: 99px;
    background: #f8fafc;
    font-size: 0.7rem;
    font-weight: 600;
    color: #64748b;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.sort-btn.active {
    background: #1e293b;
    border-color: #1e293b;
    color: white;
}


/* ── Back button ── */
.back-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 12px;
    padding: 5px 0;
    border: none;
    background: none;
    color: #3b82f6;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
}

.back-btn:hover {
    text-decoration: underline;
}

/* ── Filters ── */
.filters {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-body[hidden] {
    display: none !important;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.filter-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.filter-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.pill {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border-radius: 99px;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    font-size: 0.72rem;
    color: #64748b;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.pill.active {
    background: #1e293b;
    border-color: #1e293b;
    color: white;
}

.pill-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* ── Placeholder ── */
.placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 24px;
    color: #94a3b8;
    text-align: center;
    gap: 10px;
}

.placeholder svg {
    width: 48px;
    height: 48px;
    opacity: 0.4;
}

.placeholder p {
    font-size: 0.875rem;
}

/* ── Cleanliness score ── */
.cleanliness-score {
    font-size: 0.95rem;
    font-weight: 800;
    flex-shrink: 0;
    white-space: nowrap;
}

.cleanliness-score.large {
    font-size: 1.4rem;
}

.cs-label {
    font-size: 0.65em;
    color: #94a3b8;
    font-weight: 500;
}

/* ── Location Header ── */
.loc-header {
    margin-bottom: 16px;
}

.loc-header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
}

.loc-name {
    font-size: 1.05rem;
    font-weight: 700;
    color: #0f172a;
    line-height: 1.3;
}

.loc-meta {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.loc-meta span {
    font-size: 0.78rem;
    color: #64748b;
    display: flex;
    align-items: center;
    gap: 5px;
}

/* ── Inspection Card ── */
.inspection-card {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 14px;
    margin-bottom: 10px;
}

.card-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 6px;
}

.card-date {
    font-weight: 600;
    font-size: 0.875rem;
    color: #1e293b;
}

.card-type {
    font-size: 0.78rem;
    color: #64748b;
    margin-bottom: 10px;
}

.badge {
    padding: 3px 9px;
    border-radius: 99px;
    font-size: 0.68rem;
    font-weight: 700;
    white-space: nowrap;
    flex-shrink: 0;
}

.badge-clean {
    background: #dcfce7;
    color: #166534;
}

.badge-violations {
    background: #fee2e2;
    color: #991b1b;
}

.violation {
    font-size: 0.8rem;
    color: #dc2626;
    padding: 6px 10px;
    background: #fff5f5;
    border-left: 3px solid #fca5a5;
    border-radius: 0 5px 5px 0;
    margin: 4px 0;
    line-height: 1.4;
}

.no-violations {
    font-size: 0.8rem;
    color: #16a34a;
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
}

.report-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 10px;
    font-size: 0.78rem;
    color: #3b82f6;
    text-decoration: none;
    font-weight: 500;
}

.report-link:hover { text-decoration: underline; }

/* ── Loader ── */
.loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 60px 20px;
    color: #64748b;
    gap: 12px;
    font-size: 0.875rem;
}

.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid #e2e8f0;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

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

/* ── Error ── */
.error-msg {
    font-size: 0.875rem;
    color: #dc2626;
    padding: 14px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    line-height: 1.5;
}

/* ── Leaflet tooltip overrides ── */
.leaflet-tooltip {
    border-radius: 8px !important;
    border: none !important;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15) !important;
    padding: 8px 12px !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
    font-size: 0.8rem !important;
    color: #1e293b !important;
}

/* ── Cluster icons ── */
.cluster-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 3px solid white;
    box-shadow: 0 2px 6px rgba(0,0,0,0.25);
    color: white;
    font-size: 0.78rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── Near Me button ── */
#near-me-btn {
    position: absolute;
    top: 80px;
    left: 10px;
    z-index: 1000;
    width: 34px;
    height: 34px;
    background: white;
    border: 2px solid rgba(0,0,0,0.2);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #1e293b;
    box-shadow: none;
}

#near-me-btn:hover {
    background: #f4f4f4;
}

#near-me-btn svg {
    width: 18px;
    height: 18px;
}

#near-me-btn.loading svg {
    animation: spin 1s linear infinite;
    opacity: 0.5;
}

/* ── Legend ── */
.map-legend {
    position: absolute;
    bottom: 28px;
    left: 10px;
    z-index: 1000;
    background: white;
    border-radius: 8px;
    padding: 8px 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    font-size: 0.75rem;
    color: #1e293b;
    pointer-events: none;
}

.map-legend .legend-row {
    display: flex;
    align-items: center;
    gap: 7px;
    margin: 3px 0;
}

.map-legend .dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.15);
    flex-shrink: 0;
}

/* ── Mobile ── */
@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
    }

    #map {
        height: 35dvh;
        flex: none;
    }

    .sidebar-collapsed #map {
        height: auto;
        flex: 1;
    }

    #sidebar {
        width: 100%;
        flex: 1;
        border-left: none;
        border-top: 1px solid #e2e8f0;
    }

    .search-wrap input {
        font-size: 16px;
    }

    #sidebar-toggle {
        display: flex;
    }

    #sidebar.collapsed {
        flex: none;
    }

    #sidebar.collapsed .sidebar-body,
    #sidebar.collapsed .tab-bar,
    #sidebar.collapsed #filters-panel,
    #sidebar.collapsed #about-panel {
        display: none;
    }

    #sidebar.collapsed #toggle-icon {
        transform: rotate(180deg);
    }
}
