/* ── HA Powerflow Widget ─────────────────────────────────────────────────── */

.ha-powerflow-widget {
    position: relative;
    width: 1000px;
    height: 700px;
    max-width: 100%;
    aspect-ratio: 1000 / 700;
    background-color: #0d1117; /* Darker Lumina-style base */
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    border-radius: 20px;
    margin: 0 auto;
    font-family: 'Exo 2', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    box-shadow: 0 0 50px rgba(0,0,0,0.8), inset 0 0 100px rgba(0,0,0,0.5); /* Deeper shadow */
    overflow: hidden;
    color: #fff;
}

/* ── Glassmorphism & Glow ──────────────────────────────────────────────── */
.ha-powerflow-widget text {
    user-select: none;
    pointer-events: none;
}

/* Labels - respect the user-defined Text Colors */
.ha-powerflow-widget text[id$="-title"], 
.ha-powerflow-widget #ha-pf-home-label,
.ha-powerflow-widget #ha-pf-flow-label,
.ha-powerflow-widget #ha-pf-weather,
.ha-powerflow-widget .ha-pf-custom-entity text:first-child { 
    fill: var(--ha-pf-title-color, #8899bb); 
}

.ha-powerflow-widget text[id$="-power"],
.ha-powerflow-widget text.ha-pf-custom-value { 
    fill: var(--ha-pf-power-color, #f0a500); 
}

.ha-powerflow-widget text[id$="-energy"],
.ha-powerflow-widget text[id$="-energy-out"],
.ha-powerflow-widget text[id$="-soc"],
.ha-powerflow-widget text[id$="-efficiency"],
.ha-powerflow-widget text[id*="-price-"] { 
    fill: var(--ha-pf-energy-color, #6677aa); 
}

/* Lines - remain dynamic and controlled via JS/CSS variables */
.ha-powerflow-widget #ha-pf-line, .ha-powerflow-widget #ha-pf-path { stroke: var(--ha-pf-grid-color); }
.ha-powerflow-widget #ha-pf-load-line, .ha-powerflow-widget #ha-pf-load-path { stroke: var(--ha-pf-load-color); }
.ha-powerflow-widget #ha-pf-pv-line, .ha-powerflow-widget #ha-pf-pv-path { stroke: var(--ha-pf-pv-color); }
.ha-powerflow-widget #ha-pf-battery-line, .ha-powerflow-widget #ha-pf-battery-path { stroke: var(--ha-pf-battery-color); }
.ha-powerflow-widget #ha-pf-ev-line, .ha-powerflow-widget #ha-pf-ev-path { stroke: var(--ha-pf-ev-color); }
.ha-powerflow-widget #ha-pf-heatpump-line, .ha-powerflow-widget #ha-pf-heatpump-path { stroke: var(--ha-pf-heatpump-color); }
.ha-powerflow-widget #ha-pf-weather-icon { stroke: var(--ha-pf-title-color); }

.ha-powerflow-widget .ha-pf-laser {
    filter: drop-shadow(0 0 3px currentColor);
    transition: stroke-width 0.5s, filter 0.5s;
}

@keyframes ha-pf-overload {
    0% { opacity: 1; filter: drop-shadow(0 0 8px currentColor) brightness(1.2); }
    50% { opacity: 0.8; filter: drop-shadow(0 0 15px currentColor) brightness(1.8); }
    100% { opacity: 1; filter: drop-shadow(0 0 8px currentColor) brightness(1.2); }
}

.ha-pf-laser.overload {
    stroke-width: 5px !important;
}

/* Breathing Animation for HUD elements */
@keyframes ha-pf-breathing {
    0% { opacity: 0.6; }
    50% { opacity: 1; }
    100% { opacity: 0.6; }
}

.ha-powerflow-widget text[id$="-label"],
.ha-powerflow-widget .ha-pf-custom-entity text:first-child {
    animation: ha-pf-breathing 4s ease-in-out infinite;
}

.ha-powerflow-widget::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at center, rgba(13, 17, 23, 0.2) 0%, rgba(13, 17, 23, 0.6) 100%);
    pointer-events: none;
    z-index: 0;
}

#ha-pf-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    overflow: visible;
}

.ha-pf-status {
    position: absolute;
    bottom: 12px;
    left: 0; right: 0;
    text-align: center;
    font-size: 11px;
    font-family: 'Exo 2', sans-serif;
    color: rgba(255,255,255,0.35);
    z-index: 2;
    pointer-events: none;
    padding: 0 12px;
    transition: color 0.3s;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.ha-pf-status.ha-pf-error {
    color: #ff5e5e;
    font-weight: 700;
}

/* ── Debug bar ──────────────────────────────────────────────────────────── */
.ha-pf-debug-bar {
    display: none;
    position: absolute;
    top: 0; left: 0; right: 0;
    background: rgba(255, 180, 0, 0.92);
    color: #1a1000;
    font-size: 12px;
    font-weight: 700;
    text-align: center;
    padding: 7px 12px;
    z-index: 10;
    pointer-events: none;
    letter-spacing: 0.5px;
}

/* ── Coordinate pin ─────────────────────────────────────────────────────── */
.ha-pf-coord-pin {
    display: none;
    position: absolute;
    background: rgba(0,0,0,0.82);
    color: #f0c040;
    font-family: monospace;
    font-size: 13px;
    font-weight: 700;
    padding: 5px 10px;
    border-radius: 6px;
    border: 1px solid #f0c040;
    pointer-events: none;
    z-index: 20;
    white-space: nowrap;
    transform: translate(12px, -50%);
}

.ha-powerflow-widget[data-debug="true"] { cursor: crosshair; }
.ha-powerflow-widget[data-debug="true"] #ha-pf-svg { pointer-events: all; }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 1040px) {
    .ha-powerflow-widget { width: 100%; height: auto; }
}

/* ── Tooltips ───────────────────────────────────────────────────────────── */
.ha-pf-tooltip {
    position: absolute;
    background: rgba(13, 17, 23, 0.75);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    border-radius: 12px;
    padding: 12px 16px;
    color: #fff;
    font-family: 'Exo 2', sans-serif;
    z-index: 1000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
    transform: translateY(10px);
    min-width: 160px;
    box-sizing: border-box;
}

.ha-pf-tooltip.ha-pf-tooltip-visible {
    opacity: 1;
    transform: translateY(0);
}

.ha-pf-tooltip-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 6px;
    color: rgba(255, 255, 255, 0.6);
}

.ha-pf-tooltip-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ha-pf-tooltip-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: ha-pf-spin 1s linear infinite;
    margin: 10px auto;
}

.ha-pf-sparkline {
    width: 100%;
    height: 45px;
    margin-top: 4px;
    overflow: visible;
}

.ha-pf-sparkline path.ha-pf-sparkline-line {
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
}

.ha-pf-sparkline path.ha-pf-sparkline-fill {
    stroke: none;
}
/* ── Full Weather Card ────────────────────────────────────────────────── */
.ha-pf-weather-card {
    position: absolute;
    /* Background opacity is controlled via ::before — content stays fully visible */
    --ha-pf-weather-bg-opacity: 1;
    border-radius: 20px;
    padding: 20px;
    color: #fff;
    z-index: 100;
    pointer-events: none;
    display: none;
    flex-direction: column;
    width: 320px;
    font-family: 'Exo 2', sans-serif;
    transition: transform 0.15s ease;
}

/* The glass background layer — only this fades, not the card content */
.ha-pf-weather-card::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: rgba(0, 0, 0, calc(0.8 * var(--ha-pf-weather-bg-opacity)));
    backdrop-filter: blur(calc(30px * var(--ha-pf-weather-bg-opacity))) saturate(150%);
    -webkit-backdrop-filter: blur(calc(30px * var(--ha-pf-weather-bg-opacity))) saturate(150%);
    border: 1px solid rgba(255, 255, 255, calc(0.1 * var(--ha-pf-weather-bg-opacity)));
    box-shadow: 0 10px 40px rgba(0, 0, 0, calc(0.5 * var(--ha-pf-weather-bg-opacity)));
    pointer-events: none;
    z-index: -1;
    transition: background 0.3s ease, backdrop-filter 0.3s ease;
}

.ha-pf-weather-card.visible { display: flex; }

.ha-pf-weather-current {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    margin-bottom: 20px;
}

.ha-pf-weather-main-info {
    display: flex;
    flex-direction: column;
}

.ha-pf-weather-temp {
    font-size: 52px;
    font-weight: 800;
    line-height: 1;
    font-family: 'Orbitron', sans-serif;
    letter-spacing: -2px;
}

.ha-pf-weather-condition {
    font-size: 15px;
    font-weight: 700;
    text-transform: capitalize;
    opacity: 0.95;
    margin-top: 4px;
}

.ha-pf-weather-extra {
    font-size: 10px;
    font-weight: 700;
    opacity: 0.5;
    letter-spacing: 0.8px;
    margin-top: 4px;
    text-transform: uppercase;
}

.ha-pf-weather-icon-large {
    width: 70px;
    height: 70px;
}

.ha-pf-weather-forecast {
    border-top: 1px solid rgba(255,255,255,0.1);
    padding-top: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ha-pf-forecast-row {
    display: grid;
    grid-template-columns: 40px 30px 1fr 45px;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
}

.ha-pf-forecast-day { opacity: 0.8; }

.ha-pf-forecast-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ha-pf-forecast-bar-bg {
    height: 6px;
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
    position: relative;
    overflow: hidden;
}

.ha-pf-forecast-bar-fill {
    position: absolute;
    height: 100%;
    background: linear-gradient(90deg, #3498db, #f1c40f, #e67e22);
    border-radius: 3px;
}

.ha-pf-forecast-temp {
    text-align: right;
    font-weight: 700;
}

.ha-pf-forecast-temp span {
    opacity: 0.4;
    font-size: 11px;
    margin-right: 4px;
}

@keyframes ha-pf-rain-fall { from { stroke-dashoffset: 0; } to { stroke-dashoffset: 20; } }
.ha-pf-animate-rain { stroke-dasharray: 4 4; animation: ha-pf-rain-fall 1s linear infinite; }

@keyframes ha-pf-wind-move { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(5px); } }
.ha-pf-animate-wind { animation: ha-pf-wind-move 3s ease-in-out infinite; }
