:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --sidebar-bg: #101828;
    --sidebar-hover: #1d2a44;
    --success: #16a34a;
    --warning: #f59e0b;
    --danger: #dc2626;
    --card-radius: 14px;

    /* Thème clair (par défaut) */
    --bg-body: #f4f6fb;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --text-title: #111827;
    --card-bg: #ffffff;
    --card-border: #eef0f4;
    --table-border: #e5e7eb;
    --topbar-bg: #ffffff;
    --input-bg: #ffffff;
    --input-border: #ced4da;
    --shadow-color: rgba(0,0,0,0.05);
    --dropdown-bg: #ffffff;
    --hover-row: #f8f9fb;
}

[data-bs-theme="dark"] {
    --bg-body: #0f1420;
    --text-main: #e5e7eb;
    --text-muted: #9ca3af;
    --text-title: #f3f4f6;
    --card-bg: #1a2233;
    --card-border: #2a3448;
    --table-border: #2a3448;
    --topbar-bg: #161d2e;
    --input-bg: #1f2937;
    --input-border: #3a4356;
    --shadow-color: rgba(0,0,0,0.35);
    --dropdown-bg: #1a2233;
    --hover-row: #202a40;
    --sidebar-bg: #0a0e17;
    --sidebar-hover: #1a2233;
}

* { box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-body);
    margin: 0;
    color: var(--text-main);
    transition: background-color 0.2s ease, color 0.2s ease;
}

/* ---------- Layout ---------- */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 250px;
    background: var(--sidebar-bg);
    color: #d1d5db;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 22px 20px;
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-brand { color: #fff; }
.brand-logo { width: 34px; height: 34px; border-radius: 9px; flex-shrink: 0; }

.sidebar-nav {
    list-style: none;
    padding: 12px 10px;
    margin: 0;
}
.sidebar-nav li a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: 10px;
    color: #cbd5e1;
    text-decoration: none;
    font-size: 0.93rem;
    font-weight: 500;
    margin-bottom: 2px;
    transition: background 0.15s ease, color 0.15s ease;
}
.sidebar-nav li a:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar-nav li a.active { background: var(--primary); color: #fff; }
.sidebar-nav li a i { width: 18px; text-align: center; }
.nav-section {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #64748b;
    padding: 16px 14px 6px;
    font-weight: 600;
}

.main-content { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--topbar-bg);
    padding: 14px 26px;
    border-bottom: 1px solid var(--table-border);
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar-title { font-weight: 700; font-size: 1.1rem; color: var(--text-title); }
.avatar-circle {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
    text-transform: uppercase;
}

/* ---------- Bouton bascule thème (clair / sombre) ---------- */
.theme-toggle-btn {
    width: 38px; height: 38px;
    border-radius: 50%;
    border: 1px solid var(--table-border);
    background: var(--card-bg);
    color: var(--text-main);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease;
    font-size: 0.95rem;
}
.theme-toggle-btn:hover { background: var(--hover-row); transform: rotate(15deg); }
.theme-toggle-btn .fa-sun { display: none; color: #f59e0b; }
.theme-toggle-btn .fa-moon { display: inline-block; color: var(--primary); }
[data-bs-theme="dark"] .theme-toggle-btn .fa-sun { display: inline-block; }
[data-bs-theme="dark"] .theme-toggle-btn .fa-moon { display: none; }

.login-theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 20;
    background: rgba(255,255,255,0.12);
    border-color: rgba(255,255,255,0.25);
}
.login-theme-toggle .fa-moon { color: #fff; }
[data-bs-theme="dark"] .login-theme-toggle .fa-sun { color: #fbbf24; }

.page-content { padding: 26px; flex: 1; }

/* ---------- Pied de page ---------- */
.app-footer {
    text-align: center;
    padding: 16px 20px;
    font-size: 0.82rem;
    color: var(--text-muted);
    border-top: 1px solid var(--card-border);
    background: var(--card-bg);
}
.app-footer strong { color: var(--primary); }

/* ---------- Cards statistiques cliquables ---------- */
.stat-card {
    border-radius: var(--card-radius);
    padding: 22px;
    color: #fff;
    text-decoration: none;
    display: block;
    position: relative;
    overflow: hidden;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
    box-shadow: 0 4px 14px rgba(0,0,0,0.06);
    min-height: 130px;
}
.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(0,0,0,0.15);
    color: #fff;
}
.stat-card .stat-icon {
    font-size: 2.1rem;
    opacity: 0.35;
    position: absolute;
    top: 18px;
    right: 20px;
}
.stat-card .stat-value { font-size: 2.1rem; font-weight: 800; line-height: 1; }
.stat-card .stat-label { font-size: 0.92rem; opacity: 0.92; margin-top: 8px; font-weight: 500; }
.stat-card .stat-footer {
    margin-top: 14px; font-size: 0.78rem; opacity: 0.85;
    display: flex; align-items: center; gap: 6px;
}

.bg-total { background: linear-gradient(135deg, #2563eb, #1e40af); }
.bg-low   { background: linear-gradient(135deg, #f59e0b, #b45309); }
.bg-expired { background: linear-gradient(135deg, #dc2626, #991b1b); }
.bg-soon  { background: linear-gradient(135deg, #7c3aed, #5b21b6); }

/* ---------- Cards générales ---------- */
.card {
    background: var(--card-bg);
    border: none;
    border-radius: var(--card-radius);
    box-shadow: 0 2px 10px var(--shadow-color);
}
.card-header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--card-border);
    font-weight: 700;
    color: var(--text-title);
    border-radius: var(--card-radius) var(--card-radius) 0 0 !important;
}

.table { color: var(--text-main); }
.table thead th {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
    border-bottom: 2px solid var(--table-border);
    white-space: nowrap;
}
.table td { vertical-align: middle; border-color: var(--table-border); }
.table > :not(caption) > * > * { background-color: var(--card-bg); color: var(--text-main); }
.table-hover > tbody > tr:hover > * { background-color: var(--hover-row); }

.form-control, .form-select {
    background-color: var(--input-bg);
    border-color: var(--input-border);
    color: var(--text-main);
}
.form-control:focus, .form-select:focus {
    background-color: var(--input-bg);
    color: var(--text-main);
}
.input-group-text { background-color: var(--hover-row); color: var(--text-main); border-color: var(--input-border); }
.dropdown-menu { background-color: var(--dropdown-bg); border-color: var(--card-border); }
.dropdown-item { color: var(--text-main); }
.dropdown-item:hover { background-color: var(--hover-row); color: var(--text-main); }
.text-muted { color: var(--text-muted) !important; }

.badge-status-ok { background: #dcfce7; color: #166534; }
.badge-status-bas { background: #fef3c7; color: #92400e; }
.badge-status-rupture { background: #fee2e2; color: #991b1b; }
.badge-status-expire { background: #fee2e2; color: #991b1b; }
.badge-status-proche { background: #fef3c7; color: #92400e; }
.badge-status-valide { background: #dcfce7; color: #166534; }

[data-bs-theme="dark"] .badge-status-ok,
[data-bs-theme="dark"] .badge-status-valide { background: rgba(22,163,74,0.22); color: #4ade80; }
[data-bs-theme="dark"] .badge-status-bas,
[data-bs-theme="dark"] .badge-status-proche { background: rgba(245,158,11,0.22); color: #fbbf24; }
[data-bs-theme="dark"] .badge-status-rupture,
[data-bs-theme="dark"] .badge-status-expire { background: rgba(220,38,38,0.25); color: #f87171; }

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

/* ---------- Cloche de notifications (style Facebook) ---------- */
.notif-bell-btn {
    width: 38px; height: 38px;
    border-radius: 50%;
    border: 1px solid var(--table-border);
    background: var(--card-bg);
    color: var(--text-main);
    display: flex; align-items: center; justify-content: center;
    font-size: 1rem;
}
.notif-bell-btn:hover { background: var(--hover-row); }
.notif-badge {
    position: absolute;
    top: -4px; right: -4px;
    background: var(--danger);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 999px;
    display: flex; align-items: center; justify-content: center;
    padding: 0 4px;
    border: 2px solid var(--topbar-bg);
}

.notif-panel {
    width: 360px;
    max-width: 90vw;
    padding: 0;
    border: 1px solid var(--card-border);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 12px 32px rgba(0,0,0,0.18);
    background: var(--dropdown-bg);
}
.notif-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--text-title);
    border-bottom: 1px solid var(--card-border);
}
.notif-panel-body {
    max-height: 380px;
    overflow-y: auto;
}
.notif-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    text-decoration: none;
    color: var(--text-main);
    border-bottom: 1px solid var(--card-border);
    transition: background 0.12s ease;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--hover-row); color: var(--text-main); }

.notif-icon {
    width: 38px; height: 38px;
    min-width: 38px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.95rem;
    color: #fff;
}
.notif-icon-warning { background: var(--warning); }
.notif-icon-danger { background: var(--danger); }
.notif-icon-purple { background: #7c3aed; }

.notif-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.notif-title { font-weight: 600; font-size: 0.88rem; color: var(--text-title); }
.notif-message { font-size: 0.8rem; color: var(--text-muted); line-height: 1.35; }

.notif-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 34px 16px;
    color: var(--text-muted);
    font-size: 0.88rem;
}
.notif-empty i { font-size: 1.7rem; color: var(--success); }

.notif-panel-footer {
    display: block;
    text-align: center;
    padding: 11px;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--primary);
    text-decoration: none;
    border-top: 1px solid var(--card-border);
    background: var(--card-bg);
}
.notif-panel-footer:hover { background: var(--hover-row); color: var(--primary); }

@media (max-width: 480px) {
    .notif-panel { width: 92vw; }
}

/* ---------- Onglets (nav-pills) des rapports ---------- */
.nav-pills .nav-link {
    color: var(--text-main);
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.9rem;
    padding: 8px 16px;
}
.nav-pills .nav-link:hover { background: var(--hover-row); }
.nav-pills .nav-link.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* ---------- Login ---------- */
.login-footer {
    position: fixed;
    bottom: 16px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 0.8rem;
    color: rgba(255,255,255,0.75);
}
.login-footer strong { color: #fff; }

.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #101828 0%, #1e3a8a 100%);
    padding: 20px;
}
.login-card {
    background: var(--card-bg);
    border-radius: 18px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}
.login-icon {
    width: 72px; height: 72px;
    margin: 0 auto 18px;
    filter: drop-shadow(0 8px 16px rgba(37, 99, 235, 0.35));
}
.login-icon img { width: 100%; height: 100%; }

/* ---------- Overlay pour la sidebar mobile ---------- */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 999;
}
.sidebar-overlay.show { display: block; }

@media (max-width: 992px) {
    .sidebar {
        position: fixed;
        left: -270px;
        top: 0;
        z-index: 1000;
        transition: left 0.22s ease;
        width: 260px;
        box-shadow: 4px 0 24px rgba(0,0,0,0.25);
    }
    .sidebar.show { left: 0; }
}

/* ---------- Optimisations écrans mobiles (téléphones) ---------- */
@media (max-width: 767.98px) {
    .page-content { padding: 14px; }

    .topbar { padding: 10px 14px; }
    .topbar-title { font-size: 0.98rem; }
    .avatar-circle { width: 30px; height: 30px; font-size: 0.85rem; }

    /* Cartes statistiques : plus compactes, texte redimensionné */
    .stat-card { padding: 16px; min-height: 108px; }
    .stat-card .stat-value { font-size: 1.55rem; }
    .stat-card .stat-label { font-size: 0.82rem; margin-top: 4px; }
    .stat-card .stat-icon { font-size: 1.6rem; top: 12px; right: 14px; }
    .stat-card .stat-footer { font-size: 0.7rem; margin-top: 8px; }

    .card-header { font-size: 0.92rem; padding: 12px 14px; }
    .card-body { padding: 14px; }

    /* Tables : police réduite + cellules moins larges pour limiter le scroll */
    .table { font-size: 0.85rem; }
    .table thead th, .table td { padding: 8px 10px; }
    .table-responsive {
        -webkit-overflow-scrolling: touch;
        border-radius: 10px;
    }

    /* Formulaires de recherche : empilés verticalement sur mobile */
    .search-toolbar { flex-direction: column; align-items: stretch !important; }
    .search-toolbar form { flex-direction: column; }
    .search-toolbar .btn { width: 100%; }

    /* Boutons pleine largeur dans les listes d'actions mobiles */
    .btn { font-size: 0.9rem; }

    .login-card { padding: 26px 22px; }
    .sidebar-brand { font-size: 1.1rem; padding: 18px 16px; }

    h3.fw-bold { font-size: 1.4rem; }
}

@media (max-width: 400px) {
    .stat-card .stat-value { font-size: 1.35rem; }
    .page-content { padding: 10px; }
}

@media print {
    .sidebar, .topbar, .no-print { display: none !important; }
    .page-content { padding: 0; }
}
