body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    font-family: Arial, sans-serif;
    overflow: hidden;
}

#map {
    width: 100%;
    height: 100%;
    background-color: #e5e3df;
}

/* --- Panel für die Checkboxen --- */
#control-panel {
    position: absolute;
    top: 20px;
    right: 20px;
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    z-index: 1000;
    max-height: 80vh;
    display: none; 
    flex-direction: column;
    width: 270px; 
    transition: max-height 0.3s ease;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #E3000F;
    padding-bottom: 5px;
    margin-bottom: 10px;
}

#control-panel.collapsed .panel-header {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.panel-header h3 {
    margin: 0;
    font-size: 16px;
    color: #333;
}

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

.admin-link {
    text-decoration: none;
    font-size: 16px;
    filter: grayscale(100%);
    opacity: 0.7;
    transition: all 0.2s;
}

.admin-link:hover {
    filter: grayscale(0%);
    opacity: 1;
    transform: scale(1.1);
}

#toggle-panel-btn {
    background: none;
    border: none;
    font-size: 14px;
    font-weight: bold;
    color: #555;
    cursor: pointer;
    padding: 0 5px;
    transition: color 0.2s;
}

#toggle-panel-btn:hover {
    color: #E3000F;
}

#panel-content {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#control-panel.collapsed #panel-content {
    display: none;
}

.bulk-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-bottom: 15px;
    border-bottom: 1px dashed #ccc;
    padding-bottom: 10px;
}

.bulk-actions button {
    flex: 1 1 30%; 
    padding: 6px 4px;
    background-color: #f1f1f1;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
    color: #333;
    transition: background-color 0.2s;
}

.bulk-actions button:hover {
    background-color: #e0e0e0;
    border-color: #005A9B;
}

#route-checkboxes {
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-right: 10px;
}

.route-label {
    display: flex;
    align-items: center;
    font-size: 14px;
    cursor: pointer;
    color: #333;
}

.route-label input {
    margin-right: 8px;
    cursor: pointer;
    flex-shrink: 0;
}

.route-badge {
    display: inline-block;
    width: 38px;
    min-width: 38px;
    height: 20px;
    line-height: 20px;
    text-align: center;
    color: white;
    font-weight: bold;
    border-radius: 4px;
    margin-right: 8px;
    font-size: 12px;
    flex-shrink: 0;
}

/* Ladebildschirm */
#loading {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.95);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s;
}

.spinner {
    border: 6px solid #f3f3f3;
    border-top: 6px solid #E3000F;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#loading-text {
    font-size: 1.2rem;
    font-weight: bold;
    color: #333;
}

/* --- Fahrzeug Marker --- */
.leaflet-marker-icon.vehicle-marker {
    transition: transform 1s linear; 
}

.zooming .leaflet-marker-icon.vehicle-marker {
    transition: none !important;
}

.vehicle-container {
    width: 34px;
    height: 34px;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Der Ring dreht sich für den Pfeil, ist aber selbst UNSICHTBAR! */
.vehicle-ring {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    border-width: 0 !important;
    border-radius: 50%; 
    transform: rotate(var(--bearing, 0deg));
    transition: transform 1s linear;
    background-color: transparent;
    z-index: 1; /* WICHTIG: 1, damit der Pfeil UNTER dem Bus durchtaucht */
}

/* NEU: Der weiße Rand (ein größeres weißes Dreieck im Hintergrund) */
.vehicle-ring::before {
    content: '';
    position: absolute;
    top: -14px; /* Ragt am höchsten hinaus */
    left: 50%;
    transform: translateX(-50%);
    border-left: 9px solid transparent;
    border-right: 9px solid transparent;
    border-bottom: 23px solid white; /* Die weiße Umrandung */
    z-index: 1;
}

/* Der kleine schwarze Richtungspfeil (liegt auf dem weißen Rand) */
.vehicle-ring::after {
    content: '';
    position: absolute;
    top: -11px; /* Sitzt etwas tiefer als der weiße Rand */
    left: 50%;
    transform: translateX(-50%);
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 18px solid #222; /* Der schwarze Kern */
    z-index: 2;
}

/* Versteckt BEIDE Pfeile bei Fahrzeugen, die noch warten */
.vehicle-ring.no-arrow::after,
.vehicle-ring.no-arrow::before { display: none !important; }

/* Das eigentliche Fahrzeug */
.vehicle-icon {
    z-index: 2; /* WICHTIG: 2, damit es über dem Pfeil-Sockel liegt */
    border-radius: var(--vehicle-shape, 50%); /* Zieht sich die Form aus dem Admin-Panel */
    border: 2px solid white; 
    width: 34px; 
    height: 34px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
    box-sizing: border-box;
    overflow: hidden;
    box-shadow: 0 3px 6px rgba(0,0,0,0.5); 
}

.vehicle-line-nr {
    font-size: 10px;
    font-weight: bold;
    margin-bottom: -2px;
    white-space: nowrap;
}

/* --- Popup Styling --- */
.stop-popup {
    min-width: 300px;
    max-width: 450px;
}

.stop-popup h3 {
    margin: 0 0 10px 0;
    font-size: 16px;
    color: #333;
    border-bottom: 2px solid #E3000F;
    padding-bottom: 5px;
    line-height: 1.4;
}

.stop-popup h3 small {
    font-weight: normal;
    color: #666;
    font-size: 14px;
}

.fahrplan-info {
    font-size: 14px;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px dashed #ccc;
    position: relative;
}

.fahrplan-info strong {
    display: block;
    color: #005A9B;
    margin-bottom: 3px;
    font-size: 12px;
    text-transform: uppercase;
}

.live-status {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: bold;
    color: white;
    margin-left: 10px;
    background-color: #555; 
}
.live-status.on-time { background-color: #159655; }
.live-status.delayed { background-color: #E3000F; }

.departures-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 250px;
    overflow-y: auto;
}

.departures-list li {
    display: flex;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #eee;
    font-size: 14px;
}

.departures-list li:last-child {
    border-bottom: none;
}

.dep-line {
    font-weight: bold;
    color: #fff;
    background-color: #005A9B;
    padding: 3px 8px;
    border-radius: 4px;
    margin-right: 12px;
    min-width: 30px;
    text-align: center;
}

.dep-dir {
    flex-grow: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 10px;
    color: #444;
}

.dep-time {
    font-weight: bold;
    color: #2c3e50;
    white-space: nowrap;
}
.dep-delay { color: #E3000F; font-size: 12px; margin-left: 4px; }

@media (max-width: 600px) {
    #control-panel {
        top: 10px;
        right: 10px;
        left: 10px; 
        width: auto;
        max-height: 60vh;
    }
    .stop-popup { min-width: 250px; }
}

/* =========================================
   BASIS & LAYOUT (Ausgelagert)
   ========================================= */
#loading { position: fixed !important; left: -9999px !important; opacity: 0 !important; pointer-events: none !important; }

/* Info-Fenster WYSIWYG */
#info-modal-content p { margin-top: 0; margin-bottom: 1em; }
#info-modal-content ul, #info-modal-content ol { margin-top: 0; margin-bottom: 1em; padding-left: 20px; }
#info-modal-content a { color: #005A9B; text-decoration: underline; }

/* =========================================
   NEUES HALTESTELLEN ICON
   ========================================= */
.leaflet-marker-icon.stop-icon {
    background-image: url('https://www.irmscher.at/linzag/live/icons/haltestelle.png') !important;
    background-size: contain !important;
    background-repeat: no-repeat !important;
    background-position: center !important;
    background-color: transparent !important;
    border: none !important;
    box-shadow: none !important;
    color: transparent !important;
    font-size: 0 !important;
}
.leaflet-marker-icon.stop-icon::before,
.leaflet-marker-icon.stop-icon::after { display: none !important; content: none !important; }
.leaflet-marker-icon.stop-icon * { display: none !important; }

/* =========================================
   FORMATIERUNG FÜR VERSPÄTUNGEN
   ========================================= */
.strike-time { text-decoration: line-through; opacity: 0.6; margin-right: 6px; }
.delay-green { color: #159655 !important; font-weight: bold; }
.delay-red { color: #e3000f !important; font-weight: bold; }

/* =========================================
   DARK MODE
   ========================================= */
body.dark-mode { background-color: #121212; color: #e0e0e0; }
body.dark-mode .leaflet-tile-pane { filter: invert(100%) hue-rotate(180deg) brightness(90%) contrast(90%); }
body.dark-mode #control-panel,
body.dark-mode #info-modal > div { background-color: #1e1e1e !important; border-color: #333 !important; box-shadow: 0 5px 15px rgba(0,0,0,0.9) !important; color: #e0e0e0 !important; }
body.dark-mode .panel-header, 
body.dark-mode #settings-container { border-color: #333 !important; background-color: #1e1e1e !important; }
body.dark-mode .panel-header h3, 
body.dark-mode strong { color: #e0e0e0 !important; }
body.dark-mode button, 
body.dark-mode .route-label { background-color: #2a2a2a !important; color: #e0e0e0 !important; border-color: #444 !important; }
body.dark-mode .admin-link { background-color: #2a2a2a !important; border-color: #444 !important; }

/* Popups im Dark Mode repariert */
body.dark-mode .leaflet-popup-content-wrapper,
body.dark-mode .leaflet-popup-tip { background-color: #1e1e1e !important; color: #e0e0e0; }
body.dark-mode .leaflet-popup-content .delay-green { color: #4ade80 !important; } 
body.dark-mode .leaflet-popup-content .delay-red { color: #f87171 !important; }   
body.dark-mode .leaflet-popup-close-button { color: #aaa !important; }
body.dark-mode .departures-list li { border-bottom: 1px solid #333 !important; }
body.dark-mode .stop-popup h3 { border-bottom: 1px solid #555 !important; }

/* =========================================
   SCROLLBALKEN REPARATUR
   ========================================= */
.departures-list {
    padding-right: 12px !important; 
}
.departures-list::-webkit-scrollbar,
#info-modal-content::-webkit-scrollbar {
    width: 6px;
}
.departures-list::-webkit-scrollbar-track,
#info-modal-content::-webkit-scrollbar-track {
    background: transparent;
}
.departures-list::-webkit-scrollbar-thumb,
#info-modal-content::-webkit-scrollbar-thumb {
    background-color: #bbb;
    border-radius: 10px;
}
body.dark-mode .departures-list::-webkit-scrollbar-thumb,
body.dark-mode #info-modal-content::-webkit-scrollbar-thumb {
    background-color: #555;
}

/* =========================================
   LADEBILDSCHIRM ANIMATIONEN
   ========================================= */
@keyframes pulse-ring { 0% { transform: scale(0.8); opacity: 1; } 100% { transform: scale(2.2); opacity: 0; } }
@keyframes shimmer { 100% { left: 200%; } }

/* =========================================
   HALTESTELLEN-HITBOX & ZOOM
   ========================================= */
.stop-hitbox { display: flex; align-items: center; justify-content: center; cursor: pointer; border-radius: 50%; background-color: transparent; }
.stop-hitbox div { transition: 0.2s ease-in-out; }
.stop-hitbox:hover div { background: #ffcc00 !important; transform: scale(1.4); }
.zoom-low .stop-hitbox div { width: 4px !important; height: 4px !important; border-width: 1px !important; }
.zoom-mid .stop-hitbox div { width: 7px !important; height: 7px !important; border-width: 1.5px !important; }

/* =========================================
   SCROLLING TEXT IM POPUP
   ========================================= */
.scrolling-container { width: 100%; overflow: hidden; white-space: nowrap; box-sizing: border-box; }
.scrolling-text { display: inline-block; padding-left: 100%; animation: scroll-text 12s linear infinite; }
@keyframes scroll-text { 0% { transform: translateX(0); } 100% { transform: translateX(-100%); } }

/* =========================================
   FAHRZEUGE WARTEND (Ohne Pfeil)
   ========================================= */
.vehicle-ring.no-arrow::after,
.vehicle-ring.no-arrow::before { display: none !important; }