/**
 * ============================================================================
 * Styles des Graphiques Chart.js
 * ============================================================================
 *
 * @projet     Province de Zagora - Plateforme Territoriale Integree
 * @fichier    chart-enhancements.css
 *
 * @description
 * Styles pour les conteneurs de graphiques Chart.js :
 *   - Container avec fond degrade et bordure reactive
 *   - Barre d'outils (titre, boutons export)
 *   - Tooltips personnalises
 *   - Responsive (redimensionnement automatique)
 *
 * @utilise_par  dashboard.html, tableau-bord.html, rgph2024.html
 * ============================================================================
 */

/* =================================================================
   Container des graphiques
   ================================================================= */
.chart-container {
    position: relative;
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.95) 0%, rgba(15, 23, 42, 0.95) 100%);
    border-radius: 16px;
    padding: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.3s ease;
}

.chart-container:hover {
    border-color: rgba(249, 115, 22, 0.3);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.chart-container:fullscreen {
    background: #0f172a;
    padding: 40px;
    display: flex;
    flex-direction: column;
}

.chart-container:fullscreen canvas {
    flex: 1;
    max-height: calc(100vh - 120px);
}

/* =================================================================
   Boutons d'action
   ================================================================= */
.chart-actions {
    position: absolute;
    top: 12px;
    right: 12px;
    display: flex;
    gap: 8px;
    z-index: 10;
    opacity: 0;
    transform: translateY(-5px);
    transition: all 0.3s ease;
}

.chart-container:hover .chart-actions,
.chart-card:hover .chart-actions {
    opacity: 1;
    transform: translateY(0);
}

.chart-action-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(15, 23, 42, 0.9);
    color: #94a3b8;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all 0.2s ease;
    backdrop-filter: blur(8px);
}

.chart-action-btn:hover {
    background: rgba(249, 115, 22, 0.2);
    color: #f97316;
    border-color: rgba(249, 115, 22, 0.5);
    transform: scale(1.1);
}

.chart-action-btn:active {
    transform: scale(0.95);
}

.chart-action-btn i {
    pointer-events: none;
}

/* Bouton télécharger */
.chart-action-btn[data-action="download"]:hover {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
    border-color: rgba(34, 197, 94, 0.5);
}

/* Bouton plein écran */
.chart-action-btn[data-action="fullscreen"]:hover {
    background: rgba(59, 130, 246, 0.2);
    color: #3b82f6;
    border-color: rgba(59, 130, 246, 0.5);
}

/* =================================================================
   Toast Notifications
   ================================================================= */
.chart-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: rgba(15, 23, 42, 0.95);
    color: #fff;
    padding: 14px 24px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 10000;
    font-size: 14px;
    font-weight: 500;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(16px);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chart-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.chart-toast-success {
    border-color: rgba(34, 197, 94, 0.5);
}

.chart-toast-success i {
    color: #22c55e;
}

.chart-toast-error {
    border-color: rgba(239, 68, 68, 0.5);
}

.chart-toast-error i {
    color: #ef4444;
}

.chart-toast-info i {
    color: #3b82f6;
}

/* =================================================================
   Légende améliorée
   ================================================================= */
.chart-legend-custom {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    padding: 16px 0;
    justify-content: center;
}

.chart-legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 13px;
    color: #e2e8f0;
}

.chart-legend-item:hover {
    background: rgba(249, 115, 22, 0.15);
    border-color: rgba(249, 115, 22, 0.3);
}

.chart-legend-item.hidden {
    opacity: 0.4;
    text-decoration: line-through;
}

.chart-legend-color {
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

/* =================================================================
   Tooltips améliorés
   ================================================================= */
.chartjs-tooltip {
    background: rgba(15, 23, 42, 0.98) !important;
    border: 1px solid rgba(249, 115, 22, 0.4) !important;
    border-radius: 12px !important;
    padding: 16px !important;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5) !important;
    backdrop-filter: blur(16px);
}

.chartjs-tooltip-title {
    color: #f97316 !important;
    font-weight: 700 !important;
    font-size: 14px !important;
    margin-bottom: 8px !important;
    padding-bottom: 8px !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
}

.chartjs-tooltip-body {
    color: #e2e8f0 !important;
    font-size: 13px !important;
    line-height: 1.6 !important;
}

/* =================================================================
   Animations des graphiques
   ================================================================= */
@keyframes chartFadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes chartPulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.02);
    }
}

@keyframes chartGlow {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(249, 115, 22, 0);
    }
    50% {
        box-shadow: 0 0 20px 5px rgba(249, 115, 22, 0.2);
    }
}

.chart-animated {
    animation: chartFadeIn 0.6s ease-out;
}

.chart-container.highlight {
    animation: chartGlow 2s ease-in-out infinite;
}

/* =================================================================
   Types de graphiques spécifiques
   ================================================================= */

/* Doughnut/Pie avec centre */
.chart-center-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    pointer-events: none;
}

.chart-center-value {
    font-size: 2rem;
    font-weight: 800;
    color: #f97316;
    line-height: 1;
}

.chart-center-label {
    font-size: 0.8rem;
    color: #94a3b8;
    margin-top: 4px;
}

/* Barres avec gradient */
.chart-bar-gradient {
    background: linear-gradient(180deg, rgba(249, 115, 22, 0.8) 0%, rgba(234, 88, 12, 0.6) 100%);
}

/* =================================================================
   Options de filtrage
   ================================================================= */
.chart-filters {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.chart-filter-btn {
    padding: 8px 16px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: transparent;
    color: #94a3b8;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chart-filter-btn:hover {
    background: rgba(249, 115, 22, 0.15);
    border-color: rgba(249, 115, 22, 0.3);
    color: #f97316;
}

.chart-filter-btn.active {
    background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
    border-color: transparent;
    color: #fff;
}

/* Select amélioré */
.chart-select {
    padding: 10px 36px 10px 16px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(15, 23, 42, 0.8);
    color: #e2e8f0;
    font-size: 13px;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    transition: all 0.2s ease;
}

.chart-select:hover,
.chart-select:focus {
    border-color: rgba(249, 115, 22, 0.5);
    outline: none;
}

.chart-select option {
    background: #1e293b;
    color: #e2e8f0;
}

/* =================================================================
   En-tête de graphique avec titre
   ================================================================= */
.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.chart-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 10px;
}

.chart-title i {
    color: #f97316;
    font-size: 1rem;
}

.chart-subtitle {
    font-size: 0.85rem;
    color: #64748b;
    margin-top: 4px;
}

/* Badge de statut */
.chart-badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.chart-badge-up {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
}

.chart-badge-down {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

.chart-badge-neutral {
    background: rgba(148, 163, 184, 0.2);
    color: #94a3b8;
}

/* =================================================================
   Responsive
   ================================================================= */
@media (max-width: 768px) {
    .chart-actions {
        opacity: 1;
        transform: translateY(0);
        position: static;
        justify-content: flex-end;
        margin-bottom: 12px;
    }

    .chart-action-btn {
        width: 40px;
        height: 40px;
    }

    .chart-filters {
        overflow-x: auto;
        flex-wrap: nowrap;
        padding-bottom: 8px;
        -webkit-overflow-scrolling: touch;
    }

    .chart-filter-btn {
        flex-shrink: 0;
    }

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

    .chart-legend-custom {
        gap: 8px;
    }

    .chart-legend-item {
        padding: 6px 12px;
        font-size: 12px;
    }
}

/* =================================================================
   États de chargement
   ================================================================= */
.chart-loading {
    position: relative;
    min-height: 200px;
}

.chart-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    border: 3px solid rgba(249, 115, 22, 0.2);
    border-top-color: #f97316;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.chart-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    color: #64748b;
    text-align: center;
}

.chart-empty i {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.5;
}

.chart-empty p {
    font-size: 14px;
}

/* =================================================================
   Comparaison de périodes
   ================================================================= */
.chart-comparison {
    display: flex;
    gap: 16px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
    margin-top: 16px;
}

.chart-comparison-item {
    flex: 1;
    text-align: center;
    padding: 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
}

.chart-comparison-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #fff;
}

.chart-comparison-label {
    font-size: 0.8rem;
    color: #64748b;
    margin-top: 4px;
}

.chart-comparison-change {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 8px;
    font-size: 0.85rem;
    font-weight: 600;
}

.chart-comparison-change.positive {
    color: #22c55e;
}

.chart-comparison-change.negative {
    color: #ef4444;
}
