/* ============================================================
   U-Magis - Theme clair / sombre
   Bascule manuelle : bouton [data-theme-toggle]
   ============================================================ */

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    border: 1px solid #dce2ec;
    background: #f7f9fc;
    color: #2c3e5a;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    padding: 0;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s, border-color .15s, color .15s;
    font-family: inherit;
}
.theme-toggle:hover {
    background: #eef3fa;
    border-color: #c8d4e3;
    color: #1a2639;
}
.theme-toggle i { font-size: 13px; }
.theme-toggle-floating {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 9999;
    width: 38px;
    height: 38px;
    background: #fff;
    box-shadow: 0 8px 24px rgba(15, 23, 34, .16);
}
body:has(.topbar) .theme-toggle-floating,
body:has(.bs-top) .theme-toggle-floating { display: none; }
.topbar .user .theme-toggle { margin-right: 2px; }
.bs-nav .theme-toggle { height: 32px; }

@media (max-width: 760px) {
    .theme-toggle { padding: 0; }
}

/* ============================================================
   Palette sombre
   ============================================================ */
html[data-theme="dark"] {
    color-scheme: dark;
    --dm-bg: #0e1622;
    --dm-bg-2: #111c2a;
    --dm-surface: #172233;
    --dm-surface-2: #1d2b3f;
    --dm-surface-3: #24354b;
    --dm-border: #2d4058;
    --dm-border-soft: #25364b;
    --dm-text: #e8eef7;
    --dm-text-soft: #c8d5e5;
    --dm-muted: #9fb1c7;
    --dm-accent: #79b2ea;
    --dm-accent-soft: #1b3552;
    --dm-danger: #ff7b88;
    --dm-success: #6bd6a0;
    --dm-warning: #f4b860;
}

/* ---------- Base ---------- */
html[data-theme="dark"],
html[data-theme="dark"] body {
    background: var(--dm-bg) !important;
    color: var(--dm-text) !important;
}
html[data-theme="dark"] body,
html[data-theme="dark"] #adminWrap,
html[data-theme="dark"] .admin-body,
html[data-theme="dark"] .main-content {
    background: var(--dm-bg) !important;
    color: var(--dm-text) !important;
}
html[data-theme="dark"] h1,
html[data-theme="dark"] h2,
html[data-theme="dark"] h3,
html[data-theme="dark"] h4,
html[data-theme="dark"] h5,
html[data-theme="dark"] h6,
html[data-theme="dark"] .page-title,
html[data-theme="dark"] .page-header h2,
html[data-theme="dark"] .card h2,
html[data-theme="dark"] .modal-box h3 {
    color: var(--dm-text) !important;
}
html[data-theme="dark"] p,
html[data-theme="dark"] small,
html[data-theme="dark"] label,
html[data-theme="dark"] .text-muted,
html[data-theme="dark"] .tres-muted {
    color: var(--dm-text-soft);
}
html[data-theme="dark"] a { color: var(--dm-accent); }
html[data-theme="dark"] ::selection { background: #31557d; color: #fff; }
html[data-theme="dark"] .theme-toggle {
    background: var(--dm-surface-2) !important;
    border-color: var(--dm-border) !important;
    color: var(--dm-text) !important;
}
html[data-theme="dark"] .theme-toggle:hover {
    background: var(--dm-surface-3) !important;
    border-color: #3c5573 !important;
    color: #fff !important;
}
html[data-theme="dark"] .theme-toggle-floating {
    background: var(--dm-surface) !important;
    box-shadow: 0 8px 24px rgba(0,0,0,.4) !important;
}

/* ---------- Topbar ---------- */
html[data-theme="dark"] .topbar,
html[data-theme="dark"] .topbar.fixed-header {
    background: var(--dm-surface) !important;
    border-bottom-color: var(--dm-border) !important;
    box-shadow: 0 1px 0 var(--dm-border), 0 4px 18px rgba(0,0,0,.18) !important;
}
html[data-theme="dark"] .topbar .brand,
html[data-theme="dark"] .topbar .user,
html[data-theme="dark"] .topbar .user span,
html[data-theme="dark"] .topbar .user a {
    color: var(--dm-text) !important;
}
html[data-theme="dark"] .topbar .user i { color: var(--dm-muted) !important; }
html[data-theme="dark"] .topbar .user i:hover,
html[data-theme="dark"] .hamburger-btn:hover {
    background: var(--dm-surface-2) !important;
    color: var(--dm-accent) !important;
}
html[data-theme="dark"] .hamburger-btn { color: var(--dm-text) !important; }

/* ---------- Sidebar ---------- */
html[data-theme="dark"] .sidebar {
    background: var(--dm-surface) !important;
    border-right-color: var(--dm-border) !important;
}
html[data-theme="dark"] .sidebar-header,
html[data-theme="dark"] .sidebar-footer,
html[data-theme="dark"] .sidebar-menu {
    border-color: var(--dm-border-soft) !important;
}
html[data-theme="dark"] .sidebar-header .menu-label,
html[data-theme="dark"] .sidebar-footer .version { color: var(--dm-muted) !important; }
html[data-theme="dark"] .sidebar-toggle,
html[data-theme="dark"] .sidebar-close-mobile { color: var(--dm-muted) !important; }
html[data-theme="dark"] .sidebar-toggle:hover,
html[data-theme="dark"] .sidebar-close-mobile:hover { background: var(--dm-surface-2) !important; color: var(--dm-text) !important; }
html[data-theme="dark"] .menu-link { color: var(--dm-text-soft) !important; }
html[data-theme="dark"] .menu-link i { color: var(--dm-muted) !important; }
html[data-theme="dark"] .menu-link .submenu-arrow { color: var(--dm-muted) !important; }
html[data-theme="dark"] .menu-link:hover { background: var(--dm-surface-2) !important; color: var(--dm-text) !important; }
html[data-theme="dark"] .menu-item.active > .menu-link {
    background: var(--dm-accent-soft) !important;
    color: #dcecff !important;
}
html[data-theme="dark"] .menu-item.active > .menu-link i { color: var(--dm-accent) !important; }
html[data-theme="dark"] .submenu li a { color: var(--dm-text-soft) !important; }
html[data-theme="dark"] .submenu li a i { color: var(--dm-muted) !important; }
html[data-theme="dark"] .submenu li a:hover { background: var(--dm-surface-2) !important; color: var(--dm-text) !important; }
html[data-theme="dark"] .submenu li a.active { background: var(--dm-accent-soft) !important; color: #dcecff !important; }
html[data-theme="dark"] .sidebar-menu::-webkit-scrollbar-track { background: var(--dm-surface-2) !important; }
html[data-theme="dark"] .sidebar-menu::-webkit-scrollbar-thumb { background: #3b516b !important; }

/* ---------- Cartes / contenu / tableaux ---------- */
html[data-theme="dark"] .card,
html[data-theme="dark"] .table-container,
html[data-theme="dark"] .table-wrap,
html[data-theme="dark"] .table-responsive,
html[data-theme="dark"] .content > table,
html[data-theme="dark"] .modal-box,
html[data-theme="dark"] .alert {
    background: var(--dm-surface) !important;
    border-color: var(--dm-border) !important;
    color: var(--dm-text) !important;
    box-shadow: 0 4px 18px rgba(0,0,0,.12) !important;
}
html[data-theme="dark"] .card h2 { border-bottom-color: var(--dm-border-soft) !important; }
html[data-theme="dark"] table { color: var(--dm-text) !important; }
html[data-theme="dark"] th {
    background: var(--dm-surface-2) !important;
    color: var(--dm-text) !important;
    border-bottom-color: var(--dm-border) !important;
}
html[data-theme="dark"] td {
    color: var(--dm-text-soft) !important;
    border-bottom-color: var(--dm-border-soft) !important;
}
html[data-theme="dark"] tbody tr:nth-child(even) { background: #1a2738 !important; }
html[data-theme="dark"] tbody tr:hover { background: #223349 !important; }
html[data-theme="dark"] tr:last-child td { border-bottom-color: transparent !important; }

/* ---------- Formulaires ---------- */
html[data-theme="dark"] label { color: var(--dm-text) !important; }
html[data-theme="dark"] input[type="text"],
html[data-theme="dark"] input[type="password"],
html[data-theme="dark"] input[type="email"],
html[data-theme="dark"] input[type="number"],
html[data-theme="dark"] input[type="date"],
html[data-theme="dark"] input[type="datetime-local"],
html[data-theme="dark"] input[type="search"],
html[data-theme="dark"] input[type="tel"],
html[data-theme="dark"] input[type="url"],
html[data-theme="dark"] select,
html[data-theme="dark"] textarea {
    background: var(--dm-bg-2) !important;
    border-color: var(--dm-border) !important;
    color: var(--dm-text) !important;
}
html[data-theme="dark"] input:focus,
html[data-theme="dark"] select:focus,
html[data-theme="dark"] textarea:focus {
    background: var(--dm-surface) !important;
    border-color: var(--dm-accent) !important;
    box-shadow: 0 0 0 3px rgba(121,178,234,.15) !important;
}
html[data-theme="dark"] select option { background: var(--dm-surface); color: var(--dm-text); }
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder { color: #7f93ab !important; }
html[data-theme="dark"] input[type="checkbox"],
html[data-theme="dark"] input[type="radio"] { accent-color: var(--dm-accent); }
html[data-theme="dark"] .annee-select {
    background: var(--dm-surface-2) !important;
    border-color: var(--dm-border) !important;
    color: var(--dm-accent) !important;
}

/* ---------- Boutons neutres ---------- */
html[data-theme="dark"] .btn:not(.btn-primary):not(.btn-danger):not(.btn-success):not(.btn-info):not(.btn-warning):not(.btn-default) {
    background: var(--dm-surface-2) !important;
    border-color: var(--dm-border) !important;
    color: var(--dm-text) !important;
}
html[data-theme="dark"] .btn:not(.btn-primary):not(.btn-danger):not(.btn-success):not(.btn-info):not(.btn-warning):not(.btn-default):hover {
    background: var(--dm-surface-3) !important;
    border-color: #3c5573 !important;
}
html[data-theme="dark"] .btn-white { background: var(--dm-surface-2) !important; border-color: var(--dm-border) !important; color: var(--dm-accent) !important; }
html[data-theme="dark"] .btn-white:hover { background: var(--dm-surface-3) !important; }
html[data-theme="dark"] .btn-outline { background: transparent !important; border-color: var(--dm-border) !important; color: var(--dm-text) !important; }
html[data-theme="dark"] .btn-outline:hover { background: var(--dm-surface-2) !important; }
html[data-theme="dark"] .btn-default { background: #4a6078 !important; border-color: #4a6078 !important; color: #fff !important; }
html[data-theme="dark"] .btn-default:hover { background: #5b728b !important; border-color: #5b728b !important; }
html[data-theme="dark"] .btn-active { background: var(--dm-surface-2) !important; border-color: var(--dm-accent) !important; color: var(--dm-accent) !important; }

/* ---------- Alertes / badges ---------- */
html[data-theme="dark"] .alert-success { background: #153526 !important; border-color: #24573b !important; color: #9ce9bc !important; }
html[data-theme="dark"] .alert-error { background: #3a1820 !important; border-color: #632b36 !important; color: #ffb3bc !important; }
html[data-theme="dark"] .alert-warning { background: #3a2b14 !important; border-color: #60481f !important; color: #f4c97a !important; }
html[data-theme="dark"] .badge { background: var(--dm-surface-3) !important; color: var(--dm-text) !important; }
html[data-theme="dark"] .badge-blue { background: #2f5f91 !important; color: #fff !important; }
html[data-theme="dark"] .badge-red { background: #a32436 !important; color: #fff !important; }

/* ---------- Modales / dropdowns ---------- */
html[data-theme="dark"] .modal-overlay { background: rgba(0,0,0,.55) !important; }
html[data-theme="dark"] .modal-header { border-bottom-color: var(--dm-border) !important; }
html[data-theme="dark"] .modal-header .modal-close { color: var(--dm-muted) !important; }
html[data-theme="dark"] .modal-header .modal-close:hover { background: var(--dm-surface-2) !important; color: var(--dm-text) !important; }
html[data-theme="dark"] .dropdown-menu,
html[data-theme="dark"] .ss-list,
html[data-theme="dark"] .ss-content {
    background: var(--dm-surface) !important;
    border-color: var(--dm-border) !important;
    color: var(--dm-text) !important;
}
html[data-theme="dark"] .ss-main,
html[data-theme="dark"] .ss-values .ss-value {
    background: var(--dm-bg-2) !important;
    border-color: var(--dm-border) !important;
    color: var(--dm-text) !important;
}
html[data-theme="dark"] .ss-option:hover,
html[data-theme="dark"] .ss-option.ss-highlighted { background: var(--dm-surface-2) !important; color: var(--dm-text) !important; }
html[data-theme="dark"] .ss-option.ss-selected { background: var(--dm-accent-soft) !important; color: #dcecff !important; }

/* ---------- Connexion ---------- */
html[data-theme="dark"] .login-page { background: var(--dm-bg) !important; }
html[data-theme="dark"] .login-box {
    background: var(--dm-surface) !important;
    border-color: var(--dm-border) !important;
    box-shadow: 0 18px 46px rgba(0,0,0,.35) !important;
}
html[data-theme="dark"] .login-box h1 { color: var(--dm-text) !important; }
html[data-theme="dark"] .login-box .sub { color: var(--dm-muted) !important; border-left-color: var(--dm-accent) !important; }
html[data-theme="dark"] .login-box label { color: var(--dm-text) !important; }
html[data-theme="dark"] .login-box input {
    background: var(--dm-bg-2) !important;
    border-color: var(--dm-border) !important;
    color: var(--dm-text) !important;
}
html[data-theme="dark"] .login-box input:focus { background: var(--dm-surface) !important; border-color: var(--dm-accent) !important; }
html[data-theme="dark"] .login-box .hint { color: var(--dm-muted) !important; }
html[data-theme="dark"] .login-box .hint a { color: var(--dm-accent) !important; }
html[data-theme="dark"] .password-wrapper .toggle-pass { color: var(--dm-accent) !important; }

/* ---------- Catalogue / bibliotheque ---------- */
html[data-theme="dark"] .cat-shell { background: var(--dm-bg) !important; color: var(--dm-text) !important; }
html[data-theme="dark"] .cat-top { background: var(--dm-surface) !important; border-bottom-color: var(--dm-border) !important; color: var(--dm-text-soft) !important; }
html[data-theme="dark"] .cat-top-actions a { background: var(--dm-surface-2) !important; border-color: var(--dm-border) !important; color: var(--dm-text) !important; }
html[data-theme="dark"] .cat-top-actions a:hover { background: var(--dm-surface-3) !important; }
html[data-theme="dark"] .cat-head h1 { color: var(--dm-text) !important; }
html[data-theme="dark"] .cat-campus-note { background: var(--dm-surface-2) !important; border-color: var(--dm-border) !important; color: var(--dm-muted) !important; }
html[data-theme="dark"] .cat-filters { background: var(--dm-surface) !important; border-color: var(--dm-border) !important; box-shadow: 0 2px 12px rgba(0,0,0,.2) !important; }
html[data-theme="dark"] .cat-field label { color: var(--dm-muted) !important; }
html[data-theme="dark"] .cat-field input,
html[data-theme="dark"] .cat-field select { background: var(--dm-bg-2) !important; border-color: var(--dm-border) !important; color: var(--dm-text) !important; }
html[data-theme="dark"] .cat-submit { background: var(--dm-accent) !important; border-color: var(--dm-accent) !important; color: #0b1521 !important; }
html[data-theme="dark"] .cat-reset { background: var(--dm-surface-2) !important; border-color: var(--dm-border) !important; color: var(--dm-text) !important; }
html[data-theme="dark"] .cat-card { background: var(--dm-surface) !important; border-color: var(--dm-border) !important; }
html[data-theme="dark"] .cat-title { color: var(--dm-text) !important; }
html[data-theme="dark"] .cat-author,
html[data-theme="dark"] .cat-meta-line { color: var(--dm-muted) !important; }
html[data-theme="dark"] .cat-empty { background: var(--dm-surface) !important; border-color: var(--dm-border) !important; color: var(--dm-muted) !important; }
html[data-theme="dark"] .cat-badge.campus { background: var(--dm-surface-3) !important; color: var(--dm-text-soft) !important; }

/* ---------- Tresorerie ---------- */
html[data-theme="dark"] .tres-card,
html[data-theme="dark"] .tres-filters,
html[data-theme="dark"] .tres-table-wrap,
html[data-theme="dark"] .tres-summary,
html[data-theme="dark"] .tres-empty {
    background: var(--dm-surface) !important;
    border-color: var(--dm-border) !important;
    color: var(--dm-text) !important;
}
html[data-theme="dark"] .tres-head h1,
html[data-theme="dark"] .tres-section-title { color: var(--dm-text) !important; }
html[data-theme="dark"] .tres-muted { color: var(--dm-muted) !important; }
html[data-theme="dark"] .tres-pill { background: var(--dm-surface-3) !important; color: var(--dm-text-soft) !important; }
html[data-theme="dark"] .tres-table th { background: var(--dm-surface-2) !important; color: var(--dm-text) !important; }
html[data-theme="dark"] .tres-table td { color: var(--dm-text-soft) !important; border-color: var(--dm-border-soft) !important; }

/* ---------- Assistant IA ---------- */
html[data-theme="dark"] .ai-page,
html[data-theme="dark"] .ai-chat-page,
html[data-theme="dark"] .ai-shell { background: var(--dm-bg) !important; color: var(--dm-text) !important; }
html[data-theme="dark"] .ai-sidebar,
html[data-theme="dark"] .ai-main,
html[data-theme="dark"] .ai-topbar,
html[data-theme="dark"] .ai-chat { background: var(--dm-surface) !important; border-color: var(--dm-border) !important; color: var(--dm-text) !important; }
html[data-theme="dark"] .ai-sidebar-head,
html[data-theme="dark"] .ai-sidebar-foot { border-color: var(--dm-border) !important; }
html[data-theme="dark"] .ai-conv:hover,
html[data-theme="dark"] .ai-conv.active { background: var(--dm-surface-2) !important; }
html[data-theme="dark"] .ai-msg.assistant .ai-msg-body,
html[data-theme="dark"] .ai-msg-body { background: var(--dm-surface-2) !important; color: var(--dm-text) !important; }
html[data-theme="dark"] .ai-msg.user .ai-msg-body { background: var(--dm-accent-soft) !important; color: #e8f2ff !important; }
html[data-theme="dark"] .ai-suggestions button { background: var(--dm-surface-2) !important; border-color: var(--dm-border) !important; color: var(--dm-text) !important; }
html[data-theme="dark"] .ai-model-select select { background: var(--dm-bg-2) !important; border-color: var(--dm-border) !important; color: var(--dm-text) !important; }

/* ---------- Visio ---------- */
html[data-theme="dark"] .visio-page { background: var(--dm-bg) !important; color: var(--dm-text) !important; }
html[data-theme="dark"] .visio-card,
html[data-theme="dark"] .visio-pro-connected,
html[data-theme="dark"] .visio-admin-stats,
html[data-theme="dark"] .visio-help,
html[data-theme="dark"] .visio-credentials { background: var(--dm-surface) !important; border-color: var(--dm-border) !important; color: var(--dm-text) !important; }
html[data-theme="dark"] .visio-card h2,
html[data-theme="dark"] .visio-hero h1 { color: var(--dm-text) !important; }
html[data-theme="dark"] .visio-sub,
html[data-theme="dark"] .visio-field .hint { color: var(--dm-muted) !important; }
html[data-theme="dark"] .visio-field input { background: var(--dm-bg-2) !important; border-color: var(--dm-border) !important; color: var(--dm-text) !important; }

/* ---------- Site Business School ---------- */
html[data-theme="dark"] {
    --bs-bg: #0e1622;
    --bs-dark: #e8eef7;
    --bs-ink: #dbe6f3;
    --bs-muted: #9fb1c7;
    --bs-line: #2d4058;
    --bs-soft: #1d2b3f;
    --bs-blue: #79b2ea;
    --bs-blue-dark: #5d97cf;
}
html[data-theme="dark"] .bs-page { background: var(--bs-bg) !important; color: var(--bs-ink) !important; }
html[data-theme="dark"] .bs-top { background: #172233 !important; border-bottom-color: var(--bs-line) !important; box-shadow: 0 1px 0 var(--bs-line), 0 6px 18px rgba(0,0,0,.22) !important; }
html[data-theme="dark"] .bs-brand-text strong { color: var(--bs-dark) !important; }
html[data-theme="dark"] .bs-brand-text small { color: var(--bs-muted) !important; }
html[data-theme="dark"] .bs-nav a { background: #1d2b3f !important; border-color: #2d4058 !important; color: #c8d5e5 !important; }
html[data-theme="dark"] .bs-nav a:hover { background: #24354b !important; }
html[data-theme="dark"] .bs-nav a.active { background: var(--bs-blue) !important; border-color: var(--bs-blue) !important; color: #0b1521 !important; }
html[data-theme="dark"] .bs-card,
html[data-theme="dark"] .bs-band,
html[data-theme="dark"] .bs-cta,
html[data-theme="dark"] .bs-empty,
html[data-theme="dark"] .bs-login-card {
    background: #172233 !important;
    border-color: #2d4058 !important;
    color: var(--bs-ink) !important;
}
html[data-theme="dark"] .bs-section-head h2,
html[data-theme="dark"] .bs-feature h3,
html[data-theme="dark"] .bs-name,
html[data-theme="dark"] .bs-cta h3,
html[data-theme="dark"] .bs-login-card h1 { color: var(--bs-dark) !important; }
html[data-theme="dark"] .bs-section-head p,
html[data-theme="dark"] .bs-feature p,
html[data-theme="dark"] .bs-desc,
html[data-theme="dark"] .bs-type,
html[data-theme="dark"] .bs-cta p,
html[data-theme="dark"] .bs-login-sub { color: var(--bs-muted) !important; }
html[data-theme="dark"] .bs-foot { background: #172233 !important; border-top-color: #2d4058 !important; }
html[data-theme="dark"] .bs-foot-inner { color: var(--bs-muted) !important; }

/* ---------- Scrollbars ---------- */
html[data-theme="dark"] .main-content::-webkit-scrollbar-track { background: var(--dm-bg-2) !important; }
html[data-theme="dark"] .main-content::-webkit-scrollbar-thumb { background: #3b516b !important; }
html[data-theme="dark"] .main-content::-webkit-scrollbar-thumb:hover { background: #4b6481 !important; }
html[data-theme="dark"] * { scrollbar-color: #3b516b var(--dm-bg-2); }

/* Ne pas appliquer le sombre a l'impression */
@media print {
    html[data-theme="dark"],
    html[data-theme="dark"] body { background: #fff !important; color: #000 !important; }
}
