/* ==========================================================================
   SchoolManager — Feuille de style applicative
   Palette : bleu (principal) · vert (positif) · orange (attention)
   ========================================================================== */

:root {
    --blue-50:  #eff6ff;
    --blue-100: #dbeafe;
    --blue-600: #2563eb;
    --blue-700: #1d4ed8;
    --blue-800: #1e40af;

    --green-100: #dcfce7;
    --green-600: #16a34a;
    --green-700: #15803d;

    --orange-100: #ffedd5;
    --orange-500: #f97316;
    --orange-600: #ea580c;

    --red-100: #fee2e2;
    --red-600: #dc2626;

    --slate-50:  #f8fafc;
    --slate-100: #f1f5f9;
    --slate-200: #e2e8f0;
    --slate-300: #cbd5e1;
    --slate-400: #94a3b8;
    --slate-500: #64748b;
    --slate-600: #475569;
    --slate-700: #334155;
    --slate-800: #1e293b;
    --slate-900: #0f172a;

    --sidebar-width: 260px;
    --sidebar-collapsed: 70px;
    --topbar-height: 64px;

    --radius: 12px;
    --radius-sm: 8px;

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
    --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, .08);

    --font: "Inter", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ---------------------------------------------------------------- base */
* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: var(--font);
    font-size: 14px;
    color: var(--slate-800);
    background: var(--slate-50);
    -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; color: var(--blue-600); }
a:hover { color: var(--blue-700); }

/* ============================================================ auth (login) */
.auth-page {
    display: flex;
    min-height: 100vh;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, #1e40af 0%, #2563eb 50%, #3b82f6 100%);
}

.auth-wrapper { width: 100%; max-width: 420px; }

.auth-card {
    background: #fff;
    border-radius: 16px;
    padding: 36px 32px 28px;
    box-shadow: 0 20px 50px rgba(15, 23, 42, .25);
}

.auth-brand { text-align: center; margin-bottom: 24px; }

.auth-logo {
    display: inline-flex;
    width: 56px; height: 56px;
    align-items: center; justify-content: center;
    font-size: 28px;
    color: #fff;
    background: var(--blue-600);
    border-radius: 14px;
    margin-bottom: 12px;
}

.auth-brand h1 { font-size: 22px; font-weight: 700; margin: 0; color: var(--slate-900); }
.auth-subtitle { color: var(--slate-500); margin: 4px 0 0; }
.auth-title { font-size: 17px; font-weight: 600; margin: 0 0 18px; color: var(--slate-800); }

.auth-btn { padding: 10px; font-weight: 600; }
.auth-footer { text-align: center; color: rgba(255,255,255,.8); margin-top: 20px; font-size: 12px; }

.form-label { font-weight: 500; font-size: 13px; color: var(--slate-700); }
.input-group-text { background: var(--slate-50); color: var(--slate-500); }
.form-control:focus { border-color: var(--blue-600); box-shadow: 0 0 0 .2rem rgba(37, 99, 235, .15); }

/* ============================================================ app shell */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--slate-900) 0%, #0b1322 100%);
    color: var(--slate-300);
    display: flex;
    flex-direction: column;
    z-index: 1040;
    border-right: 1px solid rgba(255,255,255,.04);
    transition: width .22s ease, transform .22s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    height: var(--topbar-height);
    padding: 0 18px;
    border-bottom: 1px solid rgba(255,255,255,.06);
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-logo {
    display: inline-flex;
    width: 38px; height: 38px;
    align-items: center; justify-content: center;
    flex: 0 0 38px;
    color: #fff;
    background: linear-gradient(135deg, #3b82f6, #6366f1);
    border-radius: 11px;
    font-size: 19px;
    box-shadow: 0 4px 12px rgba(37, 99, 235, .45);
}

.sidebar-brand-meta { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.sidebar-brand-text { font-weight: 800; color: #fff; font-size: 16px; letter-spacing: -.01em; }
.sidebar-brand-sub { font-size: 10px; color: var(--slate-500); letter-spacing: .08em; text-transform: uppercase; }

.sidebar-nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 12px 12px 16px; }
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 2px; }

.sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 9px 12px;
    color: var(--slate-300);
    border-radius: 10px;
    font-weight: 500;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    background: transparent;
    border: none;
    transition: background .15s ease, color .15s ease;
}

.sidebar .nav-link:hover { color: #fff; background: rgba(255,255,255,.07); }

.sidebar .nav-link.active {
    color: #fff;
    background: linear-gradient(135deg, rgba(37, 99, 235, .95), rgba(99, 102, 241, .85));
    box-shadow: 0 4px 14px rgba(37, 99, 235, .4);
}

.nav-icon { flex: 0 0 22px; font-size: 16px; text-align: center; }
.nav-arrow { margin-left: auto; font-size: 11px; color: var(--slate-500); transition: transform .2s ease; }

/* --- en-têtes de section (groupes repliables) --- */
.sidebar .nav-section { margin-top: 12px; }
.sidebar .nav-section:first-child { margin-top: 0; }

.sidebar .nav-group {
    padding: 7px 12px;
    gap: 10px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--slate-500);
}
.sidebar .nav-group:hover { color: var(--slate-200); background: transparent; }
.sidebar .nav-group .nav-icon { flex: 0 0 20px; font-size: 15px; color: var(--slate-400); }
.sidebar .nav-group[aria-expanded="true"] { color: var(--slate-300); }
.sidebar .nav-group[aria-expanded="true"] .nav-arrow { transform: rotate(180deg); }

/* --- sous-menu --- */
.nav-sub {
    padding: 4px 0 6px 10px;
    margin: 2px 0 4px 20px;
    border-left: 1px solid rgba(255,255,255,.08);
}
.nav-sub .nav-link { padding: 7px 12px; font-size: 13.5px; color: var(--slate-400); }
.nav-sub .nav-link:hover { color: #fff; background: rgba(255,255,255,.06); }
.nav-sub .nav-link.active { background: rgba(37, 99, 235, .16); box-shadow: none; }
.nav-sub .nav-icon { flex: 0 0 18px; font-size: 14px; }

.sidebar-footer { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.06); }

.sidebar-collapse-btn {
    width: 100%;
    border: none;
    background: rgba(255,255,255,.06);
    color: var(--slate-300);
    padding: 8px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    transition: background .15s ease, color .15s ease;
}
.sidebar-collapse-btn:hover { color: #fff; background: rgba(255,255,255,.12); }

.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-width: 0;
    display: flex;
    flex-direction: column;
    transition: margin-left .22s ease;
}

/* --- sidebar repliée (desktop) --- */
.app.sidebar-collapsed .sidebar { width: var(--sidebar-collapsed); }
.app.sidebar-collapsed .app-main { margin-left: var(--sidebar-collapsed); }
.app.sidebar-collapsed .sidebar-brand-meta,
.app.sidebar-collapsed .nav-label,
.app.sidebar-collapsed .nav-arrow { display: none; }
.app.sidebar-collapsed .sidebar-brand { justify-content: center; padding: 0; }
.app.sidebar-collapsed .nav-link { justify-content: center; padding: 11px 0; }
.app.sidebar-collapsed .nav-link.active::before { display: none; }
.app.sidebar-collapsed .nav-section { margin-top: 6px; }
.app.sidebar-collapsed .nav-sub { display: none; }
.app.sidebar-collapsed .sidebar-collapse-btn i { transform: rotate(180deg); }
.app.sidebar-collapsed .sidebar-footer { padding: 12px 10px; }

/* ---------------------------------------------------------------- topbar */
.topbar {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    background: #fff;
    border-bottom: 1px solid var(--slate-200);
    position: sticky;
    top: 0;
    z-index: 1030;
}

.topbar-start, .topbar-end { display: flex; align-items: center; gap: 12px; }
.topbar-toggle { font-size: 20px; color: var(--slate-600); }
.topbar-toggle:hover { color: var(--slate-900); }

.breadcrumb { font-size: 13px; }
.breadcrumb-item a { color: var(--slate-500); }
.breadcrumb-item.active { color: var(--slate-700); }
.breadcrumb-item + .breadcrumb-item::before { color: var(--slate-400); }

.btn-icon {
    width: 40px; height: 40px;
    display: inline-flex;
    align-items: center; justify-content: center;
    color: var(--slate-600);
    border-radius: 50%;
    font-size: 18px;
}
.btn-icon:hover { background: var(--slate-100); color: var(--slate-900); }

.user-menu {
    display: flex;
    align-items: center;
    gap: 10px;
    border: none;
    background: transparent;
    padding: 4px 8px;
    border-radius: 10px;
}
.user-menu:hover { background: var(--slate-100); }

.user-avatar {
    display: inline-flex;
    width: 36px; height: 36px;
    align-items: center; justify-content: center;
    border-radius: 50%;
    background: var(--blue-600);
    color: #fff;
    font-weight: 600;
    font-size: 13px;
}
.user-meta { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.2; }
.user-name { font-weight: 600; color: var(--slate-800); font-size: 13px; }
.user-role { font-size: 11px; color: var(--slate-500); }

/* ---------------------------------------------------------------- content */
.app-content { flex: 1; padding: 24px; }

.app-footer {
    padding: 14px 24px;
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--slate-500);
    border-top: 1px solid var(--slate-200);
}

.page-header { margin-bottom: 20px; }
.page-title { font-size: 22px; font-weight: 700; margin: 0; color: var(--slate-900); }
.page-subtitle { color: var(--slate-500); margin: 4px 0 0; }

/* ---------------------------------------------------------------- KPI cards */
.kpi-card {
    display: flex;
    align-items: center;
    gap: 16px;
    background: #fff;
    border: 1px solid var(--slate-200);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow .15s ease, transform .15s ease;
    height: 100%;
}
.kpi-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }

.kpi-icon {
    display: inline-flex;
    width: 48px; height: 48px;
    flex: 0 0 48px;
    align-items: center; justify-content: center;
    border-radius: 12px;
    font-size: 22px;
}
.kpi-body { display: flex; flex-direction: column; min-width: 0; }
.kpi-value { font-size: 22px; font-weight: 700; color: var(--slate-900); line-height: 1.15; white-space: nowrap; }
.kpi-label { font-size: 12.5px; color: var(--slate-500); margin-top: 2px; }

.kpi-blue   .kpi-icon { color: var(--blue-700);  background: var(--blue-100); }
.kpi-green  .kpi-icon { color: var(--green-700); background: var(--green-100); }
.kpi-orange .kpi-icon { color: var(--orange-600); background: var(--orange-100); }

/* ---------------------------------------------------------------- cards */
.app-card {
    border: 1px solid var(--slate-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

/* Égalise la hauteur des cartes uniquement dans une grille (sinon une carte
   pleine largeur s'étirerait sur toute la hauteur du contenu). */
.row > [class*="col-"] > .app-card { height: 100%; }
.app-card .card-header {
    background: #fff;
    border-bottom: 1px solid var(--slate-200);
    font-weight: 600;
    color: var(--slate-700);
    padding: 14px 20px;
    border-radius: var(--radius) var(--radius) 0 0;
}
.app-card .card-body { padding: 20px; }

.chart-box { position: relative; height: 300px; }

/* ---------------------------------------------------------------- toasts */
.toast-success { background: var(--green-600); color: #fff; border: none; }
.toast-error   { background: var(--red-600); color: #fff; border: none; }
.toast-container .toast { box-shadow: var(--shadow-md); border-radius: var(--radius-sm); }
.toast .toast-body { font-weight: 500; }

/* ---------------------------------------------------------------- responsive */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .45);
    z-index: 1035;
}

@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .app-main { margin-left: 0; }
    .sidebar-backdrop { display: none; }

    .app.sidebar-mobile-open .sidebar { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.3); }
    .app.sidebar-mobile-open .sidebar-backdrop { display: block; }

    .app-content { padding: 16px; }
    .topbar { padding: 0 16px; }
    .chart-box { height: 260px; }
}

/* ---------------------------------------------------------------- avatars */
.avatar-img,
.avatar-initials {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    object-fit: cover;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    font-weight: 600;
    color: #fff;
    background: var(--blue-600);
}

.avatar-sm { width: 32px; height: 32px; font-size: 12px; }
.avatar-md { width: 48px; height: 48px; font-size: 16px; }
.avatar-xl { width: 72px; height: 72px; font-size: 22px; border-radius: 18px; }

.avatar-initials.avatar-sm { border-radius: 8px; }
.avatar-initials.avatar-md { border-radius: 12px; }

/* ---------------------------------------------------------------- bulletin */
.bulletin {
    background: #fff;
    border: 1px solid var(--slate-200);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow-sm);
}

.bulletin-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
    padding-bottom: 14px;
    border-bottom: 2px solid var(--blue-600);
    margin-bottom: 16px;
}

.bulletin-school h2 { font-size: 20px; font-weight: 700; margin: 0; color: var(--slate-900); }
.bulletin-school p { margin: 2px 0 0; color: var(--slate-500); font-size: 13px; }

.bulletin-title { text-align: right; }
.bulletin-title h3 { font-size: 16px; font-weight: 700; margin: 0; color: var(--blue-700); letter-spacing: .5px; }
.bulletin-title p { margin: 2px 0 0; color: var(--slate-500); font-size: 13px; }

.bulletin-eleve {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 6px 20px;
    background: var(--slate-50);
    border: 1px solid var(--slate-200);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: 13.5px;
}
.bulletin-eleve span { color: var(--slate-500); }

.bulletin-table { width: 100%; border-collapse: collapse; font-size: 13.5px; margin-bottom: 16px; }
.bulletin-table th, .bulletin-table td {
    border: 1px solid var(--slate-200);
    padding: 8px 10px;
    vertical-align: top;
    text-align: left;
}
.bulletin-table thead th { background: var(--slate-100); font-weight: 600; color: var(--slate-700); }
.bulletin-table tbody tr:nth-child(even) { background: #fafbfc; }

.bulletin-foot {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 28px;
    padding-top: 12px;
    border-top: 1px solid var(--slate-200);
    font-size: 14px;
}
.bulletin-foot span { color: var(--slate-500); }
.bulletin-appreciation { width: 100%; }

/* ---------------------------------------------------------------- impression */
.print-page { background: #fff; padding: 20px; }
.print-toolbar { display: flex; gap: 8px; justify-content: flex-end; margin-bottom: 16px; }

@media print {
    .no-print { display: none !important; }
    body { background: #fff !important; }
    .print-page { padding: 0; }
    .bulletin { border: none; box-shadow: none; padding: 0; }
}

/* ---------------------------------------------------------------- emploi du temps */
.edt-table { font-size: 13px; }
.edt-periode-col { width: 140px; white-space: nowrap; }
.edt-select { min-width: 110px; }

/* ---------------------------------------------------------------- rapports */
.rapport-card { transition: box-shadow .15s ease, transform .15s ease; }
.rapport-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.rapport-icon {
    display: inline-flex;
    width: 48px; height: 48px;
    align-items: center; justify-content: center;
    border-radius: 12px;
    font-size: 22px;
    flex-shrink: 0;
}
.rapport-blue   { color: var(--blue-700);   background: var(--blue-100); }
.rapport-green  { color: var(--green-700);  background: var(--green-100); }
.rapport-orange { color: var(--orange-600); background: var(--orange-100); }
.rapport-title  { font-size: 16px; font-weight: 700; margin: 0 0 4px; color: var(--slate-900); }

/* ==========================================================================
   Modernisation « SPA » — transitions, animations, barre de progression
   ========================================================================== */

html { scroll-behavior: smooth; }

/* --- barre de progression en haut de page (style Next.js / NProgress) --- */
#sm-progress {
    position: fixed;
    top: 0; left: 0;
    width: 100%;
    height: 3px;
    background: transparent;
    z-index: 1080;
    pointer-events: none;
}
#sm-progress .bar {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, #2563eb, #3b82f6, #60a5fa);
    box-shadow: 0 0 10px rgba(37, 99, 235, .55);
    transition: width .25s ease, opacity .25s ease;
}

/* --- apparition du contenu à l'arrivée sur la page --- */
.app-content > * {
    animation: sm-rise .5s cubic-bezier(.22, 1, .36, 1) both;
}
.app-content > *:nth-child(2) { animation-delay: .05s; }
.app-content > *:nth-child(3) { animation-delay: .1s; }
.app-content > *:nth-child(4) { animation-delay: .15s; }
.app-content > *:nth-child(5) { animation-delay: .2s; }

@keyframes sm-rise {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* --- cartes et boutons : micro-interactions --- */
.kpi-card:active { transform: scale(.99); }

.btn {
    transition: transform .12s ease, box-shadow .12s ease,
                background-color .12s ease, border-color .12s ease;
}
.btn:active:not(.disabled) { transform: translateY(1px) scale(.99); }
.btn-primary { box-shadow: 0 1px 2px rgba(37, 99, 235, .35); }

.app-card { transition: box-shadow .18s ease, transform .18s ease; }
.app-card:hover { box-shadow: var(--shadow-md); }

/* --- barre latérale : indicateur actif --- */
.sidebar .nav-link { position: relative; }
.sidebar .nav-link.active::before {
    content: "";
    position: absolute;
    left: 0; top: 50%;
    transform: translateY(-50%);
    height: 22px; width: 3px;
    border-radius: 0 3px 3px 0;
    background: #fff;
}

/* --- tables : en-têtes nets, lignes douces --- */
.table thead th {
    text-transform: uppercase;
    font-size: 11.5px;
    letter-spacing: .03em;
    color: var(--slate-500);
    border-bottom-width: 2px;
}
.table tbody tr { transition: background-color .12s ease; }

/* --- champs de formulaire --- */
.form-control, .form-select { transition: border-color .15s ease, box-shadow .15s ease; }

/* --- page d'authentification : dégradé animé --- */
.auth-page {
    background: linear-gradient(-45deg, #1e40af, #2563eb, #4f46e5, #1e40af);
    background-size: 400% 400%;
    animation: sm-gradient 14s ease infinite;
}
@keyframes sm-gradient {
    0%   { background-position: 0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}
.auth-card { animation: sm-rise .55s cubic-bezier(.22, 1, .36, 1) both; }

/* --- accessibilité : focus visible --- */
a:focus-visible, .btn:focus-visible, .form-control:focus-visible, .form-select:focus-visible {
    outline: 2px solid var(--blue-600);
    outline-offset: 2px;
}

/* --- respect de la préférence « réduire les animations » --- */
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    .app-content > *, .auth-card { animation: none; }
    .auth-page { animation: none; }
    #sm-progress .bar { transition: none; }
}
