/* Globale Variablen für Farben */
:root {
    --bg-color-light: #ffffff;
    --text-color-light: #222222;
    --ui-bg-light: rgba(255, 255, 255, 0.9);
    --shadow-light: 0 4px 12px rgba(0,0,0,0.15);
    --border-color-light: #ccc;
    
    --bg-color-dark: #222222;
    --text-color-dark: #eeeeee;
    --ui-bg-dark: rgba(34, 34, 34, 0.9);
    --shadow-dark: 0 4px 12px rgba(0,0,0,0.4);
    --border-color-dark: #555;

    --accent-color: #007bff;
    --green: #28a745;
    --yellow: #ffc107;
    --red: #dc3545;
    --grey: #888;
}

/* Basis-Styles & Theme-Umschaltung */
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    transition: background-color 0.3s ease;
}
body.dark-mode {
    --bg-color: var(--bg-color-dark);
    --text-color: var(--text-color-dark);
    --ui-bg: var(--ui-bg-dark);
    --shadow: var(--shadow-dark);
    --border-color: var(--border-color-dark);
}
body.light-mode {
    --bg-color: var(--bg-color-light);
    --text-color: var(--text-color-light);
    --ui-bg: var(--ui-bg-light);
    --shadow: var(--shadow-light);
    --border-color: var(--border-color-light);
}

/* Karte */
#map {
    width: 100vw;
    height: 100vh;
    z-index: 1;
}
.leaflet-container {
    background: var(--bg-color);
}

/* Preis-Pills als Marker */
.price-pill {
    background: var(--ui-bg);
    color: var(--text-color);
    padding: 3px 8px;
    border-radius: 12px;
    font-weight: bold;
    font-size: 14px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.3s, border-color 0.3s;
}
.price-pill sup { font-size: 0.8em; font-weight: 900; }
.price-pill.pill-green { background-color: var(--green); color: white; border-color: var(--green); }
.price-pill.pill-yellow { background-color: var(--yellow); color: #333; border-color: var(--yellow); }
.price-pill.pill-red { background-color: var(--red); color: white; border-color: var(--red); }
.price-pill.pill-closed { background-color: var(--grey); color: white; border-color: var(--grey); opacity: 0.7; }

/* Stile für das Popup */
.custom-popup .leaflet-popup-content-wrapper {
    background: var(--ui-bg);
    color: var(--text-color);
    border-radius: 10px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    max-width: 280px;
}
.custom-popup .leaflet-popup-content {
    margin: 12px;
    font-size: 14px;
    line-height: 1.4;
}
.custom-popup .leaflet-popup-tip { background: var(--ui-bg); }
.popup-header { margin-bottom: 8px; }
.popup-header strong { font-size: 16px; display: block; }
.popup-header span { font-size: 12px; opacity: 0.8; }
.popup-status { margin-bottom: 12px; font-weight: bold; }
.status-open { color: var(--green); }
.status-closed { color: var(--red); }
.popup-actions { display: flex; gap: 10px; }
.popup-actions a { flex: 1; text-align: center; padding: 8px; background-color: var(--accent-color); color: white; text-decoration: none; border-radius: 6px; font-weight: 500; }

/* Warnungs-Styles */
.zoom-warning {
    position: absolute;
    bottom: 100%;
    margin-bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--yellow);
    color: #333;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 500;
    box-shadow: var(--shadow);
    z-index: 1001;
    white-space: nowrap;
    max-width: 90%;
    text-align: center;
}

.rate-limit-warning {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--red);
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow);
    z-index: 10000;
    animation: slideDown 0.3s ease-out;
    max-width: 90%;
    text-align: center;
}

@keyframes slideDown {
    from {
        top: -100px;
        opacity: 0;
    }
    to {
        top: 20px;
        opacity: 1;
    }
}

/* --- UI-LAYOUT (Mobile First) --- */
.ui-container {
    position: absolute;
    z-index: 1000;
    pointer-events: none;
    bottom: 15px;
    left: 15px;
    right: 15px;
    display: flex;
    justify-content: center;
}

.ui-controls {
    pointer-events: auto;
    display: flex;
    gap: 10px;
    width: 100%;
    max-width: 500px;
    flex-wrap: wrap; 
}

.search-container {
    flex-basis: 100%; 
    display: flex;
    flex-direction: column;
}
#location-search, #route-start-search, .route-start-badge {
    padding: 10px 15px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: var(--ui-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: var(--text-color);
    width: 100%;
    font-size: 16px;
    box-sizing: border-box;
    box-shadow: var(--shadow);
    transition: border-radius 0.2s ease, border-bottom 0.2s ease;
}
#location-search:focus, #route-start-search:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25), var(--shadow);
}
.route-start-container {
    width: 100%;
}
.route-start-container.hidden {
    display: none;
}
.route-start-badge.hidden, #route-start-search.hidden, .route-start-input-wrapper.hidden {
    display: none !important;
}

.route-start-input-wrapper {
    position: relative;
    width: 100%;
    display: flex;
    align-items: center;
}
.route-start-input-wrapper #route-start-search {
    padding-right: 40px;
}
.input-btn-location {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--accent-color);
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    transition: background-color 0.2s, transform 0.15s, color 0.2s;
    opacity: 0.85;
}
.input-btn-location:hover {
    opacity: 1;
    background: rgba(0, 123, 255, 0.15);
    transform: translateY(-50%) scale(1.08);
}
.input-btn-location:active {
    transform: translateY(-50%) scale(0.95);
}
.input-btn-location svg {
    width: 19px;
    height: 19px;
}

/* Innere Elemente des Badges */
.route-start-badge {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.route-start-badge .badge-icon {
    display: flex;
    align-items: center;
    color: var(--accent-color);
    width: 18px;
    height: 18px;
    margin-right: 8px;
    flex-shrink: 0;
}
.route-start-badge .badge-icon svg {
    width: 100%;
    height: 100%;
}
.route-start-badge .badge-text {
    flex-grow: 1;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
    line-height: 1;
}
.route-start-badge .badge-clear {
    background: none;
    border: none;
    color: var(--text-color);
    opacity: 0.6;
    cursor: pointer;
    padding: 0;
    font-size: 16px;
    line-height: 1;
    transition: opacity 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
}
.route-start-badge .badge-clear:hover {
    opacity: 1;
}

.search-container.route-mode #route-start-search,
.search-container.route-mode .route-start-badge {
    border-bottom: none;
    border-radius: 12px 12px 0 0;
}
.search-container.route-mode #location-search {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}

.control-group {
    flex-basis: 100%; 
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--ui-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 5px;
    border: 1px solid var(--border-color);
}

.fuel-selector {
    display: flex;
    flex-grow: 1;
    background: var(--bg-color);
    border-radius: 8px;
    padding: 3px;
    border: 1px solid var(--border-color);
}
.fuel-selector input[type="radio"] { display: none; }
.fuel-selector label {
    padding: 6px 0;
    flex-grow: 1;
    text-align: center;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s ease-in-out;
    color: var(--text-color);
    font-weight: 500;
    font-size: 14px;
}
.fuel-selector input[type="radio"]:checked + label {
    background-color: var(--accent-color);
    color: white;
}
.actions { display: flex; align-items: center; gap: 10px; padding-right: 5px;}
#relocate-btn {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    color: var(--text-color);
}
#relocate-btn svg { width: 20px; height: 20px; }

/* Darkmode-Schalter mit Icons */
.theme-switch-wrapper { display: flex; align-items: center; }
.theme-switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.theme-switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; transition: .4s; }
.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    background-image: url('data:image/svg+xml;utf8,<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 122.88 122.88"><title>sun-warm</title><path d="M30,13.21A3.93,3.93,0,1,1,36.8,9.27L41.86,18A3.94,3.94,0,1,1,35.05,22L30,13.21Zm31.45,13A35.23,35.23,0,1,1,36.52,36.52,35.13,35.13,0,0,1,61.44,26.2ZM58.31,4A3.95,3.95,0,1,1,66.2,4V14.06a3.95,3.95,0,1,1-7.89,0V4ZM87.49,10.1A3.93,3.93,0,1,1,94.3,14l-5.06,8.76a3.93,3.93,0,1,1-6.81-3.92l5.06-8.75ZM109.67,30a3.93,3.93,0,1,1,3.94,6.81l-8.75,5.06a3.94,3.94,0,1,1-4-6.81L109.67,30Zm9.26,28.32a3.95,3.95,0,1,1,0,7.89H108.82a3.95,3.95,0,1,1,0-7.89Zm-6.15,29.18a3.93,3.93,0,1,1-3.91,6.81l-8.76-5.06A3.93,3.93,0,1,1,104,82.43l8.75,5.06ZM92.89,109.67a3.93,3.93,0,1,1-6.81,3.94L81,104.86a3.94,3.94,0,0,1,6.81-4l5.06,8.76Zm-28.32,9.26a3.95,3.95,0,1,1-7.89,0V108.82a3.95,3.95,0,1,1,7.89,0v10.11Zm-29.18-6.15a3.93,3.93,0,0,1-6.81-3.91l5.06-8.76A3.93,3.93,0,1,1,40.45,104l-5.06,8.75ZM13.21,92.89a3.93,3.93,0,1,1-3.94-6.81L18,81A3.94,3.94,0,1,1,22,87.83l-8.76,5.06ZM4,64.57a3.95,3.95,0,1,1,0-7.89H14.06a3.95,3.95,0,1,1,0,7.89ZM10.1,35.39A3.93,3.93,0,1,1,14,28.58l8.76,5.06a3.93,3.93,0,1,1-3.92,6.81L10.1,35.39Z"/></svg>');
    background-size: 12px 12px;
    background-repeat: no-repeat;
    background-position: center;
}
input:checked + .slider { background-color: var(--accent-color); }
input:checked + .slider:before {
    transform: translateX(20px);
    background-image: url('data:image/svg+xml;utf8,<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 122.56 122.88"><defs><style>.cls-1{fill-rule:evenodd;}</style></defs><title>night</title><path class="cls-1" d="M121.85,87.3A64.31,64.31,0,1,1,36.88.4c2.94-1.37,5.92.91,4.47,4.47a56.29,56.29,0,0,0,75.75,77.4l.49-.27a3.41,3.41,0,0,1,4.61,4.61l-.35.69ZM92.46,74.67H92A16.11,16.11,0,0,0,76.2,58.93v-.52a15.08,15.08,0,0,0,11-4.72,15.19,15.19,0,0,0,4.72-11h.51a15.12,15.12,0,0,0,4.72,11,15.12,15.12,0,0,0,11,4.72v.51A16.13,16.13,0,0,0,92.46,74.67Zm10.09-46.59h-.27a7.94,7.94,0,0,0-2.49-5.81A7.94,7.94,0,0,0,94,19.78v-.27A7.94,7.94,0,0,0,99.79,17a8,8,0,0,0,2.49-5.8h.27A8,8,0,0,0,105,17a8,8,0,0,0,5.81,2.49v.27A8,8,0,0,0,105,22.27a7.94,7.94,0,0,0-2.49,5.81Zm-41.5,8h-.41a12.06,12.06,0,0,0-3.78-8.82A12.06,12.06,0,0,0,48,23.5v-.41a12.07,12.07,0,0,0,8.82-3.78,12.09,12.09,0,0,0,3.78-8.82h.41a12.08,12.08,0,0,0,3.77,8.82,12.09,12.09,0,0,0,8.83,3.78v.41a12.09,12.09,0,0,0-8.83,3.78,12.08,12.08,0,0,0-3.77,8.82Z"/></svg>');
}
.slider.round { border-radius: 24px; }
.slider.round:before { border-radius: 50%; }

/* --- DESKTOP LAYOUT (ab 769px) --- */
@media (min-width: 769px) {
    .ui-container {
        top: 15px;
        bottom: auto;
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        width: auto;
        justify-content: initial;
    }
    .ui-controls {
        flex-wrap: nowrap;
        max-width: none;
        background: var(--ui-bg);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        border-radius: 16px;
        box-shadow: var(--shadow);
        padding: 8px 12px; /* reduced from 12px 15px for a sleeker bar */
        border: 1px solid var(--border-color);
        gap: 15px;
        align-items: center;
    }
    
    /* Inline-Anzeige der Routen-Zusammenfassung auf Desktop */
    .route-info-box {
        flex-basis: auto;
        background: none !important;
        border: none !important;
        border-right: 1px solid var(--border-color) !important;
        box-shadow: none !important;
        padding: 0 15px 0 0 !important;
        border-radius: 0 !important;
        margin-right: 5px;
    }
    .search-container, .control-group {
        flex-basis: auto;
    }
    #location-search, #route-start-search, .route-start-badge {
        width: 300px;
        box-shadow: none;
        padding: 12px 16px;
        font-size: 15px;
        border-radius: 10px;
    }
    .search-container.route-mode #route-start-search,
    .search-container.route-mode .route-start-badge {
        border-bottom: none;
        border-radius: 10px 10px 0 0;
    }
    .search-container.route-mode #location-search {
        border-top-left-radius: 0;
        border-top-right-radius: 0;
    }
    .control-group {
        padding: 0;
        background: none;
        box-shadow: none;
        border: none;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }
    .fuel-selector {
        padding: 4px;
        border-radius: 10px;
    }
    .fuel-selector label {
        padding: 8px 16px;
        font-size: 15px;
        border-radius: 8px;
    }
    .actions {
        gap: 15px;
    }
    #relocate-btn {
        width: 44px;
        height: 44px;
    }
    #relocate-btn svg {
        width: 24px;
        height: 24px;
    }
    .theme-switch {
        width: 50px;
        height: 28px;
    }
    .slider.round {
        border-radius: 28px;
    }
    .slider:before {
        height: 22px;
        width: 22px;
        background-size: 14px 14px;
    }
    input:checked + .slider:before {
        transform: translateX(22px);
    }
    
    /* Desktop Warnungs-Anpassungen */
    .zoom-warning {
        top: 100%;
        bottom: auto;
        margin-top: 10px;
        margin-bottom: 0;
        font-size: 13px;
        padding: 8px 16px;
    }
}

/* --- USER LOCATION MARKER (Google Maps Style) --- */

/* Container für das Icon (Leaflet divIcon Klasse) */
.user-location-icon {
    background: transparent;
    border: none;
}

/* Der innere blaue Punkt mit weißem Rand */
.user-dot {
    width: 16px;
    height: 16px;
    background-color: #4285F4; /* Typisches "Google Blue" */
    border: 2px solid #ffffff;
    border-radius: 50%;
    box-shadow: 0 0 4px rgba(0,0,0,0.3);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2;
    pointer-events: none;
}

/* Der pulsierende äußere Kreis */
.user-pulse {
    width: 40px;
    height: 40px;
    background-color: rgba(66, 133, 244, 0.4);
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1;
    animation: pulse-animation 2s infinite;
    pointer-events: none;
}

/* Animation Definition */
@keyframes pulse-animation {
    0% {
        transform: translate(-50%, -50%) scale(0.5);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(1.5);
        opacity: 0;
    }
}

/* --- ROUTEN-FUNKTIONALITÄT STYLES --- */

/* Routen-Modus Umschalt-Button */
#route-toggle-btn {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    color: var(--text-color);
    transition: all 0.2s ease-in-out;
    position: relative;
}
#route-toggle-btn .route-icon {
    width: 20px;
    height: 20px;
    transition: all 0.2s ease-in-out;
}
#route-toggle-btn:hover {
    opacity: 0.9;
}
#route-toggle-btn.active {
    background-color: var(--accent-color);
    border-color: var(--accent-color);
    color: white;
}
#route-toggle-btn.loading {
    background-color: var(--bg-color) !important;
    border-color: transparent !important;
    color: var(--text-color) !important;
}
#route-toggle-btn.loading .route-icon {
    transform: scale(0.85);
    color: var(--accent-color) !important;
}
.progress-ring {
    position: absolute;
    top: -1px;
    left: -1px;
    width: calc(100% + 2px);
    height: calc(100% + 2px);
    transform: rotate(-90deg);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}
#route-toggle-btn.loading .progress-ring {
    opacity: 1;
}
.progress-ring__circle {
    transition: stroke-dashoffset 0.15s ease-out;
    stroke-linecap: round;
}

@media (min-width: 769px) {
    #route-toggle-btn {
        width: 44px;
        height: 44px;
    }
    #route-toggle-btn .route-icon {
        width: 24px;
        height: 24px;
    }
}



/* Routen-Info Container */
.route-info-box {
    flex-basis: 100%;
    background: var(--ui-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 10px 15px;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    font-size: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-sizing: border-box;
}
.route-info-box.hidden {
    display: none !important;
}
.route-info-close {
    background: transparent;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    font-weight: bold;
    font-size: 18px;
    padding: 0 5px;
    line-height: 1;
    display: flex;
    align-items: center;
}
.route-info-close:hover {
    color: var(--red);
}

/* Custom Marker Pins für Start (A) und Ende (B) */
.price-marker-container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: auto !important;
    height: auto !important;
}
.route-marker-pin {
    width: 32px;
    height: 32px;
    border-radius: 50% 50% 50% 0;
    background: var(--accent-color);
    position: absolute;
    transform: rotate(-45deg);
    left: 50%;
    top: 50%;
    margin: -16px 0 0 -16px;
    box-shadow: 0 3px 6px rgba(0,0,0,0.3);
    border: 2px solid white;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}
.route-marker-pin.end-pin {
    background: var(--red);
}
.route-marker-pin span {
    transform: rotate(45deg);
    color: white;
    font-weight: 800;
    font-size: 14px;
}

/* MapLibre GL Canvas Styles (Home Assistant PR #53816 compatibility) */
.maplibregl-map {
    position: relative;
    overflow: hidden;
    width: 100%;
    height: 100%;
}
.maplibregl-canvas {
    position: absolute;
    top: 0;
    left: 0;
}

/* PWA Install Banner */
.pwa-install-banner {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 92%;
    max-width: 480px;
    background: var(--ui-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    z-index: 10000;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
    animation: pwaSlideUp 0.4s ease-out forwards;
}

.pwa-install-banner.hidden {
    display: none !important;
}

@keyframes pwaSlideUp {
    from {
        opacity: 0;
        transform: translate(-50%, 20px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

.pwa-install-content {
    display: flex;
    align-items: center;
    gap: 12px;
    overflow: hidden;
}

.pwa-install-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.pwa-install-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.pwa-install-text strong {
    font-size: 14px;
    color: var(--text-color);
    font-weight: 600;
}

.pwa-install-text span {
    font-size: 12px;
    color: var(--subtext-color, #94a3b8);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pwa-install-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.pwa-btn-install {
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 10px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.15s;
    box-shadow: 0 2px 8px rgba(0, 123, 255, 0.35);
}

.pwa-btn-install:hover {
    opacity: 0.92;
    transform: scale(1.02);
}

.pwa-btn-install:active {
    transform: scale(0.97);
}

.pwa-btn-dismiss {
    background: transparent;
    border: none;
    color: var(--text-color);
    opacity: 0.6;
    font-size: 16px;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s;
}

.pwa-btn-dismiss:hover {
    opacity: 1;
}