/* ========================================
   FusionSolar Dashboard - v2.16.1 Layout Triangolare Compatto
   Fedeltà target: 70-85%
   ======================================== */

/* ========================================
   1. BASE & RESET
   ======================================== */

.fusionsolar-dashboard {
    background: #0a0a0f;
    color: #ffffff;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    padding: 0;
    margin: 0;
    /* TV FULLSCREEN — viewport-scale (1920×1080 fisso, scalato via JS) */
    width: 1920px;
    height: 1080px;
    position: fixed;
    top: 0;
    left: 0;
    transform-origin: top left;
    overflow: hidden;
    z-index: 9999;
}

/* ========================================
   2. SFONDO ATMOSFERICO
   ======================================== */

.fusionsolar-dashboard::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        radial-gradient(circle at 15% 70%, rgba(0, 153, 255, 0.25) 0%, transparent 40%),
        radial-gradient(circle at 85% 30%, rgba(255, 153, 51, 0.15) 0%, transparent 40%),
        radial-gradient(circle at 50% 50%, rgba(0, 212, 255, 0.08) 0%, transparent 60%);
    z-index: 0;
    pointer-events: none;
}

.fsd-background-effects {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image:
        repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(255,255,255,.03) 2px, rgba(255,255,255,.03) 4px),
        repeating-linear-gradient(90deg, transparent, transparent 2px, rgba(255,255,255,.03) 2px, rgba(255,255,255,.03) 4px);
    opacity: 0.4;
    z-index: 1;
    pointer-events: none;
}

.fsd-container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 24px;
    box-sizing: border-box;   /* padding incluso negli 1080px */
    position: relative;
    z-index: 2;
    height: 1080px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ========================================
   3. HEADER (INGRANDITO)
   ======================================== */

.fsd-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding: 24px 32px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 20px;
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    min-height: 140px;
    flex-shrink: 0;
}

.fsd-logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.fsd-logo-ecosumma {
    height: 110px;
    width: auto;
    filter: drop-shadow(0 0 10px rgba(0, 212, 255, 0.4));
}

.fsd-logo-tagline {
    font-size: 21px;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.55);
    letter-spacing: 0.3px;
    font-style: italic;
}

.fsd-logo svg {
    filter: drop-shadow(0 0 8px rgba(0, 212, 255, 0.8));
}

.fsd-station-name {
    display: flex;
    align-items: center;
    justify-content: center;
}

.fsd-logo-powerlog {
    height: 86px;
    width: auto;
    filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.3));
}

/* Powerlog spostato a sinistra, più piccolo */
.fsd-logo-powerlog-wrap {
    display: flex;
    align-items: center;
}

.fsd-logo-powerlog-small {
    height: 67px;
    width: auto;
    filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.25));
    opacity: 0.85;
}

.fsd-status {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    background: rgba(0, 255, 136, 0.1);
    border-radius: 20px;
    border: 1px solid rgba(0, 255, 136, 0.3);
}

.fsd-status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #00ff88;
    box-shadow:
        0 0 10px rgba(0, 255, 136, 0.8),
        0 0 20px rgba(0, 255, 136, 0.4);
    animation: pulse-status 2s ease-in-out infinite;
}

@keyframes pulse-status {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.7;
        transform: scale(1.1);
    }
}

#fsd-status-text {
    font-size: 14px;
    font-weight: 600;
    color: #00ff88;
}

/* ========================================
   4. LAYOUT PRINCIPALE (2 COLONNE)
   ======================================== */

.fsd-main-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 20px;
    flex: 1;
    min-height: 0;
}

/* ========================================
   5. SIDEBAR SINISTRA - METRICHE KPI
   ======================================== */

.fsd-sidebar-left {
    display: flex;
    flex-direction: column;
    gap: 12px;
    height: 100%;
}

.fsd-metric-card {
    background: rgba(255, 255, 255, 0.06);
    border-radius: 16px;
    padding: 16px;
    backdrop-filter: blur(30px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.fsd-metric-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(0, 212, 255, 0.1) 0%, transparent 50%);
    opacity: 0;
    transition: opacity 0.4s ease;
}

.fsd-metric-card:hover {
    transform: translateX(8px);
    box-shadow:
        0 8px 24px rgba(0, 212, 255, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.15);
    border-color: rgba(0, 212, 255, 0.4);
}

.fsd-metric-card:hover::before {
    opacity: 1;
}

.fsd-metric-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 8px;
    color: #00d4ff;
    filter: drop-shadow(0 0 12px currentColor);
}

.fsd-metric-content {
    position: relative;
    z-index: 1;
}

.fsd-metric-label {
    font-size: 12px;
    color: #888;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 500;
}

.fsd-metric-value {
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.fsd-metric-number {
    font-size: 26px;
    font-weight: 700;
    color: #ffffff;
    font-variant-numeric: tabular-nums;
}

.fsd-metric-unit {
    font-size: 14px;
    color: #999;
    font-weight: 500;
}

/* ========================================
   6. AREA CENTRALE - VISUALIZZAZIONE 3D
   ======================================== */

.fsd-center-area {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 20px;
    padding: 32px;
    position: relative;
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow:
        0 20px 60px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.fsd-3d-scene {
    flex: 1;
    min-height: 0;
    position: relative;
    width: 100%;
}

/* SVG Flussi energetici */
.fsd-energy-flows {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

.energy-flow-path {
    stroke-dasharray: 10 5;
    animation: flow-dash 2s linear infinite;
    filter: drop-shadow(0 0 8px rgba(0, 212, 255, 0.8));
}

@keyframes flow-dash {
    to {
        stroke-dashoffset: -15;
    }
}

.energy-particle {
    filter: drop-shadow(0 0 6px currentColor);
}

/* ========================================
   v2.16.1: Grid componenti 3D - Layout triangolare 120°
   Posizionamento matematicamente preciso:
   SVG viewBox="0 0 1000 600" + preserveAspectRatio="none"
   → x% = x/1000*100, y% = y/600*100
   Edificio=(500,150)→(50%,25%), PV=(750,450)→(75%,75%), Rete=(250,450)→(25%,75%)
   ======================================== */

/* fsd-components-grid è non-posizionato (position:static) così i figli
   position:absolute sono relativi a fsd-3d-scene (position:relative)
   e top/left % sono calcolati sull'altezza REALE della scene */
.fsd-components-grid {
    position: static;
    width: 100%;
}

/* Edificio: vertice alto centro → SVG (500,150) = (50%, 25%)
   Struttura: [icon 100px][label][value]
   Centro icona al vertice: component_top = 25% - 50px
   (confermato via debug JS su WordPress) */
.fsd-component-load {
    position: absolute;
    left: 50%;
    top: calc(25% - 50px);
    transform: translateX(-50%);
    z-index: 2;
}

/* Pannelli FV: vertice basso destra → SVG (750,450) = (75%, 75%)
   Struttura: [label ~20px][value ~35px][icon 100px]
   Centro icona al vertice: component_top = 75% - 110px
   (confermato via debug JS su WordPress) */
.fsd-component-pv {
    position: absolute;
    left: 75%;
    top: calc(75% - 110px);
    transform: translateX(-50%);
    z-index: 2;
}

/* Rete: vertice basso sinistra → SVG (250,450) = (25%, 75%)
   Identica struttura e formula di PV. */
.fsd-component-grid {
    position: absolute;
    left: 25%;
    top: calc(75% - 110px);
    transform: translateX(-50%);
    z-index: 2;
}

/* ========================================
   Componenti 3D
   ======================================== */

.fsd-3d-component {
    text-align: center;
    position: relative;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Hover Edificio: mantiene translateX(-50%) e solleva 10px */
.fsd-3d-component:hover {
    transform: translateX(-50%) translateY(-10px) scale(1.05);
}

/* Hover Rete e PV: mantiene translateX(-50%) e solleva 10px */
.fsd-component-pv:hover,
.fsd-component-grid:hover {
    transform: translateX(-50%) translateY(-10px) scale(1.05);
}

@media (max-width: 900px) {
    .fsd-3d-component:hover {
        transform: translateY(-10px) scale(1.05);
    }
}

.fsd-svg-wrapper {
    width: 120px;
    height: 100px;
    margin: 0 auto 8px;
    position: relative;
    filter: drop-shadow(0 10px 30px rgba(0, 0, 0, 0.5));
}

.fsd-svg-3d {
    width: 100%;
    height: 100%;
    object-fit: contain;
    animation: float-3d 4s ease-in-out infinite;
}

@keyframes float-3d {
    0%, 100% {
        transform: translateY(0px);
    }
    50% {
        transform: translateY(-12px);
    }
}

.fsd-component-pv .fsd-svg-3d {
    animation-delay: 0s;
}

.fsd-component-load .fsd-svg-3d {
    animation-delay: 0.6s;
}

.fsd-component-grid .fsd-svg-3d {
    animation-delay: 1.2s;
}

.fsd-component-label {
    font-size: 11px;
    color: #888;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

.fsd-component-value {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 6px;
}

.fsd-value-number {
    font-size: 26px;
    font-weight: 700;
    color: #ffffff;
    text-shadow: 0 2px 8px rgba(0, 212, 255, 0.3);
    font-variant-numeric: tabular-nums;
}

.fsd-value-unit {
    font-size: 14px;
    color: #aaa;
    font-weight: 500;
}

/* Glow specifici per tipo componente */
.fsd-component-pv .fsd-svg-wrapper {
    filter: drop-shadow(0 10px 30px rgba(255, 204, 0, 0.4));
}

.fsd-component-load .fsd-svg-wrapper {
    filter: drop-shadow(0 10px 30px rgba(0, 212, 255, 0.4));
}

.fsd-component-grid .fsd-svg-wrapper {
    filter: drop-shadow(0 10px 30px rgba(0, 153, 255, 0.4));
}

/* ========================================
   7. LOADING STATE
   ======================================== */

.fsd-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 100;
    background: rgba(10, 10, 15, 0.95);
    padding: 30px 40px;
    border-radius: 16px;
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.fsd-spinner {
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top: 4px solid #00d4ff;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    animation: spin-loader 1s linear infinite;
    margin: 0 auto 16px;
    box-shadow: 0 0 20px rgba(0, 212, 255, 0.4);
}

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

.fsd-loading-text {
    color: #00d4ff;
    font-size: 14px;
    font-weight: 600;
}

/* ========================================
   7B. DATI AMBIENTALI - RIMOSSO IN v2.16.1
   Spostati in sidebar come card KPI
   ======================================== */

/* ========================================
   8. SEZIONE MEDIA: foto | video | foto
   ======================================== */

.fsd-installation-media {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-top: 12px;
    flex-shrink: 0;
}

.fsd-media-item {
    aspect-ratio: 16 / 9;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.fsd-media-img,
.fsd-media-video {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

/* ========================================
   10. RESPONSIVE
   ======================================== */

@media (max-width: 1400px) {
    .fsd-main-layout {
        grid-template-columns: 260px 1fr 180px;
    }

    .fsd-svg-wrapper {
        width: 150px;
        height: 120px;
    }
}

@media (max-width: 1200px) {
    .fsd-main-layout {
        grid-template-columns: 240px 1fr;
    }
}

@media (max-width: 900px) {
    .fsd-main-layout {
        grid-template-columns: 1fr;
    }

    .fsd-sidebar-left {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 12px;
    }

    .fsd-components-grid {
        position: static;
        width: 100%;
        height: auto;
    }

    .fsd-component-load,
    .fsd-component-grid,
    .fsd-component-pv {
        position: static;
        transform: none;
        left: auto;
        top: auto;
        margin-bottom: 30px;
    }

    .fsd-svg-wrapper {
        width: 200px;
        height: 150px;
    }

    .fsd-installation-media {
        grid-template-columns: 1fr;
        gap: 16px;
    }
}

@media (max-width: 640px) {
    .fsd-container {
        padding: 16px;
    }

    .fsd-header {
        flex-direction: column;
        gap: 12px;
    }

    .fsd-sidebar-left {
        grid-template-columns: 1fr;
    }

    .fsd-metric-number {
        font-size: 22px;
    }

    .fsd-value-number {
        font-size: 24px;
    }
}

/* ========================================
   11. ANIMAZIONI AVANZATE
   ======================================== */

@keyframes glow-pulse {
    0%, 100% {
        box-shadow: 0 0 20px rgba(0, 212, 255, 0.4);
    }
    50% {
        box-shadow: 0 0 40px rgba(0, 212, 255, 0.8);
    }
}

/* Smooth scroll */
html {
    scroll-behavior: smooth;
}

/* Transizioni globali */
* {
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}
