/* ============================================================
   assets/css/main.css — Variables, reset, composants partagés
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap');

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

/* ── Variables Light ── */
:root {
    --accent:           #2563eb;
    --accent-hover:     #1d4ed8;
    --accent-light:     #eff6ff;

    --bg-page:          #f5f7fa;
    --bg-card:          #ffffff;
    --bg-input:         #ffffff;
    --bg-sidebar:       #ffffff;
    --bg-header:        #ffffff;

    --text-primary:     #1f2937;
    --text-secondary:   #4b5563;
    --text-muted:       #9ca3af;

    --border:           #e5e7eb;

    --success:          #10b981;  --success-light: #d1fae5;
    --error:            #ef4444;  --error-light:   #fee2e2;
    --warning:          #f59e0b;  --warning-light: #fef3c7;
    --info:             #3b82f6;  --info-light:    #dbeafe;

    --shadow-sm:  0 1px 3px rgba(0,0,0,.06);
    --shadow:     0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -1px rgba(0,0,0,.05);
    --shadow-lg:  0 20px 25px -5px rgba(0,0,0,.06), 0 10px 10px -5px rgba(0,0,0,.04);
    --shadow-xl:  0 25px 50px -12px rgba(0,0,0,.12);

    --toggle-bg:      #e5e7eb;
    --toggle-circle:  #ffffff;
    --loader-overlay: rgba(255,255,255,0.93);
    --spinner-border: #e5e7eb;
    --spinner-top:    #2563eb;

    --font-sans:  'Inter', system-ui, -apple-system, sans-serif;
    --radius-sm:  8px;
    --radius:     12px;
    --radius-lg:  16px;
    --radius-xl:  24px;
    --radius-2xl: 32px;
}

/* ── Variables Dark  (html.dark pour init immédiate, body.dark pour l'état runtime) ── */
html.dark,
body.dark {
    color-scheme: dark;

    --accent:           #3b82f6;
    --accent-hover:     #60a5fa;
    --accent-light:     #1e3a5f;

    --bg-page:          #0f172a;
    --bg-card:          #1e293b;
    --bg-input:         #0f172a;
    --bg-sidebar:       #1e293b;
    --bg-header:        #1e293b;

    --text-primary:     #f1f5f9;
    --text-secondary:   #94a3b8;
    --text-muted:       #64748b;

    --border:           #334155;

    --success:          #34d399;  --success-light: #064e3b;
    --error:            #f87171;  --error-light:   #7f1d1d;
    --warning:          #fbbf24;  --warning-light: #78350f;
    --info:             #60a5fa;  --info-light:    #1e3a5f;

    --shadow-sm:  0 1px 3px rgba(0,0,0,.3);
    --shadow:     0 4px 6px -1px rgba(0,0,0,.4);
    --shadow-lg:  0 20px 25px -5px rgba(0,0,0,.5);
    --shadow-xl:  0 25px 50px -12px rgba(0,0,0,.6);

    --toggle-bg:      #3b82f6;
    --toggle-circle:  #ffffff;
    --loader-overlay: rgba(15,23,42,0.93);
    --spinner-border: #334155;
    --spinner-top:    #3b82f6;
}

/* Background immédiat sur html pour éviter le flash blanc */
html.dark { background: #0f172a; }

/* ── Base ── */
html { scroll-behavior: smooth; }
body {
    font-family: var(--font-sans);
    background: var(--bg-page);
    color: var(--text-primary);
    transition: background .25s, color .25s;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    min-height: 100dvh;
}

a { color: var(--accent); text-decoration: none; transition: color .15s; }
a:hover { color: var(--accent-hover); }

::-webkit-scrollbar { width:6px; height:6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius:3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ════════════════════════════════════════════════════════════
   COMPOSANTS
   ════════════════════════════════════════════════════════════ */

/* ── Loader ── */
.page-loader {
    position: fixed; inset: 0;
    background: var(--loader-overlay);
    backdrop-filter: blur(6px);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    z-index: 9999;
    transition: opacity .4s;
}
.page-loader.fade-out { opacity:0; pointer-events:none; }
.spinner {
    width:72px; height:72px;
    border: 5px solid var(--spinner-border);
    border-top-color: var(--spinner-top);
    border-radius: 50%;
    animation: spin .9s linear infinite;
    margin-bottom: 24px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-text-pill {
    font-size: 1rem; font-weight:500; color: var(--text-primary);
    background: var(--bg-card);
    padding: 10px 24px; border-radius: 60px;
    box-shadow: var(--shadow-lg); border: 1px solid var(--border);
    min-width: 280px; text-align: center;
    transition: opacity .3s;
}

/* ── Toggle dark/light ── */
.theme-toggle {
    background: var(--toggle-bg);
    border: none;
    width: 52px; height: 28px;
    border-radius: 40px;
    display: flex; align-items: center;
    padding: 4px; cursor: pointer;
    transition: background .25s;
    flex-shrink: 0;
}
.theme-toggle-circle {
    background: var(--toggle-circle);
    width: 20px; height: 20px;
    border-radius: 50%;
    transition: transform .25s cubic-bezier(.4,0,.2,1);
    box-shadow: 0 1px 4px rgba(0,0,0,.25);
}
/* Déplace le cercle en mode dark */
html.dark .theme-toggle-circle,
body.dark .theme-toggle-circle { transform: translateX(24px); }

/* ── Boutons ── */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 8px; padding: 10px 20px;
    border: none; border-radius: var(--radius);
    font-size: .93rem; font-weight:600;
    cursor: pointer; transition: background .2s, transform .15s, box-shadow .2s;
    text-decoration: none; white-space: nowrap; line-height:1;
    font-family: var(--font-sans);
}
.btn:active { transform: translateY(1px); }
.btn svg { width:16px; height:16px; flex-shrink:0; }

.btn-primary   { background: var(--accent); color:#fff; }
.btn-primary:hover { background: var(--accent-hover); box-shadow: 0 4px 12px rgba(37,99,235,.3); color:#fff; }
.btn-secondary { background: var(--border); color: var(--text-primary); }
.btn-secondary:hover { background: var(--text-muted); color:#fff; }
.btn-danger    { background: var(--error); color:#fff; }
.btn-danger:hover { background: #dc2626; }
.btn-success   { background: var(--success); color:#fff; }
.btn-outline {
    background: transparent;
    border: 1.5px solid var(--border);
    color: var(--text-primary);
}
.btn-outline:hover { background: var(--bg-page); }
.btn-sm   { padding: 7px 14px; font-size: .82rem; }
.btn-lg   { padding: 14px 28px; font-size: 1rem; }
.btn-full { width:100%; }
.btn-icon { padding: 8px; width:36px; height:36px; border-radius: var(--radius-sm); }

/* ── Badges ── */
.badge {
    display: inline-flex; align-items: center; gap:4px;
    padding: 3px 10px; border-radius: 99px;
    font-size: .78rem; font-weight:600; white-space:nowrap;
}
.badge-green  { background: var(--success-light); color: var(--success); }
.badge-red    { background: var(--error-light);   color: var(--error); }
.badge-orange { background: var(--warning-light); color: var(--warning); }
.badge-blue   { background: var(--info-light);    color: var(--info); }
.badge-gray   { background: var(--border);        color: var(--text-secondary); }
.badge-yellow { background: #fef9c3; color: #92400e; }
.badge-purple { background: #f3e8ff; color: #7c3aed; }
html.dark .badge-yellow,
body.dark .badge-yellow { background: #78350f; color: #fbbf24; }
html.dark .badge-purple,
body.dark .badge-purple { background: #3b0764; color: #c084fc; }

/* ── Formulaires ── */
.form-group { margin-bottom: 18px; }
.form-label { display:block; font-size:.87rem; font-weight:600; color: var(--text-primary); margin-bottom:6px; }
.form-label .required { color: var(--error); margin-left:2px; }

.form-control {
    width: 100%; padding: 11px 14px;
    border: 1.5px solid var(--border); border-radius: var(--radius);
    font-size: .93rem; font-family: var(--font-sans);
    color: var(--text-primary); background: var(--bg-input);
    outline: none; -webkit-appearance: none;
    transition: border-color .2s, box-shadow .2s, background .25s, color .25s;
}
.form-control:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.form-control.error { border-color: var(--error); box-shadow: 0 0 0 3px rgba(239,68,68,.1); }
.form-control::placeholder { color: var(--text-muted); }
textarea.form-control { resize:vertical; min-height:100px; }

select.form-control {
    cursor:pointer;
    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='%236b7280' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center;
    padding-right: 36px;
}
html.dark select.form-control,
body.dark select.form-control {
    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%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}
.form-error { display:block; font-size:.8rem; color: var(--error); margin-top:5px; min-height:18px; }

/* ── Cards ── */
.card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding:24px;
    transition: background .25s, border-color .25s, box-shadow .2s;
}
.card:hover { box-shadow: var(--shadow); }

/* ── Flash messages ── */
.flash-message {
    padding: 14px 18px; border-radius: var(--radius);
    margin-bottom: 20px; font-size:.9rem; font-weight:500;
    display:flex; align-items:center; gap:10px;
}
.flash-success { background: var(--success-light); color: var(--success); border: 1px solid var(--success); }
.flash-error   { background: var(--error-light);   color: var(--error);   border: 1px solid var(--error); }
.flash-warning { background: var(--warning-light); color: var(--warning); border: 1px solid var(--warning); }
.flash-info    { background: var(--info-light);    color: var(--info);    border: 1px solid var(--info); }

/* ── Tables ── */
.table-wrapper { overflow-x:auto; border-radius: var(--radius-lg); border: 1px solid var(--border); }
table { width:100%; border-collapse:collapse; font-size:.9rem; }
thead th {
    background: var(--bg-page); color: var(--text-secondary);
    font-weight:600; font-size:.8rem; text-transform:uppercase;
    letter-spacing:.05em; padding: 12px 16px;
    border-bottom: 1px solid var(--border); white-space:nowrap; text-align:left;
}
tbody td { padding: 14px 16px; border-bottom: 1px solid var(--border); vertical-align:middle; }
tbody tr:last-child td { border-bottom:none; }
tbody tr:hover { background: var(--bg-page); }

/* ── Pagination ── */
.pagination { display:flex; gap:6px; justify-content:center; margin-top:24px; flex-wrap:wrap; }
.page-btn {
    display:inline-flex; align-items:center; justify-content:center;
    width:36px; height:36px; border-radius: var(--radius);
    font-size:.88rem; font-weight:500;
    color: var(--text-secondary); background: var(--bg-card);
    border: 1px solid var(--border); text-decoration:none; transition: all .15s;
}
.page-btn.active, .page-btn:hover { background: var(--accent); color:#fff; border-color: var(--accent); }

/* ── Section header ── */
.section-header {
    display:flex; align-items:center; justify-content:space-between;
    margin-bottom:24px; flex-wrap:wrap; gap:12px;
}
.section-title   { font-size:1.4rem; font-weight:700; color: var(--text-primary); }
.section-subtitle { font-size:.9rem; color: var(--text-secondary); margin-top:4px; }

/* ── Modal ── */
.modal-overlay {
    position:fixed; inset:0;
    background: rgba(0,0,0,.5); backdrop-filter:blur(4px);
    display:flex; align-items:center; justify-content:center;
    z-index:1000; padding:20px;
    opacity:0; pointer-events:none; transition: opacity .25s;
}
.modal-overlay.open { opacity:1; pointer-events:all; }
.modal {
    background: var(--bg-card); border-radius: var(--radius-xl);
    max-width:560px; width:100%; padding:32px;
    border: 1px solid var(--border);
    transform: translateY(20px); transition: transform .25s;
    max-height: 90dvh; overflow-y:auto;
}
.modal-overlay.open .modal { transform:translateY(0); }
.modal-header { display:flex; align-items:center; justify-content:space-between; margin-bottom:24px; }
.modal-title  { font-size:1.2rem; font-weight:700; color: var(--text-primary); }
.modal-close {
    background:none; border:none; color: var(--text-muted); cursor:pointer;
    width:32px; height:32px; display:flex; align-items:center; justify-content:center;
    border-radius: var(--radius-sm); transition: background .15s;
}
.modal-close:hover { background: var(--bg-page); color: var(--text-primary); }
.modal-footer { display:flex; gap:10px; justify-content:flex-end; margin-top:24px; flex-wrap:wrap; }

/* ── Code ── */
code {
    background: var(--bg-page); color: var(--accent);
    padding: 2px 6px; border-radius:4px;
    font-size:.88em; border: 1px solid var(--border);
}

/* ════════════════════════════════════════════════════════════
   RESPONSIVE GLOBAL
   ════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    .section-header { flex-direction:column; align-items:flex-start; gap:10px; }
    .section-header .btn { width:100%; justify-content:center; }
    .section-title { font-size:1.15rem; }

    .modal { padding:20px 16px; border-radius: var(--radius-lg); max-height:95dvh; }
    .modal-footer { flex-direction:column; }
    .modal-footer .btn { width:100%; justify-content:center; }

    tbody td, thead th { padding:10px 10px; font-size:.82rem; }
    .pagination .page-btn { width:32px; height:32px; font-size:.82rem; }

    .flash-message { font-size:.85rem; padding:11px 14px; }

    /* Utility : masquer sur petit écran */
    .hide-mobile { display:none !important; }
}

@media (max-width: 480px) {
    .modal { padding:16px 12px; }
}
