:root {
    --ink: #f6f0df;
    --muted: rgba(246, 240, 223, 0.66);
    --faint: rgba(246, 240, 223, 0.42);
    --panel: rgba(17, 23, 33, 0.88);
    --panel-solid: #111721;
    --rail: rgba(255, 255, 255, 0.1);
    --rail-strong: rgba(255, 255, 255, 0.18);
    --city-night: #0b1018;
    --route-yellow: #ffcf4a;
    --signal-cyan: #63d7ff;
    --signal-green: #1fbf75;
    --signal-red: #ff5a5f;
    --bus-color: #2f80ed;
    --tram-color: #1fbf75;
    --trolley-color: #ffb020;
    --shadow: 0 18px 40px rgba(0, 0, 0, 0.38);
    --ring: 0 0 0 3px rgba(99, 215, 255, 0.18);
    --radius: 8px;
    --sidebar-width: 320px;
    --header-height: 72px;
    --fast: 140ms ease;
    --normal: 260ms ease;
}

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

html,
body {
    height: 100%;
}

body {
    margin: 0;
    overflow: hidden;
    color: var(--ink);
    background:
        linear-gradient(135deg, rgba(255, 207, 74, 0.08) 0 1px, transparent 1px 34px),
        linear-gradient(45deg, rgba(99, 215, 255, 0.06) 0 1px, transparent 1px 42px),
        var(--city-night);
    font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
}

button,
input {
    font: inherit;
}

button {
    -webkit-tap-highlight-color: transparent;
}

.header {
    position: fixed;
    inset: 0 0 auto 0;
    z-index: 1000;
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 12px 18px;
    background: rgba(13, 18, 27, 0.86);
    border-bottom: 1px solid var(--rail);
    backdrop-filter: blur(18px);
}

.brand-block,
.header-actions,
.status-bar,
.filter-btn,
.sidebar-header,
.panel-header,
.info-section > div,
.search-box {
    display: flex;
    align-items: center;
}

.brand-block {
    gap: 12px;
    min-width: 0;
}

.logo-mark {
    position: relative;
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    border: 1px solid rgba(255, 207, 74, 0.42);
    border-radius: 50%;
    background: radial-gradient(circle at 52% 50%, rgba(255, 207, 74, 0.2), rgba(255, 207, 74, 0.04) 58%, transparent 60%);
}

.logo-route {
    position: absolute;
    top: 20px;
    left: 8px;
    width: 26px;
    height: 2px;
    background: var(--route-yellow);
    transform: rotate(-32deg);
    transform-origin: center;
}

.logo-dot {
    position: absolute;
    right: 7px;
    top: 7px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--signal-cyan);
    box-shadow: 0 0 16px rgba(99, 215, 255, 0.9);
}

.eyebrow {
    margin: 0 0 2px;
    color: var(--route-yellow);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    line-height: 1;
    text-transform: uppercase;
}

h1,
h2,
h3,
p {
    margin: 0;
}

h1 {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    font-size: clamp(1.05rem, 2vw, 1.35rem);
    font-weight: 700;
    letter-spacing: 0;
    white-space: nowrap;
}

.live-badge {
    display: inline-flex;
    align-items: center;
    min-height: 21px;
    padding: 2px 8px;
    border: 1px solid rgba(31, 191, 117, 0.45);
    border-radius: 999px;
    color: #b9ffd9;
    background: rgba(31, 191, 117, 0.13);
    font-size: 0.64rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.header-actions {
    gap: 10px;
}

.status-bar {
    gap: 9px;
    min-height: 40px;
    padding: 0 13px;
    border: 1px solid var(--rail);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.055);
    white-space: nowrap;
}

.status-indicator {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--signal-green);
    box-shadow: 0 0 18px rgba(31, 191, 117, 0.8);
    animation: heartbeat 1.8s ease-in-out infinite;
}

.status-indicator.loading {
    background: var(--route-yellow);
    box-shadow: 0 0 18px rgba(255, 207, 74, 0.75);
}

.status-indicator.error {
    background: var(--signal-red);
    box-shadow: 0 0 18px rgba(255, 90, 95, 0.75);
}

@keyframes heartbeat {
    50% {
        transform: scale(0.72);
        opacity: 0.65;
    }
}

.status-text {
    color: var(--muted);
    font-size: 0.88rem;
}

.icon-btn,
.sidebar-toggle,
.panel-close,
.refresh-btn,
.search-clear {
    display: inline-grid;
    place-items: center;
    border: 1px solid var(--rail);
    color: var(--ink);
    background: rgba(255, 255, 255, 0.07);
    cursor: pointer;
    transition: transform var(--fast), border-color var(--fast), background var(--fast), color var(--fast);
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.12rem;
}

.icon-btn:hover,
.icon-btn.active,
.sidebar-toggle:hover,
.panel-close:hover,
.search-clear:hover {
    border-color: rgba(255, 207, 74, 0.5);
    background: rgba(255, 207, 74, 0.12);
}

.main-container {
    display: flex;
    height: 100%;
    padding-top: var(--header-height);
}

.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: calc(100vh - var(--header-height));
    padding: 18px;
    overflow-y: auto;
    background: var(--panel);
    border-right: 1px solid var(--rail);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
    z-index: 650;
    transition: transform var(--normal), opacity var(--normal);
}

.sidebar.collapsed {
    position: absolute;
    transform: translateX(-104%);
    opacity: 0;
    pointer-events: none;
}

.sidebar-header {
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--rail);
}

.sidebar-header h2 {
    font-size: 1.22rem;
    letter-spacing: 0;
}

.sidebar-toggle {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    font-size: 1.55rem;
    line-height: 1;
}

.filter-section,
.stats-section,
.info-section {
    margin-top: 20px;
}

.filter-section h3,
.stats-section h3 {
    margin-bottom: 10px;
    color: var(--faint);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.filter-buttons {
    display: grid;
    gap: 8px;
}

.filter-btn {
    position: relative;
    justify-content: space-between;
    min-height: 46px;
    gap: 10px;
    width: 100%;
    padding: 9px 10px;
    color: var(--muted);
    border: 1px solid var(--rail);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.052);
    cursor: pointer;
    text-align: left;
    transition: transform var(--fast), border-color var(--fast), background var(--fast), color var(--fast);
}

.filter-btn span:nth-child(2) {
    flex: 1;
}

.filter-btn strong {
    min-width: 30px;
    padding: 3px 7px;
    border-radius: 999px;
    color: var(--ink);
    background: rgba(255, 255, 255, 0.08);
    font-family: "JetBrains Mono", monospace;
    font-size: 0.72rem;
    text-align: center;
}

.filter-btn:hover {
    transform: translateX(3px);
    color: var(--ink);
    border-color: var(--rail-strong);
}

.filter-btn.active {
    color: var(--ink);
    border-color: rgba(255, 207, 74, 0.45);
    background: linear-gradient(90deg, rgba(255, 207, 74, 0.16), rgba(99, 215, 255, 0.06));
}

.filter-dot {
    width: 11px;
    height: 11px;
    flex: 0 0 11px;
    border-radius: 50%;
    background: var(--signal-cyan);
    box-shadow: 0 0 14px currentColor;
}

.filter-dot.bus {
    color: var(--bus-color);
    background: var(--bus-color);
}

.filter-dot.tram {
    color: var(--tram-color);
    background: var(--tram-color);
}

.filter-dot.trolleybus {
    color: var(--trolley-color);
    background: var(--trolley-color);
}

.filter-dot.all {
    color: var(--route-yellow);
    background: var(--route-yellow);
}

.search-box {
    gap: 8px;
    height: 46px;
    padding: 0 10px 0 12px;
    border: 1px solid var(--rail);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.06);
}

.search-box > span {
    color: var(--route-yellow);
    font-size: 1.05rem;
}

.search-box input {
    min-width: 0;
    flex: 1;
    height: 100%;
    color: var(--ink);
    border: 0;
    outline: 0;
    background: transparent;
}

.search-box:focus-within {
    border-color: rgba(99, 215, 255, 0.55);
    box-shadow: var(--ring);
}

.search-box input::placeholder {
    color: var(--faint);
}

.search-clear {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    color: var(--faint);
    opacity: 0;
    pointer-events: none;
}

.search-box input:not(:placeholder-shown) + .search-clear {
    opacity: 1;
    pointer-events: auto;
}

.result-line {
    margin-top: 8px;
    color: var(--faint);
    font-size: 0.82rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.stat-item {
    min-height: 82px;
    padding: 12px;
    border: 1px solid var(--rail);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.052);
}

.stat-item.primary {
    grid-column: 1 / -1;
    min-height: 92px;
    background:
        linear-gradient(120deg, rgba(255, 207, 74, 0.16), rgba(99, 215, 255, 0.07)),
        rgba(255, 255, 255, 0.052);
}

.stat-value {
    display: block;
    font-family: "JetBrains Mono", monospace;
    font-size: 1.62rem;
    font-weight: 700;
    letter-spacing: 0;
}

.stat-item.primary .stat-value {
    color: var(--route-yellow);
    font-size: 2rem;
}

.stat-label {
    display: block;
    margin-top: 4px;
    color: var(--faint);
    font-size: 0.78rem;
}

.info-section {
    display: grid;
    gap: 8px;
}

.info-section > div {
    justify-content: space-between;
    gap: 14px;
    padding: 11px 12px;
    border: 1px dashed rgba(255, 255, 255, 0.18);
    border-radius: var(--radius);
    color: var(--muted);
    background: rgba(255, 255, 255, 0.035);
    font-size: 0.82rem;
}

.info-section strong {
    color: var(--ink);
    font-size: 0.82rem;
}

.map-wrapper {
    position: relative;
    flex: 1;
    min-width: 0;
    height: calc(100vh - var(--header-height));
}

#map {
    width: 100%;
    height: 100%;
    background: var(--city-night);
}

.map-scrim {
    position: absolute;
    inset: 0;
    z-index: 401;
    pointer-events: none;
    background:
        linear-gradient(90deg, rgba(11, 16, 24, 0.32), transparent 25%, transparent 76%, rgba(11, 16, 24, 0.16)),
        linear-gradient(180deg, rgba(11, 16, 24, 0.2), transparent 22%, rgba(11, 16, 24, 0.18));
}

.vehicle-marker-container {
    background: transparent;
    border: 0;
}

.vehicle-marker {
    position: relative;
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border: 2px solid rgba(255, 255, 255, 0.92);
    border-radius: 50%;
    color: #fff;
    background: var(--marker-color);
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.36), 0 0 0 5px rgba(0, 0, 0, 0.16);
    cursor: pointer;
    transition: transform var(--fast), box-shadow var(--fast);
}

.vehicle-marker:hover {
    transform: scale(1.12);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.46), 0 0 0 7px rgba(255, 207, 74, 0.18);
    z-index: 1000 !important;
}

.marker-label {
    position: relative;
    z-index: 1;
    max-width: 34px;
    overflow: hidden;
    font-family: "JetBrains Mono", monospace;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0;
    line-height: 1;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.marker-heading {
    position: absolute;
    top: -8px;
    left: 50%;
    width: 0;
    height: 0;
    margin-left: -5px;
    border-right: 5px solid transparent;
    border-bottom: 9px solid rgba(255, 255, 255, 0.92);
    border-left: 5px solid transparent;
    transform-origin: 5px 29px;
}

.vehicle-marker.delayed {
    animation: delayPulse 1.2s ease-in-out infinite;
}

@keyframes delayPulse {
    50% {
        box-shadow: 0 8px 18px rgba(0, 0, 0, 0.36), 0 0 0 8px rgba(255, 90, 95, 0.32);
    }
}

.vehicle-panel,
.empty-state {
    position: absolute;
    z-index: 560;
    border: 1px solid var(--rail-strong);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
}

.empty-state[hidden] {
    display: none;
}

.vehicle-panel {
    left: 18px;
    bottom: 18px;
    width: min(360px, calc(100% - 96px));
    padding: 17px;
    transform: translateY(calc(100% + 30px));
    opacity: 0;
    pointer-events: none;
    transition: transform var(--normal), opacity var(--normal);
}

.vehicle-panel.visible {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}

.panel-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    color: var(--muted);
    font-size: 1.05rem;
}

.panel-header {
    gap: 13px;
    padding-right: 32px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--rail);
}

.vehicle-line {
    display: grid;
    place-items: center;
    min-width: 58px;
    height: 58px;
    padding: 0 10px;
    border-radius: var(--radius);
    color: #0f151f;
    background: var(--route-yellow);
    font-family: "JetBrains Mono", monospace;
    font-size: 1.25rem;
    font-weight: 700;
}

.vehicle-type {
    display: block;
    margin-bottom: 3px;
    color: var(--signal-cyan);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

#panel-destination {
    display: block;
    color: var(--ink);
    font-size: 1rem;
    line-height: 1.18;
}

.panel-body {
    padding-top: 8px;
}

.panel-row {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    padding: 10px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.075);
}

.panel-row:last-child {
    border-bottom: 0;
}

.panel-label {
    color: var(--faint);
    font-size: 0.86rem;
}

.panel-value {
    color: var(--ink);
    font-weight: 600;
    text-align: right;
}

.panel-value.delayed {
    color: #ff9b9f;
}

.mono {
    font-family: "JetBrains Mono", monospace;
    font-size: 0.78rem;
}

.refresh-btn {
    position: absolute;
    right: 18px;
    bottom: 18px;
    z-index: 570;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    color: #0d121b;
    border-color: rgba(255, 207, 74, 0.64);
    background: var(--route-yellow);
    box-shadow: 0 18px 30px rgba(0, 0, 0, 0.35), 0 0 24px rgba(255, 207, 74, 0.22);
    font-size: 1.55rem;
}

.refresh-btn:hover {
    transform: translateY(-2px) scale(1.03);
}

.refresh-btn.loading .refresh-icon {
    animation: spin 900ms linear infinite;
}

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

.empty-state {
    top: 20px;
    left: 50%;
    display: grid;
    gap: 4px;
    width: min(360px, calc(100% - 32px));
    padding: 14px 16px;
    transform: translateX(-50%);
    text-align: center;
}

.empty-state strong {
    color: var(--route-yellow);
}

.empty-state span {
    color: var(--muted);
    font-size: 0.9rem;
}

.leaflet-control-zoom {
    border: 0 !important;
    box-shadow: var(--shadow) !important;
}

.leaflet-control-zoom a {
    color: var(--ink) !important;
    background: var(--panel-solid) !important;
    border: 1px solid var(--rail) !important;
}

.leaflet-control-zoom a:hover {
    background: #1a2330 !important;
}

.leaflet-control-attribution {
    color: var(--faint) !important;
    background: rgba(13, 18, 27, 0.76) !important;
    backdrop-filter: blur(12px);
}

.leaflet-control-attribution a {
    color: var(--muted) !important;
}

@media (max-width: 900px) {
    :root {
        --sidebar-width: 300px;
    }

    .status-text {
        max-width: 180px;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

@media (max-width: 768px) {
    :root {
        --header-height: 64px;
    }

    .header {
        gap: 10px;
        padding: 10px 12px;
    }

    .logo-mark {
        width: 36px;
        height: 36px;
        flex-basis: 36px;
    }

    h1 {
        font-size: 1rem;
    }

    .live-badge,
    .status-bar {
        display: none;
    }

    .sidebar {
        position: absolute;
        top: var(--header-height);
        left: 0;
        width: 100%;
        min-width: 0;
        height: auto;
        max-height: min(70vh, 620px);
        border-right: 0;
        border-bottom: 1px solid var(--rail);
        transform: translateY(-104%);
        opacity: 0;
        pointer-events: none;
    }

    .sidebar.open {
        transform: translateY(0);
        opacity: 1;
        pointer-events: auto;
    }

    .sidebar.collapsed {
        position: absolute;
        transform: translateY(-104%);
    }

    .stats-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .stat-item,
    .stat-item.primary {
        grid-column: auto;
        min-height: 74px;
        padding: 10px 8px;
    }

    .stat-value,
    .stat-item.primary .stat-value {
        font-size: 1.25rem;
    }

    .vehicle-panel {
        right: 12px;
        bottom: 12px;
        left: 12px;
        width: auto;
        max-height: 46vh;
        overflow: auto;
    }

    .refresh-btn {
        right: 12px;
        bottom: 12px;
        width: 52px;
        height: 52px;
    }
}

@media (max-width: 520px) {
    .brand-block {
        gap: 9px;
    }

    .header-actions {
        gap: 6px;
    }

    .icon-btn {
        width: 38px;
        height: 38px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .filter-btn {
        min-height: 44px;
    }

    .vehicle-panel {
        bottom: 76px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: 0.001ms !important;
    }
}
