/* =============================================================================
   ERP SCOLAIRE — Design System
   Stack : Django Templates + HTMX + Alpine.js
   Palette inspirée des interfaces modernes SaaS
   ============================================================================= */

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

:root {
    /* Couleurs principales */
    --primary: #4F46E5;        /* Indigo — boutons, liens, accents */
    --primary-light: #EEF2FF;  /* Fond des badges actifs */
    --primary-dark: #3730A3;

    /* Surfaces */
    --bg-body: #F1F5F9;        /* Fond de page */
    --bg-card: #FFFFFF;         /* Cartes et conteneurs */
    --bg-sidebar: #1E293B;     /* Sidebar sombre */
    --bg-sidebar-hover: #334155;

    /* Texte */
    --text-primary: #0F172A;
    --text-secondary: #64748B;
    --text-muted: #94A3B8;
    --text-on-dark: #F8FAFC;
    --text-on-dark-muted: #94A3B8;

    /* Bordures */
    --border: #E2E8F0;
    --border-light: #F1F5F9;

    /* Statuts */
    --success: #10B981;
    --success-light: #ECFDF5;
    --warning: #F59E0B;
    --warning-light: #FFFBEB;
    --danger: #EF4444;
    --danger-light: #FEF2F2;
    --info: #3B82F6;
    --info-light: #EFF6FF;

    /* Dimensions */
    --sidebar-width: 260px;
    --sidebar-collapsed: 72px;
    --topbar-height: 64px;
    --radius: 8px;
    --radius-lg: 12px;

    /* Typographie */
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

    /* Ombres */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
}


/* --- Global --------------------------------------------------------------- */
html { font-size: 16px; }
body {
    font-family: var(--font);
    background: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }


/* --- Layout App ----------------------------------------------------------- */
.app-body {
    display: flex;
    min-height: 100vh;
}


/* =============================================================================
   SIDEBAR
   ============================================================================= */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    transition: width 0.25s ease;
    z-index: 100;
    overflow: hidden;
}

.sidebar--collapsed {
    width: var(--sidebar-collapsed);
}

/* Logo */
.sidebar__header {
    padding: 20px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar__logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar__logo-icon {
    font-size: 28px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar__logo-text {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-on-dark);
    white-space: nowrap;
}

/* Navigation */
.sidebar__nav {
    flex: 1;
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.sidebar__link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius);
    color: var(--text-on-dark-muted);
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s ease;
    white-space: nowrap;
    cursor: pointer;
}

.sidebar__link i {
    font-size: 20px;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar__link:hover {
    background: var(--bg-sidebar-hover);
    color: var(--text-on-dark);
}

.sidebar__link--active {
    background: var(--primary);
    color: #FFFFFF;
}

.sidebar__link--active:hover {
    background: var(--primary-dark);
    color: #FFFFFF;
}

/* Section divider in sidebar */
.sidebar__section {
    font-size: 11px;
    font-weight: 600;
    color: rgba(148, 163, 184, 0.6);
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 16px 12px 6px;
    margin-top: 4px;
}

/* Section labels dans la sidebar */
.sidebar__section {
    font-size: 11px;
    font-weight: 600;
    color: rgba(148, 163, 184, 0.5);
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 16px 12px 6px;
    margin-top: 4px;
}

/* Footer sidebar */
.sidebar__footer {
    padding: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar__annee {
    padding: 8px 12px;
    margin-bottom: 8px;
}

.sidebar__annee-badge {
    display: inline-block;
    background: rgba(79, 70, 229, 0.2);
    color: #A5B4FC;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 20px;
}


/* =============================================================================
   MAIN CONTENT
   ============================================================================= */
.main {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
}


/* --- Top Bar -------------------------------------------------------------- */
.topbar {
    position: sticky;
    top: 0;
    height: var(--topbar-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    z-index: 50;
}

.topbar__toggle {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 8px;
    border-radius: var(--radius);
    transition: background 0.15s;
}

.topbar__toggle:hover { background: var(--bg-body); }
.topbar__toggle i { font-size: 22px; }

.topbar__title {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}

.topbar__right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar__user {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}


/* --- Content Area --------------------------------------------------------- */
.content {
    padding: 24px;
}


/* =============================================================================
   DASHBOARD — Cartes de statistiques
   ============================================================================= */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 20px 24px;
    border: 1px solid var(--border);
    transition: box-shadow 0.2s;
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
}

.stat-card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.stat-card__label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-card__icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.stat-card__icon--blue { background: var(--info-light); color: var(--info); }
.stat-card__icon--green { background: var(--success-light); color: var(--success); }
.stat-card__icon--amber { background: var(--warning-light); color: var(--warning); }
.stat-card__icon--purple { background: var(--primary-light); color: var(--primary); }

.stat-card__value {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.stat-card__footer {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}


/* =============================================================================
   TABLEAUX DE DONNÉES
   ============================================================================= */
.data-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    overflow: hidden;
}

.data-card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 12px;
}

.data-card__title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

/* Barre de recherche */
.search-box {
    position: relative;
}

.search-box i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 16px;
}

.search-box input {
    padding: 8px 12px 8px 36px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: var(--font);
    color: var(--text-primary);
    background: var(--bg-body);
    width: 280px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.search-box input::placeholder {
    color: var(--text-muted);
}

/* Tableau */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    text-align: left;
    padding: 12px 24px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: var(--bg-body);
    border-bottom: 1px solid var(--border);
}

.data-table td {
    padding: 14px 24px;
    font-size: 14px;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-light);
}

.data-table tbody tr {
    transition: background 0.1s;
}

.data-table tbody tr:hover {
    background: var(--bg-body);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}


/* =============================================================================
   BADGES DE STATUT
   ============================================================================= */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.badge--success { background: var(--success-light); color: #065F46; }
.badge--warning { background: var(--warning-light); color: #92400E; }
.badge--danger { background: var(--danger-light); color: #991B1B; }
.badge--info { background: var(--info-light); color: #1E40AF; }
.badge--neutral { background: var(--bg-body); color: var(--text-secondary); }


/* =============================================================================
   INDICATEUR DE REMPLISSAGE
   ============================================================================= */
.fill-bar {
    width: 100%;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 6px;
}

.fill-bar__inner {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s ease;
}

.fill-bar__inner--ok { background: var(--success); }
.fill-bar__inner--warn { background: var(--warning); }
.fill-bar__inner--full { background: var(--danger); }


/* =============================================================================
   BOUTONS
   ============================================================================= */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px;
    font-size: 14px;
    font-weight: 500;
    font-family: var(--font);
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
}

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

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

.btn--outline {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn--outline:hover { background: var(--bg-body); }

.btn--sm { padding: 6px 12px; font-size: 13px; }


/* =============================================================================
   SECTION : CLASSES (grille de cartes)
   ============================================================================= */
.classes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
}

.class-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    padding: 20px;
    transition: box-shadow 0.2s;
}

.class-card:hover { box-shadow: var(--shadow-md); }

.class-card__title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.class-card__subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.class-card__stats {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: var(--text-secondary);
}

.class-card__stats strong {
    color: var(--text-primary);
}


/* =============================================================================
   ANIMATIONS HTMX
   ============================================================================= */
/* Indicateur de chargement HTMX */
.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator {
    display: inline-block;
}

/* Transition douce du contenu */
#main-content {
    transition: opacity 0.15s ease;
}

.htmx-swapping #main-content {
    opacity: 0.5;
}


/* =============================================================================
   RESPONSIVE — Mobile First
   ============================================================================= */

/* Hamburger menu button (shown on mobile) */
.topbar__toggle {
    display: none;
}

/* Scrollable tables on mobile */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Tablet */
@media (max-width: 1024px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .modules-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
    .classes-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
}

/* Mobile */
@media (max-width: 768px) {
    .topbar__toggle { display: flex; }

    .sidebar {
        position: fixed;
        transform: translateX(-100%);
        z-index: 200;
        transition: transform 0.3s ease;
    }

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

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

    .main { margin-left: 0 !important; }

    .topbar { padding: 0 16px; }
    .topbar__title { font-size: 16px; }

    .content { padding: 16px; }

    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .stat-card { padding: 14px 16px; }
    .stat-card__value { font-size: 24px; }

    .data-card__header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        padding: 12px 16px;
    }

    .search-box input { width: 100%; }
    .search-box { width: 100%; }

    .data-table th, .data-table td { padding: 10px 12px; font-size: 13px; }

    .modules-grid { grid-template-columns: repeat(3, 1fr); gap: 10px; }
    .module-icon { width: 44px; height: 44px; font-size: 20px; }
    .module-name { font-size: 12px; }
    .module-desc { display: none; }

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

    .form-card { margin: 0 -16px; border-radius: 0; border-left: none; border-right: none; }
    .form-card__body { padding: 16px; }
    .form-row { grid-template-columns: 1fr; }
    .form-actions { padding: 16px; flex-wrap: wrap; }

    .btn--sm { padding: 6px 10px; font-size: 12px; }

    /* Sidebar overlay */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 199;
    }

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

/* Small mobile */
@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .modules-grid { grid-template-columns: repeat(2, 1fr); }

    .data-table { font-size: 12px; }
    .data-table th, .data-table td { padding: 8px 10px; }

    .welcome-card { padding: 20px; }
    .welcome-card h2 { font-size: 18px; }

    .parent-nav__inner { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 8px; }
    .parent-nav__links { order: 3; width: 100%; overflow-x: auto; flex-wrap: nowrap; }
    .parent-nav__link { white-space: nowrap; font-size: 12px; padding: 6px 10px; }
}

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

    .content {
        padding: 16px;
    }
}


/* =============================================================================
   FORMULAIRES
   ============================================================================= */
.form-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    max-width: 800px;
}

.form-card__header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.form-card__title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.form-card__body {
    padding: 24px;
}

/* Section avec titre dans le formulaire */
.form-section {
    margin-bottom: 28px;
}

.form-section__title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-light);
}

/* Grille de champs (2 colonnes) */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.form-row--single {
    grid-template-columns: 1fr;
}

@media (max-width: 600px) {
    .form-row { grid-template-columns: 1fr; }
}

/* Groupe label + input */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group label .required {
    color: var(--danger);
    margin-left: 2px;
}

/* Inputs */
.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="date"],
.form-group input[type="number"],
.form-group input[type="tel"],
.form-group input[type="search"],
.form-group select,
.form-group textarea {
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: var(--font);
    color: var(--text-primary);
    background: #FFFFFF;
    transition: border-color 0.15s, box-shadow 0.15s;
    width: 100%;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
    color: var(--text-muted);
}

.form-group select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

/* Checkbox */
.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
}

.form-check input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    cursor: pointer;
}

.form-check label {
    font-size: 14px;
    color: var(--text-primary);
    cursor: pointer;
}

/* Erreurs */
.form-group .errorlist {
    list-style: none;
    padding: 0;
    margin: 4px 0 0;
}

.form-group .errorlist li {
    font-size: 12px;
    color: var(--danger);
    padding: 2px 0;
}

/* Barre d'actions en bas */
.form-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 24px;
    border-top: 1px solid var(--border);
    background: var(--bg-body);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.form-actions .btn { min-width: 120px; justify-content: center; }

/* Message de succès */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.alert--success {
    background: var(--success-light);
    color: #065F46;
    border: 1px solid #A7F3D0;
}

.alert--error {
    background: var(--danger-light);
    color: #991B1B;
    border: 1px solid #FECACA;
}


/* =============================================================================
   GRILLE DE MODULES (Admin Dashboard)
   ============================================================================= */
.modules-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.module-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px 16px;
    text-decoration: none;
    text-align: center;
    transition: all 0.2s ease;
}

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

.module-icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}

.module-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.module-desc {
    font-size: 12px;
    color: var(--text-muted);
}

/* Page module placeholder */
.module-page {
    max-width: 900px;
}

.module-page__header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

.module-page__icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
}

.module-page__title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
}

.module-page__subtitle {
    font-size: 14px;
    color: var(--text-secondary);
}

/* =============================================================================
   BREADCRUMB — Fil d'Ariane
   ============================================================================= */
.topbar__center {
    flex: 1;
    min-width: 0;
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    margin-top: 2px;
}

.breadcrumb__item {
    color: var(--text-muted);
    text-decoration: none;
    cursor: pointer;
}

.breadcrumb__item:hover {
    color: var(--primary);
}

.breadcrumb__item--current {
    color: var(--text-secondary);
    cursor: default;
}

.breadcrumb__sep {
    color: var(--text-muted);
    font-size: 11px;
}

@media (max-width: 768px) {
    .breadcrumb { display: none; }
}

/* Field errors */
.field-error {
    display: block;
    font-size: 12px;
    color: var(--danger);
    margin-top: 4px;
}
.field-error::before {
    content: '⚠ ';
}
