/* ═══════════════════════════════════════════════════════════════════
   DPB Live — Bratislava Transport Tracker
   Premium Dark Theme with Glassmorphism
   ═══════════════════════════════════════════════════════════════════ */

:root {
    --bg-dark: #0a0e17;
    --bg-panel: rgba(15, 20, 35, 0.85);
    --bg-panel-solid: #0f1423;
    --bg-hover: rgba(30, 40, 70, 0.7);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --text-primary: #e8ecf4;
    --text-secondary: #8892a8;
    --text-muted: #505a70;
    --accent-blue: #3b82f6;
    --accent-cyan: #06b6d4;
    --accent-green: #10b981;
    --accent-yellow: #f59e0b;
    --accent-red: #ef4444;
    --accent-purple: #8b5cf6;
    --gradient-main: linear-gradient(135deg, #3b82f6, #06b6d4);
    --gradient-bus: linear-gradient(135deg, #3b82f6, #6366f1);
    --gradient-trolley: linear-gradient(135deg, #10b981, #06b6d4);
    --gradient-tram: linear-gradient(135deg, #f59e0b, #ef4444);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: var(--font);
    background: var(--bg-dark);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* ── Map ──────────────────────────────────────────────────────────── */
#map {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* Tile styling — voyager is already clean, just a subtle tweak */
.leaflet-tile-pane {
    filter: saturate(0.9);
}

.leaflet-control-attribution {
    background: rgba(0, 0, 0, 0.5) !important;
    color: #333 !important;
    font-size: 10px !important;
}

.leaflet-control-attribution a {
    color: #555 !important;
}

.leaflet-control-zoom a {
    background: var(--bg-panel) !important;
    color: var(--text-primary) !important;
    border-color: var(--glass-border) !important;
    backdrop-filter: blur(20px);
}

.leaflet-control-zoom a:hover {
    background: var(--bg-hover) !important;
}

/* ── Header ───────────────────────────────────────────────────────── */
#header {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 12px 24px;
    background: var(--bg-panel);
    backdrop-filter: blur(24px) saturate(1.5);
    -webkit-backdrop-filter: blur(24px) saturate(1.5);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xl);
    box-shadow: var(--glass-shadow);
    min-width: 420px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

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

.logo-icon {
    font-size: 24px;
    filter: drop-shadow(0 0 8px rgba(59, 130, 246, 0.5));
}

.logo h1 {
    font-size: 20px;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: var(--gradient-main);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.logo .accent {
    font-weight: 400;
}

.subtitle {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ── Status Badge ─────────────────────────────────────────────────── */
.status-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 100px;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.2);
    transition: var(--transition);
}

.status-badge.error {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.2);
}

.status-badge.error .status-dot {
    background: var(--accent-red);
    box-shadow: 0 0 8px var(--accent-red);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-green);
    box-shadow: 0 0 8px var(--accent-green);
    animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.5;
        transform: scale(0.8);
    }
}

.status-text {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.3px;
}

/* ── Controls Panel ───────────────────────────────────────────────── */
#controls {
    position: fixed;
    top: 80px;
    left: 16px;
    z-index: 1000;
    width: 280px;
    padding: 20px;
    background: var(--bg-panel);
    backdrop-filter: blur(24px) saturate(1.5);
    -webkit-backdrop-filter: blur(24px) saturate(1.5);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--glass-shadow);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
}

/* ── Transport Buttons ────────────────────────────────────────────── */
.transport-buttons {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.transport-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    font-family: var(--font);
    font-size: 13px;
}

.transport-btn:hover {
    background: var(--bg-hover);
    border-color: rgba(255, 255, 255, 0.15);
    transform: translateX(4px);
}

.transport-btn.active {
    border-color: rgba(59, 130, 246, 0.4);
    color: var(--text-primary);
}

.transport-btn.active[data-type="T"] {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.15), rgba(99, 102, 241, 0.1));
    box-shadow: inset 0 0 20px rgba(59, 130, 246, 0.05);
}

.transport-btn.active[data-type="O"] {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.15), rgba(6, 182, 212, 0.1));
    box-shadow: inset 0 0 20px rgba(16, 185, 129, 0.05);
}

.transport-btn.active[data-type="A"] {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.15), rgba(239, 68, 68, 0.1));
    box-shadow: inset 0 0 20px rgba(245, 158, 11, 0.05);
}

.btn-icon {
    font-size: 18px;
}

.btn-label {
    flex: 1;
    text-align: left;
    font-weight: 500;
}

.btn-count {
    font-size: 12px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 100px;
    background: rgba(255, 255, 255, 0.06);
    min-width: 32px;
    text-align: center;
}

/* ── Line Filter ──────────────────────────────────────────────────── */
.line-filter select {
    width: 100%;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 13px;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238892a8' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    transition: var(--transition);
}

.line-filter select:hover {
    border-color: rgba(255, 255, 255, 0.2);
}

.line-filter select:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.line-filter select option {
    background: var(--bg-panel-solid);
    color: var(--text-primary);
    padding: 8px;
}

/* ── Stats Panel ──────────────────────────────────────────────────── */
.stats-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 8px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
}

.stat-value {
    font-size: 20px;
    font-weight: 800;
    background: var(--gradient-main);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.stat-label {
    font-size: 10px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 2px;
}

/* ── Refresh Bar ──────────────────────────────────────────────────── */
.refresh-bar {
    height: 3px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 100px;
    overflow: hidden;
}

.refresh-progress {
    height: 100%;
    background: var(--gradient-main);
    border-radius: 100px;
    width: 0%;
    transition: width 0.3s linear;
}

.refresh-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 10px;
    color: var(--text-muted);
}

.source-badge {
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 9px;
}

.source-badge.live {
    background: rgba(16, 185, 129, 0.15);
    color: var(--accent-green);
}

.source-badge.cache {
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent-blue);
}

.source-badge.fallback {
    background: rgba(245, 158, 11, 0.15);
    color: var(--accent-yellow);
}

.source-badge.stale-cache {
    background: rgba(239, 68, 68, 0.15);
    color: var(--accent-red);
}

/* ── Legend ────────────────────────────────────────────────────────── */
#legend {
    position: fixed;
    bottom: 24px;
    left: 16px;
    z-index: 1000;
    display: flex;
    gap: 16px;
    padding: 10px 16px;
    background: var(--bg-panel);
    backdrop-filter: blur(24px) saturate(1.5);
    -webkit-backdrop-filter: blur(24px) saturate(1.5);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    box-shadow: var(--glass-shadow);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.legend-dot.on-time {
    background: var(--accent-green);
    box-shadow: 0 0 6px var(--accent-green);
}

.legend-dot.slight {
    background: var(--accent-yellow);
    box-shadow: 0 0 6px var(--accent-yellow);
}

.legend-dot.delayed {
    background: var(--accent-red);
    box-shadow: 0 0 6px var(--accent-red);
}

/* ── Cluster Markers ──────────────────────────────────────────────── */
.cluster-marker {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: white;
    font-family: var(--font);
    font-weight: 800;
    border: 2px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
}

.cluster-sm {
    width: 36px;
    height: 36px;
    font-size: 12px;
}

.cluster-md {
    width: 42px;
    height: 42px;
    font-size: 14px;
}

.cluster-lg {
    width: 50px;
    height: 50px;
    font-size: 16px;
}

.cluster-type-T {
    background: var(--gradient-bus);
}

.cluster-type-O {
    background: var(--gradient-trolley);
}

.cluster-type-A {
    background: var(--gradient-tram);
}

/* Override default markercluster styles */
.marker-cluster {
    background: none !important;
}

.marker-cluster div {
    background: none !important;
}

/* ── Map Markers ──────────────────────────────────────────────────── */
/* Marker wrapper — holds arrow + circle */
.vehicle-marker-wrap {
    position: relative;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Direction arrow */
.vehicle-arrow {
    position: absolute;
    top: -6px;
    left: 50%;
    transform-origin: 50% 28px;
    margin-left: -10px;
    z-index: 3;
    filter: drop-shadow(0 0 4px rgba(0, 0, 0, 0.7)) drop-shadow(0 0 8px rgba(0, 0, 0, 0.3));
    pointer-events: none;
}

.vehicle-marker {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 800;
    font-family: var(--font);
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    border: 2.5px solid rgba(255, 255, 255, 0.4);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35), 0 0 20px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    position: relative;
    z-index: 2;
}

.vehicle-marker-wrap:hover .vehicle-marker {
    transform: scale(1.25);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.vehicle-marker.type-T {
    background: var(--gradient-bus);
}

.vehicle-marker.type-O {
    background: var(--gradient-trolley);
}

.vehicle-marker.type-A {
    background: var(--gradient-tram);
}

/* Delay indicator ring */
.vehicle-marker.delay-ok {
    border-color: var(--accent-green);
}

.vehicle-marker.delay-warn {
    border-color: var(--accent-yellow);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35), 0 0 6px rgba(245, 158, 11, 0.4);
}

.vehicle-marker.delay-bad {
    border-color: var(--accent-red);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35), 0 0 8px rgba(239, 68, 68, 0.5);
}

/* ── Popup ─────────────────────────────────────────────────────────── */
.leaflet-popup-content-wrapper {
    background: var(--bg-panel-solid) !important;
    border: 1px solid var(--glass-border) !important;
    border-radius: var(--radius-md) !important;
    box-shadow: var(--glass-shadow) !important;
    color: var(--text-primary) !important;
    padding: 0 !important;
}

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

.leaflet-popup-close-button {
    color: var(--text-muted) !important;
    font-size: 18px !important;
    top: 8px !important;
    right: 10px !important;
}

.leaflet-popup-close-button:hover {
    color: var(--text-primary) !important;
}

.vehicle-popup {
    padding: 16px;
    min-width: 200px;
}

.popup-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--glass-border);
}

.popup-line-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    font-size: 20px;
    font-weight: 900;
    color: white;
}

.popup-line-badge.type-T {
    background: var(--gradient-bus);
}

.popup-line-badge.type-O {
    background: var(--gradient-trolley);
}

.popup-line-badge.type-A {
    background: var(--gradient-tram);
}

.popup-title {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.popup-title .line-name {
    font-size: 16px;
    font-weight: 700;
}

.popup-title .transport-type {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
}

.popup-details {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.popup-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
}

.popup-row .label {
    color: var(--text-muted);
    font-weight: 500;
}

.popup-row .value {
    font-weight: 600;
    color: var(--text-primary);
}

.delay-badge {
    padding: 3px 8px;
    border-radius: 100px;
    font-size: 11px;
    font-weight: 700;
}

.delay-badge.on-time {
    background: rgba(16, 185, 129, 0.15);
    color: var(--accent-green);
}

.delay-badge.slight {
    background: rgba(245, 158, 11, 0.15);
    color: var(--accent-yellow);
}

.delay-badge.delayed {
    background: rgba(239, 68, 68, 0.15);
    color: var(--accent-red);
}

/* ── Loading Overlay ──────────────────────────────────────────────── */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-dark);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    transition: opacity 0.5s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--glass-border);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading-text {
    margin-top: 16px;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
}

/* ── Responsive ───────────────────────────────────────────────────── */
@media (max-width: 768px) {
    #header {
        min-width: auto;
        left: 8px;
        right: 8px;
        top: 8px;
        transform: none;
        padding: 8px 14px;
        gap: 8px;
        border-radius: var(--radius-md);
    }

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

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

    .subtitle {
        display: none;
    }

    .status-text {
        font-size: 10px;
    }

    .status-badge {
        padding: 4px 8px;
    }

    /* Controls = compact bottom sheet */
    #controls {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        padding: 12px 12px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        gap: 10px;
        max-height: 45vh;
        overflow-y: auto;
    }

    .control-label {
        display: none;
    }

    /* Transport buttons: horizontal compact */
    .transport-buttons {
        flex-direction: row;
        gap: 6px;
    }

    .transport-btn {
        flex: 1;
        flex-direction: column;
        padding: 8px 4px;
        text-align: center;
        gap: 2px;
        border-radius: var(--radius-sm);
    }

    .btn-icon {
        font-size: 16px;
    }

    .btn-label {
        font-size: 9px;
        text-align: center;
        font-weight: 600;
    }

    .btn-count {
        font-size: 13px;
        font-weight: 800;
        padding: 0;
        background: none;
        min-width: auto;
    }

    /* Line filter compact */
    .line-filter select {
        padding: 8px 10px;
        font-size: 12px;
    }

    /* Stats = single row */
    .stats-panel {
        grid-template-columns: 1fr 1fr 1fr 1fr;
        gap: 4px;
    }

    .stat {
        padding: 6px 4px;
    }

    .stat-value {
        font-size: 15px;
    }

    .stat-label {
        font-size: 8px;
        letter-spacing: 0;
    }

    /* Refresh bar + info */
    .refresh-bar {
        height: 2px;
    }

    .refresh-info {
        font-size: 9px;
    }

    /* Legend — hide on mobile, info is in stats */
    #legend {
        display: none;
    }

    /* Move zoom controls to right side, above panel */
    .leaflet-control-zoom {
        margin-right: 8px !important;
    }
}

/* Extra small phones */
@media (max-width: 380px) {
    .btn-label {
        display: none;
    }

    .stat-label {
        font-size: 7px;
    }
}