/* ==========================================================================
   1. VARIABLES & RESET (Design System)
   ========================================================================== */
:root {
    /* Couleurs Principales (Thème Juridique / Confiance) */
    --primary: #b45309;
    --primary-light: #fbbf24;
    --primary-dark: #78350f;
    --primary-bg: #fffbeb;
    
    /* Couleurs de statut */
    --success: #16a34a;
    --danger: #dc2626;
    --info: #2563eb;
    
    /* Couleurs Neutres */
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --bg-body: #fefce8;
    --bg-card: #ffffff;
    --border-color: #e5e7eb;
    
    /* Typographie */
    --font-ui: 'Tajawal', sans-serif;
    --font-doc: 'Amiri', serif;
    --font-title: 'Lalezar', cursive;
    
    /* Ombres (SaaS Feel) */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    
    /* Transitions */
    --transition: all 0.3s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-ui);
    background: linear-gradient(135deg, var(--bg-body) 0%, #fff7ed 50%, #fef3c7 100%);
    color: var(--text-main);
    min-height: 100vh;
    direction: rtl;
    line-height: 1.6;
}

/* ==========================================================================
   2. INTERFACE UTILISATEUR (UI)
   ========================================================================== */

/* Header */
.header {
    background: linear-gradient(to left, var(--primary-dark), var(--primary));
    color: white;
    padding: 1rem;
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1000px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.header-text h1 { font-size: 1.5rem; font-weight: 800; }
.header-text p { font-size: 0.85rem; opacity: 0.9; }
.header-icon { font-size: 2rem; }

/* Progress Bar */
.progress-container {
    background: var(--bg-card);
    padding: 1rem;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 76px;
    z-index: 99;
}

.progress-inner {
    max-width: 900px;
    margin: 0 auto;
}

.steps {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.step {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: var(--transition);
}

.step:hover { transform: translateY(-2px); }

.step-circle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    background: var(--border-color);
    color: var(--text-muted);
    transition: var(--transition);
}

.step-circle.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 0 0 4px var(--primary-bg);
}

.step-circle.completed {
    background: var(--success);
    color: white;
}

.step-label {
    font-size: 0.75rem;
    margin-top: 0.5rem;
    color: var(--text-muted);
    font-weight: 500;
}

.step-label.active { color: var(--primary); font-weight: 700; }

.progress-bar {
    height: 6px;
    background: var(--border-color);
    border-radius: 10px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(to left, var(--primary-light), var(--primary));
    border-radius: 10px;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Layout Principal & Cartes */
.main {
    max-width: 900px;
    margin: 2rem auto;
    padding: 0 1rem;
}

.card {
    background: var(--bg-card);
    border-radius: 1rem;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    animation: fadeIn 0.4s ease-out;
}

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

.card-content { padding: 2.5rem; }

.card-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-dark);
    margin-bottom: 2rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 2px solid var(--primary-bg);
    padding-bottom: 1rem;
}

/* Grille de sélection (Type de contrat) */
.type-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
}

.type-card {
    padding: 2rem;
    border: 2px solid var(--border-color);
    border-radius: 1rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background: var(--bg-card);
}

.type-card:hover {
    border-color: var(--primary-light);
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
}

.type-card.selected {
    border-color: var(--primary);
    background: var(--primary-bg);
    box-shadow: 0 0 0 2px rgba(180, 83, 9, 0.2);
}

.type-icon { font-size: 3rem; margin-bottom: 1rem; }
.type-title { font-weight: 700; color: var(--primary-dark); margin-bottom: 0.5rem; font-size: 1.2rem; }
.type-desc { font-size: 0.85rem; color: var(--text-muted); }

/* Formulaires */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.form-group { display: flex; flex-direction: column; }
.form-group.full-width { grid-column: 1 / -1; }

.form-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

.form-label .required { color: var(--danger); }

.form-input {
    width: 100%;
    padding: 0.875rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: 0.5rem;
    font-family: var(--font-ui);
    font-size: 1rem;
    background: #f9fafb;
    transition: var(--transition);
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--bg-card);
    box-shadow: 0 0 0 3px var(--primary-bg);
}

.form-input.error {
    border-color: var(--danger);
    background: #fef2f2;
}

.error-text {
    color: var(--danger);
    font-size: 0.8rem;
    margin-top: 0.4rem;
    font-weight: 500;
}

/* Boutons */
.card-footer {
    background: #f9fafb;
    padding: 1.5rem 2.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 0.5rem;
    font-family: var(--font-ui);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: var(--transition);
}

.btn-secondary { background: var(--border-color); color: var(--text-main); }
.btn-secondary:hover { background: #d1d5db; }

.btn-primary {
    background: linear-gradient(to left, var(--primary), var(--primary-dark));
    color: white;
    box-shadow: var(--shadow-md);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #15803d; transform: translateY(-2px); }

.btn-info { background: var(--info); color: white; }
.btn-info:hover { background: #1d4ed8; }

.btn-group { display: flex; gap: 1rem; }

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text-main);
    color: white;
    padding: 1rem 2rem;
    border-radius: 0.5rem;
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    font-weight: 500;
}

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

/* Footer */
.footer {
    background: var(--primary-dark);
    color: var(--primary-bg);
    padding: 2rem 1rem;
    text-align: center;
    margin-top: 4rem;
}
.footer p { margin-bottom: 0.5rem; }
.footer-sub { font-size: 0.8rem; opacity: 0.7; }

/* ==========================================================================
   3. MODAL (Aperçu) & STYLE D'IMPRESSION (Le Contrat Officiel)
   ========================================================================== */

/* Modal Web (Aperçu avant impression) */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000; padding: 2rem; overflow: auto;
}

.modal {
    background: white;
    border-radius: 1rem;
    max-width: 210mm; /* Taille A4 */
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.modal-header {
    background: var(--bg-card);
    padding: 1.5rem;
    display: flex; justify-content: space-between; align-items: center;
    position: sticky; top: 0; z-index: 10;
    border-bottom: 1px solid var(--border-color);
}

.modal-body {
    padding: 2rem 3rem;
    /* Application de la police officielle pour l'aperçu */
    font-family: var(--font-doc);
    font-size: 16px;
    line-height: 2;
    color: #000;
}

/* Styles partagés entre l'aperçu (Modal) et l'impression (Print) */
.doc-title-container {
    text-align: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 3px double var(--primary-dark);
}

.doc-title {
    font-family: var(--font-title);
    font-size: 2rem;
    color: var(--primary-dark);
    border: 2px solid var(--primary-dark);
    display: inline-block;
    padding: 0.5rem 3rem;
    border-radius: 4px;
}

.doc-section {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: #fafaf8;
    border-right: 4px solid var(--primary-dark);
}

.doc-section-title {
    font-family: var(--font-ui);
    font-weight: 700;
    color: var(--primary-dark);
    margin-bottom: 1rem;
    font-size: 1.1rem;
    border-bottom: 1px solid #ddd;
    padding-bottom: 0.5rem;
}

.doc-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem 2rem;
}

.doc-item { display: flex; gap: 0.5rem; }
.doc-label { font-weight: bold; color: #333; min-width: 120px; }
.doc-value { border-bottom: 1px dotted #999; flex: 1; color: #000; font-family: var(--font-ui); font-weight: 500;}
.doc-full { grid-column: 1 / -1; }

.doc-clauses-title {
    text-align: center;
    font-family: var(--font-title);
    font-size: 1.5rem;
    color: var(--primary-dark);
    margin: 2.5rem 0 1.5rem;
}

.doc-clause {
    margin-bottom: 1rem;
    text-align: justify;
    font-size: 1.1rem;
}

.doc-clause-num {
    font-weight: bold;
    color: var(--primary-dark);
}

.doc-signatures {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4rem;
    margin-top: 3rem;
    page-break-inside: avoid;
}

.doc-sig-box {
    text-align: center;
    padding: 2rem;
    border: 1px solid #ccc;
    border-radius: 8px;
    min-height: 150px;
}

.doc-sig-title { font-weight: bold; font-size: 1.2rem; margin-bottom: 0.5rem; }
.doc-sig-name { font-family: var(--font-ui); color: #555; }

/* --- LA MAGIE DE L'IMPRESSION (PRINT CSS) --- */
@media print {
    /* Cacher toute l'interface web */
    body > *:not(#modal-root) { display: none !important; }
    
    /* Configuration de la page A4 */
    @page {
        size: A4;
        margin: 15mm 20mm;
    }

    body {
        background: white;
        margin: 0;
        padding: 0;
    }

    /* Le modal devient la page imprimée */
    #modal-root, .modal-overlay, .modal {
        position: static !important;
        display: block !important;
        background: transparent !important;
        box-shadow: none !important;
        width: 100% !important;
        max-width: none !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    /* Cacher les boutons du modal */
    .modal-header { display: none !important; }
    
    .modal-body {
        padding: 0 !important;
        color: black !important;
    }

    /* Forcer les couleurs d'impression (pour les bordures et titres) */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Éviter que les clauses soient coupées au milieu d'une page */
    .doc-clause { page-break-inside: avoid; }
    .doc-section { page-break-inside: avoid; }
}

/* Responsive Design */
@media (max-width: 768px) {
    .form-grid, .doc-grid, .doc-signatures { grid-template-columns: 1fr; }
    .btn-group { flex-direction: column; width: 100%; }
    .btn { justify-content: center; }
    .steps { flex-wrap: wrap; gap: 1rem; justify-content: center; }
    .progress-bar { display: none; } /* Cacher la barre sur mobile, garder les cercles */
}
