/* Anti-flash thème : appliqué AVANT que le JS charge */
html.light-mode-html body {
    background-color: #f1f5f9 !important;
}

/* Variables globales */
:root {
    --primary-color: #2563eb;
    --primary-dark: #1e40af;
    --secondary-color: #0ea5e9;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --info-color: #06b6d4;
    
    --bg-dark: #0f172a;
    --bg-darker: #020617;
    --bg-light: #1e293b;
    --bg-lighter: #334155;
    
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    
    --border-color: #334155;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
    
    --sidebar-width: 260px;
    --header-height: 70px;
}

/* Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-darker);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden; /* jamais de scroll horizontal sur la page */
    height: 100vh;
    overflow-y: hidden; /* le scroll est géré dans #page-content */
}

/* Pages d'authentification */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--bg-darker) 0%, var(--bg-dark) 100%);
    padding: 20px;
}

.auth-container {
    max-width: 450px;
    width: 100%;
}

.auth-header {
    text-align: center;
    margin-bottom: 30px;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    font-size: 32px;
    color: var(--primary-color);
    margin-bottom: 10px;
}

.logo i {
    font-size: 40px;
}

.logo h1 {
    font-size: 32px;
    font-weight: 800;
    color: var(--text-primary);
}

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

.auth-box {
    background-color: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 40px;
    box-shadow: var(--shadow-lg);
}

.auth-box h2 {
    margin-bottom: 25px;
    font-size: 24px;
    text-align: center;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 14px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 16px;
    background-color: var(--bg-darker);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    transition: all 0.3s ease;
}

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

.form-group textarea {
    resize: vertical;
    min-height: 100px;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
}

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

.btn-primary:hover {
    background-color: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.btn-secondary {
    background-color: var(--bg-lighter);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background-color: var(--border-color);
}

.btn-success {
    background-color: var(--success-color);
    color: white;
}

.btn-danger {
    background-color: var(--danger-color);
    color: white;
}

.btn-warning {
    background-color: var(--warning-color);
    color: white;
}

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

.btn-sm {
    padding: 8px 16px;
    font-size: 13px;
}

.auth-footer {
    margin-top: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

.auth-footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
}

.auth-footer a:hover {
    text-decoration: underline;
}

/* Application principale */
#main-app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-dark);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    z-index: 1000;
}

.sidebar-header {
    display: none; /* Desktop : pas de header sidebar, le nav commence directement en haut */
}

.sidebar-nav {
    flex: 1;
    padding: 12px 10px 20px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 8px;
    margin-bottom: 5px;
    transition: all 0.3s ease;
    font-size: 14px;
    font-weight: 500;
}

.nav-item:hover {
    background-color: var(--bg-light);
    color: var(--text-primary);
}

.nav-item.active {
    background-color: var(--primary-color);
    color: white;
}

.nav-item i {
    width: 20px;
    text-align: center;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.user-info i {
    font-size: 32px;
    color: var(--primary-color);
}

.user-name {
    font-weight: 600;
    font-size: 14px;
}

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

.btn-logout {
    background-color: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: all 0.3s ease;
}

.btn-logout:hover {
    background-color: var(--danger-color);
    color: white;
}

/* Contenu principal */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
    background-color: var(--bg-darker);
    /* Hauteur fixe pour que sticky fonctionne + pas de scroll horizontal */
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#page-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 30px;
    /* Scroll vertical uniquement ici, jamais horizontal sur la page */
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    /* Contraindre la largeur pour éviter tout débordement */
    width: 100%;
    box-sizing: border-box;
}

/* En-tête de page */
.page-header {
    margin-bottom: 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
}

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

.page-title h1 {
    font-size: 28px;
    font-weight: 700;
}

.page-title i {
    font-size: 28px;
    color: var(--primary-color);
}

.page-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* Cartes */
.card {
    background-color: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

.card-title {
    font-size: 18px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.card-body {
    color: var(--text-secondary);
}

/* Grille de statistiques */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-light) 100%);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 24px;
    box-shadow: var(--shadow);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
}

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

.stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.stat-icon.primary {
    background-color: rgba(37, 99, 235, 0.2);
    color: var(--primary-color);
}

.stat-icon.success {
    background-color: rgba(16, 185, 129, 0.2);
    color: var(--success-color);
}

.stat-icon.warning {
    background-color: rgba(245, 158, 11, 0.2);
    color: var(--warning-color);
}

.stat-icon.danger {
    background-color: rgba(239, 68, 68, 0.2);
    color: var(--danger-color);
}

.stat-trend {
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 4px;
}

.stat-trend.up {
    background-color: rgba(16, 185, 129, 0.2);
    color: var(--success-color);
}

.stat-trend.down {
    background-color: rgba(239, 68, 68, 0.2);
    color: var(--danger-color);
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 5px;
}

.stat-label {
    color: var(--text-muted);
    font-size: 14px;
}

/* Tableaux */
.table-container {
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    /* Contenu scrollable uniquement dans ce bloc */
    max-width: 100%;
}

table {
    width: 100%;
    min-width: 600px; /* force le scroll horizontal sur le tableau, pas sur la page */
    border-collapse: collapse;
}

thead {
    background-color: var(--bg-light);
    border-bottom: 2px solid var(--border-color);
}

th {
    padding: 14px;
    text-align: left;
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
}

td {
    padding: 14px;
    border-bottom: 1px solid var(--border-color);
    font-size: 14px;
}

tr:hover {
    background-color: var(--bg-light);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge.success {
    background-color: rgba(16, 185, 129, 0.2);
    color: var(--success-color);
}

.badge.warning {
    background-color: rgba(245, 158, 11, 0.2);
    color: var(--warning-color);
}

.badge.danger {
    background-color: rgba(239, 68, 68, 0.2);
    color: var(--danger-color);
}

.badge.info {
    background-color: rgba(6, 182, 212, 0.2);
    color: var(--info-color);
}

.badge.primary {
    background-color: rgba(37, 99, 235, 0.2);
    color: var(--primary-color);
}

.badge.secondary {
    background-color: rgba(148, 163, 184, 0.2);
    color: var(--text-muted);
}

/* Stat cards cliquables */
.stat-card.clickable,
.stat-card[onclick] {
    cursor: pointer;
    transition: box-shadow 0.18s, transform 0.18s;
}
.stat-card.clickable:hover,
.stat-card[onclick]:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(0,0,0,0.18);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.modal.active {
    display: flex;
}

.modal-content {
    background-color: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

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

.modal-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    transition: color 0.3s ease;
}

.modal-close:hover {
    color: var(--danger-color);
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    padding: 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* Alertes */
.alert {
    padding: 16px 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
}

.alert i {
    font-size: 20px;
}

.alert.success {
    background-color: rgba(16, 185, 129, 0.2);
    border-left: 4px solid var(--success-color);
    color: var(--success-color);
}

.alert.warning {
    background-color: rgba(245, 158, 11, 0.2);
    border-left: 4px solid var(--warning-color);
    color: var(--warning-color);
}

.alert.danger {
    background-color: rgba(239, 68, 68, 0.2);
    border-left: 4px solid var(--danger-color);
    color: var(--danger-color);
}

.alert.info {
    background-color: rgba(6, 182, 212, 0.2);
    border-left: 4px solid var(--info-color);
    color: var(--info-color);
}

/* Barre de recherche */
.search-box {
    position: relative;
    flex: 1;
    max-width: 400px;
}

.search-box input {
    width: 100%;
    padding: 12px 16px 12px 45px;
    background-color: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
}

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

/* Filtres */
.filters {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

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

.filter-group select {
    padding: 8px 12px;
    background-color: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 14px;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin-top: 30px;
}

.pagination button {
    padding: 8px 16px;
    background-color: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.3s ease;
}

.pagination button:hover:not(:disabled) {
    background-color: var(--primary-color);
}

.pagination button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination .page-info {
    color: var(--text-secondary);
    font-size: 14px;
}

/* Progress bars */
.progress {
    height: 8px;
    background-color: var(--bg-light);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background-color: var(--primary-color);
    transition: width 0.3s ease;
}

.progress-bar.success {
    background-color: var(--success-color);
}

.progress-bar.warning {
    background-color: var(--warning-color);
}

.progress-bar.danger {
    background-color: var(--danger-color);
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 64px;
    margin-bottom: 20px;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 20px;
    margin-bottom: 10px;
    color: var(--text-secondary);
}

.empty-state p {
    font-size: 14px;
    margin-bottom: 20px;
}

/* ============================================================
   RESPONSIVE — Sidebar hamburger + layout adaptatif
   ============================================================ */

/* Bouton × dans la sidebar (visible uniquement en mode réduit) */
.sidebar-close-btn {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
    transition: all 0.2s ease;
    margin-left: auto;
    flex-shrink: 0;
}
.sidebar-close-btn:hover {
    background: var(--bg-light);
    color: var(--text-primary);
}

/* Topbar mobile (cachée sur grand écran) */
.topbar {
    display: none;
    align-items: center;
    gap: 14px;
    padding: 0 16px;
    height: 56px;
    min-height: 56px;
    background: var(--bg-dark);
    border-bottom: 1px solid var(--border-color);
    /* Sticky dans le flex container main-content */
    position: sticky;
    top: 0;
    z-index: 100;
    flex-shrink: 0;
    width: 100%;
    box-sizing: border-box;
}
.hamburger-btn {
    display: none; /* Masqué sur desktop — visible uniquement mobile/tablette */
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 22px;
    cursor: pointer;
    padding: 8px 10px;
    border-radius: 6px;
    transition: background 0.2s ease;
    flex-shrink: 0;
    line-height: 1;
}
.hamburger-btn:hover {
    background: var(--bg-light);
}
.topbar-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
}
.topbar-logo i {
    color: var(--primary-color);
}
.topbar-user {
    margin-left: auto;
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 130px;
}

/* Overlay — position fixed pour couvrir toute la page */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 998;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}
.sidebar-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* ── Breakpoint 1024px ── */
@media (max-width: 1024px) {

    /* Hamburger visible sur mobile/tablette */
    .hamburger-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* La sidebar sort vers la gauche par défaut */
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 999;
        position: fixed;
    }

    /* Classe ajoutée par JS pour l'afficher */
    .sidebar.mobile-open {
        transform: translateX(0);
    }

    /* En mobile, afficher le header sidebar avec le bouton fermer */
    .sidebar-header {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        padding: 0 16px;
        height: 56px;
        border-bottom: 1px solid var(--border-color);
    }

    .sidebar-close-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .sidebar-overlay {
        display: block;
    }

    .topbar {
        display: flex;
    }

    .main-content {
        margin-left: 0;
        height: 100vh;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    #page-content {
        padding: 20px;
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
    }
}

/* ── Breakpoint 768px ── */
@media (max-width: 768px) {

    #page-content {
        padding: 15px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .page-actions {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }

    .modal-content {
        width: 95vw;
        max-width: 95vw;
        margin: 10px auto;
    }

    /* Grilles de contenu */
    .grid-2col,
    .grid-3col,
    .grid-main-aside,
    .grid-auto {
        grid-template-columns: 1fr !important;
    }

    /* Grilles inline dans les pages JS */
    [style*="grid-template-columns: 2fr 1fr"],
    [style*="grid-template-columns: 1fr 1fr; gap"],
    [style*="grid-template-columns: 1fr 1fr 1fr"],
    [style*="grid-template-columns:1fr 1fr;"],
    [style*="grid-template-columns:1fr 1fr 1fr;"] {
        grid-template-columns: 1fr !important;
    }

    /* Grilles auto-fit avec minmax > 280px */
    [style*="minmax(300px"],
    [style*="minmax(350px"],
    [style*="minmax(220px"] {
        grid-template-columns: 1fr !important;
    }

    /* Cards billing et settings — réduire padding */
    .card {
        padding: 16px;
    }
}

/* ── Breakpoint 480px ── */
@media (max-width: 480px) {

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

    .topbar-user {
        display: none;
    }

    .page-header h1 {
        font-size: 20px;
    }

    /* Toutes les grilles en 1 colonne */
    [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }

    .card {
        padding: 12px;
        border-radius: 8px;
    }

    .stat-card {
        padding: 16px;
    }

    .stat-value {
        font-size: 24px;
    }

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

/* ============================================================
   Grilles utilitaires responsives (à utiliser dans les pages JS)
   ============================================================ */

/* 2 colonnes égales */
.grid-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

/* 3 colonnes égales */
.grid-3col {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
}

/* Layout principal 2/3 + sidebar 1/3 */
.grid-main-aside {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

/* Auto-fit adaptatif (cartes de plan, intégrations, etc.) */
.grid-auto {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
}

/* Auto-fit avec minimum plus grand */
.grid-auto-lg {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
}

/* Grille de clé/valeur (détails) */
.grid-detail {
    display: grid;
    grid-template-columns: 150px 1fr;
    gap: 10px;
    font-size: 14px;
    line-height: 1.8;
}

/* Utilities */
.text-center { text-align: center; }
.text-right  { text-align: right; }
.mt-20 { margin-top: 20px; }
.mb-20 { margin-bottom: 20px; }
.flex  { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-center  { display: flex; justify-content: center; align-items: center; }
.gap-10 { gap: 10px; }
.hidden { display: none; }

/* ── Logo upload drop zone ─────────────────────────────── */
#logo-drop-zone:hover {
    border-color: var(--primary-color) !important;
    background: rgba(37,99,235,0.05) !important;
}
#logo-drop-zone:active {
    transform: scale(0.99);
}


/* ═══════════════════════════════════════════════════════════════
   NOUVEAUX STYLES v9 — Header fixe, Nav-groups, Langue, Filtre
   ═══════════════════════════════════════════════════════════════ */

/* ── Ajustements layout pour le header fixe ── */
:root {
    --app-header-height: 62px;
}

.main-content {
    margin-top: var(--app-header-height) !important;
    min-height: calc(100vh - var(--app-header-height)) !important;
}

.sidebar {
    top: var(--app-header-height) !important;
    height: calc(100vh - var(--app-header-height)) !important;
    /* Le nav Pilotage démarre directement sous le header, sans header sidebar */
}

/* ═══ APP HEADER FIXE ═══════════════════════════════════════════ */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--app-header-height);
    background-color: var(--bg-dark);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 18px;
    z-index: 1100;
    gap: 12px;
}

.app-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 200px;
}

.app-header-center {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.app-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 200px;
    justify-content: flex-end;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
}
.header-brand #header-brand-icon {
    color: var(--primary-color);
    font-size: 20px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
}
.header-brand #header-brand-icon i {
    font-size: 20px;
}
.header-brand #header-brand-logo {
    height: 28px;
    width: auto;
    max-width: 120px;
    object-fit: contain;
    border-radius: 4px;
    flex-shrink: 0;
}
.header-brand #header-brand-name {
    font-size: 16px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ═══ FILTRE CLIENT GLOBAL ══════════════════════════════════════ */
.global-client-filter {
    display: flex;
    align-items: center;
    gap: 10px;
}

.filter-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
}

.filter-select-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.filter-icon {
    position: absolute;
    left: 12px;
    color: var(--primary-color);
    font-size: 13px;
    pointer-events: none;
    z-index: 1;
}

.filter-chevron {
    position: absolute;
    right: 12px;
    color: var(--text-muted);
    font-size: 11px;
    pointer-events: none;
}

.filter-select {
    appearance: none;
    -webkit-appearance: none;
    background: var(--bg-lighter);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    padding: 8px 36px 8px 34px;
    cursor: pointer;
    min-width: 200px;
    transition: all 0.2s;
    font-family: inherit;
}
.filter-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}
.filter-select:hover {
    border-color: var(--primary-color);
    background: var(--bg-light);
}

/* ═══ BOUTON LANGUE HEADER ══════════════════════════════════════ */
.btn-lang-header {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-lighter);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 700;
    padding: 7px 12px;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 0.5px;
    font-family: inherit;
}
.btn-lang-header:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}
.btn-lang-header i { font-size: 13px; }

/* Bouton langue pages login */
.auth-lang-switch {
    position: fixed;
    top: 20px;
    right: 24px;
    z-index: 100;
}
.btn-lang {
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 700;
    padding: 8px 14px;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 0.8px;
    font-family: inherit;
}
.btn-lang:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* ═══ ICÔNES HEADER DROITE ══════════════════════════════════════ */
.header-icon-btn {
    position: relative;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: all 0.2s;
}
.header-icon-btn:hover {
    background: var(--bg-lighter);
    color: var(--text-primary);
}
.header-badge {
    position: absolute;
    top: 2px; right: 2px;
    background: var(--danger-color);
    color: white;
    font-size: 9px;
    font-weight: 700;
    border-radius: 8px;
    padding: 1px 4px;
    min-width: 16px;
    text-align: center;
}

/* ═══ USER ZONE HEADER ══════════════════════════════════════════ */
.header-user {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 10px 5px 8px;
    background: var(--bg-lighter);
    border: 1px solid var(--border-color);
    border-radius: 10px;
}
.header-avatar {
    font-size: 24px;
    color: var(--primary-color);
}
.header-user-info {
    display: flex;
    flex-direction: column;
    line-height: 1.3;
}
.header-user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}
.header-user-role {
    font-size: 11px;
    color: var(--text-muted);
}

/* ═══ SIDEBAR NAV GROUPS ════════════════════════════════════════ */
.nav-group {
    margin-bottom: 2px;
}
.nav-group + .nav-group {
    margin-top: 4px;
    padding-top: 4px;
    border-top: 1px solid rgba(255,255,255,0.05);
}
.nav-group-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 8px 16px 4px;
    opacity: 0.55;
    user-select: none;
}

/* ═══ TOPBAR MOBILE MASQUÉE (remplacée par app-header) ══════════ */
/* La .topbar originale est désormais remplacée par .app-header    */
.topbar { display: none !important; }

/* ═══ RESPONSIVE ════════════════════════════════════════════════ */
@media (max-width: 1024px) {
    .header-brand #header-brand-name { display: none; }  /* Mobile : masquer le nom, garder le logo/icône */
    .header-user-info  { display: none; }
    .filter-select     { min-width: 150px; }
}
@media (max-width: 768px) {
    .app-header-center { display: none; }
    .header-user {
        background: transparent;
        border: none;
        padding: 4px;
    }
    .btn-lang-header span { display: none; }
}

/* ═══════════════════════════════════════════════════════════════ */
/* ═══ LIGHT MODE (theme clair) ══════════════════════════════════ */
/* ═══════════════════════════════════════════════════════════════ */
body.light-mode {
    --bg-dark: #e2e8f0;
    --bg-darker: #f1f5f9;
    --bg-light: #ffffff;
    --bg-lighter: #e2e8f0;
    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #64748b;
    --border-color: #cbd5e1;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.12);
}

body.light-mode .auth-page {
    background: linear-gradient(135deg, #e2e8f0 0%, #f1f5f9 100%);
}

body.light-mode .auth-container .logo i,
body.light-mode .auth-container .logo h1 {
    color: var(--primary-color);
}

body.light-mode .auth-box {
    background: #ffffff;
    border: 1px solid var(--border-color);
    box-shadow: 0 8px 30px rgba(0,0,0,0.1);
}

body.light-mode .auth-box h2 { color: var(--text-primary); }

body.light-mode input[type="email"],
body.light-mode input[type="password"],
body.light-mode input[type="text"],
body.light-mode input[type="number"],
body.light-mode select,
body.light-mode textarea {
    background: #f8fafc;
    border-color: #cbd5e1;
    color: var(--text-primary);
}

body.light-mode input:focus,
body.light-mode select:focus,
body.light-mode textarea:focus {
    background: #ffffff;
    border-color: var(--primary-color);
}

body.light-mode .app-header {
    background: #ffffff;
    border-bottom: 1px solid var(--border-color);
}

body.light-mode .sidebar {
    background: #ffffff;
    border-right: 1px solid var(--border-color);
}

body.light-mode .main-content {
    background: var(--bg-darker);
}

body.light-mode .card,
body.light-mode .stat-card,
body.light-mode .modal-content {
    background: #ffffff;
    border: 1px solid var(--border-color);
}

body.light-mode .table-container,
body.light-mode .data-table thead th {
    background: #ffffff;
}

body.light-mode .data-table tbody tr:hover {
    background: #f8fafc;
}

body.light-mode .data-table td,
body.light-mode .data-table th {
    border-bottom-color: var(--border-color);
}

body.light-mode .nav-item:hover {
    background: rgba(37, 99, 235, 0.08);
}

body.light-mode .nav-item.active {
    background: rgba(37, 99, 235, 0.15);
}

body.light-mode .nav-group + .nav-group {
    border-top-color: rgba(0,0,0,0.07);
}

body.light-mode .header-user {
    background: var(--bg-lighter);
}

body.light-mode .btn-lang-header {
    background: var(--bg-lighter);
    color: var(--text-secondary);
}

body.light-mode .form-group label { color: var(--text-secondary); }

body.light-mode .modal-overlay { background: rgba(0,0,0,0.4); }

body.light-mode .empty-state { color: var(--text-muted); }

body.light-mode .sidebar-footer {
    border-top-color: var(--border-color);
}

body.light-mode .page-header {
    background: #ffffff;
    border-bottom: 1px solid var(--border-color);
}

/* ═══ BOUTON DARK/LIGHT MODE ════════════════════════════════════ */
.btn-theme-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-lighter);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 13px;
    padding: 7px 11px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}
.btn-theme-toggle:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}
.btn-theme-toggle i { font-size: 14px; }

/* Auth page theme toggle */
.auth-controls {
    position: fixed;
    top: 20px;
    right: 24px;
    z-index: 100;
    display: flex;
    gap: 8px;
    align-items: center;
}

/* ═══ CORRECTIONS MODE LIGHT — inputs et tables ══════════════════ */
body.light-mode input[type="text"],
body.light-mode input[type="email"],
body.light-mode input[type="password"],
body.light-mode input[type="number"],
body.light-mode input[type="url"],
body.light-mode select,
body.light-mode textarea {
    background: #f8fafc !important;
    border-color: #cbd5e1 !important;
    color: #0f172a !important;
}
body.light-mode .stat-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
}
body.light-mode .page-header {
    background: #ffffff;
    border-bottom: 1px solid #e2e8f0;
}
body.light-mode .modal-content {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
body.light-mode .modal-header {
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}
body.light-mode .modal-footer {
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
}
body.light-mode .card-header {
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}
body.light-mode .badge {
    opacity: 0.9;
}
body.light-mode .data-table thead tr {
    background: #f1f5f9;
}
body.light-mode .data-table tbody tr:nth-child(even) {
    background: #f8fafc;
}
body.light-mode pre {
    background: #f1f5f9;
    color: #334155;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 10px;
}
body.light-mode .alert.info {
    background: rgba(6,182,212,0.08);
    border-color: rgba(6,182,212,0.3);
    color: #0369a1;
}
body.light-mode .alert.success {
    background: rgba(16,185,129,0.08);
    border-color: rgba(16,185,129,0.3);
    color: #065f46;
}
body.light-mode .alert.warning {
    background: rgba(245,158,11,0.08);
    border-color: rgba(245,158,11,0.3);
    color: #92400e;
}
body.light-mode .alert.danger {
    background: rgba(239,68,68,0.08);
    border-color: rgba(239,68,68,0.3);
    color: #991b1b;
}
body.light-mode .sidebar-footer {
    background: #f8fafc;
}
body.light-mode .header-icon-btn {
    color: #64748b;
}
body.light-mode .header-icon-btn:hover {
    background: #e2e8f0;
    color: #0f172a;
}
body.light-mode .btn-logout {
    color: #64748b;
}
body.light-mode .btn-logout:hover {
    color: #ef4444;
}
body.light-mode .nav-item {
    color: #475569;
}
body.light-mode .nav-item.active {
    color: var(--primary-color);
    background: rgba(37,99,235,0.1);
}
body.light-mode .nav-item:hover {
    background: rgba(37,99,235,0.06);
    color: var(--primary-color);
}
body.light-mode .table-container table {
    background: #ffffff;
}
body.light-mode .table-container table th {
    background: #f1f5f9;
    color: #475569;
}
body.light-mode .table-container table td {
    border-bottom: 1px solid #e2e8f0;
    color: #334155;
}
body.light-mode .table-container table tr:hover td {
    background: #f8fafc;
}
body.light-mode .empty-state {
    color: #94a3b8;
}
body.light-mode .global-client-filter .filter-select {
    background: #f1f5f9;
    color: #334155;
    border-color: #cbd5e1;
}
/* Transition douce lors du changement de thème */
body {
    transition: background-color 0.2s ease, color 0.2s ease;
}
.sidebar, .app-header, .card, .stat-card, .modal-content {
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

/* ═══ TOAST NOTIFICATIONS ═══════════════════════════════════════ */
@keyframes slideInRight {
    from { transform: translateX(120%); opacity: 0; }
    to   { transform: translateX(0);    opacity: 1; }
}
@keyframes fadeOut {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(120%); }
}
.klarion-toast.success { background: #065f46; border: 1px solid #10b981; color: #d1fae5; }
.klarion-toast.danger  { background: #7f1d1d; border: 1px solid #ef4444; color: #fecaca; }
.klarion-toast.info    { background: #0c4a6e; border: 1px solid #0ea5e9; color: #e0f2fe; }
.klarion-toast.warning { background: #78350f; border: 1px solid #f59e0b; color: #fef3c7; }
body.light-mode .klarion-toast.success { background: #d1fae5; border-color: #10b981; color: #065f46; }
body.light-mode .klarion-toast.danger  { background: #fee2e2; border-color: #ef4444; color: #7f1d1d; }
body.light-mode .klarion-toast.info    { background: #e0f2fe; border-color: #0ea5e9; color: #0c4a6e; }
body.light-mode .klarion-toast.warning { background: #fef3c7; border-color: #f59e0b; color: #78350f; }

/* ═══ MODAL OVERLAY CLICK CLOSE ════════════════════════════════ */
.modal { cursor: pointer; }
.modal-content { cursor: default; }

/* ═══ BADGE SECONDARY ═══════════════════════════════════════════ */
.badge.secondary { background: rgba(148,163,184,0.2); color: var(--text-secondary); border: 1px solid var(--border-color); }
body.light-mode .badge.secondary { background: #e2e8f0; color: #475569; }
