/* ==========================================================================
   LAMTEC — Cartes scolaires — Système de design
   ========================================================================== */

:root {
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

    /* Marque (bleu LAMTEC existant, affiné) */
    --primary-50:  #eef2fb;
    --primary-100: #dde6f7;
    --primary-500: #2c4f8f;
    --primary-600: #1f3b73;
    --primary-700: #16294f;

    /* Neutres */
    --gray-25:  #fbfcfe;
    --gray-50:  #f7f8fa;
    --gray-100: #eef0f3;
    --gray-200: #e2e5ea;
    --gray-300: #cbd1db;
    --gray-400: #9aa3b2;
    --gray-500: #6b7385;
    --gray-600: #4b5262;
    --gray-700: #333a48;
    --gray-800: #1f2430;
    --gray-900: #12151c;

    /* Sémantique */
    --success:    #16a34a;
    --success-bg: #e8f8ee;
    --success-fg: #146c37;
    --danger:     #dc2626;
    --danger-bg:  #fdeceb;
    --danger-fg:  #a31d1d;
    --warning:    #d97706;
    --warning-bg: #fef3e2;
    --warning-fg: #92400e;
    --info:       #2563eb;
    --info-bg:    #eaf1fe;
    --info-fg:    #1e40af;

    /* Surfaces */
    --bg-page:    var(--gray-50);
    --bg-surface: #ffffff;
    --bg-sidebar: var(--primary-700);
    --text-body:  var(--gray-800);
    --text-muted: var(--gray-500);
    --border:     var(--gray-200);

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-pill: 999px;

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
    --shadow-md: 0 4px 16px rgba(15, 23, 42, .08);
    --shadow-lg: 0 12px 32px rgba(15, 23, 42, .14);

    --sidebar-width: 236px;
    --topbar-height: 59px;
    color-scheme: light;
}

:root[data-theme="dark"] {
    --bg-page:    #0f1117;
    --bg-surface: #161923;
    --bg-sidebar: #0c0e14;
    --text-body:  #e7e9ee;
    --text-muted: #9099ab;
    --border:     #262b38;
    --gray-50:  #1a1d27;
    --gray-100: #1f2330;
    --gray-200: #262b38;
    --success-bg: rgba(22,163,74,.15);
    --danger-bg:  rgba(220,38,38,.15);
    --warning-bg: rgba(217,119,6,.15);
    --info-bg:    rgba(37,99,235,.18);
    color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg-page);
    color: var(--text-body);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary-600); }
:root[data-theme="dark"] a { color: #8fb3ff; }

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }

/* ---------- Shell : sidebar + topbar + contenu ---------- */

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

.app-sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--bg-sidebar);
    color: #e8ecf7;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: 40;
    transition: transform .2s ease;
}

.app-sidebar__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 20px;
    font-weight: 700;
    font-size: 15px;
    letter-spacing: .01em;
    color: #fff;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.app-sidebar__brand img { width: 26px; height: 26px; border-radius: 6px; background: #fff; padding: 2px; }

.app-sidebar__nav { flex: 1; padding: 14px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }

.app-sidebar__link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: #c3cbe0;
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 500;
    transition: background .12s ease, color .12s ease;
}
.app-sidebar__link svg { flex-shrink: 0; opacity: .85; }
.app-sidebar__link:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.app-sidebar__link.is-active { background: rgba(255,255,255,.14); color: #fff; }
.app-sidebar__link.is-active svg { opacity: 1; }

.app-sidebar__section-label {
    padding: 14px 12px 4px;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: #7c88ab;
}

.app-sidebar__footer {
    padding: 12px;
    border-top: 1px solid rgba(255,255,255,.08);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.app-user {
    display: flex; align-items: center; gap: 9px;
    padding: 6px 8px; border-radius: var(--radius-sm);
}
.app-user__avatar {
    width: 30px; height: 30px; border-radius: 50%;
    background: var(--primary-500); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 12.5px; flex-shrink: 0;
}
.app-user__meta { min-width: 0; }
.app-user__name { font-size: 13px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-user__role { font-size: 11px; color: #9aa6c4; }

.app-main { margin-left: var(--sidebar-width); flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }

.app-topbar {
    display: none;
    align-items: center;
    justify-content: space-between;
    min-height: var(--topbar-height);
    padding: 12px 16px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 30;
}

.app-content { padding: 24px 28px 40px; flex: 1; }

.sidebar-overlay { display: none; }

@media (max-width: 960px) {
    .app-sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
    .app-sidebar.is-open { transform: translateX(0); }
    .app-main { margin-left: 0; }
    .app-topbar { display: flex; }
    .app-content { padding: 18px 16px 32px; }
    .sidebar-overlay.is-visible {
        display: block; position: fixed; inset: 0; background: rgba(10,12,18,.5); z-index: 35;
    }
}

/* ---------- Page header ---------- */

.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 22px; }
.page-head__title { font-size: 21px; margin-bottom: 3px; }
.page-head__subtitle { color: var(--text-muted); font-size: 13.5px; }
.page-head__actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Cartes ---------- */

.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.card__body { padding: 18px 20px; }
.card__title { font-size: 14.5px; font-weight: 650; margin-bottom: 4px; }
.card__hint { color: var(--text-muted); font-size: 12.5px; margin-bottom: 14px; }

/* ---------- Boutons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background .12s ease, border-color .12s ease, color .12s ease, opacity .12s ease;
}
.btn svg { flex-shrink: 0; }
.btn:hover { text-decoration: none; }
.btn:disabled, .btn.is-disabled { opacity: .55; cursor: not-allowed; pointer-events: none; }

.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-icon { padding: 7px; }

.btn-primary { background: var(--primary-600); border-color: var(--primary-600); color: #fff; }
.btn-primary:hover { background: var(--primary-700); border-color: var(--primary-700); color: #fff; }

.btn-outline { background: transparent; border-color: var(--gray-300); color: var(--text-body); }
.btn-outline:hover { background: var(--gray-50); border-color: var(--gray-400); color: var(--text-body); }

.btn-danger-outline { background: transparent; border-color: var(--danger-bg); color: var(--danger); }
.btn-danger-outline:hover { background: var(--danger-bg); border-color: var(--danger); }

.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; }

.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--gray-100); color: var(--text-body); }

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

/* ---------- Formulaires ---------- */

.field { margin-bottom: 14px; }
.field--full { grid-column: 1 / -1; }
.field label {
    display: block; font-size: 12.5px; font-weight: 650;
    color: var(--gray-600); margin-bottom: 5px;
}
:root[data-theme="dark"] .field label { color: var(--gray-400); }
.field .hint { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }

.input, select.input, textarea.input {
    width: 100%;
    padding: 9px 11px;
    font-size: 13.5px;
    font-family: inherit;
    color: var(--text-body);
    background: var(--bg-surface);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    transition: border-color .12s ease, box-shadow .12s ease;
}
.input:focus, select.input:focus, textarea.input:focus {
    outline: none;
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px var(--primary-50);
}
.input::placeholder { color: var(--gray-400); }
.input:disabled { background: var(--gray-50); color: var(--text-muted); }

.form-grid { display: grid; grid-template-columns: 1fr; gap: 0 16px; }
@media (min-width: 720px) { .form-grid { grid-template-columns: repeat(2, minmax(0,1fr)); } }

.checkline { display: flex; align-items: center; gap: 7px; font-size: 13px; }

/* ---------- Tableaux ---------- */

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-md); }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 620px; }
table.data-table thead th {
    text-align: left; padding: 10px 14px; background: var(--gray-50);
    color: var(--gray-600); font-size: 11.5px; font-weight: 700;
    letter-spacing: .04em; text-transform: uppercase;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
:root[data-theme="dark"] table.data-table thead th { color: var(--gray-400); }
table.data-table tbody td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data-table tbody tr:last-child td { border-bottom: none; }
table.data-table tbody tr:hover { background: var(--gray-50); }
.table-actions { display: flex; gap: 6px; flex-wrap: nowrap; justify-content: flex-end; }

.avatar-sm {
    width: 34px; height: 34px; border-radius: 50%; object-fit: cover;
    border: 1px solid var(--border); display: block;
}

/* ---------- Badges / statut ---------- */

.pill {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 10px; border-radius: var(--radius-pill);
    font-size: 11.5px; font-weight: 650; line-height: 1.4;
}
.pill-success { background: var(--success-bg); color: var(--success-fg); }
.pill-danger  { background: var(--danger-bg); color: var(--danger-fg); }
.pill-warning { background: var(--warning-bg); color: var(--warning-fg); }
.pill-info    { background: var(--info-bg); color: var(--info-fg); }
.pill-neutral { background: var(--gray-100); color: var(--gray-600); }

/* ---------- Alertes ---------- */

.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius-md); font-size: 13px; margin-bottom: 16px; border: 1px solid transparent; }
.alert svg { flex-shrink: 0; margin-top: 1px; }
.alert-success { background: var(--success-bg); color: var(--success-fg); border-color: rgba(22,163,74,.25); }
.alert-danger  { background: var(--danger-bg); color: var(--danger-fg); border-color: rgba(220,38,38,.22); }
.alert-info    { background: var(--info-bg); color: var(--info-fg); border-color: rgba(37,99,235,.2); }
.alert-warning { background: var(--warning-bg); color: var(--warning-fg); border-color: rgba(217,119,6,.22); }

/* ---------- Stat tiles ---------- */

.stat-tile__label { font-size: 11.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 6px; }
.stat-tile__value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.stat-tile__meta { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ---------- Barre KPI + filtres compacte (sticky) ---------- */

.dash-stickybar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 20px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 11px 18px;
    margin-bottom: 18px;
    box-shadow: var(--shadow-sm);
}

.dash-stats { display: flex; align-items: center; gap: 18px; flex-shrink: 0; }
.dash-stat__value { font-size: 18px; font-weight: 700; letter-spacing: -.01em; line-height: 1.15; white-space: nowrap; }
.dash-stat__value .dash-stat__of { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.dash-stat__label { font-size: 10.5px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase; color: var(--text-muted); margin-top: 1px; white-space: nowrap; }

.dash-stickybar__divider { width: 1px; height: 30px; background: var(--border); flex-shrink: 0; }

.dash-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; flex: 1; min-width: 0; }
.dash-filters .input { width: auto; padding: 6px 10px; font-size: 13px; }
.dash-filters .field-inline { display: flex; align-items: center; gap: 6px; }
.dash-filters .field-inline > label { font-size: 11.5px; font-weight: 650; color: var(--text-muted); white-space: nowrap; }
.dash-filters .sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

@media (max-width: 960px) {
    .dash-stickybar { top: var(--topbar-height); }
}

@media (max-width: 760px) {
    .dash-stickybar__divider { display: none; }
    .dash-stats { width: 100%; justify-content: space-between; }
    .dash-filters { width: 100%; }
}

/* ---------- Pagination ---------- */

.pager { display: flex; align-items: center; justify-content: center; gap: 4px; margin-top: 18px; }
.pager a, .pager span {
    min-width: 32px; height: 32px; padding: 0 10px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm); font-size: 12.5px; font-weight: 600;
    color: var(--text-body); text-decoration: none; border: 1px solid var(--border);
}
.pager a:hover { background: var(--gray-50); text-decoration: none; }
.pager .is-current { background: var(--primary-600); border-color: var(--primary-600); color: #fff; }
.pager .is-disabled { opacity: .4; pointer-events: none; }

/* ---------- Empty state ---------- */

.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state svg { margin-bottom: 12px; opacity: .5; }
.empty-state__title { font-size: 14px; font-weight: 650; color: var(--text-body); margin-bottom: 4px; }

/* ---------- Zone de recadrage photo (Cropper.js) ---------- */

.cropper-zone {
    margin-top: 10px;
    border: 1px dashed var(--gray-300);
    border-radius: var(--radius-md);
    padding: 12px;
    background: var(--gray-50);
    display: none;
}
.cropper-zone__hint { font-size: 12px; color: var(--text-muted); margin: 0 0 8px; }
.cropper-zone img { max-width: 100%; max-height: 300px; display: block; margin: 0 auto; }
.photo-current {
    width: 96px; height: 120px; object-fit: cover;
    border-radius: var(--radius-sm); border: 1px solid var(--border);
}

/* ---------- Utilitaires ---------- */

.text-muted { color: var(--text-muted); }
.mt-0 { margin-top: 0; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
