@charset "UTF-8";

/* ========================================= */
/* 1. DESIGN TOKENS & VARIABLES              */
/* ========================================= */
:root {
    --primary: #0f172a;
    --primary-hover: #1e293b;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-light: #eff6ff;
    
    --bg-page: #f8fafc;
    --surface: #ffffff;
    --surface-hover: #f1f5f9;
    
    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    
    --success: #10b981;
    --success-light: #ecfdf5;
    --danger: #ef4444;
    --danger-light: #fef2f2;
    --warning: #f59e0b;
    --warning-light: #fffbeb;
    --extra: #8b5cf6;
    --extra-light: #f5f3ff;
    
    --border-color: #e2e8f0;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.03);
}

/* ========================================= */
/* 2. BASE & RESET                           */
/* ========================================= */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Cairo', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-page);
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    direction: rtl;
    text-align: right;
    -webkit-font-smoothing: antialiased;
}

i, i::before, .fas, .far, .fal, .fab, .fa-solid, .fa-regular {
    font-family: "Font Awesome 6 Free", "Font Awesome 6 Brands" !important;
}

.main-content {
    margin: 0 auto;
    width: 100%;
    max-width: 96%;
    padding: 24px 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* ========================================= */
/* 3. BARRE SUPÉRIEURE (TOPBAR)              */
/* ========================================= */
.topbar {
    background: var(--surface);
    padding: 16px 28px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border: 1px solid var(--border-color);
    position: relative;
    overflow: hidden;
}

.topbar::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary), var(--accent));
}

.topbar-right, .topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo-box {
    width: 60px;
    height: 60px;
    flex-shrink: 0;
}
.logo-box img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: var(--radius-sm);
    background: #fff;
    padding: 2px;
    border: 1px solid var(--border-color);
}

.brand-title {
    margin: 0;
    font-size: 20px;
    font-weight: 800;
    color: var(--primary);
    line-height: 1.2;
}

.brand-subtitle {
    margin: 4px 0 0;
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
}

.user-pill {
    background: var(--bg-page);
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: 30px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13.5px;
    font-weight: 700;
    color: var(--primary);
}

/* ========================================= */
/* 4. BARRE DE COMMANDE & NAVIGATION         */
/* ========================================= */
.global-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    background: var(--surface);
    padding: 12px 18px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    margin-bottom: 28px;
    border: 1px solid var(--border-color);
}

.nav-pills {
    display: flex;
    align-items: center;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
}
.nav-pills::-webkit-scrollbar { display: none; }

.nav-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: var(--radius-md);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 700;
    color: var(--text-muted);
    background: transparent;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.nav-item:hover { color: var(--accent); background: var(--surface-hover); }
.nav-item.active { color: var(--accent); background: var(--accent-light); }

.calendar-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    background: var(--bg-page);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 4px 12px;
}
.calendar-wrapper input[type="month"] {
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    color: var(--primary);
    outline: none;
    cursor: pointer;
    padding: 6px 0;
}

/* ========================================= */
/* 5. ÉLÉMENTS DE FORMULAIRE                 */
/* ========================================= */
select, input[type="text"], input[type="number"], input[type="date"], input[type="password"], textarea, .form-control {
    font-family: inherit;
    font-size: 14px;
    padding: 10px 14px;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    outline: none;
    transition: all 0.2s ease;
    width: 100%;
    background-color: var(--bg-page);
    color: var(--text-main);
    font-weight: 600;
}
select:focus, input:focus, textarea:focus, .form-control:focus {
    border-color: var(--accent);
    background-color: #fff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* ========================================= */
/* 6. TABLEAUX                               */
/* ========================================= */
.table-responsive {
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: var(--surface);
    margin-bottom: 20px;
}
table { width: 100%; border-collapse: separate; border-spacing: 0; white-space: nowrap; }
th { background: #f8fafc; font-weight: 700; color: var(--text-muted); font-size: 13px; padding: 14px 18px; border-bottom: 1.5px solid var(--border-color); text-align: right; }
td { padding: 14px 18px; border-bottom: 1px solid var(--border-color); font-size: 14px; font-weight: 600; color: var(--text-main); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background-color: #f8fbff; }
table th:first-child, table td:first-child { text-align: center; }

/* ========================================= */
/* 7. BOUTONS & BADGES                       */
/* ========================================= */
.btn {
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 700;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
    text-decoration: none;
    white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 2px 8px rgba(15, 23, 42, 0.15); }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); }
.btn-outline { background: transparent; border: 1.5px solid var(--border-color); color: var(--text-main); }
.btn-outline:hover { border-color: var(--primary); background: var(--bg-page); }

.btn-logout { background: var(--danger-light); color: var(--danger); padding: 8px 16px; border-radius: 30px; text-decoration: none; font-size: 13px; font-weight: 700; display: inline-flex; align-items: center; gap: 8px; }
.btn-logout:hover { background: var(--danger); color: #fff; }

.badge { padding: 6px 14px; border-radius: 20px; font-size: 12.5px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: none; cursor:pointer;}
.badge-paid { background: var(--success-light); color: var(--success); }
.badge-unpaid { background: var(--danger-light); color: var(--danger); }
.badge-info { background: var(--accent-light); color: var(--accent); }

/* ========================================= */
/* 8. MODALS & TOASTS                        */
/* ========================================= */
.modal-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(15, 23, 42, 0.7); z-index: 10000; align-items: center; justify-content: center; padding: 20px; backdrop-filter: blur(4px);}
.modal-content { background: var(--surface); padding: 24px; border-radius: var(--radius-lg); width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);}

#toast-container { position: fixed; bottom: 24px; left: 24px; display: flex; flex-direction: column; gap: 12px; z-index: 99999; }
.custom-toast { display: flex; align-items: center; gap: 12px; background: var(--surface); color: var(--text-main); padding: 14px 18px; border-radius: var(--radius-md); box-shadow: 0 10px 30px rgba(15, 23, 42, 0.12); border: 1px solid var(--border-color); min-width: 300px; transform: translateX(-120%); opacity: 0; transition: all 0.3s ease; position: relative; overflow: hidden; }
.custom-toast.active { transform: translateX(0); opacity: 1; }

/* ========================================= */
/* 9. RÈGLES D'IMPRESSION (PORTRAIT PLEINE PAGE + SAUTS DE PAGE) */
/* ========================================= */
.print-header-only, .print-signature { 
    display: none !important; 
}

@media print {
    /* Format Portrait et marges optimisées pour plein page */
    @page { 
        size: A4 portrait !important; 
        margin: 10mm 10mm 15mm 10mm; 
    } 
    
    * { 
        -webkit-print-color-adjust: exact !important; 
        print-color-adjust: exact !important; 
    }
    
    body, html { 
        background: #fff !important; 
        color: #000 !important; 
        height: 100%;
    }
    
    /* Marge en bas pour le pied de page fixe */
    body {
        padding-bottom: 25px !important;
    }
    
    /* Masquer l'interface Web */
    .topbar, .global-controls, .controls-bar, .hide-print, .btn, #toast-container, .app-footer, .modal-overlay, .filter-grid-inline {
        display: none !important; 
    }
    
    .main-content { 
        max-width: 100% !important; 
        padding: 0 !important; 
        margin: 0 !important; 
    }
    
    /* Nettoyage du style d'écran pour la zone d'impression */
    .print-page { 
        border: none !important; 
        box-shadow: none !important; 
        padding: 0 !important; 
        margin-bottom: 0 !important; 
    }

    /* 
     * SÉPARATION PAR IMMEUBLE ET PLEINE PAGE:
     * Utilisation de flexbox pour étirer le conteneur sur toute la hauteur
     * et forcer la signature en bas.
     */
    .print-container {
        page-break-after: always !important;
        break-after: page !important;
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        margin: 0 !important;
        
        /* Étirer sur la page entière */
        min-height: calc(100vh - 40px) !important; 
        display: flex !important;
        flex-direction: column !important;
    }
    
    /* Le dernier immeuble ne doit pas générer de page blanche */
    .print-container:last-child {
        page-break-after: auto !important;
        break-after: auto !important;
    }
    
    /* En-tête d'impression (Logo + Titre) */
    .print-header-only {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        border-bottom: 2px solid #000 !important;
        padding-bottom: 6px !important;
        margin-bottom: 8px !important;
        page-break-after: avoid !important;
        /* L'en-tête ne doit pas s'étirer */
        flex-shrink: 0 !important;
    }
    
    .header-logo-part img { width: 60px !important; height: auto !important; }
    .header-text-part { text-align: center !important; flex: 1; }
    .header-text-part h2 { font-size: 15pt !important; margin: 0 0 2px 0 !important; font-weight: 800; color: #000 !important;}
    .header-text-part h4 { font-size: 11pt !important; margin: 0 !important; color: #333 !important;}
    
    /* Le conteneur du tableau prend l'espace restant, mais ne force pas l'étirement des lignes du tableau */
    .table-responsive { 
        border: none !important; 
        box-shadow: none !important; 
        margin: 0 !important; 
        padding: 0 !important;
        overflow: visible !important;
        flex-grow: 1 !important; 
        display: flex !important;
        flex-direction: column !important;
        justify-content: flex-start !important; /* Le tableau reste en haut */
    }
    
    table { 
        border: 1px solid #000 !important; 
        width: 100% !important; 
        border-collapse: collapse !important; 
        /* Retrait du margin-bottom pour que flexbox gère l'espacement */
        margin-bottom: 0 !important;
    }
    
    th, td { 
        border: 1px solid #000 !important; 
        /* On peut augmenter légèrement le padding pour donner plus d'air au tableau si désiré, 
           mais l'objectif principal est de repousser la signature */
        padding: 8px 4px !important; 
        font-size: 9.5pt !important; 
        line-height: 1.2 !important; 
        color: #000 !important; 
        text-align: center !important; 
        vertical-align: middle !important;
    }
    
    th { 
        background: #f0f0f0 !important; 
        color: #000 !important; 
        font-weight: bold !important; 
    }
    
    /* Éviter de couper une ligne de données en deux entre deux pages */
    tr { page-break-inside: avoid !important; }
    
    .badge { 
        border: none !important; 
        background: transparent !important; 
        color: #000 !important; 
        font-weight: bold !important; 
        padding: 0 !important; 
    }

    /* La signature est poussée vers le bas grâce au margin-top: auto */
    .print-signature {
        display: block !important;
        margin-top: auto !important; /* Pousse la signature en bas de la zone disponible */
        margin-bottom: 20px !important; /* Ajoute un peu d'espace avant le footer fixe */
        font-size: 11pt !important;
        line-height: 1.5 !important;
        font-weight: bold !important;
        text-align: left !important;
        padding-left: 10% !important;
        color: #000 !important;
        page-break-inside: avoid !important;
        flex-shrink: 0 !important; /* La signature ne doit pas être écrasée */
    }

    /* PIED DE PAGE AUTOMATIQUE FIXÉ EN BAS DE TOUTES LES PAGES */
    body::after {
        content: "Syndic Résidence AlQods, Immeuble A RDC, Ard AlOmani, Laayayda, Salé - alqodsresidence@gmail.com - 0661295346";
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        text-align: center !important;
        font-size: 9.5pt !important;
        font-weight: 600 !important;
        color: #333 !important;
        padding-top: 5px !important;
        border-top: 1px solid #000 !important;
        direction: ltr !important; 
        background: #fff !important;
        z-index: 9999 !important;
    }
}

/* === Ajouts de conformité === */
[hidden] { display: none !important; }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.annonce-body img { max-width: 100%; height: auto; }
.annonce-body table { max-width: 100%; display: block; overflow-x: auto; }
:focus-visible { outline: 3px solid rgba(59,130,246,.45); outline-offset: 2px; }


/* === Impression : immeuble par page, tableau pleine hauteur === */
@media print {
    .print-building { break-inside: avoid !important; page-break-inside: avoid !important; }
    .print-building th, .print-building td {
        height: var(--row-h, auto) !important;
        font-size: var(--row-font, 9.5pt) !important;
    }
    .print-building .badge { font-size: var(--row-font, 9.5pt) !important; }
    .print-building .header-text-part h2 { font-size: 18pt !important; }
    .print-building .print-signature { font-size: 13pt !important; margin-top: 14px !important; }
}


/* === Statuts de paiement en couleur (écran et impression) === */
.badge.badge-paid { color: #059669; }
.badge.badge-unpaid { color: #dc2626; }
.badge.badge-paid *, .badge.badge-paid span { color: #059669 !important; }
.badge.badge-unpaid *, .badge.badge-unpaid span { color: #dc2626 !important; }

@media print {
    .print-building .badge.badge-paid,
    .print-building .badge.badge-paid * { color: #059669 !important; font-weight: 900 !important; }
    .print-building .badge.badge-unpaid,
    .print-building .badge.badge-unpaid * { color: #dc2626 !important; font-weight: 900 !important; }
}


/* === Rappels de paiement : montant et période d'impayés en rouge === */
.impaye-rouge { color: #dc2626 !important; font-weight: 800; }
@media print { .impaye-rouge { color: #dc2626 !important; } }

/* === Tous les rappels (titre « تذكير ») en rouge, écran et impression === */
.rappel-rouge, .rappel-rouge * { color: #dc2626 !important; }
@media print { .rappel-rouge, .rappel-rouge * { color: #dc2626 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; } }
