:root {
    --cfdt-orange: #f37021; 
    --cfdt-orange-hover: #d65b13; 
    --cfdt-bg: #f4f7f6;
    --text-color: #333333; 
    --text-light: #666666; 
    --card-shadow: 0 10px 25px rgba(0,0,0,0.05);
    --border-radius: 12px; 
    --danger-color: #e74c3c;
    --success-color: #2e7d32;
}

body { 
    margin: 0; 
    font-family: 'Montserrat', sans-serif; 
    background: var(--cfdt-bg); 
    color: var(--text-color); 
    line-height: 1.5; 
    padding-top: 40px; 
}

/* =========================================
   1. AUTH OVERLAY (OPTIMISÉ MOBILE)
   ========================================= */
body.locked { overflow: hidden; }
body.locked main, body.locked header { filter: blur(5px); pointer-events: none; }

#auth-overlay { 
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; 
    background: rgba(255, 247, 239, 0.95); backdrop-filter: blur(5px); 
    z-index: 9999; display: flex; align-items: center; justify-content: center; 
    padding: 10px; /* Petit padding pour éviter de coller aux bords */
}

.auth-card { 
    background: white; width: 100%; max-width: 420px; 
    padding: 25px; /* Réduit de 30 à 25 */
    border-radius: 15px; box-shadow: 0 15px 40px rgba(0,0,0,0.15); 
    text-align: center; border-top: 5px solid var(--cfdt-orange); 
    max-height: 90vh; /* Empêche de déborder de l'écran */
    overflow-y: auto; /* Scroll si vraiment trop petit */
}

/* Logo réduit sur mobile */
.auth-logo { width: 150px; margin-bottom: 5px; } 

.auth-header h2 { color: var(--cfdt-orange); margin: 5px 0; font-size: 1.3rem; }
.auth-header p { color: #666; font-size: 0.85rem; margin-bottom: 15px; }

.auth-tabs { display: flex; margin-bottom: 15px; border-bottom: 2px solid #eee; }
.tab-btn { 
    flex: 1; background: none; border: none; padding: 8px; 
    font-family: 'Montserrat', sans-serif; font-weight: 600; color: #999; 
    cursor: pointer; border-bottom: 3px solid transparent; font-size: 0.9rem;
}
.tab-btn.active { color: var(--cfdt-orange); border-bottom-color: var(--cfdt-orange); }

.auth-form { display: none; text-align: left; }
.auth-form.active { display: block; }

/* Espacements réduits dans le formulaire */
.form-group { margin-bottom: 15px; }
.form-instruction { font-size: 0.8rem; color: #888; margin-bottom: 10px; font-style: italic; line-height: 1.3; }
.full-width { width: 100%; margin-top: 5px; padding: 12px; }
.error-msg { color: var(--danger-color); font-size: 0.85rem; margin-top: 5px; text-align: center; min-height: 20px; }

/* --- CHAMPS DE CONNEXION --- */
.input-group, .password-wrapper { position: relative; display: flex; align-items: center; }
.input-icon-left { position: absolute; left: 12px; font-size: 1.1rem; color: #777; pointer-events: none; }
.toggle-password { position: absolute; right: 12px; cursor: pointer; font-size: 1.1rem; color: #777; user-select: none; transition: color 0.2s; }
.toggle-password:hover { color: var(--cfdt-orange); }

/* Inputs : padding ajusté */
.input-group input, .password-wrapper input {
    padding-left: 35px !important; padding-right: 35px !important;
    height: 45px; /* Hauteur fixe confortable */
}

.remember-me-group { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: #555; cursor: pointer; margin-bottom: 0; }
.remember-me-group input[type="checkbox"] { accent-color: var(--cfdt-orange); width: 16px; height: 16px; cursor: pointer; margin: 0; }
.remember-me-group label { cursor: pointer; margin-bottom: 0; font-weight: 500; }

.form-options { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; font-size: 0.85rem; }
a.forgot-pass { color: var(--cfdt-orange); text-decoration: none; font-weight: 600; }

/* === MODALE NOTIF === */
#notification-modal { z-index: 10000; text-align: center; }
.notification-content { max-width: 380px; padding: 30px; border-top: 5px solid var(--success-color); border-radius: 15px; animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
@keyframes popIn { from { opacity: 0; transform: scale(0.8); } to { opacity: 1; transform: scale(1); } }
.icon-circle { width: 60px; height: 60px; background: #e8f5e9; color: var(--success-color); font-size: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin: 0 auto 15px auto; }
#notif-title { color: var(--success-color); font-size: 1.4rem; margin: 0 0 8px 0; }
#notif-message { color: #555; font-size: 0.95rem; margin-bottom: 20px; line-height: 1.4; }

/* =========================================
   2. HEADER & MAIN
   ========================================= */
header { 
    max-width: 900px; margin: 0 auto 30px; background: white; 
    box-shadow: var(--card-shadow); border-radius: var(--border-radius); 
    padding: 20px 30px; box-sizing: border-box; position: relative; z-index: 1; 
}
.header-inner { display: flex; flex-direction: row; justify-content: space-between; align-items: center; gap: 40px; }
.header-left { display: flex; flex-direction: column; align-items: center; gap: 15px; flex-shrink: 0; }
.cfdt-logo { width: 140px; height: auto; }
.contact-under-logo { display: flex; flex-direction: column; gap: 5px; font-size: 0.85rem; color: var(--text-light); text-align: center; }
.contact-under-logo span { background: #f9f9f9; padding: 4px 10px; border-radius: 15px; border: 1px solid #eee; white-space: nowrap; }
.header-right { text-align: right; flex: 1; display: flex; flex-direction: column; align-items: flex-end; }
.header-right h1 { font-size: 1.6rem; color: var(--cfdt-orange); margin: 0 0 5px 0; font-weight: 800; line-height: 1.2; }
.subtitle-group { margin-bottom: 12px; }
.main-subtitle { font-size: 1rem; font-weight: 700; color: #222; margin: 0; }
.sub-subtitle { font-size: 0.9rem; font-weight: 700; color: #666; margin: 0; }
.user-welcome { color: var(--success-color); font-weight: 600; font-size: 1rem; margin: 5px 0 15px 0; }
.header-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.header-btn { text-decoration: none; background: #fff; color: var(--cfdt-orange); padding: 6px 12px; border-radius: 20px; border: 1px solid var(--cfdt-orange); font-weight: 600; font-size: 0.85rem; transition: all 0.3s ease; display: flex; align-items: center; gap: 5px; }
.header-btn:hover { background: var(--cfdt-orange); color: white; transform: translateY(-2px); box-shadow: 0 4px 8px rgba(243, 112, 33, 0.2); }
.logout-link { color: var(--danger-color) !important; margin-left: 10px; font-weight: bold; font-size: 0.85rem; text-decoration: none; border-bottom: 1px dashed transparent; transition: 0.3s; cursor: pointer; }
.logout-link:hover { border-bottom-color: var(--danger-color); }

main { max-width: 900px; margin: 0 auto 50px; background: white; padding: 40px; border-radius: var(--border-radius); box-shadow: var(--card-shadow); box-sizing: border-box; }
.info-section { background: #fff8f3; border-left: 5px solid var(--cfdt-orange); padding: 15px 20px; border-radius: 8px; margin-bottom: 30px; }
.info-section h2 { font-size: 1.1rem; color: var(--cfdt-orange); margin: 0 0 5px 0; }
.info-section p { margin: 0; font-size: 0.9rem; color: #555; }

.calculator-form { display: flex; flex-direction: column; gap: 20px; }
.form-row { display: flex; gap: 20px; }
.form-group { flex: 1; display: flex; flex-direction: column; }
.form-group label { font-size: 0.9rem; font-weight: 600; margin-bottom: 8px; color: #444; display: flex; align-items: center; }
.form-group input, .form-group select { padding: 12px 15px; border: 1px solid #ddd; border-radius: 8px; font-size: 1rem; font-family: 'Montserrat', sans-serif; transition: all 0.3s ease; background-color: #fcfcfc; width: 100%; box-sizing: border-box; }
.form-group input:focus { border-color: var(--cfdt-orange); outline: none; background-color: white; box-shadow: 0 0 0 3px rgba(243, 112, 33, 0.15); }

.tooltip-icon { display: inline-block; width: 18px; height: 18px; background: #eee; color: #666; border-radius: 50%; text-align: center; line-height: 18px; font-size: 0.75rem; font-weight: bold; margin-left: 6px; cursor: help; position: relative; vertical-align: middle; }
.tooltip-icon:hover { background: var(--cfdt-orange); color: white; }
.tooltip-icon:hover::after { content: attr(data-tooltip); position: absolute; bottom: 135%; left: 50%; transform: translateX(-50%); background: #333; color: white; padding: 8px 12px; border-radius: 6px; font-size: 0.75rem; width: 220px; text-align: center; line-height: 1.4; z-index: 100; box-shadow: 0 4px 10px rgba(0,0,0,0.2); font-weight: normal; }
.tooltip-icon:hover::before { content: ""; position: absolute; bottom: 110%; left: 50%; margin-left: -5px; border-width: 5px; border-style: solid; border-color: #333 transparent transparent transparent; }

.dates-section { background: #fdfdfd; border: 1px solid #eee; padding: 20px; border-radius: 8px; }
.dates-top-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
.section-label { display: block; font-weight: 700; color: var(--cfdt-orange); margin: 0; }
.btn-reset-dates { background: none; border: none; color: #999; font-size: 0.75rem; text-decoration: underline; cursor: pointer; }
.btn-reset-dates:hover { color: var(--danger-color); }

.dates-header-row, .date-row { display: grid; grid-template-columns: 1fr 1fr 210px 40px; gap: 30px; align-items: center; }
.dates-header-row { font-weight: 600; font-size: 0.9rem; color: #444; margin-bottom: 10px; }
.date-row { margin-bottom: 15px; padding-bottom: 15px; border-bottom: 1px dashed #f0f0f0; }
.date-input-group input { padding: 10px; width: 100%; border: 1px solid #ddd; border-radius: 6px; }
.mobile-label { display: none; font-size: 0.8rem; font-weight: bold; margin-bottom: 4px; color: #666; }

.checkbox-wrapper { display: flex; align-items: center; gap: 12px; white-space: nowrap; background: #fff; padding: 8px 12px; border-radius: 6px; border: 1px solid #f0f0f0; }
.checkbox-wrapper input[type="checkbox"] { width: 20px; height: 20px; cursor: pointer; margin: 0; flex-shrink: 0; }
.checkbox-wrapper label { font-size: 0.85rem; line-height: 1.2; cursor: pointer; color: #555; margin: 0; }
.checkbox-wrapper small { color: var(--success-color); font-weight: bold; display: block; }

.btn-remove { background: #ffecec; color: #cc0000; border: 1px solid #ffcccc; width: 32px; height: 32px; border-radius: 50%; cursor: pointer; font-weight: bold; display: flex; align-items: center; justify-content: center; transition: 0.2s; justify-self: center; }
.btn-remove:hover { background: #ffcccc; }
.btn-add-date { background: none; border: 2px dashed #ddd; color: #666; padding: 10px; width: 100%; border-radius: 6px; cursor: pointer; font-weight: 600; transition: 0.3s; margin-top: 5px; }
.btn-add-date:hover { border-color: var(--cfdt-orange); color: var(--cfdt-orange); background: #fff8f3; }

.button-row { margin-top: 20px; display: flex; gap: 15px; }
.btn-primary { flex: 2; background: var(--cfdt-orange); color: white; border: none; padding: 14px 20px; font-size: 1rem; font-weight: 600; border-radius: 8px; cursor: pointer; transition: all 0.3s ease; box-shadow: 0 4px 6px rgba(243, 112, 33, 0.2); display: flex; align-items: center; justify-content: center; gap: 10px; }
.btn-primary:hover { background: var(--cfdt-orange-hover); transform: translateY(-2px); }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
.spinner { border: 3px solid rgba(255,255,255,0.3); border-top: 3px solid white; border-radius: 50%; width: 16px; height: 16px; animation: spin 1s linear infinite; display: inline-block; vertical-align: middle; margin-right: 8px; }
.btn-loading { background-color: #d65b13; cursor: not-allowed; opacity: 0.8; pointer-events: none; }
.btn-secondary { flex: 1; background: white; color: #555; border: 2px solid #eee; padding: 14px 20px; font-size: 1rem; font-weight: 600; border-radius: 8px; cursor: pointer; transition: all 0.3s; }
.btn-secondary:hover { border-color: var(--cfdt-orange); color: var(--cfdt-orange); background: #fff8f3; }
.btn-reset { flex: 0.8; background: #fdfdfd; color: var(--danger-color); border: 1px solid #eee; padding: 14px 10px; font-size: 1rem; font-weight: 600; border-radius: 8px; cursor: pointer; transition: all 0.3s; }
.btn-reset:hover { background: #fff5f5; border-color: #ffcccc; }

.modal { display: none; position: fixed; z-index: 2000; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.5); backdrop-filter: blur(3px); overflow: auto; padding: 20px 0; }
.modal-content { background-color: #fff; margin: 2% auto; padding: 30px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.3); width: 90%; max-width: 700px; position: relative; animation: slideDown 0.4s ease; }
@keyframes slideDown { from {opacity: 0; transform: translateY(-50px);} to {opacity: 1; transform: translateY(0);} }
.close-btn { color: #aaa; float: right; font-size: 28px; font-weight: bold; cursor: pointer; margin-top: -10px; }
.close-btn:hover { color: var(--cfdt-orange); }
.modal-header { text-align: center; border-bottom: 2px dashed #eee; padding-bottom: 15px; margin-bottom: 20px; display: flex; flex-direction: column; align-items: center; }
.modal-logo { width: 250px; height: auto; margin-bottom: 10px; }
.modal-header h3 { color: var(--cfdt-orange); margin: 0; font-size: 1.4rem; font-weight: 700; }
#modal-username { color: var(--success-color); font-weight: 800; }
.modal-footer-actions { margin-top: 30px; display: flex; justify-content: center; gap: 15px; }

.separator-dashed { border: 0; border-top: 2px dashed #e0e0e0; margin: 40px 0; width: 100%; }
.result-section { padding: 0 10px; text-align: center; position: relative; overflow: visible; }
.result-section h3 { color: var(--cfdt-orange); font-size: 1.6rem; font-weight: 800; margin-bottom: 30px; text-transform: none; }
.placeholder-text { text-align: center; color: #999; font-size: 1.2rem; font-weight: 300; }
.results-table { width: 100%; max-width: 600px; margin: 0 auto 30px auto; border-collapse: separate; border-spacing: 0; background: #fff; border-radius: 12px; overflow: hidden; box-shadow: 0 4px 15px rgba(0,0,0,0.05); border: 1px solid #eee; }
.results-table td { padding: 15px 20px; border-bottom: 1px solid #f0f0f0; text-align: left; font-size: 1rem; }
.results-table td:last-child { text-align: right; font-weight: 600; color: #333; }
.results-table tr:last-child td { border-bottom: none; background-color: #fff8f3; padding: 20px; font-size: 1.1rem; }
.total-amount { color: var(--cfdt-orange) !important; font-weight: 800 !important; font-size: 1.5rem !important; }
.details-list { list-style: none; padding: 0; margin: 0 auto; max-width: 600px; text-align: left; background: #fafafa; padding: 20px; border-radius: 12px; font-size: 0.85rem; color: #666; border: 1px solid #eee; }
.details-list li { margin-bottom: 8px; border-bottom: 1px dashed #e0e0e0; padding-bottom: 8px; display: flex; justify-content: space-between; }
.details-list li:last-child { border-bottom: none; margin-bottom: 0; }
footer { margin-top: 50px; text-align: center; color: #999; font-size: 0.8rem; border-top: 1px solid #eee; padding-top: 20px; }

@media (max-width: 800px) {
    .header-inner { flex-direction: column; text-align: center; gap: 20px; }
    .header-right { align-items: center; text-align: center; }
    .header-actions { justify-content: center; }
    .form-row { flex-direction: column; gap: 0; }
    .form-group { margin-bottom: 15px; width: 100%; }
    .dates-header-row { display: none; }
    .date-row { display: flex; flex-direction: column; gap: 15px; border: 1px solid #eee; padding: 20px; border-radius: 8px; background: #fafafa; position: relative; }
    .mobile-label { display: block; }
    .checkbox-wrapper { width: 100%; box-sizing: border-box; margin-top: 5px; justify-content: flex-start; }
    .btn-remove { position: absolute; top: 15px; right: 15px; bottom: auto; margin: 0; }
    .btn-placeholder { display: none; }
    .button-row { flex-direction: column; }
    header, main { padding: 20px; margin: 10px auto; width: auto; }
}

/* =========================================
   7. PRINT (CORRECTION : UNIQUEMENT LE RÉSULTAT)
   ========================================= */
@media print {
    /* 1. On cache tout ce qui est dans le body par défaut */
    body > * { display: none !important; }

    /* 2. On affiche 'main' mais on cache tout ce qu'il contient... */
    main { 
        display: block !important; 
        margin: 0 !important; 
        padding: 0 !important; 
        box-shadow: none !important; 
        border: none !important; 
        width: 100% !important; 
        max-width: 100% !important; 
        background: transparent !important;
    }
    main > * { display: none !important; }

    /* 3. ...sauf la modale de résultat qui nous intéresse */
    #result-modal { 
        display: block !important; 
        position: absolute !important; 
        left: 0 !important; 
        top: 0 !important; 
        width: 100% !important; 
        background: white !important; 
        z-index: 9999 !important;
        overflow: visible !important;
        padding: 0 !important;
    }

    /* 4. Style de la modale pour l'impression */
    #result-modal .modal-content {
        box-shadow: none !important; 
        border: none !important; 
        width: 100% !important; 
        max-width: 100% !important; 
        margin: 0 !important; 
        padding: 0 !important; 
        animation: none !important;
    }

    /* 5. On cache les boutons de la modale */
    .close-btn, .modal-footer-actions { display: none !important; }

    /* 6. On force les couleurs */
    .modal-header { border-bottom: 2px solid #f37021 !important; margin-bottom: 20px; }
    .total-amount, .modal-header h3 { color: #f37021 !important; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
    body, h1, h2, h3, p, td, li { color: #000 !important; }
    
    /* 7. Graphique */
    canvas { max-width: 100% !important; height: auto !important; }
}

/* =========================================
   8. CORRECTION Z-INDEX
   ========================================= */
#reset-request-modal, #new-password-modal, #notification-modal { z-index: 2147483647 !important; }
#reset-request-modal, #new-password-modal { background-color: rgba(0, 0, 0, 0.85) !important; }

.modal-footer-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 30px; }
.btn-modal { flex: 1; min-width: 130px; padding: 12px 10px; border-radius: 8px; border: none; font-family: 'Montserrat', sans-serif; font-weight: 600; font-size: 0.9rem; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; color: white; transition: all 0.2s ease; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
.btn-modal:active { transform: translateY(1px); box-shadow: none; }
.btn-save { background-color: #27ae60; } .btn-save:hover { background-color: #219150; box-shadow: 0 4px 12px rgba(39, 174, 96, 0.3); }
.btn-email { background-color: #2980b9; } .btn-email:hover { background-color: #2471a3; box-shadow: 0 4px 12px rgba(41, 128, 185, 0.3); }
.btn-pdf { background-color: #e74c3c; } .btn-pdf:hover { background-color: #c0392b; box-shadow: 0 4px 12px rgba(231, 76, 60, 0.3); }
.btn-close-action { background-color: #95a5a6; max-width: 100px; } .btn-close-action:hover { background-color: #7f8c8d; box-shadow: 0 4px 12px rgba(149, 165, 166, 0.3); }
.btn-modal svg { width: 20px; height: 20px; fill: white; }
@media (max-width: 600px) { .modal-footer-actions { flex-direction: column; } .btn-modal { width: 100%; max-width: none; } }