/* ============================================
   🎯 STYLES AFFECTATION RÉSULTAT ANNUEL
   ============================================
   
   Styles spécialisés pour le module d'affectation du résultat.
   
   🏗️ ARCHITECTURE:
   - Variables CSS centralisées dans ui/styles/styles.css
   - Utilise le préfixe --af- pour toutes les variables spécifiques
   - Méthodologie BEM avec préfixe .fv-af-
   - Support complet du mode sombre automatique
   
   📋 DÉPENDANCES:
   - ui/styles/styles.css (variables globales et système de design)
   - ui/js/modules/affectationResultatAnnuel/af.js (logique métier)
   
   @author Ibrahim SOULA
   @version 2.0
   @architecture BEM + CSS Custom Properties centralisées
   ============================================ */

/* 
   Variables centralisées dans ui/styles/styles.css
   Ce fichier utilise uniquement les variables globales
*/

/* ============================================
   🎯 COMPOSANTS SPÉCIFIQUES AFFECTATION
   ============================================ */

/* Page header affectation */
.fv-af-page-header {
    text-align: center;
    padding: var(--space-xl) 0;
    margin-bottom: var(--space-lg);
}

.fv-af-page-title {
    font-size: var(--font-3xl);
    font-weight: 700;
    color: var(--page-title);
    margin-bottom: var(--space-md);
    text-shadow: 0 1px 3px var(--page-title-shadow);
    background: linear-gradient(135deg, var(--page-title), var(--gray-700));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.fv-af-tutorial-link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-md);
    background: var(--primary);
    color: var(--white);
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: var(--transition);
    font-weight: 500;
}

.fv-af-tutorial-link:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* ============================================
   📝 FORMULAIRES D'AFFECTATION
   ============================================ */

/* Formulaire principal société */
.fv-form--af-societe {
    border-left: 4px solid var(--af-primary);
    background: var(--af-bg-secondary);
    border: 1px solid var(--af-border);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    margin-bottom: var(--space-xl);
    box-shadow: var(--shadow-sm);
}

/* Formulaire affectations */
.fv-form--af-affectations {
    background: var(--af-bg-secondary);
    border: 1px solid var(--af-border);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    margin-bottom: var(--space-xl);
    box-shadow: var(--shadow-sm);
}

/* Container des affectations */
.fv-af-affectations-container {
    margin: var(--space-lg) 0;
    display: flex;
        flex-direction: column;
    gap: var(--space-md);
}

/* Item d'affectation individuel */
.fv-af-affectation-item {
    background: var(--gray-50);
    border: 1px solid var(--af-border);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    transition: var(--transition);
}

.fv-af-affectation-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--af-primary);
}

/* Grilles de formulaires */
.fv-af-societe-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: var(--space-lg);
    margin: var(--space-lg) 0;
}

.fv-af-affectation-item.fv-form__grid {
    display: grid;
    grid-template-columns: 1fr 1fr 2fr auto;
    gap: var(--space-md);
    align-items: end;
}

/* ============================================
   🔘 ACTIONS ET BOUTONS
   ============================================ */

/* Actions des formulaires */
.fv-af-affectations-actions {
    display: flex;
    justify-content: center;
    gap: var(--space-md);
    flex-wrap: wrap;
    margin-top: var(--space-lg);
}

/* Bouton d'ajout d'affectation avec animation */
.fv-af-add-affectation-btn {
    position: relative;
    overflow: hidden;
}

.fv-af-add-affectation-btn::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(
        to right,
        rgba(255, 255, 255, 0) 0%,
        rgba(255, 255, 255, 0.3) 50%,
        rgba(255, 255, 255, 0) 100%
    );
    transform: rotate(45deg);
    animation: shimmer 3s infinite;
}

/* Bouton de calcul avec effet shimmer */
.fv-af-calculate-btn {
    background: linear-gradient(90deg, var(--af-primary), var(--primary-dark));
    position: relative;
    overflow: hidden;
}

.fv-af-calculate-btn::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(
        to right,
        rgba(255, 255, 255, 0) 0%,
        rgba(255, 255, 255, 0.3) 50%,
        rgba(255, 255, 255, 0) 100%
    );
    transform: rotate(45deg);
    animation: shimmer 3s infinite;
}

/* Bouton abattement fiscal */
.fv-af-tax-relief-btn {
    background: var(--gray-600);
    border: 1px solid var(--gray-600);
}

.fv-af-tax-relief-btn:hover {
    background: var(--gray-700);
    border-color: var(--gray-700);
}

/* Animation shimmer */
@keyframes shimmer {
    0% {
        transform: translateX(-100%) rotate(45deg);
    }
    100% {
        transform: translateX(100%) rotate(45deg);
    }
}

/* ============================================
   📊 RÉSULTATS ET VALIDATION
   ============================================ */

/* Section de résultats */
.fv-af-results-container {
    background: var(--af-bg-secondary);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    margin-bottom: var(--space-xl);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--af-border);
}

.fv-af-results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-lg);
    padding-bottom: var(--space-md);
    border-bottom: 1px solid var(--af-border);
}

.fv-af-results-title {
    font-size: var(--font-2xl);
    font-weight: 600;
    color: var(--af-text-primary);
    margin: 0;
}

.fv-af-initial-situation,
.fv-af-affectations-detail {
    padding: var(--space-md);
    border-radius: var(--radius-sm);
    background: var(--gray-50);
    margin-bottom: var(--space-md);
}

.fv-af-initial-content {
    color: var(--af-text-secondary);
    line-height: 1.6;
}

/* Détails des affectations */
.fv-af-affectation-detail {
    margin: var(--space-sm) 0;
    padding: var(--space-sm);
    background: var(--gray-50);
    border-radius: var(--radius-sm);
    border-left: 4px solid var(--af-primary);
}

.fv-af-dividend-info {
    margin-top: var(--space-md);
    padding: var(--space-md);
    background: rgba(37, 99, 235, 0.08);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(37, 99, 235, 0.2);
    color: var(--primary-dark);
}

/* Messages de validation */
.fv-af-validation-section .fv-verification {
    background: var(--af-bg-secondary);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    margin-bottom: var(--space-xl);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--af-border);
}

.fv-af-error-item,
.fv-af-warning-item {
    margin: var(--space-xs) 0;
    color: inherit;
}

/* ============================================
   🪟 MODALES AFFECTATION
   ============================================ */

/* Modale d'abattement fiscal */
.fv-af-modal-content {
    background: var(--af-bg-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.fv-af-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-lg);
    border-bottom: 1px solid var(--af-border);
    background: var(--gray-50);
}

.fv-af-modal-title {
    margin: 0;
    font-size: var(--font-xl);
    font-weight: 600;
    color: var(--af-text-primary);
}

.fv-af-modal-close {
    background: none;
    border: none;
    color: var(--af-text-secondary);
    cursor: pointer;
    padding: var(--space-xs);
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.fv-af-modal-close:hover {
    background: var(--gray-100);
    color: var(--af-text-primary);
}

.fv-af-modal-body {
    padding: var(--space-lg);
    overflow-y: auto;
    flex: 1;
}

.fv-af-modal-footer {
    display: flex;
    gap: var(--space-sm);
    justify-content: flex-end;
    padding: var(--space-lg);
    border-top: 1px solid var(--af-border);
    background: var(--gray-50);
}

/* ============================================
   🔧 COMPOSANTS SPÉCIALISÉS
   ============================================ */

/* Toggles et switches */
.fv-af-switch-container {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin: var(--space-xs) 0;
}

.fv-af-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 28px;
}

.fv-af-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.fv-af-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--gray-300);
    transition: var(--transition);
    border-radius: 34px;
}

.fv-af-slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: var(--white);
    transition: var(--transition);
    border-radius: 50%;
}

.fv-af-switch input:checked + .fv-af-slider {
    background-color: var(--af-primary);
}

.fv-af-switch input:focus + .fv-af-slider {
    box-shadow: 0 0 1px var(--af-primary);
}

.fv-af-switch input:checked + .fv-af-slider:before {
    transform: translateX(20px);
}

/* Indicateurs de statut */
.fv-af-status-indicator {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--gray-300);
    transition: var(--transition);
}

.fv-af-status-indicator.valid {
    background: var(--af-success);
}

.fv-af-status-indicator.warning {
    background: var(--af-warning);
}

.fv-af-status-indicator.error {
    background: var(--af-danger);
}

/* ============================================
   📱 RESPONSIVE DESIGN
   ============================================ */

@media (max-width: 768px) {
    .fv-af-page-title {
        font-size: var(--font-2xl);
    }
    
    .fv-af-societe-grid {
        grid-template-columns: 1fr;
        gap: var(--space-md);
    }
    
    .fv-af-affectation-item.fv-form__grid {
        grid-template-columns: 1fr;
        gap: var(--space-sm);
    }
    
    .fv-af-affectations-actions {
        flex-direction: column;
        gap: var(--space-sm);
    }
    
    .fv-form--af-societe,
    .fv-form--af-affectations {
        padding: var(--space-lg);
        margin-bottom: var(--space-lg);
    }
    
    .fv-af-tutorial-link {
        width: 100%;
        justify-content: center;
        padding: var(--space-md);
    }
    
    .fv-af-modal-content {
        width: 95%;
        margin: 2% auto;
    }
    
    .fv-af-modal-header,
    .fv-af-modal-body,
    .fv-af-modal-footer {
        padding: var(--space-md);
    }
}

/* ============================================
   🌙 MODE SOMBRE
   ============================================ */

/* Variables mode sombre héritées de ui/styles/styles.css */

/* Styles spécifiques mode sombre */
[data-theme="dark"] .fv-af-page-title {
    color: var(--page-title);
    text-shadow: 0 2px 4px var(--page-title-shadow), 0 1px 2px rgba(0, 0, 0, 0.8);
    background: linear-gradient(135deg, var(--page-title), var(--gray-300));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

[data-theme="dark"] .fv-form--af-societe,
[data-theme="dark"] .fv-form--af-affectations,
[data-theme="dark"] .fv-af-results-container,
[data-theme="dark"] .fv-af-validation-section .fv-verification {
    background: var(--gray-100);
    border-color: var(--gray-300);
}

[data-theme="dark"] .fv-af-affectation-item {
    background: var(--gray-50);
    border-color: var(--gray-300);
}

[data-theme="dark"] .fv-af-initial-situation,
[data-theme="dark"] .fv-af-affectations-detail {
    background: var(--gray-50);
}

[data-theme="dark"] .fv-af-initial-content {
    color: var(--gray-700);
}

[data-theme="dark"] .fv-af-results-title {
    color: var(--gray-900);
}

[data-theme="dark"] .fv-af-affectation-detail {
    background: var(--gray-800);
    border-color: var(--af-primary);
}

[data-theme="dark"] .fv-af-dividend-info {
    background: rgba(59, 130, 246, 0.1);
    border-color: rgba(59, 130, 246, 0.3);
    color: var(--primary);
}

[data-theme="dark"] .fv-af-tutorial-link {
    background: var(--primary);
    color: var(--white);
}

[data-theme="dark"] .fv-af-tutorial-link:hover {
    background: var(--primary-dark);
}

/* Mode sombre pour les modales */
[data-theme="dark"] .fv-af-modal-content {
    background: var(--gray-100);
}

[data-theme="dark"] .fv-af-modal-header,
[data-theme="dark"] .fv-af-modal-footer {
    background: var(--gray-50);
    border-color: var(--gray-300);
}

[data-theme="dark"] .fv-af-modal-title {
    color: var(--gray-900);
}

[data-theme="dark"] .fv-af-modal-close {
    color: var(--gray-700);
}

[data-theme="dark"] .fv-af-modal-close:hover {
    background: var(--gray-100);
    color: var(--gray-900);
}

/* Mode sombre pour les switches */
[data-theme="dark"] .fv-af-slider {
    background-color: var(--gray-600);
}

[data-theme="dark"] .fv-af-slider:before {
    background-color: var(--gray-200);
}

[data-theme="dark"] .fv-af-switch input:checked + .fv-af-slider {
    background-color: var(--af-primary);
}

/* ============================================
   🎯 COMPATIBILITÉ LEGACY
   ============================================ */

/* Support des anciennes classes pour compatibilité ascendante */
.form-section {
    background: var(--af-bg-secondary);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    margin: 0 auto var(--space-xl);
    box-shadow: var(--shadow-sm);
    max-width: 1200px;
    border: 1px solid var(--af-border);
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: var(--space-lg);
    margin: var(--space-xl) auto;
    padding: 0 var(--space-lg);
    max-width: 1200px;
}

.info-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    padding: var(--space-md);
    background: var(--af-bg-secondary);
    border-radius: var(--radius-md);
}

.input-field {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--af-border);
    border-radius: var(--radius-sm);
    transition: var(--transition);
    background: var(--af-bg-secondary);
    color: var(--af-text-primary);
}

.input-field:focus {
    outline: none;
    border-color: var(--af-primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.action-btn {
    background-color: var(--af-primary);
    color: var(--white);
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    font-weight: 500;
    min-width: 150px;
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
}

.action-btn:hover {
    background-color: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.button-section {
    display: flex;
    gap: var(--space-md);
    margin: var(--space-xl) auto;
    justify-content: center;
    flex-wrap: wrap;
    max-width: 1200px;
    padding: 0 var(--space-lg);
}

.hidden {
    display: none !important;
}

/* Styles de résultats legacy */
.result-header {
    margin-bottom: var(--space-lg);
    font-size: var(--font-xl);
    font-weight: 600;
    color: var(--af-text-primary);
}

.result-initial-situation,
.result-operation-details,
.result-final-situation,
.result-affectations {
    margin-top: var(--space-lg);
    padding-top: var(--space-md);
    border-top: 1px solid var(--af-border);
    line-height: 1.8;
}

.result-initial-situation em,
.result-operation-details em {
    display: block;
    margin-top: var(--space-sm);
    color: var(--af-text-secondary);
    font-style: italic;
    font-size: var(--font-sm);
    line-height: 1.4;
}

.result-initial-situation strong,
.result-final-situation strong,
.result-affectations strong {
    color: var(--af-text-primary);
    font-weight: 600;
}

.affectation-detail {
    margin: var(--space-sm) 0;
    padding-left: var(--space-md);
    color: var(--af-text-secondary);
}

.dividend-details {
    margin-top: var(--space-md);
    padding: var(--space-md);
    background-color: var(--gray-50);
    border-radius: var(--radius-sm);
    border: 1px solid var(--af-border);
}

.dividend-info {
    margin-top: var(--space-md);
    padding: var(--space-sm);
    background-color: rgba(37, 99, 235, 0.08);
    border-radius: var(--radius-sm);
    color: var(--primary-dark);
}

.errors-container {
    color: var(--danger-dark);
    background-color: rgba(220, 38, 38, 0.08);
    border: 1px solid rgba(220, 38, 38, 0.3);
    padding: var(--space-sm);
    margin-bottom: var(--space-sm);
    border-radius: var(--radius-sm);
}

.warnings-container {
    color: var(--warning-dark);
    background-color: rgba(245, 158, 11, 0.08);
    border: 1px solid rgba(245, 158, 11, 0.3);
    padding: var(--space-sm);
    border-radius: var(--radius-sm);
}

.error-item, .warning-item {
    margin: var(--space-xs) 0;
}

/* Mode sombre pour les classes legacy */
[data-theme="dark"] .form-section {
    background: var(--gray-100);
    border-color: var(--gray-300);
}

[data-theme="dark"] .info-group {
    background: var(--gray-100);
}

[data-theme="dark"] .input-field {
    background: var(--gray-50);
    border-color: var(--gray-300);
    color: var(--gray-900);
}

[data-theme="dark"] .action-btn {
    background-color: var(--af-primary);
}

[data-theme="dark"] .action-btn:hover {
    background-color: var(--primary-dark);
}

[data-theme="dark"] .result-header,
[data-theme="dark"] .result-initial-situation strong,
[data-theme="dark"] .result-final-situation strong,
[data-theme="dark"] .result-affectations strong {
    color: var(--gray-900);
}

[data-theme="dark"] .result-initial-situation,
[data-theme="dark"] .result-operation-details,
[data-theme="dark"] .result-final-situation,
[data-theme="dark"] .result-affectations {
    border-color: var(--gray-300);
}

[data-theme="dark"] .result-initial-situation em,
[data-theme="dark"] .result-operation-details em,
[data-theme="dark"] .affectation-detail {
    color: var(--gray-700);
}

[data-theme="dark"] .dividend-details {
    background-color: var(--gray-800);
    border-color: var(--gray-700);
}

[data-theme="dark"] .dividend-info {
    background-color: rgba(59, 130, 246, 0.1);
    color: var(--primary);
}

[data-theme="dark"] .errors-container {
    background-color: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.3);
    color: var(--danger);
}

[data-theme="dark"] .warnings-container {
    background-color: rgba(245, 158, 11, 0.1);
    border-color: rgba(245, 158, 11, 0.3);
    color: var(--warning);
}

/* ============================================
   🖨️ MODE IMPRESSION
   ============================================ */

@media print {
    .header {
        position: static;
        box-shadow: none;
        border-bottom: 1px solid var(--af-border);
    }

    .footer,
    .fv-af-help-container,
    .fv-af-affectations-actions {
        display: none !important;
    }
    
    .fv-af-page-header {
        page-break-before: avoid;
    }
    
    .fv-form--af-societe,
    .fv-form--af-affectations {
        page-break-inside: avoid;
        box-shadow: none;
        border: 1px solid var(--af-border);
    }
}

/* ============================================
   ⚡ OPTIMISATIONS ET ACCESSIBILITÉ
   ============================================ */

/* Performance */
.fv-af-affectation-item,
.fv-form--af-societe,
.fv-form--af-affectations {
    will-change: transform;
}

/* Focus visible pour l'accessibilité */
.fv-form__input:focus-visible,
.btn:focus-visible {
    outline: 2px solid var(--af-primary);
    outline-offset: 2px;
}

/* Réduction de mouvement pour l'accessibilité */
@media (prefers-reduced-motion: reduce) {
    .fv-af-affectation-item,
    .fv-form--af-societe,
    .fv-form--af-affectations,
    .fv-af-modal-content {
        transition: none;
    }
    
    .fv-af-add-affectation-btn::before,
    .fv-af-calculate-btn::before {
        animation: none;
    }
}

/* États de chargement */
.fv-af-loading {
    opacity: 0.6;
    pointer-events: none;
    cursor: wait;
}

.fv-af-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid var(--af-primary);
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 1s linear infinite;
}

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

/* États d'erreur et de succès */
.fv-af-success {
    border-color: var(--af-success) !important;
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.1) !important;
}

.fv-af-error {
    border-color: var(--af-danger) !important;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1) !important;
}

/* Animation d'apparition */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fv-af-fade-in {
    animation: fadeInUp 0.6s ease-out;
}

/* Styles finaux pour la cohérence */
.fv-app .fv-af-page-header,
.fv-app .fv-form--af-societe,
.fv-app .fv-form--af-affectations {
    animation: fadeInUp 0.6s ease-out;
}