/* =============================================
   CAFA Exercices — Charte graphique Berry & Cream
   ============================================= */

/* ── Variables CSS ── */
:root {
    --primary: #6D2E46;
    --primary-dark: #2D1B2E;
    --accent: #D4A574;
    --bg-light: #F5F0EB;
    --rose: #A26769;
    --cream: #ECE2D0;
    --success: #27AE60;
    --error: #C0392B;
    --warning: #F39C12;
    --text-dark: #2D1B2E;
    --text-light: #6B5B6E;
    --white: #FFFFFF;
    --border: #D5C8C0;
    --shadow: 0 2px 8px rgba(45, 27, 46, 0.1);
    --shadow-lg: 0 4px 16px rgba(45, 27, 46, 0.15);
    --radius: 8px;
    --radius-lg: 12px;
}

/* ── Reset & Base ── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-light);
    color: var(--text-dark);
    line-height: 1.6;
    min-height: 100vh;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color 0.2s;
}

a:hover {
    color: var(--rose);
}

img {
    max-width: 100%;
    height: auto;
}

/* ── Layout principal ── */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
    width: 260px;
    background: linear-gradient(180deg, var(--primary-dark) 0%, var(--primary) 100%);
    color: var(--white);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent);
}

.sidebar-logo small {
    display: block;
    font-size: 0.75rem;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.6);
    margin-top: 0.25rem;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0;
    overflow-y: auto;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.5rem;
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.9rem;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: rgba(255, 255, 255, 0.1);
    color: var(--white);
    border-left-color: var(--accent);
}

.sidebar-nav .nav-section {
    padding: 0.5rem 1.5rem 0.25rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgba(255, 255, 255, 0.4);
    margin-top: 0.5rem;
}

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 0.85rem;
}

.sidebar-footer a {
    color: rgba(255, 255, 255, 0.7);
}

.sidebar-footer a:hover {
    color: var(--white);
}

/* ── Contenu principal ── */
.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 2rem;
    max-width: 1200px;
}

.main-content-full {
    flex: 1;
    margin-left: 260px;
    padding: 2rem;
}

/* ── Header de page ── */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.page-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary-dark);
}

.page-header h1 small {
    display: block;
    font-size: 0.9rem;
    font-weight: 400;
    color: var(--text-light);
}

/* ── Cartes ── */
.card {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.card-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary-dark);
}

.card-body {
    font-size: 0.95rem;
}

/* ── Boutons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    line-height: 1.4;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.btn-primary {
    background: var(--primary);
    color: var(--white);
}

.btn-primary:hover {
    background: var(--primary-dark);
    color: var(--white);
}

.btn-accent {
    background: var(--accent);
    color: var(--primary-dark);
}

.btn-accent:hover {
    background: #C49564;
    color: var(--primary-dark);
}

.btn-success {
    background: var(--success);
    color: var(--white);
}

.btn-success:hover {
    background: #219A52;
    color: var(--white);
}

.btn-danger {
    background: var(--error);
    color: var(--white);
}

.btn-danger:hover {
    background: #A93226;
    color: var(--white);
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--primary);
    color: var(--primary);
}

.btn-outline:hover {
    background: var(--primary);
    color: var(--white);
}

.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
}

.btn-lg {
    padding: 0.8rem 2rem;
    font-size: 1rem;
}

/* ── Formulaires ── */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.4rem;
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text-dark);
}

.form-control {
    width: 100%;
    padding: 0.6rem 0.85rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--text-dark);
    background: var(--white);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(109, 46, 70, 0.15);
}

.form-control.is-invalid {
    border-color: var(--error);
}

textarea.form-control {
    resize: vertical;
    min-height: 100px;
}

select.form-control {
    appearance: auto;
}

.form-error {
    color: var(--error);
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

.form-hint {
    color: var(--text-light);
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

/* ── Tableau ── */
.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

table th,
table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

table th {
    background: var(--bg-light);
    font-weight: 600;
    color: var(--primary-dark);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

table tr:hover {
    background: rgba(236, 226, 208, 0.3);
}

/* ── Messages flash ── */
.flash-messages {
    margin-bottom: 1.5rem;
}

.flash {
    padding: 0.85rem 1.25rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    animation: flashIn 0.3s ease;
}

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

.flash-success {
    background: #D5F5E3;
    color: #1B7A3D;
    border-left: 4px solid var(--success);
}

.flash-error {
    background: #FADBD8;
    color: #922B21;
    border-left: 4px solid var(--error);
}

.flash-warning {
    background: #FEF5E7;
    color: #9A7D0A;
    border-left: 4px solid var(--warning);
}

.flash-info {
    background: #D6EAF8;
    color: #21618C;
    border-left: 4px solid #3498DB;
}

/* ── Badges ── */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success {
    background: #D5F5E3;
    color: #1B7A3D;
}

.badge-warning {
    background: #FEF5E7;
    color: #9A7D0A;
}

.badge-danger {
    background: #FADBD8;
    color: #922B21;
}

.badge-info {
    background: #D6EAF8;
    color: #21618C;
}

.badge-primary {
    background: rgba(109, 46, 70, 0.15);
    color: var(--primary);
}

/* ── Cadenas (exercice verrouillé) ── */
.locked {
    opacity: 0.5;
    position: relative;
}

.locked::after {
    content: "🔒";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2rem;
}

.lock-icon {
    color: var(--text-light);
    font-size: 1.2rem;
}

.unlock-icon {
    color: var(--success);
    font-size: 1.2rem;
}

/* ── Barre de progression ── */
.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--cream);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    border-radius: 4px;
    transition: width 0.5s ease;
}

/* ── Stats cards ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    text-align: center;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-card .stat-label {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-top: 0.25rem;
}

/* ── Grille de cartes ── */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

/* ── Page de login ── */
.auth-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 50%, var(--rose) 100%);
    padding: 1rem;
}

.auth-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem;
    width: 100%;
    max-width: 420px;
}

.auth-card h1 {
    text-align: center;
    color: var(--primary-dark);
    margin-bottom: 0.5rem;
    font-size: 1.5rem;
}

.auth-card .subtitle {
    text-align: center;
    color: var(--text-light);
    margin-bottom: 2rem;
    font-size: 0.9rem;
}

/* ── Barre mobile ── */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--primary-dark);
    color: var(--white);
    z-index: 200;
    align-items: center;
    justify-content: space-between;
    padding: 0 0.75rem;
    box-shadow: var(--shadow);
}

.mobile-header .mobile-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    position: static;
    background: transparent;
    color: var(--white);
    border: none;
    width: 44px;
    height: 44px;
    font-size: 1.5rem;
    cursor: pointer;
    border-radius: var(--radius);
    box-shadow: none;
}

.mobile-header .mobile-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
}

.mobile-header-title {
    font-weight: 600;
    font-size: 1rem;
    color: var(--accent);
}

.mobile-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.35rem 0.75rem;
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.8rem;
    font-weight: 500;
    border-radius: var(--radius);
    text-decoration: none;
    transition: all 0.2s;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.mobile-logout:hover {
    background: rgba(255, 255, 255, 0.2);
    color: var(--white);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 90;
}

/* ── Empty state ── */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-light);
}

.empty-state .empty-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state p {
    margin-bottom: 1rem;
    font-size: 1rem;
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .mobile-header {
        display: flex;
    }

    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay.open {
        display: block;
    }

    .main-content,
    .main-content-full {
        margin-left: 0;
        padding: 1rem;
        padding-top: calc(56px + 1rem);
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .page-header h1 {
        font-size: 1.35rem;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .card-grid {
        grid-template-columns: 1fr;
    }

    .form-actions {
        flex-direction: column;
    }

    .form-actions .btn {
        width: 100%;
        justify-content: center;
    }

    table {
        font-size: 0.8rem;
    }

    table th,
    table td {
        padding: 0.5rem;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .auth-card {
        padding: 1.5rem;
    }
}

/* ── Utilitaires ── */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-light); }
.text-success { color: var(--success); }
.text-danger { color: var(--error); }
.text-warning { color: var(--warning); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.d-flex { display: flex; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
