/* ============================================================
   Pothole Retracking Map — Dark Glassmorphism Theme
   ============================================================ */

/* --- CSS Custom Properties --- */
:root {
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

    /* Colors - Light Theme */
    --bg-dark: #f8fafc;
    --bg-surface: #ffffff;
    --bg-surface-hover: #f1f5f9;
    --bg-glass: rgba(255, 255, 255, 0.85);
    --bg-glass-strong: rgba(255, 255, 255, 0.95);
    --border-glass: rgba(0, 0, 0, 0.08);
    --border-glass-hover: rgba(0, 0, 0, 0.15);

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;

    --accent-blue: #3b82f6;
    --accent-blue-glow: rgba(59, 130, 246, 0.3);
    --accent-emerald: #10b981;
    --accent-amber: #f59e0b;
    --accent-rose: #f43f5e;
    --accent-violet: #8b5cf6;

    /* Marker severity colors */
    --marker-low: #10b981;
    --marker-med: #f59e0b;
    --marker-high: #f43f5e;

    /* Sizing */
    --top-bar-height: 60px;
    --panel-width: 420px;

    /* Transitions */
    --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-panel: 0.35s cubic-bezier(0.4, 0, 0.2, 1);

    /* Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
}

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

html,
body {
    height: 100%;
    overflow: hidden;
    font-family: var(--font-family);
    font-size: 14px;
    color: var(--text-primary);
    background: var(--bg-dark);
    -webkit-font-smoothing: antialiased;
}

/* ============================================================
   Top Bar
   ============================================================ */
.top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--top-bar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    background: #0f172a;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    z-index: 1000;
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 24px;
}

.brand-logos {
    display: flex;
    align-items: center;
    gap: 16px;
    padding-right: 16px;
    border-right: 1px solid rgba(255, 255, 255, 0.15);
}

.header-logo {
    height: 28px;
    width: auto;
    object-fit: contain;
}

.vsb-logo {
    height: 38px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    font-size: 24px;
}

.logo h1 {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.02em;
    /* background: linear-gradient(135deg, var(--accent-blue), var(--accent-violet)); */
    background: #ffffff;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Stats chips */
.stats-bar {
    display: flex;
    gap: 10px;
}

.stat-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 12px;
    transition: background var(--transition-fast);
}

.stat-chip:hover {
    background: rgba(255, 255, 255, 0.15);
}

.stat-chip-icon {
    font-size: 14px;
}

.stat-chip-value {
    font-weight: 600;
    color: #ffffff;
}

.stat-chip-label {
    color: #cbd5e1;
}

/* Geocoder */
.top-bar-right {
    display: flex;
    align-items: center;
}

.geocoder {
    position: relative;
    display: flex;
    align-items: center;
}

.geocoder input {
    width: 280px;
    padding: 8px 40px 8px 14px;
    border: 1px solid var(--border-glass);
    border-radius: 20px;
    background: var(--bg-surface);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 13px;
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.geocoder input::placeholder {
    color: var(--text-muted);
}

.geocoder input:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px var(--accent-blue-glow);
}

.geocoder button {
    position: absolute;
    right: 4px;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color var(--transition-fast), background var(--transition-fast);
}

.geocoder button:hover {
    color: var(--accent-blue);
    background: var(--accent-blue-glow);
}

/* Geocoder dropdown results */
.geocoder-results {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    width: 340px;
    max-height: 280px;
    overflow-y: auto;
    list-style: none;
    background: var(--bg-glass-strong);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.1);
    z-index: 1100;
}

.geocoder-results.visible {
    display: block;
}

.geocoder-results li {
    padding: 10px 14px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 1px solid var(--border-glass);
    transition: background var(--transition-fast), color var(--transition-fast);
}

.geocoder-results li:last-child {
    border-bottom: none;
}

.geocoder-results li:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
}

/* ============================================================
   Map
   ============================================================ */
#map {
    position: fixed;
    top: var(--top-bar-height);
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
}

/* Remove map tile filter for light theme */
.leaflet-tile-pane {
    filter: none;
}

/* Override leaflet popup styles */
.leaflet-popup-content-wrapper {
    background: var(--bg-glass-strong) !important;
    backdrop-filter: blur(16px) !important;
    border: 1px solid var(--border-glass) !important;
    border-radius: var(--radius-md) !important;
    color: var(--text-primary) !important;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1) !important;
}

.leaflet-popup-tip {
    background: var(--bg-glass-strong) !important;
    border: 1px solid var(--border-glass) !important;
}

.leaflet-popup-content {
    margin: 10px 14px !important;
    font-family: var(--font-family) !important;
    font-size: 13px !important;
    line-height: 1.5 !important;
}

.popup-title {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 6px;
    color: var(--accent-blue);
}

.popup-meta {
    color: var(--text-secondary);
    font-size: 12px;
}

.popup-meta span {
    display: block;
    margin-bottom: 2px;
}

.popup-btn {
    display: inline-block;
    margin-top: 8px;
    padding: 5px 14px;
    font-size: 12px;
    font-weight: 500;
    font-family: var(--font-family);
    color: #fff;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-violet));
    border: none;
    border-radius: 14px;
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.popup-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 16px var(--accent-blue-glow);
}

/* MarkerCluster overrides */
.marker-cluster-small {
    background-color: rgba(16, 185, 129, 0.25) !important;
}

.marker-cluster-small div {
    background-color: var(--marker-low) !important;
    color: #fff !important;
    font-family: var(--font-family) !important;
    font-weight: 600 !important;
}

.marker-cluster-medium {
    background-color: rgba(245, 158, 11, 0.25) !important;
}

.marker-cluster-medium div {
    background-color: var(--marker-med) !important;
    color: #fff !important;
    font-family: var(--font-family) !important;
    font-weight: 600 !important;
}

.marker-cluster-large {
    background-color: rgba(244, 63, 94, 0.25) !important;
}

.marker-cluster-large div {
    background-color: var(--marker-high) !important;
    color: #fff !important;
    font-family: var(--font-family) !important;
    font-weight: 600 !important;
}

/* ============================================================
   Side Panel
   ============================================================ */
.side-panel {
    position: fixed;
    top: var(--top-bar-height);
    right: 0;
    bottom: 0;
    width: var(--panel-width);
    background: var(--bg-glass-strong);
    backdrop-filter: blur(24px) saturate(1.4);
    -webkit-backdrop-filter: blur(24px) saturate(1.4);
    border-left: 1px solid var(--border-glass);
    box-shadow: -8px 0 40px rgba(0, 0, 0, 0.08);
    z-index: 900;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform var(--transition-panel);
    overflow: hidden;
}

.side-panel.open {
    transform: translateX(0);
}

.panel-header {
    padding: 18px 20px 14px;
    border-bottom: 1px solid var(--border-glass);
    flex-shrink: 0;
}

.panel-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-title-row h2 {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.panel-close {
    width: 30px;
    height: 30px;
    border: none;
    background: var(--bg-surface);
    border-radius: 50%;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.panel-close:hover {
    background: var(--accent-rose);
    color: #fff;
}

.panel-meta {
    margin-top: 10px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.panel-meta .meta-tag {
    padding: 3px 10px;
    font-size: 11px;
    font-weight: 500;
    border-radius: 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border-glass);
    color: var(--text-secondary);
}

.panel-meta .meta-tag.accent {
    background: var(--accent-blue-glow);
    border-color: var(--accent-blue);
    color: var(--accent-blue);
}

/* Panel body / gallery */
.panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px 20px;
}

.panel-body::-webkit-scrollbar {
    width: 5px;
}

.panel-body::-webkit-scrollbar-track {
    background: transparent;
}

.panel-body::-webkit-scrollbar-thumb {
    background: var(--border-glass-hover);
    border-radius: 3px;
}

.panel-loading {
    display: none;
    text-align: center;
    padding: 40px 0;
    color: var(--text-secondary);
}

.panel-loading.visible {
    display: block;
}

/* Spinner */
.spinner {
    width: 32px;
    height: 32px;
    margin: 0 auto 14px;
    border: 3px solid var(--border-glass);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Tracking Summary */
.tracking-summary {
    display: flex;
    justify-content: space-between;
    background: var(--bg-surface);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.02);
}

.summary-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.summary-item span.summary-value {
    font-size: 16px;
    font-weight: 700;
    color: var(--accent-blue);
}

.summary-item span.summary-label {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    letter-spacing: 0.02em;
}

/* Detection cards */
.detection-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    overflow: hidden;
    margin-bottom: 20px;
    transition: border-color var(--transition-fast), transform var(--transition-fast);
    animation: cardSlideIn 0.3s ease-out both;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.02);
}

.detection-card:hover {
    border-color: var(--border-glass-hover);
    transform: translateY(-1px);
}

.detection-card.reference {
    border-color: var(--accent-emerald);
    box-shadow: 0 0 0 1px var(--accent-emerald), 0 0 20px rgba(16, 185, 129, 0.1);
}

@keyframes cardSlideIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.detection-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid var(--border-glass);
}

.detection-card-header .badge {
    padding: 2px 8px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-radius: 8px;
}

.badge-reference {
    background: rgba(16, 185, 129, 0.15);
    color: var(--accent-emerald);
}

.badge-similar {
    background: rgba(139, 92, 246, 0.15);
    color: var(--accent-violet);
}

.detection-time-highlight {
    font-size: 12px;
    color: var(--text-primary);
    font-weight: 600;
}

.highlight-pulse {
    position: relative;
    padding-left: 12px;
}

.highlight-pulse::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-blue);
    box-shadow: 0 0 8px var(--accent-blue-glow);
}

.detection-metrics {
    display: flex;
    gap: 10px;
    padding: 10px 14px;
    background: var(--bg-dark);
    border-bottom: 1px solid var(--border-glass);
}

.metric-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--bg-surface);
    border: 1px solid var(--border-glass);
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
}

.metric-pill.metric-ref {
    color: var(--accent-emerald);
    border-color: rgba(16, 185, 129, 0.3);
    background: rgba(16, 185, 129, 0.05);
}

.metric-icon {
    font-size: 12px;
}

.detection-img-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    cursor: pointer;
    background: var(--bg-dark);
}

.detection-img-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.detection-img-wrap:hover img {
    transform: scale(1.03);
}

.detection-img-wrap .img-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.6) 0%, transparent 50%);
    opacity: 0;
    transition: opacity var(--transition-fast);
    display: flex;
    align-items: flex-end;
    padding: 10px;
}

.detection-img-wrap:hover .img-overlay {
    opacity: 1;
}

.img-overlay span {
    font-size: 11px;
    color: #fff;
    font-weight: 500;
}

.detection-info {
    padding: 12px 14px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.detection-info .info-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.detection-info .info-label {
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.detection-info .info-value {
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 500;
}

/* ============================================================
   Image Modal
   ============================================================ */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.modal.visible {
    display: flex;
}

.modal-close {
    position: absolute;
    top: 20px;
    right: 28px;
    font-size: 36px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color var(--transition-fast);
    z-index: 2001;
}

.modal-close:hover {
    color: #fff;
}

.modal-image {
    max-width: 90vw;
    max-height: 80vh;
    border-radius: var(--radius-md);
    box-shadow: 0 16px 60px rgba(0, 0, 0, 0.2);
}

.modal-caption {
    margin-top: 14px;
    font-size: 13px;
    color: var(--text-secondary);
    text-align: center;
}

/* ============================================================
   Empty State
   ============================================================ */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

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

.empty-state-text {
    font-size: 14px;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 768px) {
    .top-bar {
        padding: 0 12px;
    }

    .logo h1 {
        font-size: 15px;
    }

    .stats-bar {
        display: none;
    }

    .geocoder input {
        width: 200px;
    }

    .side-panel {
        width: 100%;
    }

    :root {
        --panel-width: 100%;
    }
}

@media (max-width: 480px) {
    .geocoder input {
        width: 160px;
        font-size: 12px;
    }

    .geocoder-results {
        width: 260px;
    }
}