/* =========================================
   VARIABLES & DESIGN SYSTEM
   ========================================= */
:root {
    --bg-body: #f1f5f9;
    --bg-card: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --accent: #3b82f6;
    --accent-soft: rgba(59, 130, 246, 0.1);
    --shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
    --btn-group-bg: #f8fafc;
}

[data-theme="dark"] {
    --bg-body: #0f172a;
    --bg-card: #1e293b;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --border-color: #334155;
    --accent: #60a5fa;
    --accent-soft: rgba(96, 165, 250, 0.1);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    --btn-group-bg: #0f172a;
}

/* =========================================
   STRUCTURE & BASE
   ========================================= */
body { 
    font-family: 'Inter', -apple-system, sans-serif; 
    background-color: var(--bg-body); 
    color: var(--text-main);
    margin: 0; 
    padding: 20px; 
    transition: background 0.3s ease;
}

.container { 
    max-width: 1400px; 
    margin: auto; 
}

/* =========================================
   HEADER CLINIQUE
   ========================================= */
.clinical-header {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 20px 30px;
    margin-bottom: 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
}

.brand-identity { display: flex; flex-direction: column; gap: 8px; }
.app-logo { display: flex; align-items: center; gap: 12px; font-weight: 800; font-size: 1.1rem; }
.logo-circle { width: 28px; height: 28px; background: linear-gradient(135deg, #3b82f6, #2dd4bf); border-radius: 8px; }

.header-actions { display: flex; align-items: center; gap: 15px; }
.status-badge { font-size: 0.65rem; text-transform: uppercase; font-weight: 700; color: var(--text-muted); background: var(--btn-group-bg); padding: 4px 10px; border-radius: 100px; border: 1px solid var(--border-color); }

.theme-btn {
    background: var(--btn-group-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 8px 15px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-main);
    transition: 0.2s;
}

/* INPUTS */
.clinical-inputs { display: flex; gap: 20px; }
.input-field { display: flex; align-items: center; gap: 10px; padding-left: 20px; border-left: 1px solid var(--border-color); }
.field-content { display: flex; flex-direction: column; }
.field-content label { font-size: 0.6rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; }
.field-content input { border: none; background: transparent; font-size: 0.85rem; font-weight: 600; color: var(--text-main); outline: none; width: 120px; }

/* =========================================
   GRILLE & PANELS (ALIGNEMENT PARFAIT)
   ========================================= */
.section-container { margin-bottom: 40px; }

.section-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border-color);
}

.graph-grid { 
    display: grid; 
    /* Crée des colonnes flexibles mais centrées */
    grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); 
    gap: 30px; 
    justify-items: center; /* Centre les panels dans leurs colonnes respectives */
    width: 100%;
}

.panel { 
    background: var(--bg-card); 
    padding: 30px; 
    border-radius: 24px; 
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    
    width: 100%;
    max-width: 700px; /* Brider la largeur pour la précision clinique */
    box-sizing: border-box;
    
    display: flex;
    flex-direction: column;
}

.graph-header { 
    width: 100%; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    margin-bottom: 30px; 
}

.side-label { font-weight: 800; font-size: 1.1rem; color: var(--text-main); }

/* =========================================
   CANVAS - OCCUPATION TOTALE
   ========================================= */
canvas { 
    /* Indispensable pour supprimer le vide à droite */
    width: 100% !important; 
    height: 300px; 
    display: block;
    cursor: crosshair;
    /* On s'assure qu'aucune marge parasite n'existe */
    margin: 0; 
}

/* =========================================
   CONTROLES & BOUTONS
   ========================================= */
.btn-group { background: var(--btn-group-bg); padding: 4px; border-radius: 12px; display: flex; border: 1px solid var(--border-color); }
.btn-group button { border: none; padding: 8px 16px; cursor: pointer; border-radius: 8px; font-size: 0.75rem; font-weight: 700; background: transparent; color: var(--text-muted); transition: 0.2s; }
.btn-group button.active { background: var(--bg-card); color: var(--accent); box-shadow: 0 4px 10px rgba(0,0,0,0.08); }

.display-options { display: flex; gap: 12px; }
.chip-checkbox {
    background: var(--bg-card);
    padding: 8px 16px;
    border-radius: 100px;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
    cursor: pointer;
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 8px;
    transition: 0.2s;
}
.chip-checkbox:has(input:checked) { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

/* =========================================
   RESPONSIVE
   ========================================= */
@media (max-width: 1100px) {
    .clinical-header { flex-direction: column; align-items: stretch; gap: 20px; }
    .clinical-inputs { flex-wrap: wrap; }
    .input-field { border: none; padding-left: 0; border-left: none; }
}

@media (max-width: 500px) {
    .graph-grid { grid-template-columns: 1fr; }
    .panel { padding: 20px; }
}

/* Style du bouton Exporter PDF */
.export-pdf-btn {
    background-color: var(--bg-card);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 8px 16px;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
    box-shadow: var(--shadow);
}

/* Petite icône avant le texte PDF */
.export-pdf-btn::before {
    content: ""; /* Icône de téléchargement discrète */
    font-size: 1.1rem;
}


@media print {
    /* 1. On cache l'interface inutile */
    #theme-toggle, .btn-group, .header-actions, .display-options, button, .status-badge {
        display: none !important;
    }
    .export-pdf-btn {
        display: none !important;
    }
    /* 2. On prépare la page */
    body {
        background: white !important;
        color: black !important;
        padding: 0;
        margin: 0;
    }

    .container {
        max-width: 100% !important;
        width: 100% !important;
        margin: 0 !important;
    }

    /* 3. GESTION DES COUPURES (Le secret est ici) */
    .section-container {
        page-break-inside: avoid; /* Empêche de couper entre le titre et ses graphs */
        break-inside: avoid;
        margin-bottom: 30px !important;
    }

    .panel {
        page-break-inside: avoid !important; /* Force le graph à rester d'un seul bloc */
        break-inside: avoid !important;
        border: 1px solid #eee !important;
        box-shadow: none !important;
        display: block !important;
        margin-bottom: 20px !important;
    }

    /* 4. On force une colonne unique pour que les graphs soient bien larges sur le PDF */
    .graph-grid {
        display: block !important;
    }

    /* 5. On s'assure que le texte est bien noir (pas de gris clair du mode sombre) */
    .side-label, .field-content label, .field-content input {
        color: black !important;
    }
}

.lang-selector {
    position: absolute; /* Ou 'fixed' si tu veux qu'il reste visible au scroll */
    top: 20px;
    right: 20px;
    z-index: 9999; /* Pour passer par-dessus les autres éléments */
}
/* On peaufine le bouton pour qu'il soit discret mais élégant */
.btn-globe {
    background: rgba(44, 62, 80, 0.8); /* Fond sombre semi-transparent */
    backdrop-filter: blur(5px); /* Effet de flou moderne */
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 8px 15px;
    border-radius: 30px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    transition: all 0.2s ease;
}

.btn-globe:hover {
    background: #2c3e50;
    transform: translateY(-1px);
}

/* Le menu doit s'ouvrir vers la gauche pour ne pas sortir de l'écran */
.lang-dropdown {
    display: none;
    position: absolute;
    right: 0; 
    top: 45px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    min-width: 160px;
    overflow: hidden;
    border: 1px solid #eee;
}

.lang-dropdown a {
    color: #2c3e50;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    font-size: 14px;
    border-bottom: 1px solid #f8f9fa;
}

.lang-dropdown a:last-child { border-bottom: none; }

.lang-dropdown a:hover {
    background: #f8f9fa;
    color: #3498db;
}

.show-lang {
    display: block !important;
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.error-label {
    background-color: rgba(231, 76, 60, 0.1);
    color: #e74c3c;
    padding: 12px 15px;
    border-radius: 8px;
    border: 1px solid rgba(231, 76, 60, 0.3);
    margin: 10px auto 10px auto; /* Centrage du bloc (haut, droite, bas, gauche) */
    font-size: 0.9em;
    
    display: flex;
    align-items: center;    /* Aligne l'icône et le texte verticalement */
    justify-content: center; /* Aligne le contenu horizontalement au centre */
    text-align: center;      /* Centre le texte si celui-ci passe sur deux lignes */
    
    max-width: 400px;        /* Optionnel : limite la largeur pour un meilleur look */
    animation: shake 0.4s ease-in-out;
}

.error-icon {
    font-size: 1.1em;
}

/* Animation pour attirer l'oeil sur l'erreur */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.lang-settings-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.lang-button-group {
    display: flex;
    background: #f1f3f5;
    padding: 5px;
    border-radius: 50px; /* Forme pilule */
    gap: 5px;
}

.lang-btn {
    border: none;
    background: none;
    padding: 10px 25px;
    border-radius: 40px;
    cursor: pointer;
    font-weight: 500;
    color: #495057;
    transition: all 0.3s ease;
}

/* Style du bouton sélectionné (surbrillance) */
.lang-btn.active {
    background: #ffffff;
    color: #3498db; /* Couleur de ta charte */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transform: scale(1.05);
}

.lang-btn:hover:not(.active) {
    background: rgba(255, 255, 255, 0.5);
}

/* Bouton enregistrer */
.btn-save-lang {
    background: #3498db;
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.2s;
}

.btn-save-lang:hover {
    background: #2980b9;
}