/**
 * Home Assistant Frontend Styles
 *
 * Styles for frontend entities and controls
 */

/* Base styles */
html:has(body.admin-bar):not(:has(.fixed-top)) {
    margin-top: 0 !important;
}
html {
    body {
        a.btn-primary,a.btn-primary:hover {
            color:#fff;
            border-radius: 8px;
            padding: 5px 10px;
            background-color: #CB2F23;
            text-decoration: none;
        }
        a.btn-secondary,a.btn-secondary:hover {
            color:#fff;
            border-radius: 8px;
            padding: 5px 10px;
            background-color: #28a745;
            text-decoration: none;
            svg {
                position: relative;
                top: -2px;
            }
        }
    }
}
:root {
    --asgbrandred: "#CB2F23";
}
.ha-entity {
    margin: 1rem 0;
    padding: 1rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
    position: relative;
}

.ha-entity:hover {
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.ha-entity.ha-control {
    cursor: pointer;
}

.ha-entity.ha-control:hover {
    border-color: #0073aa;
}

/* Labels */
.ha-label {
    display: block;
    font-weight: 600;
    color: #333;
    margin-bottom: 0.5rem;
    font-size: 1.1em;
}

/* Values and states */
.ha-value {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0.5rem 0;
}

.ha-state {
    font-size: 1em;
    font-weight: 700;
    color: #000000;
}

.ha-unit {
    font-size: 0.9em;
    color: #666;
    font-weight: 500;
}
.ha-gauge-needle {
    line {
        stroke: #CB2F23;
    }
    circle {
        fill: #eeeeee;
    }
}

/* Status indicators */
.ha-status {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-left: 0.5rem;
}

.ha-status.ha-loading {
    background: #CB2F23;
    animation: pulse 1.5s infinite;
}

.ha-status.ha-success {
    background: #28a745;
}

.ha-status.ha-error {
    background: #dc3545;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

/* Switch controls */
.ha-switch {
    display: inline-block;
    position: relative;
    width: 60px;
    height: 34px;
}

.ha-switch-toggle {
    display: inline-block;
    position: relative;
    width: 60px;
    height: 34px;
}

.ha-switch-input {
    opacity: 0;
    width: 0;
    height: 0;
}

.ha-toggle-track {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: 0.4s;
    border-radius: 34px;
}

.ha-toggle-track:before {
    position: absolute;
    content: "";
    height: 26px;
    width: 26px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: 0.4s;
    border-radius: 50%;
}

.ha-switch-input:checked + .ha-toggle-track {
    background-color: #0073aa;
}

.ha-switch-input:checked + .ha-toggle-track:before {
    transform: translateX(26px);
}

/* Button controls */
.ha-control-btn {
    background: #0073aa;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    transition: background 0.3s ease;
}

.ha-control-btn:hover {
    background: #005a87;
}

.ha-control-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.ha-control-btn.ha-loading {
    opacity: 0.7;
}

/* Light controls */
.ha-light-controls {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1rem;
}

.ha-light-toggle {
    align-self: flex-start;
}

.ha-brightness-control {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.ha-brightness-slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.ha-brightness-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #0073aa;
    cursor: pointer;
}

.ha-brightness-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #0073aa;
    cursor: pointer;
    border: none;
}

.ha-color-picker {
    width: 50px;
    height: 50px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    align-self: flex-start;
}

/* Thermostat controls */
.ha-thermostat-controls {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1rem;
}

.ha-temperature-display {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.2em;
}

.ha-current-temp,
.ha-target-temp {
    font-weight: 700;
    color: #0073aa;
}

.ha-temperature-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
}

.ha-temp-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid #0073aa;
    background: white;
    color: #0073aa;
    font-size: 1.2em;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
}

.ha-temp-btn:hover {
    background: #0073aa;
    color: white;
}

.ha-mode-select {
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9em;
    background: white;
}

.ha-fan-btn {
    padding: 0.5rem 1rem;
    background: #6c757d;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
}

.ha-fan-btn:hover {
    background: #5a6268;
}

/* Weather controls */
.ha-weather-current {
    margin: 1rem 0;
}

.ha-weather-main {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.ha-weather-condition {
    font-size: 1.2em;
    color: #333;
}

.ha-weather-temp {
    font-size: 1.5em;
    font-weight: 700;
    color: #0073aa;
}

.ha-weather-details {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    font-size: 0.9em;
    color: #666;
}

.ha-weather-forecast {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #eee;
}

.ha-weather-forecast h4 {
    margin: 0 0 0.5rem 0;
    color: #333;
    font-size: 1em;
}

.ha-forecast-items {
    display: flex;
    gap: 1rem;
    overflow-x: auto;
}

/* Entities list */
.ha-entities-list {
    margin: 1rem 0;
}

.ha-entities-container {
    margin-top: 1rem;
}

.ha-loading-text {
    color: #666;
    font-style: italic;
}

/* Error states */
.ha-error {
    color: #dc3545;
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    padding: 0.5rem;
    border-radius: 4px;
    margin: 0.5rem 0;
}

/* Responsive design */
@media (max-width: 768px) {
    .ha-entity {
        margin: 0.5rem 0;
        padding: 0.75rem;
    }

    .ha-state {
        font-size: 1.3em;
    }

    .ha-temperature-controls {
        gap: 0.5rem;
    }

    .ha-temp-btn {
        width: 35px;
        height: 35px;
        font-size: 1em;
    }

    .ha-weather-main {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
}

/* Loading animations */
.ha-loading {
    position: relative;
}

.ha-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #0073aa;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Success and error animations */
.ha-success {
    animation: successPulse 0.5s ease-in-out;
}

.ha-error {
    animation: errorShake 0.5s ease-in-out;
}

@keyframes successPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

@keyframes errorShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* Widget styles */
.ha-widget {
    margin: 1rem 0;
    padding: 1rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.ha-widget-label {
    font-weight: 600;
    color: #333;
    margin-bottom: 0.5rem;
    font-size: 1em;
}

.ha-widget-value {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0.5rem 0;
}

.ha-widget-controls {
    margin-top: 1rem;
}

.ha-widget-status {
    margin-top: 0.5rem;
}

/* Domain-specific styling */
.ha-entity[data-entity-id*="sensor."] .ha-state {
    color: #28a745;
}

.ha-entity[data-entity-id*="switch."] .ha-state {
    color: #0073aa;
}

.ha-entity[data-entity-id*="light."] .ha-state {
    color: #ffc107;
}

.ha-entity[data-entity-id*="climate."] .ha-state {
    color: #17a2b8;
}

.ha-entity[data-entity-id*="weather."] .ha-state {
    color: #6f42c1;
}

/* Entity card */
.ha-entity-card {
    margin: 1rem 0;
    padding: 1rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Gauge styles */
.ha-gauge {
    margin: 0.75rem 0 1rem 0;
}

.ha-gauge-arc {
    width: 100%;
    height: 12px;
    background: #eee;
    border-radius: 6px;
    overflow: hidden;
}

.ha-gauge-fill {
    height: 100%;
    width: 0;
    background: #28a745;
    transition: width 0.5s ease, background-color 0.5s ease;
}

.ha-gauge-readout {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-top: 0.25rem;
    font-weight: 600;
}

.ha-gauge-label {
    font-size: 0.85em;
    color: #666;
}

/* Semicircle gauge */
.ha-gauge-semicircle {
    margin: 0.75rem 0 1rem 0;
    text-align: center;
}

.ha-gauge-svg {
    width: 100%;
    height: auto;
}

.ha-gauge-bg,
.ha-gauge-fg {
    fill: none;
    stroke-width: 8;
    /*stroke-linecap: round;*/
}

.ha-gauge-bg {
    stroke: #eee;
}

.ha-gauge-fg {
    stroke: #28a745;
    transition: stroke-dasharray 0.4s ease, stroke 0.4s ease;
}

/* Charging indicator */
.ha-charge {
    display: none;
    align-items: center;
    gap: 0.25rem;
    margin-left: 0.25rem;
}

.ha-charging .ha-charge {
    display: inline-flex;
}
.ha-charging {
    .ha-gauge-readout {
        .ha-state {
            display: none;
        }
        .ha-unit {
            display: none;
        }
        .ha-charge {
            margin: 0 auto;
        }
    }
}
.ha-charge-icon {
    font-size: 0.95em;
    line-height: 1;
    color: #17a2b8;
}

.ha-charging .ha-gauge-fg {
    /* optional tint while charging */
    filter: saturate(1.2);
}

/* Battery Status Banner */
.ha-battery-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.75rem;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.3s ease;
}

.ha-battery-status.ha-online {
    background-color: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #166534;
}

.ha-battery-status.ha-offline {
    background-color: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

.ha-status-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #6b7280;
    transition: background-color 0.3s ease;
}

.ha-status-text {
    font-weight: 600;
    .ha-entity {
        margin: 0;
        padding: 0;
        border: none;
        background: none;
        box-shadow: none;
        .ha-state {
            color: unset;
        }
    }
}
.ha-global-values {
    border: 1px solid #ddd;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    .ha-entity {
        margin: 0;
        padding: 0;
        border: none;
        background: none;
        box-shadow: none;
    }
    .fleet-summary {
        border-top-left-radius: 8px;
        border-top-right-radius: 8px;
        background-color: #28a745;
        color: #fff;
        font-weight: bold;
    }
    .fleet-alerts {
        height: 300px;
        overflow: auto;
        .ha-entity-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 12px 16px;
            border-bottom: 1px solid #e0e0e0;
            width: 100%;
        }

        .ha-entity-item:last-child {
            border-bottom: none;
        }

        .ha-entity-info {
            flex: 1;
            min-width: 0;
        }

        .ha-entity-name {
            font-size: 14px;
            color: #333;
            display: block;
        }

        .ha-entity-state {
            flex-shrink: 0;
            margin-left: 16px;
        }

        .ha-state-value {
            font-weight: 600;
            padding: 4px 12px;
            border-radius: 12px;
            font-size: 13px;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .ha-state-value.ms-2 {
            margin-left: 8px;
        }

        /* State colors */
        .ha-entity-item:has(.ha-state-value:contains("on")) .ha-state-value,
        .ha-entity-state strong:not(:is([class*="idle"])) {
            background: #4caf50;
            color: white;
        }

        /* Default styling for all states */
        strong.ha-state-value {
            background: #e0e0e0;
            color: #666;
        }

        /* Target specific "on" state */
        .ha-entity-item:first-child .ha-state-value,
        .ha-entity-item:last-child .ha-state-value {
            background: #4caf50;
            color: white;
        }
    }
}

/* Ensure multiple .ha-value within card are not hidden */
.ha-entity-card .ha-value {
    display: inline-flex;
}
.discharge-history {
    .ha-sensor {
        border: 1px solid #e5e7eb;
        background: #f7f7f8;
        box-shadow: none;
        padding: 5px 10px;
        .ha-label {
            margin-bottom: 0;
            font-size: 0.85rem;
            color: #6b7280;
            text-transform: capitalize;
            .ha-unit {
                font-weight: bolder;
            }
        }
        .ha-value {
            margin: 0;
            .ha-state {
                color: #CB2F23;
                font-size: 0.85rem;
                font-weight: bold;
            }
        }
    }
}
.page-template-template-batteries {
    .ha-last-seen-online {

    }
}
.ha-time-to-charge-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 15px;
}
@media (max-width: 768px) {
    .ha-time-to-charge-grid {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
        gap: 15px;
    }
}
@media (max-width: 480px) {
    .ha-time-to-charge-grid {
        grid-template-columns: 1fr;
    }
}
.ha-charge-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.ha-charge-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}
.battery-location {
    .ha-sensor {
        .ha-label {
            svg {
                vertical-align: baseline;
            }
        }
        .ha-value {
            margin: 0;
            .ha-state, .ha-unit {
                color: #000;
                font-size: 1rem;
                font-weight: bold;
            }
        }
    }
}
.ha-battery-card-wrapper {
    .ha-entity {
        .ha-label.ha-title {
            position: absolute;
            width: 100%;
            left: 0;
            top: 0;
            text-align: center;
            background: #28a745;
            color: #fff;
            padding: 10px 0;
            border-top-right-radius: 8px;
            border-top-left-radius: 8px;
            svg {
                path {
                    fill: #fff;
                }
            }
        }
    }
}
.red-text {
    color: #CB2F23;
}
.ha-fleet-map-wrapper {
   padding: 0 !important;
}
@media(max-width: 768px) {
    .discharge-history {
        .ha-sensor {
            .ha-value {
                margin: 0;
                .ha-state, .ha-unit {
                    font-size: 0.75rem;
                }
            }
        }
    }
}

/* Dark Mode Styles */
body.dark-mode {
    background-color: #1a1a1a;
    color: #e0e0e0;
}

body.dark-mode .ha-entity {
    background: #2d2d2d;
    border-color: #404040;
    color: #e0e0e0;
}

body.dark-mode .ha-entity:hover {
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

body.dark-mode .ha-label {
    color: #e0e0e0;
}

body.dark-mode .ha-state {
    color: #ffffff;
}

body.dark-mode .ha-unit {
    color: #b0b0b0;
}

body.dark-mode .ha-entity-card {
    background: #2d2d2d;
    border-color: #404040;
}

body.dark-mode .ha-battery-card-wrapper .ha-entity .ha-label.ha-title {
    background: #28a745;
    color: #fff;
}

body.dark-mode .discharge-history .ha-sensor {
    background: #3a3a3a;
    border-color: #555;
}

body.dark-mode .discharge-history .ha-sensor .ha-label {
    color: #b0b0b0;
}

body.dark-mode .discharge-history .ha-sensor .ha-value .ha-state,
body.dark-mode .discharge-history .ha-sensor .ha-value .ha-unit {
    color: #CB2F23;
}

body.dark-mode .battery-location .ha-sensor .ha-value .ha-state,
body.dark-mode .battery-location .ha-sensor .ha-value .ha-unit {
    color: #ffffff;
}

body.dark-mode .ha-gauge-bg {
    stroke: #404040;
}

body.dark-mode .ha-battery-status.ha-online {
    background-color: #1a3a1a;
    border-color: #2d5a2d;
    color: #90ee90;
}

body.dark-mode .ha-battery-status.ha-offline {
    background-color: #3a1a1a;
    border-color: #5a2d2d;
    color: #ff6b6b;
}

body.dark-mode .ha-control-btn {
    background: #CB2F23;
    color: white;
}

body.dark-mode .ha-control-btn:hover {
    background: #CB2F23;
}

body.dark-mode .ha-switch-input:checked + .ha-toggle-track {
    background-color: #CB2F23;
}

body.dark-mode .ha-switch-input:checked + .ha-toggle-track:before {
    transform: translateX(26px);
}

body.dark-mode .ha-toggle-track {
    background-color: #555;
}

body.dark-mode .ha-toggle-track:before {
    background-color: #ccc;
}
body.dark-mode .ha-gauge-needle {
    line {
        stroke: #eeeeee;
    }
    circle {
        fill: #404040;
    }
}
body.dark-mode {
    .ha-global-values {
        border-color: #404040;
    }
    .fleet-block {
        background-color: #2d2d2d;
    }
    .fleet-alerts {
        background-color: #2d2d2d;
        .ha-entity-item {
            .ha-entity-name {
                color: #e0e0e0;
            }
        }
    }
    .bg-light {
        background-color: #2d2d2d !important;
    }
    .ha-map-info-window {
        color: #000;
    }
}

/* Dark Mode Switch Specific Styles */
.ha-dark-mode-switch {
    position: relative;
    .ha-label {
        font-size: 12px;
        position: relative;
        top: 4px;
        margin-right: 10px;
    }
}

.ha-dark-mode-toggle {
    display: inline-block;
    position: relative;
    width: 60px;
    height: 34px;
}

.ha-dark-mode-switch-label {
    display: inline-block;
    position: relative;
    width: 60px;
    height: 34px;
}

.ha-dark-mode-input {
    opacity: 0;
    width: 0;
    height: 0;
}

.ha-dark-mode-toggle .ha-toggle-track,
.ha-dark-mode-switch-label .ha-switch-track {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: 0.4s;
    border-radius: 34px;
}

.ha-dark-mode-toggle .ha-toggle-track:before,
.ha-dark-mode-switch-label .ha-switch-track:before {
    position: absolute;
    content: "";
    height: 26px;
    width: 26px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: 0.4s;
    border-radius: 50%;
}

.ha-dark-mode-input:checked + .ha-toggle-track,
.ha-dark-mode-input:checked + .ha-switch-track {
    background-color: #CB2F23;
}

.ha-dark-mode-input:checked + .ha-toggle-track:before,
.ha-dark-mode-input:checked + .ha-switch-track:before {
    transform: translateX(26px);
}

.ha-dark-mode-btn {
    background: #CB2F23;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    transition: background 0.3s ease;
}

.ha-dark-mode-btn:hover {
    background: #CB2F23;
}

.ha-dark-mode-btn:disabled {
    background: #666;
    cursor: not-allowed;
}

