/* ============================================================
   TABLEAU DE BORD ÉNERGIE - Styles
   ============================================================ */

/* --- Google Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* --- CSS Variables (Design Tokens) --- */
:root {
    /* Couleurs principales */
    --color-bg: #0b0f1a;
    --color-bg-secondary: #111827;
    --color-surface: #1a2035;
    --color-surface-hover: #1f2847;
    --color-surface-border: rgba(255, 255, 255, 0.06);

    /* Accents */
    --color-elec: #3b82f6;
    --color-elec-light: #60a5fa;
    --color-elec-glow: rgba(59, 130, 246, 0.25);
    --color-elec-bg: rgba(59, 130, 246, 0.08);

    --color-gas: #f59e0b;
    --color-gas-light: #fbbf24;
    --color-gas-glow: rgba(245, 158, 11, 0.25);
    --color-gas-bg: rgba(245, 158, 11, 0.08);

    --color-success: #10b981;
    --color-danger: #ef4444;

    /* Texte */
    --color-text-primary: #f1f5f9;
    --color-text-secondary: #94a3b8;
    --color-text-muted: #64748b;

    /* Spacing */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-elec: 0 0 20px var(--color-elec-glow);
    --shadow-gas: 0 0 20px var(--color-gas-glow);
}

/* --- Reset & Base --- */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--color-bg);
    color: var(--color-text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Background gradient effect */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background:
        radial-gradient(ellipse 80% 50% at 20% 0%, rgba(59, 130, 246, 0.08) 0%, transparent 60%),
        radial-gradient(ellipse 60% 40% at 80% 10%, rgba(245, 158, 11, 0.06) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

/* --- Layout --- */
.app-container {
    position: relative;
    z-index: 1;
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px 32px 48px;
}

.main-content {
    opacity: 1;
    transition: opacity 150ms ease;
}

.main-content.fade-out {
    opacity: 0;
}

.main-content.fade-in {
    opacity: 1;
}

/* --- Header --- */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--color-elec), var(--color-gas));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    box-shadow: var(--shadow-md);
}

.header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--color-text-primary) 0%, var(--color-text-secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-subtitle {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    font-weight: 400;
    margin-top: 2px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.data-source-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0 16px;
    height: 36px;
    box-sizing: border-box;
    border-radius: 9999px;
    font-size: 0.85rem;
    font-weight: 500;
}

.badge-success {
    background: rgba(16, 185, 129, 0.12);
    color: var(--color-success);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.badge-loading {
    background: rgba(245, 158, 11, 0.12);
    color: var(--color-gas-light);
    border: 1px solid rgba(245, 158, 11, 0.2);
}

.badge-error {
    background: rgba(239, 68, 68, 0.12);
    color: var(--color-danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.badge-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.last-updated {
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

/* --- Clean Buttons --- */
.btn-clean {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.08);
    color: #94a3b8;
    height: 36px;
    padding: 0 16px;
    box-sizing: border-box;
    border-radius: 9999px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s ease;
}
.btn-clean:hover {
    background: rgba(255,255,255,0.05);
    color: #f1f5f9;
}
.refresh-icon {
    display: inline-block;
}
.refresh-icon.spin {
    animation: spin-icon 1s linear infinite;
}
@keyframes spin-icon {
    100% { transform: rotate(360deg); }
}

/* --- KPI Cards Section --- */
.kpi-section {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 32px;
}

.kpi-card {
    background: var(--color-surface);
    border: 1px solid var(--color-surface-border);
    border-radius: var(--radius-lg);
    padding: 24px;
    position: relative;
    overflow: hidden;
    transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
}

.kpi-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.kpi-card.elec:hover {
    border-color: rgba(59, 130, 246, 0.3);
    box-shadow: var(--shadow-elec);
}

.kpi-card.gas:hover {
    border-color: rgba(245, 158, 11, 0.3);
    box-shadow: var(--shadow-gas);
}

/* Accent bar at top of card */
.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.kpi-card.elec::before {
    background: linear-gradient(90deg, var(--color-elec), var(--color-elec-light));
}

.kpi-card.gas::before {
    background: linear-gradient(90deg, var(--color-gas), var(--color-gas-light));
}

/* Icon glow behind card */
.kpi-card::after {
    content: '';
    position: absolute;
    top: -40px;
    right: -40px;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    opacity: 0.06;
    transition: opacity 0.3s ease;
}

.kpi-card.elec::after {
    background: var(--color-elec);
}

.kpi-card.gas::after {
    background: var(--color-gas);
}

.kpi-card:hover::after {
    opacity: 0.12;
}

.kpi-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.kpi-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--color-text-secondary);
}

.kpi-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.kpi-card.elec .kpi-icon {
    background: var(--color-elec-bg);
}

.kpi-card.gas .kpi-icon {
    background: var(--color-gas-bg);
}

.kpi-variation {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.kpi-variation.positive {
    background: rgba(239, 68, 68, 0.12);
    color: var(--color-danger);
}

.kpi-variation.negative {
    background: rgba(16, 185, 129, 0.12);
    color: var(--color-success);
}

.kpi-value {
    font-size: 2.2rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.1;
    margin-bottom: 4px;
}

.kpi-card.elec .kpi-value {
    color: var(--color-elec-light);
}

.kpi-card.gas .kpi-value {
    color: var(--color-gas-light);
}

.kpi-unit {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    font-weight: 400;
}

.kpi-footer {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--color-surface-border);
    font-size: 0.78rem;
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

/* --- Charts Section --- */
.charts-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-bottom: 32px;
}

.chart-card {
    background: var(--color-surface);
    border: 1px solid var(--color-surface-border);
    border-radius: var(--radius-lg);
    padding: 28px;
    transition: box-shadow 0.3s ease;
}

.chart-card:hover {
    box-shadow: var(--shadow-md);
}

.chart-card.full-width {
    grid-column: 1 / -1;
}

.chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.chart-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--color-text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.chart-title-icon {
    font-size: 18px;
}

.chart-legend {
    display: flex;
    align-items: center;
    gap: 20px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--color-text-secondary);
}

.legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.legend-dot.elec {
    background: var(--color-elec);
    box-shadow: 0 0 8px var(--color-elec-glow);
}

.legend-dot.gas {
    background: var(--color-gas);
    box-shadow: 0 0 8px var(--color-gas-glow);
}

.chart-container {
    position: relative;
    height: 320px;
    width: 100%;
}

.chart-scroll-wrapper {
    width: 100%;
    margin-top: 10px;
}

.chart-inner-container {
    position: relative;
    width: 100%;
    height: 100%;
}

canvas {
    width: 100% !important;
    height: 100% !important;
}

/* --- Daily Chart (full width) --- */
.daily-chart-container {
    height: 260px;
}

/* --- Loading & Error States --- */
.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(11, 15, 26, 0.85);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 10;
    opacity: 1;
    transition: opacity 0.4s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--color-surface-border);
    border-top-color: var(--color-elec);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.error-message {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: var(--radius-md);
    padding: 16px 20px;
    color: var(--color-danger);
    font-size: 0.85rem;
    display: none;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
}

.error-message.visible {
    display: flex;
}

/* --- Footer --- */
.footer {
    text-align: center;
    padding-top: 24px;
    border-top: 1px solid var(--color-surface-border);
    font-size: 0.78rem;
    color: var(--color-text-muted);
}

.footer a {
    color: var(--color-elec-light);
    text-decoration: none;
    transition: color 0.2s ease;
}

.footer a:hover {
    color: var(--color-elec);
}

/* --- Skeleton Loading Animation --- */
.skeleton {
    background: linear-gradient(90deg,
        var(--color-surface) 25%,
        var(--color-surface-hover) 50%,
        var(--color-surface) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-sm);
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-value {
    width: 120px;
    height: 36px;
    margin-bottom: 4px;
}

.skeleton-text {
    width: 80px;
    height: 14px;
}

/* --- Responsive Design --- */
@media (max-width: 1200px) {
    .kpi-section {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 900px) {
    .app-container {
        padding: 16px 20px 32px;
    }

    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    .charts-section {
        grid-template-columns: 1fr;
    }

    .kpi-section {
        grid-template-columns: 1fr 1fr;
    }

    .kpi-value {
        font-size: 1.8rem;
    }
}

@media (max-width: 600px) {
    .kpi-section {
        grid-template-columns: 1fr;
    }

    .header h1 {
        font-size: 1.35rem;
    }

    .chart-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
}

/* --- Fade-in animation --- */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-in {
    animation: fadeInUp 0.5s ease forwards;
    opacity: 0;
}

.animate-in:nth-child(1) { animation-delay: 0.05s; }
.animate-in:nth-child(2) { animation-delay: 0.1s; }
.animate-in:nth-child(3) { animation-delay: 0.15s; }
.animate-in:nth-child(4) { animation-delay: 0.2s; }
/* ============================================================
   NAVIGATION BAR
   ============================================================ */
.main-nav {
    margin: 0 0 24px 0;
    padding: 0;
}

.nav-list {
    list-style: none;
    display: flex;
    justify-content: center;
    gap: 20px;
    padding: 4px;
    margin: 0;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 9999px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.nav-link {
    display: flex;
    justify-content: center;
    text-align: center;
    padding: 8px 24px;
    color: #94a3b8; /* text muted */
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9em;
    border-radius: 9999px;
    transition: all 0.2s ease;
}

.nav-link:hover {
    color: #f8fafc;
    background: rgba(255, 255, 255, 0.05);
}

.nav-link.active {
    color: #f8fafc;
    background: #1e293b;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

@media (max-width: 768px) {
    /* 0. Bloquer le scroll général destructeur */
    html, body {
        overflow-x: hidden !important;
        width: 100vw !important;
        max-width: 100vw !important;
    }

    /* 1. Cartes de données (KPI & Chart) : Contraintes à l'écran */
    .kpi-section {
        display: flex !important;
        flex-direction: column !important;
        gap: 15px !important;
        width: 100% !important;
    }
    .kpi-card,
    .chart-card,
    .table-card {
        width: 100% !important;
        max-width: 100vw !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
    }

    /* 2. Menu de Navigation : Scroll horizontal fluide */
    .nav-list {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        justify-content: flex-start !important;
        gap: 10px !important;
        padding-bottom: 5px !important;
        width: 100% !important;
        border: none !important;
        background: transparent !important;
        -ms-overflow-style: none;
        scrollbar-width: none;
    }
    .nav-list::-webkit-scrollbar {
        display: none;
    }
    .nav-link {
        flex-shrink: 0 !important;
    }

    /* 3. Graphiques et Tableaux : Scroll horizontal contrôlé (WRAPPER) */
    .chart-scroll-wrapper,
    .data-table-container,
    .table-responsive {
        width: 100% !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    .chart-inner-container {
        min-width: 600px !important;
    }
    
    .data-table {
        min-width: 600px !important;
    }

    /* 4. En-tête et alignements mobiles */
    .header {
        flex-direction: column !important;
        align-items: center !important;
        text-align: center !important;
        gap: 20px !important;
    }
    .header-left, .header-right {
        flex-direction: column !important;
        align-items: center !important;
        width: 100% !important;
        gap: 12px !important;
    }
    .row-header {
        flex-direction: column !important;
        align-items: center !important;
        text-align: center !important;
        gap: 15px !important;
    }
    .input-date {
        width: 100% !important;
        max-width: 300px !important;
    }
}
.input-date {
    padding: 10px 16px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: #111827;
    color: #f8fafc;
    font-size: 0.95rem;
    width: 280px;
    font-family: inherit;
    font-weight: 500;
    text-align: center;
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.input-date:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.row-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.row-date {
    display: flex;
    align-items: center;
}
/* ============================================================
   TABLEAUX DE DONN�ES
   ============================================================ */
.data-table-section {
    margin-top: 30px;
}

.table-card {
    background: var(--color-surface);
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    border: 1px solid var(--color-surface-border);
}

.table-card h3 {
    margin: 0 0 20px 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: white;
}

.table-responsive {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.95rem;
}

.data-table th, .data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-surface-border);
}

.data-table th {
    font-weight: 600;
    color: #94a3b8;
    background-color: var(--color-bg-secondary);
}

.data-table tbody tr {
    transition: background-color 0.2s ease;
    color: #f8fafc;
}

.data-table tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.04);
}

.text-center {
    text-align: center;
}

.page-title {
    margin-bottom: 30px;
}

.page-title h2 {
    font-size: 1.8rem;
    color: white;
    margin: 0 0 8px 0;
}

.page-title p {
    color: #94a3b8;
    margin: 0;
}

/* NEW: Cost Badges */
.kpi-cost-badge {
    margin-top: 8px;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-elec-light);
    background: var(--color-bg-secondary);
    display: inline-block;
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid var(--color-surface-border);
}
.kpi-card.gas .kpi-cost-badge {
    color: var(--color-gas-light);
}
