/**
 * PVDashboard Base Layout
 *
 * Layout, typography, components, animations, and responsive styles.
 * Merged from styles.css + dashboard.html inline <style>.
 * All colors reference CSS variables from base-variables.css.
 */

/* ============================================
   RESET & BASE
   ============================================ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-sans, 'Inter', sans-serif);
    background: var(--bg-page);
    color: var(--text-primary);
    overflow: hidden;
    width: 100vw;
    height: 100vh;
}

/* ============================================
   MAIN GRID LAYOUT
   ============================================ */

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 350px;
    grid-template-rows: auto 1fr;
    gap: 1rem;
    height: 100vh;
    padding: 1rem;
    box-sizing: border-box;
}

/* ============================================
   HEADER
   ============================================ */

.header {
    grid-column: 1 / -1;
    background: var(--bg-header);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: var(--radius, 0);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.tenant-logo {
    height: 60px;
    width: auto;
}

.sirdal-logo {
    width: 60px;
    height: 60px;
    border-radius: 0;
    object-fit: contain;
}

.logo-placeholder {
    width: 60px;
    height: 60px;
    background: white;
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.plant-summary {
    text-align: left;
}

.plant-name {
    font-size: 2.2rem;
    font-weight: 800;
    color: white;
    margin: 0;
}

.plant-stats {
    font-size: 1.25rem;
    opacity: 0.95;
    margin-top: 0.5rem;
}

.total-stats {
    text-align: right;
}

.total-power {
    font-size: 3rem;
    font-weight: 800;
    color: var(--secondary-300, #fcd34d);
    text-shadow: 0 2px 8px rgba(0,0,0,0.3);
    line-height: 1;
}

.total-label {
    font-size: 0.9rem;
    opacity: 0.9;
    margin-top: 0.5rem;
}

/* ============================================
   CHARTS COLUMN
   ============================================ */

.charts-column {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    overflow: hidden;
}

.chart-card {
    background: var(--bg-card);
    border-radius: var(--radius, 0);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-light);
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.chart-card.daily { flex: 1.5; }
.chart-card.weekly { flex: 1.2; }
.chart-card.monthly { flex: 1; }

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.chart-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.chart-subtitle {
    font-size: 0.85rem;
    color: var(--text-tertiary);
    margin-top: 0.25rem;
}

.chart-container {
    position: relative;
    height: calc(100% - 60px);
    flex: 1;
    min-height: 0;
}

/* Solar loader (NSK stripe wave animation) */
.solar-loader {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
    transition: opacity 0.3s ease;
}
.sl-stripe {
    fill: none;
    stroke-width: 8;
    stroke-linecap: round;
    animation: solarWave 1.3s infinite ease-in-out;
    transform-origin: center;
    transform-box: fill-box;
}
.sl-y { stroke: #FDB913; }
.sl-b { stroke: #0076A9; }
@keyframes solarWave {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.3; transform: scale(0.97); }
}

.chart-stats {
    text-align: right;
}

.chart-total {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--secondary-600, #f59e0b);
}

.chart-detail {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Chart Legend */
.chart-legend {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-light);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: var(--radius, 0);
}

canvas {
    max-height: 100% !important;
}

/* ============================================
   SIDEBAR
   ============================================ */

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overflow: hidden;
}

/* ============================================
   KPI CARDS
   ============================================ */

.kpi-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.kpi-card {
    background: var(--bg-card);
    border-radius: var(--radius, 0);
    padding: 0.75rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-light);
    transition: all 0.2s;
}

.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.kpi-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.kpi-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--primary-500);
    line-height: 1;
}

.kpi-unit {
    font-size: 0.65rem;
    color: var(--text-tertiary);
    margin-top: 0.15rem;
}

/* ============================================
   PLANT CAROUSEL
   ============================================ */

.plant-carousel {
    background: linear-gradient(135deg, var(--primary-600), var(--primary-700));
    color: white;
    border-radius: var(--radius, 0);
    padding: 1rem;
    box-shadow: var(--shadow-lg);
    position: relative;
    overflow: hidden;
}

.carousel-header {
    font-size: 0.75rem;
    opacity: 0.9;
    margin-bottom: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.05em;
}

.plant-display {
    animation: fadeIn 0.5s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.plant-display-name {
    font-size: 1.25rem;
    font-weight: 800;
    margin-bottom: 0.75rem;
    color: var(--secondary-300, #fcd34d);
}

.plant-display-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
}

.plant-stat {
    background: rgba(255,255,255,0.1);
    border-radius: var(--radius, 0);
    padding: 0.5rem;
}

.plant-stat-label {
    font-size: 0.65rem;
    opacity: 0.8;
    margin-bottom: 0.15rem;
}

.plant-stat-value {
    font-size: 1rem;
    font-weight: 700;
}

/* ============================================
   VISSTE DU AT? (Fun Facts)
   ============================================ */

.visste-du-at {
    background: linear-gradient(135deg, var(--primary-700), var(--primary-800));
    border: 1px solid var(--border-light);
    border-radius: var(--radius, 0);
    padding: 1rem;
    box-shadow: var(--shadow-lg);
}

.visste-du-at-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.6rem;
}

.visste-du-at-icon {
    font-size: 1.4rem;
}

.visste-du-at-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--secondary-300, #fcd34d);
}

.visste-du-at-content {
    font-size: 0.8rem;
    color: rgba(255,255,255,0.8);
    line-height: 1.6;
}

.visste-du-at-highlight {
    color: var(--secondary-300, #fcd34d);
    font-weight: 700;
}

/* Fun facts (styles.css variant) */
.fun-facts {
    background: var(--primary-600);
    border-radius: var(--radius, 0);
    padding: 1.75rem;
    box-shadow: var(--shadow-green, 0 2px 8px rgba(30, 125, 30, 0.3));
    border: 2px solid var(--primary-700);
    margin-top: 0.5rem;
}

.fun-facts-title {
    font-size: 1.225rem;
    font-weight: 700;
    color: #FFFFFF;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.fun-facts-icon {
    font-size: 1.75rem;
}

.fun-facts-text {
    font-size: 1.225rem;
    line-height: 1.5;
    color: #FFFFFF;
}

/* ============================================
   LOGO FOOTER
   ============================================ */

.logo-footer {
    background: var(--bg-card);
    border-radius: var(--radius, 0);
    padding: 0.75rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-light);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: auto;
}

.logo-footer-image,
.logo-image {
    width: 100%;
    max-width: 160px;
    height: auto;
    margin: 0.25rem 0;
}

.logo-footer-text {
    font-size: 0.65rem;
    color: var(--text-tertiary);
    text-align: center;
    margin-top: 0.25rem;
}

/* ============================================
   RESPONSIVE - Mobile (<768px)
   ============================================ */

@media (max-width: 767px) {
    body {
        overflow-y: auto;
        overflow-x: hidden;
        height: auto;
    }

    .dashboard-grid {
        display: flex;
        flex-direction: column;
        height: auto;
        min-height: 100vh;
        padding: 1rem;
        gap: 1rem;
    }

    .header {
        flex-direction: column;
        padding: 1rem;
        gap: 1rem;
        text-align: center;
    }

    .logo-section {
        flex-direction: column;
        gap: 0.75rem;
    }

    .tenant-logo { height: 50px; }
    .sirdal-logo { width: 40px; height: 40px; }
    .plant-name { font-size: 1.25rem; }
    .plant-stats { font-size: 0.8rem; }
    .total-stats { text-align: center; }
    .total-power { font-size: 2rem; }

    .charts-column {
        padding: 0;
        gap: 1rem;
        overflow: visible;
    }

    .chart-card {
        min-height: 280px;
        padding: 1rem;
    }

    .chart-card.daily,
    .chart-card.weekly,
    .chart-card.monthly {
        flex: none;
        min-height: 280px;
    }

    .chart-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .chart-title { font-size: 1rem; }
    .chart-subtitle { font-size: 0.8125rem; }

    .sidebar {
        width: 100%;
        padding: 0;
    }

    .kpi-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
    }

    .kpi-card { padding: 0.75rem; }
    .kpi-label { font-size: 0.6875rem; }
    .kpi-value { font-size: 1.5rem; }
    .kpi-unit { font-size: 0.6875rem; }

    .fun-facts { padding: 1.25rem; margin-top: 0; }
    .fun-facts-title { font-size: 1rem; }
    .fun-facts-text { font-size: 1rem; }

    .logo-footer { padding: 0.75rem; }
    .logo-footer-image,
    .logo-image { max-width: 200px; }
}

/* ============================================
   RESPONSIVE - Tablet (768px - 1023px)
   ============================================ */

@media (min-width: 768px) and (max-width: 1023px) {
    body {
        overflow-y: auto;
        height: auto;
    }

    .dashboard-grid {
        display: flex;
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }

    .chart-card {
        min-height: 320px;
    }

    .chart-card.daily,
    .chart-card.weekly,
    .chart-card.monthly {
        flex: none;
        min-height: 320px;
    }

    .kpi-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .logo-footer-image,
    .logo-image { max-width: 240px; }
}

/* ============================================
   RESPONSIVE - Desktop (1024px+)
   ============================================ */

@media (min-width: 1024px) {
    body {
        overflow: hidden;
        height: 100vh;
    }

    .dashboard-grid {
        display: grid;
        grid-template-columns: 1fr 350px;
        grid-template-rows: auto 1fr;
        height: 100vh;
    }

    .header {
        grid-column: 1 / -1;
    }

    .charts-column {
        overflow: hidden;
    }

    .chart-card.daily { flex: 1.5 !important; min-height: 0; }
    .chart-card.weekly { flex: 1.2 !important; min-height: 0; }
    .chart-card.monthly { flex: 1 !important; min-height: 0; }

    .sidebar {
        overflow-y: auto;
    }
}

/* ============================================
   RESPONSIVE - Large Desktop (1280px+)
   ============================================ */

@media (min-width: 1280px) {
    .dashboard-grid {
        grid-template-columns: 1fr 380px;
    }
}

/* ============================================
   TV MODE - Auto-scales via rem cascade
   html font-size is set by JS (autoScaleToFit) based on viewport.
   All rem values scale automatically. Only structural overrides here.
   ============================================ */

body[data-mode="tv"],
html[data-mode="tv"] body {
    overflow: hidden !important;
    height: 100vh !important;
    width: 100vw !important;
}

body[data-mode="tv"] .dashboard-grid,
html[data-mode="tv"] .dashboard-grid {
    display: grid !important;
    grid-template-columns: 1fr 17.5rem !important;
    grid-template-rows: auto 1fr !important;
    gap: 0.5rem !important;
    padding: 0.5rem !important;
    height: 100vh !important;
}

body[data-mode="tv"] .header,
html[data-mode="tv"] .header {
    grid-column: 1 / -1 !important;
    padding: 0.5rem 1rem !important;
}

body[data-mode="tv"] .tenant-logo,
html[data-mode="tv"] .tenant-logo {
    height: 2.5rem !important;
}

body[data-mode="tv"] .charts-column,
html[data-mode="tv"] .charts-column {
    display: flex !important;
    flex-direction: column !important;
    gap: 0.5rem !important;
    overflow: hidden !important;
}

body[data-mode="tv"] .chart-card,
html[data-mode="tv"] .chart-card {
    flex: 1 1 0 !important;
    min-height: 0 !important;
    padding: 0.75rem !important;
    overflow: hidden !important;
}

body[data-mode="tv"] .sidebar,
html[data-mode="tv"] .sidebar {
    gap: 0.5rem !important;
    overflow: hidden !important;
}

body[data-mode="tv"] .kpi-grid,
html[data-mode="tv"] .kpi-grid {
    gap: 0.35rem !important;
}

body[data-mode="tv"] .kpi-card,
html[data-mode="tv"] .kpi-card {
    padding: 0.5rem !important;
}

body[data-mode="tv"] .plant-carousel,
html[data-mode="tv"] .plant-carousel {
    padding: 0.75rem !important;
}

body[data-mode="tv"] .logo-footer,
html[data-mode="tv"] .logo-footer {
    padding: 0.5rem !important;
}

body[data-mode="tv"] .logo-image,
html[data-mode="tv"] .logo-image {
    max-width: 7.5rem !important;
}

/* TV: Hide low-priority components on small screens */
@media (max-height: 800px) {
    body[data-mode="tv"] .visste-du-at,
    body[data-mode="tv"] .fun-facts {
        display: none !important;
    }
    body[data-mode="tv"] .logo-footer-text {
        display: none !important;
    }
}

@media (max-height: 650px) {
    body[data-mode="tv"] .plant-carousel {
        display: none !important;
    }
}

