:root {
    /* Brand */
    --color-blue:         #1d4ed8;
    --color-blue-light:   #3b82f6;

    /* Neumorphic base */
    --color-bg:           #e0e5ec;
    --color-shadow-dark:  #b8bec7;
    --color-shadow-light: #ffffff;

    /* Unit type colors */
    --color-bus:          #1d4ed8;
    --color-van:          #16a34a;
    --color-car:          #ea580c;
    --color-train:        #7c3aed;

    /* Text */
    --color-text:         #374151;
    --color-text-muted:   #6b7280;
    --color-text-dark:    #111827;

    /* UI */
    --color-white:        #ffffff;
    --color-black:        #000000;
    --color-overlay:      rgba(0, 0, 0, 0.65);
    --color-danger:       #dc2626;
    --color-bg-gray:      #f3f4f6;
}

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

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* -------------------------------------------------------------------------
   Map
------------------------------------------------------------------------- */
#map {
    position: fixed;
    inset: 0;
    z-index: 1;
}

/* -------------------------------------------------------------------------
   Top bar
------------------------------------------------------------------------- */
#topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 20;
    height: 56px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: transparent;
    pointer-events: none;
}

#topbar .app-name {
    font-size: 19px;
    font-weight: 800;
    color: var(--color-blue);
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 6px;
    text-shadow: 0 1px 4px rgba(255,255,255,0.9), 0 0 12px rgba(255,255,255,0.7);
    pointer-events: all;
}

#topbar .app-name span {
    font-size: 22px;
}

#topbar .topbar-actions {
    pointer-events: all;
}

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

.btn-login {
    padding: 8px 18px;
    background: var(--color-bg);
    color: var(--color-blue);
    border: none;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    box-shadow: 4px 4px 8px var(--color-shadow-dark), -4px -4px 8px var(--color-shadow-light);
    transition: box-shadow 0.15s, transform 0.1s;
}

.btn-login:hover {
    box-shadow: 6px 6px 12px var(--color-shadow-dark), -6px -6px 12px var(--color-shadow-light);
}

.btn-login:active {
    box-shadow: inset 3px 3px 6px var(--color-shadow-dark), inset -3px -3px 6px var(--color-shadow-light);
    transform: scale(0.97);
}

.user-menu {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--color-blue);
    color: var(--color-white);
    font-size: 14px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--color-white);
    box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}

.user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text);
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    background: var(--color-white);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    min-width: 160px;
    overflow: hidden;
    z-index: 20;
}

.user-dropdown.open {
    display: block;
}

.user-dropdown a {
    display: block;
    padding: 12px 16px;
    font-size: 14px;
    color: var(--color-text);
    text-decoration: none;
    transition: background 0.15s;
}

.user-dropdown a:hover {
    background: var(--color-bg-gray);
}

.user-dropdown a.danger {
    color: var(--color-danger);
}

/* -------------------------------------------------------------------------
   Route filter bar
------------------------------------------------------------------------- */
#route-filters {
    position: fixed;
    top: 52px;
    left: 0;
    right: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
    background: transparent;
    pointer-events: none;
}

#route-filters::-webkit-scrollbar {
    display: none;
}

.route-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px 6px 10px;
    border-radius: 20px;
    border: none;
    background: var(--color-bg);
    box-shadow: 4px 4px 8px var(--color-shadow-dark), -4px -4px 8px var(--color-shadow-light);
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text);
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    pointer-events: all;
    transition: opacity 0.2s, box-shadow 0.15s, transform 0.1s;
    user-select: none;
}

.route-chip:active {
    box-shadow: inset 3px 3px 6px var(--color-shadow-dark), inset -3px -3px 6px var(--color-shadow-light);
    transform: scale(0.97);
}

.route-chip.inactive {
    opacity: 0.5;
    box-shadow: inset 3px 3px 6px var(--color-shadow-dark), inset -3px -3px 6px var(--color-shadow-light);
}

.route-chip-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* -------------------------------------------------------------------------
   Locate button
------------------------------------------------------------------------- */
#btn-locate {
    position: fixed;
    bottom: 72px;
    right: 16px;
    z-index: 10;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--color-bg);
    border: none;
    box-shadow: 5px 5px 10px var(--color-shadow-dark), -5px -5px 10px var(--color-shadow-light);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: box-shadow 0.15s, transform 0.1s;
}

#btn-locate:active {
    box-shadow: inset 3px 3px 6px var(--color-shadow-dark), inset -3px -3px 6px var(--color-shadow-light);
    transform: scale(0.95);
}

#btn-locate svg {
    width: 20px;
    height: 20px;
    fill: var(--color-blue);
}

/* -------------------------------------------------------------------------
   Ad banner
------------------------------------------------------------------------- */
#ad-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10;
    background: var(--color-black);
    transform: translateY(0);
    transition: transform 0.3s ease, opacity 0.25s ease;
    line-height: 0;
    display: flex;
    justify-content: center;
}

#ad-banner.hidden {
    transform: translateY(100%);
}

#ad-link {
    display: block;
    width: 100%;
    line-height: 0;
}

#ad-image {
    width: 100%;
    height: 50px;
    object-fit: fill;
    display: block;
}

#ad-close {
    position: absolute;
    top: 4px;
    right: 6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    border: none;
    font-size: 13px;
    color: var(--color-white);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    z-index: 1;
}

/* -------------------------------------------------------------------------
   Unit markers
------------------------------------------------------------------------- */
.unit-icon-wrapper {
    background: transparent !important;
    border: none !important;
}

.unit-marker {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
}

.unit-marker-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    border: 2.5px solid var(--color-white);
    transition: transform 0.2s;
}

.unit-marker-icon:hover {
    transform: scale(1.12);
}

.unit-marker-icon.type-bus   { background: var(--color-bus); }
.unit-marker-icon.type-van   { background: var(--color-van); }
.unit-marker-icon.type-car   { background: var(--color-car); }
.unit-marker-icon.type-train { background: var(--color-train); }

.unit-marker-icon svg {
    width: 20px;
    height: 20px;
    fill: var(--color-white);
}

.unit-marker-arrow {
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    margin-top: -1px;
}

.type-bus   .unit-marker-arrow, .arrow-bus   { border-top: 7px solid var(--color-bus); }
.type-van   .unit-marker-arrow, .arrow-van   { border-top: 7px solid var(--color-van); }
.type-car   .unit-marker-arrow, .arrow-car   { border-top: 7px solid var(--color-car); }
.type-train .unit-marker-arrow, .arrow-train { border-top: 7px solid var(--color-train); }

/* -------------------------------------------------------------------------
   Leaflet popup
------------------------------------------------------------------------- */
.leaflet-popup-content-wrapper {
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    padding: 0;
    overflow: hidden;
}

.leaflet-popup-content {
    margin: 0;
    min-width: 170px;
}

.popup-header {
    padding: 10px 14px 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

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

.popup-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--color-text-dark);
}

.popup-body {
    padding: 0 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.popup-row {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--color-text-muted);
}

.popup-row span:last-child {
    font-weight: 600;
    color: var(--color-text);
}

.leaflet-popup-tip {
    box-shadow: none;
}

/* -------------------------------------------------------------------------
   Dark mode
------------------------------------------------------------------------- */
body.dark {
    --color-bg:           #1e2130;
    --color-shadow-dark:  #161923;
    --color-shadow-light: #26293d;
    --color-text:         #cbd5e1;
    --color-text-muted:   #94a3b8;
    --color-text-dark:    #f1f5f9;
    --color-bg-gray:      #252a3d;
    --color-overlay:      rgba(0, 0, 0, 0.85);
}

body.dark .user-dropdown {
    background: #252a3d;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

body.dark .user-dropdown a {
    color: #cbd5e1;
}

body.dark .user-dropdown a:hover {
    background: #2e3347;
}

.dark-tiles {
    filter: invert(100%) hue-rotate(180deg) saturate(0.4) brightness(0.95) contrast(0.9);
}

body.dark #topbar .app-name {
    text-shadow: 0 1px 4px rgba(0,0,0,0.6);
}

@media (min-width: 768px) {
    #ad-banner {
        display: none !important;
    }
}

body.dark #ad-close {
    background: rgba(255,255,255,0.15);
}

/* -------------------------------------------------------------------------
   Loading indicator
------------------------------------------------------------------------- */
#map-loading {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    background: var(--color-overlay);
    color: var(--color-white);
    font-size: 12px;
    padding: 6px 14px;
    border-radius: 20px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}

#map-loading.visible {
    opacity: 1;
}

/* -------------------------------------------------------------------------
   Version label
------------------------------------------------------------------------- */
#map-version {
    position: fixed;
    bottom: 58px;
    left: 8px;
    z-index: 11;
    font-size: 11px;
    color: rgba(120, 120, 120, 0.7);
    background: transparent;
    pointer-events: none;
    user-select: none;
    font-family: monospace;
}

@media (max-width: 767px) {
    .leaflet-bottom {
        bottom: 50px;
    }
}

@media (min-width: 768px) {
    #map-version {
        bottom: 8px;
    }
}

/* -------------------------------------------------------------------------
   Service alerts banner
------------------------------------------------------------------------- */
#alert-banner {
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    z-index: 25;
    background: #f97316;
    color: #fff;
    padding: 10px 44px 10px 14px;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.45;
    box-shadow: 0 2px 8px rgba(0,0,0,0.18);
    max-height: 180px;
    overflow-y: auto;
}

#alert-banner.dark-alert {
    background: #c2410c;
}

#alert-banner ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

#alert-banner li {
    padding: 2px 0;
}

#alert-banner li + li {
    border-top: 1px solid rgba(255,255,255,0.25);
    margin-top: 6px;
    padding-top: 6px;
}

#alert-banner .alert-route {
    font-size: 11px;
    font-weight: 700;
    opacity: 0.85;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

#alert-close {
    position: absolute;
    top: 8px;
    right: 10px;
    width: 26px;
    height: 26px;
    border: none;
    background: rgba(255,255,255,0.25);
    color: #fff;
    border-radius: 50%;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    flex-shrink: 0;
}

#alert-close:hover {
    background: rgba(255,255,255,0.4);
}

/* -------------------------------------------------------------------------
   Geolocation denied message
------------------------------------------------------------------------- */
#geo-denied-msg {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: none;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

#geo-denied-msg .geo-denied-card {
    background: var(--color-bg);
    border-radius: 20px;
    padding: 32px 28px;
    max-width: 300px;
    width: calc(100% - 48px);
    text-align: center;
    box-shadow: 8px 8px 16px var(--color-shadow-dark), -8px -8px 16px var(--color-shadow-light);
    pointer-events: auto;
}

#geo-denied-msg .geo-denied-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

#geo-denied-msg p {
    color: var(--color-text);
    font-size: 14px;
    line-height: 1.5;
    margin: 0 0 20px;
}

#geo-denied-msg .btn-retry {
    display: inline-block;
    padding: 10px 24px;
    background: var(--color-blue);
    color: #fff;
    border: none;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
}

#geo-denied-msg .btn-retry:active {
    opacity: 0.8;
}
