/**
 * OLBA SIRH — Shell de base (ex-CSS inline de templates/base.html)
 * Design tokens, navbar, dropdowns, sidebar moderne.
 *
 * Le layout conditionné à l'authentification utilise body.has-sidebar
 * (classe posée par base.html quand user.is_authenticated).
 */

/* ── Design tokens OLBA SIRH ── */
:root {
    /* Brand */
    --brand-primary:   #3b5bdb;   /* indigo 600 */
    --brand-primary-d: #2f4ac0;   /* indigo 700 — hover */
    --brand-primary-l: #e8f0fe;   /* indigo 50  — bg léger */
    --brand-accent:    #4263eb;   /* indigo vif */

    /* Sémantique */
    --primary-color:   #3b5bdb;
    --secondary-color: #6c757d;
    --success-color:   #2f9e44;
    --danger-color:    #c92a2a;
    --warning-color:   #e67700;
    --info-color:      #0097a7;
    --light-color:     #f8f9fa;
    --dark-color:      #212529;

    /* Sidebar */
    --sidebar-bg:      #1e2a4a;   /* navy-indigo foncé */
    --sidebar-bg-d:    #16213a;   /* plus foncé pour header */
    --sidebar-text:    rgba(255,255,255,.78);
    --sidebar-active:  #3b5bdb;
    --sidebar-hover:   rgba(255,255,255,.08);
    --sidebar-border:  rgba(255,255,255,.07);
    --sidebar-width:   240px;

    /* Composants */
    --border-radius:   0.5rem;
    --border-radius-lg:0.9rem;
    --transition-speed:0.2s;
    --shadow-sm:       0 2px 8px rgba(0,0,0,.07);
    --shadow-md:       0 4px 20px rgba(0,0,0,.1);
}

/* Police système fiable pour éviter les problèmes d'affichage */
body, html {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif !important;
}

/* Fallback pour les polices personnalisées. Les icônes en sont exclues :
   cette règle leur imposait la police du texte, et Font Awesome ne pouvait
   plus afficher que des carrés. :where() garde une spécificité nulle. */
:where(*:not(.fa, .fas, .far, .fab, .fa-solid, .fa-regular, .fa-brands, .fa-classic)) {
    font-family: inherit !important;
}

/* Skip link for accessibility */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--primary-color);
    color: white;
    padding: 8px;
    text-decoration: none;
    z-index: 100;
}

.skip-link:focus {
    top: 0;
}

/* Dropdown animations */
.dropdown-menu {
    border: none;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    border-radius: var(--border-radius);
    padding: 0.5rem 0;
    min-width: 280px;
    opacity: 0;
    transform: translateY(-10px);
    transition: all var(--transition-speed) ease;
}

.dropdown-menu.show {
    opacity: 1;
    transform: translateY(0);
}

.dropdown-item {
    padding: 0.5rem 1rem;
    transition: all 0.2s ease;
}

.dropdown-item:hover {
    background-color: var(--light-color);
    transform: translateX(5px);
}

.dropdown-item i {
    width: 20px;
    margin-right: 0.5rem;
    color: var(--secondary-color);
}

/* Navbar enhancements */
.navbar-nav .nav-link {
    transition: all 0.2s ease;
    border-radius: var(--border-radius);
    margin: 0 0.25rem;
}

.navbar-nav .nav-link:hover {
    background-color: rgba(59, 91, 219, 0.08);
}

/* Loading state */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

/* Alert animations */
.alert {
    animation: slideInRight 0.3s ease-out;
}

@keyframes slideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to   { transform: translateX(0);    opacity: 1; }
}

/* ══════════════════════════════════════════════════
   SIDEBAR MODERNE — OLBA SIRH
══════════════════════════════════════════════════ */
.sidebar-modern {
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    z-index: 1030;
    border-right: 1px solid var(--sidebar-border);
    overflow: hidden;
}

/* Header */
.sidebar-header {
    padding: .9rem 1rem;
    background: var(--sidebar-bg-d);
    border-bottom: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    text-decoration: none;
}
.sidebar-brand img { border-radius: .3rem; }
.sidebar-brand-fallback {
    width: 30px; height: 30px;
    border-radius: .3rem;
    background: var(--brand-primary);
    display: none;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: .85rem;
    flex-shrink: 0;
}
.sidebar-brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
}
.brand-name {
    font-size: .9rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: .03em;
}
.brand-sub {
    font-size: .65rem;
    color: rgba(255,255,255,.45);
    text-transform: uppercase;
    letter-spacing: .06em;
}

/* Scroll zone */
.sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: .5rem 0;
}
.sidebar-scroll::-webkit-scrollbar { width: 4px; }
.sidebar-scroll::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,.15);
    border-radius: 2px;
}

/* Nav list */
.sidebar-nav {
    list-style: none;
    padding: 0;
    margin: 0;
}

/* Items de base (hérités des _*.html) */
.sidebar-modern .nav-item { margin: 0; }

.sidebar-modern .nav-link {
    display: flex;
    align-items: center;
    gap: .55rem;
    padding: .52rem 1.1rem;
    color: var(--sidebar-text);
    font-size: .835rem;
    font-weight: 500;
    border-radius: 0;
    border-left: 3px solid transparent;
    transition: background var(--transition-speed), color var(--transition-speed), border-color var(--transition-speed);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-decoration: none;
}
.sidebar-modern .nav-link i {
    width: 18px;
    text-align: center;
    font-size: .85rem;
    flex-shrink: 0;
    opacity: .75;
    transition: opacity var(--transition-speed);
}
.sidebar-modern .nav-link:hover {
    background: var(--sidebar-hover);
    color: #fff;
}
.sidebar-modern .nav-link:hover i { opacity: 1; }

/* Item actif */
.sidebar-modern .nav-link.active {
    background: rgba(59,91,219,.18);
    color: #fff;
    border-left-color: var(--brand-primary);
    font-weight: 600;
}
.sidebar-modern .nav-link.active i { opacity: 1; color: var(--brand-accent); }

/* Sous-menus collapse */
.sidebar-modern .collapse .nav-link {
    padding-left: 2.4rem;
    font-size: .81rem;
    border-left: none;
}
.sidebar-modern .collapse .nav-link:hover { border-left: none; }

/* Labels de section (small.text-muted) */
.sidebar-modern small.text-muted {
    display: block;
    font-size: .67rem !important;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: rgba(255,255,255,.3) !important;
    padding: .6rem 1.1rem .2rem;
    font-weight: 700;
}

/* Chevron collapse */
.sidebar-modern [data-bs-toggle="collapse"] .fa-chevron-down {
    transition: transform .2s;
    font-size: .65rem;
    opacity: .5;
    margin-left: auto;
}
.sidebar-modern [aria-expanded="true"] .fa-chevron-down { transform: rotate(180deg); }

/* Footer user */
.sidebar-footer {
    border-top: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}
.sidebar-footer-inner { padding: .75rem 1rem; }
.sb-user {
    display: flex;
    align-items: center;
    gap: .6rem;
}
.sb-user-avatar {
    width: 30px; height: 30px;
    border-radius: 50%;
    background: var(--brand-primary);
    color: #fff;
    font-size: .78rem;
    font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.sb-user-info {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    overflow: hidden;
}
.sb-user-name {
    font-size: .8rem;
    font-weight: 600;
    color: rgba(255,255,255,.85);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sb-user-role {
    font-size: .68rem;
    color: rgba(255,255,255,.4);
    text-transform: uppercase;
    letter-spacing: .05em;
}

/* Ajustement layout : main content décalé de la sidebar.
   body.has-sidebar est posé par base.html pour les utilisateurs
   connectés — les pages publiques n'ont pas de sidebar et ne
   doivent pas être décalées. */
@media (min-width: 768px) {
    body.has-sidebar { padding-left: var(--sidebar-width); }
    body.has-sidebar .sidebar-modern { display: flex !important; }

    /* Navbar : plus de col-md-3 offset car sidebar est fixed */
    body.has-sidebar .navbar { padding-left: calc(var(--sidebar-width) + .5rem); }
}
@media (max-width: 767.98px) {
    body.has-sidebar .sidebar-modern {
        transform: translateX(-100%);
        transition: transform .25s ease;
    }
    body.has-sidebar .sidebar-modern.show {
        transform: translateX(0);
    }
    body.has-sidebar { padding-left: 0; }
}

/* Main content : plus besoin de ms-sm-auto ni col-md-10 offset */
@media (min-width: 768px) {
    main#main-content.col-md-10 {
        max-width: 100%;
        flex: 0 0 100%;
        margin-left: 0 !important;
    }
}
