/* ═══════════════════════════════════════════════════════════════════════
   BMDHub — Modern Design System (Aligné sur BMDSpoke)
   ═══════════════════════════════════════════════════════════════════════ */

:root {
    --bg-body: #f1f5f9;
    --bg-card: #ffffff;
    --bg-header: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    --border-light: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --accent-indigo: #6366f1;
    --accent-blue: #2563eb;
    --accent-teal: #0d9488;
    --accent-emerald: #059669;
    --accent-amber: #f59e0b;
    --accent-rose: #e11d48;
    --topbar-height: 46px;
    --subbar-height: 40px;
    --logo-corner-size: calc(var(--topbar-height) + var(--subbar-height));
    --sidebar-width: 250px;
    --sidebar-collapsed-width: 60px;
}

* {
    -webkit-tap-highlight-color: transparent;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 0.85rem;
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    margin: 0;
    padding: 0;
    background: var(--bg-body);
}

/* ================= LAYOUT PRINCIPAL APPLICATION ================= */
.bmd-app-layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    overflow: hidden;
    background: var(--bg-body);
}

/* ================= HEADER : COIN LOGO + PILE DES 2 BARRES ================= */
.bmd-header-container {
    display: flex;
    flex-direction: row;
    height: calc(var(--topbar-height) + var(--subbar-height));
    width: 100%;
    flex-shrink: 0;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* Coin Logo carré couvrant la hauteur des deux barres (94px x 94px) */
.bmd-logo-corner {
    width: calc(var(--topbar-height) + var(--subbar-height));
    height: calc(var(--topbar-height) + var(--subbar-height));
    background: var(--bg-header);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 7px;
    flex-shrink: 0;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom: 1px solid #e2e8f0;
    box-sizing: border-box;
}

.bmd-logo-corner-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    text-decoration: none;
}

/* Boîte blanche arrondie pour faire ressortir le logo */
.bmd-logo-box {
    background: #ffffff;
    border-radius: 10px;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.22);
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-sizing: border-box;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.bmd-logo-box:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.bmd-logo-corner-img {
    max-height: 68px;
    max-width: 68px;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
}

/* Pile des 2 barres horizontales à droite du logo */
.bmd-bars-stack {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    height: 100%;
}

/* ================= 1. PREMIÈRE BARRE HORIZONTALE (Top bar) ================= */
.top-bar {
    height: var(--topbar-height);
    background: var(--bg-header);
    color: #f8fafc;
    display: flex;
    align-items: center;
    padding: 0 1.25rem 0 1rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    z-index: 1001;
    border-bottom: 1px solid #334155;
    flex-shrink: 0;
    box-sizing: border-box;
    gap: 12px;
}

/* Module à droite du logo */
.topbar-identity {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.bmdhub-brand-icon {
    width: 28px;
    height: 28px;
    border-radius: 7px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-size: 0.75rem;
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.3);
}

.topbar-module-name {
    font-size: 1.02rem;
    font-weight: 700;
    color: #f1f5f9;
    letter-spacing: -0.2px;
    white-space: nowrap;
}

.topbar-divider {
    color: #475569;
    font-size: 1rem;
    margin: 0 1px;
}

.topbar-page-name {
    font-size: 0.8rem;
    color: #94a3b8;
    font-weight: 500;
    white-space: nowrap;
}

/* Search Bar */
.top-bar .search-bar {
    flex: 0 1 360px;
    position: relative;
    margin-left: auto;
    margin-right: 12px;
}

.top-bar .search-bar input {
    width: 100%;
    padding: 0.4rem 1rem 0.4rem 2.4rem;
    border: 1px solid #475569;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.08);
    font-size: 0.8rem;
    color: #f1f5f9;
    transition: all 0.2s;
    outline: none;
}

.top-bar .search-bar input:focus {
    border-color: #60a5fa;
    background: rgba(255, 255, 255, 0.15);
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.2);
}

.top-bar .search-bar input::placeholder {
    color: #94a3b8;
}

.top-bar .search-bar i {
    position: absolute;
    left: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    font-size: 0.78rem;
}

/* Topbar Année Widget (placé juste avant les boutons de langue) */
.topbar-annee-widget {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(99, 102, 241, 0.18);
    border: 1px solid rgba(129, 140, 248, 0.35);
    border-radius: 9px;
    padding: 3px 8px 3px 10px;
    position: relative;
    height: 34px;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.topbar-annee-widget:hover {
    background: rgba(99, 102, 241, 0.28);
    border-color: #818cf8;
}

.topbar-annee-widget .annee-icon {
    font-size: 0.8rem;
    color: #a5b4fc;
}

.topbar-annee-widget .topbar-annee-select {
    background: transparent;
    border: none;
    outline: none;
    color: #ffffff;
    font-size: 0.76rem;
    font-weight: 700;
    cursor: pointer;
    padding-right: 18px;
    -webkit-appearance: none;
    appearance: none;
}

.topbar-annee-widget .topbar-annee-select option {
    background: #1e293b;
    color: #ffffff;
    font-weight: 600;
    padding: 6px;
}

.topbar-annee-widget .annee-chevron {
    position: absolute;
    right: 8px;
    pointer-events: none;
    font-size: 0.55rem;
    color: #a5b4fc;
}

/* Language Switcher Group */
.topbar-lang-group {
    display: flex;
    align-items: center;
    gap: 2px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 7px;
    padding: 2px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.topbar-lang-btn {
    font-size: 0.7rem;
    font-weight: 700;
    padding: 3px 8px !important;
    border-radius: 5px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: #94a3b8;
    text-decoration: none;
    transition: all 0.2s ease;
}

.topbar-lang-btn:hover {
    color: #f1f5f9;
}

.topbar-lang-btn.active {
    background: rgba(99, 102, 241, 0.85);
    color: #ffffff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* Icon Buttons (Notifications, etc.) */
.topbar-icon-btn {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    padding: 0.4rem;
    border-radius: 6px;
    font-size: 0.9rem;
    transition: color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.topbar-icon-btn:hover {
    color: #f1f5f9;
}

/* User Avatar Dropdown */
.topbar-user-avatar {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: white;
    font-size: 0.75rem;
    text-decoration: none;
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.3);
    border: none;
    cursor: pointer;
    flex-shrink: 0;
}

.bmd-user-dropdown {
    min-width: 240px;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    padding: 8px;
    border: 1px solid #e2e8f0;
}

/* ================= 2. DEUXIÈME BARRE HORIZONTALE (Sub-bar / Context bar) ================= */
.me-top-context-bar {
    height: var(--subbar-height);
    background: #ffffff;
    border-bottom: 1px solid #e2e8f0;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 0 0.85rem 0 0.65rem;
    box-sizing: border-box;
    z-index: 1000;
    flex-shrink: 0;
    margin-bottom: 0 !important;
    gap: 10px;
}

.me-context-left {
    display: flex !important;
    align-items: center !important;
    gap: 8px;
    min-width: 0;
    flex-shrink: 1;
}

/* Sidebar Toggle Button */
.sidebar-toggle-btn {
    background: none;
    border: 1px solid #cbd5e1;
    color: #475569;
    font-size: 0.92rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    transition: all 0.2s ease;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 28px;
    width: 30px;
}

.sidebar-toggle-btn:hover {
    background: #f1f5f9;
    color: #1e293b;
    border-color: #94a3b8;
}

.etab-context-label {
    font-size: 0.8rem;
    font-weight: 700;
    color: #1e293b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 480px;
}

.me-context-right {
    display: flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    margin-left: auto !important;
    flex-shrink: 0;
    gap: 6px;
}

/* Context Tabs in Sub-bar */
.context-tabs-group {
    display: flex;
    align-items: center;
    gap: 3px;
    background: #f1f5f9;
    padding: 2px 3px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    flex-shrink: 0;
}

.context-tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    font-size: 0.74rem;
    font-weight: 600;
    color: #64748b;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    text-decoration: none;
    line-height: 1.2;
    height: 28px;
}

.context-tab-btn:hover {
    background: #ffffff;
    color: #1e293b;
    border-color: #cbd5e1;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.context-tab-btn.active {
    background: #ffffff;
    color: #2563eb;
    font-weight: 700;
    border-color: #93c5fd;
    box-shadow: 0 1px 4px rgba(37, 99, 235, 0.12);
}

.context-tab-btn.active i {
    color: #2563eb;
}

.context-tab-btn i {
    font-size: 0.72rem;
    color: #64748b;
}

.me-hero-stats-row {
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
}

/* ================= ZONE CORPS (SIDEBAR + WORKSPACE) ================= */
.bmd-main-area {
    display: flex;
    flex-direction: row;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    position: relative;
}

/* Colonne Menu Latéral (Sidebar) */
.me-sidebar-col {
    width: var(--sidebar-width);
    flex-shrink: 0;
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 6px 0 6px 6px;
    box-sizing: border-box;
    overflow: hidden;
    position: relative;
    z-index: 100;
    transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1), padding 0.25s ease;
}

.me-sidebar {
    width: 100%;
    margin: 0;
    flex: 1;
    min-height: 0;
    background: #f8fafc;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.03);
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    padding: 6px;
    box-sizing: border-box;
}

.me-sidebar::-webkit-scrollbar {
    width: 3px;
}

.me-sidebar::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

/* Centrage vertical équilibré des éléments de navigation */
.me-sidebar-inner {
    display: flex;
    flex-direction: column;
    justify-content: center;
    height: 100%;
    min-height: 0;
    position: relative;
}

.me-nav-list {
    margin-top: auto;
    margin-bottom: auto;
    max-height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 4px 2px;
    width: 100%;
}

/* Nav Item Base */
.me-nav-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 6px 9px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    background: #ffffff;
    color: #334155;
    text-decoration: none;
    font-size: 0.78rem;
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
    transition: all 0.15s ease;
    position: relative;
    width: 100%;
    box-sizing: border-box;
    user-select: none;
}

.me-nav-item:hover {
    border-color: #cbd5e1;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
    transform: translateY(-1px);
    color: #0f172a;
}

/* Active Nav Item */
.me-nav-item.active {
    background: linear-gradient(135deg, #4338ca 0%, #6366f1 100%) !important;
    color: #ffffff !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    box-shadow: 0 3px 10px rgba(99, 102, 241, 0.25) !important;
}

.me-nav-item.active .me-mod-title {
    color: #ffffff !important;
    font-weight: 700;
}

.me-nav-item.active .me-mod-icon-badge {
    background: rgba(255, 255, 255, 0.25) !important;
    border: 1px solid rgba(255, 255, 255, 0.45);
}

.me-nav-item.active .me-mod-icon-badge i {
    color: #ffffff !important;
}

/* Badges Icônes Colorés */
.me-mod-icon-badge {
    width: 26px;
    height: 26px;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-size: 0.72rem;
    flex-shrink: 0;
    transition: all 0.15s ease;
}

.me-mod-icon-badge.badge-emerald {
    background: linear-gradient(135deg, #059669, #34d399);
}

.me-mod-icon-badge.badge-blue {
    background: linear-gradient(135deg, #2563eb, #60a5fa);
}

.me-mod-icon-badge.badge-indigo {
    background: linear-gradient(135deg, #4338ca, #6366f1);
}

.me-mod-icon-badge.badge-teal {
    background: linear-gradient(135deg, #0d9488, #2dd4bf);
}

.me-mod-icon-badge.badge-purple {
    background: linear-gradient(135deg, #7c3aed, #a78bfa);
}

.me-mod-icon-badge.badge-orange {
    background: linear-gradient(135deg, #ea580c, #fb923c);
}

.me-mod-icon-badge.badge-amber {
    background: linear-gradient(135deg, #d97706, #fbbf24);
}

.me-mod-title {
    font-size: 0.77rem;
    font-weight: 600;
    color: #1e293b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

/* Nav Item Disabled / Future */
.me-nav-item.disabled {
    opacity: 0.38;
    cursor: default;
    pointer-events: none;
    background: #f8fafc;
}

/* ================= SIDEBAR MINI / REPLIÉE (ICÔNES SEULES — COMME BMDSpoke) ================= */
.bmd-main-area.sidebar-collapsed .me-sidebar-col,
.me-sidebar-col.collapsed {
    width: 60px !important;
    min-width: 60px !important;
    max-width: 60px !important;
    padding: 6px 0 6px 6px !important;
}

.bmd-main-area.sidebar-collapsed .me-sidebar,
.me-sidebar-col.collapsed .me-sidebar {
    width: 100% !important;
    padding: 8px 4px !important;
    align-items: center;
    border-radius: 10px;
}

.bmd-main-area.sidebar-collapsed .me-nav-list,
.me-sidebar-col.collapsed .me-nav-list {
    width: 100%;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
}

.bmd-main-area.sidebar-collapsed .me-nav-item,
.me-sidebar-col.collapsed .me-nav-item {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
    transition: all 0.15s ease;
    overflow: hidden;
    flex-shrink: 0;
    cursor: pointer;
    padding: 0 !important;
}

.bmd-main-area.sidebar-collapsed .me-nav-item:hover,
.me-sidebar-col.collapsed .me-nav-item:hover {
    transform: translateY(-1px);
    border-color: #cbd5e1;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

.bmd-main-area.sidebar-collapsed .me-nav-item.active,
.me-sidebar-col.collapsed .me-nav-item.active {
    border: 1.5px solid #6366f1;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.2);
}

.bmd-main-area.sidebar-collapsed .me-mod-icon-badge,
.me-sidebar-col.collapsed .me-mod-icon-badge {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    font-size: 0.9rem;
}

/* Cacher texte des libellés en mode replié */
.bmd-main-area.sidebar-collapsed .me-mod-title,
.me-sidebar-col.collapsed .me-mod-title {
    display: none !important;
}

/* ================= ZONE DE TRAVAIL (WORKSPACE) ================= */
.me-workspace {
    flex: 1;
    min-width: 0;
    background: var(--bg-body);
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    padding: 3px 6px 3px 4px;
    box-sizing: border-box;
    overflow: hidden;
}

.me-content-area,
.content-area {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 6px 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
    -webkit-overflow-scrolling: touch;
}

/* ================= GLOBAL TAB BAR (STYLE BMDSpoke) ================= */
.tab-bar {
    display: flex;
    gap: 8px;
    padding: 0.5rem 0.8rem;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 9px;
    margin-bottom: 8px;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
}

.tab-link {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0.45rem 0.9rem;
    font-size: 0.78rem;
    font-weight: 500;
    color: #64748b;
    background: #f1f5f9;
    border-radius: 7px;
    border: 1px solid #e2e8f0;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    user-select: none;
    text-decoration: none;
}

.tab-link:hover {
    background: #ffffff;
    border-color: #cbd5e1;
    color: #1e293b;
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.tab-link.active {
    background: #ffffff;
    color: #2563eb;
    font-weight: 700;
    border-color: #2563eb;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.12);
}

.tab-link i {
    font-size: 0.8rem;
    opacity: 0.7;
}

.tab-link.active i {
    opacity: 1;
    color: #2563eb;
}

/* ================= LOADER & TOAST ================= */
.loader-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 1rem;
}

.loader-overlay.active {
    display: flex;
}

.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.custom-toast {
    background: #ffffff;
    border-radius: 10px;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
    font-size: 0.82rem;
    animation: toastSlideIn 0.3s ease;
    border: 1px solid #e2e8f0;
}

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

/* ================= OVERLAY MOBILE ================= */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1040;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* ================= RESPONSIVE ================= */
@media (max-width: 992px) {
    .me-sidebar-col {
        position: fixed;
        top: calc(var(--topbar-height) + var(--subbar-height));
        left: 0;
        bottom: 0;
        height: calc(100vh - var(--topbar-height) - var(--subbar-height));
        height: calc(100dvh - var(--topbar-height) - var(--subbar-height));
        transform: translateX(-100%);
        z-index: 1050;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.25);
        background: #f8fafc;
        width: 250px !important;
        padding: 6px !important;
        transition: transform 0.25s ease;
    }

    .me-sidebar-col.open {
        transform: translateX(0);
    }

    .top-bar .search-bar {
        flex: 0 1 220px;
    }

    .me-workspace {
        padding: 6px;
    }
}

@media (max-width: 768px) {
    .bmd-logo-corner {
        width: 70px;
        height: calc(var(--topbar-height) + var(--subbar-height));
        padding: 4px;
    }

    .bmd-logo-corner-img {
        max-height: 48px;
        max-width: 48px;
    }

    .top-bar .search-bar {
        display: none;
    }

    .etab-context-label {
        max-width: 220px;
    }

    .topbar-page-name,
    .topbar-divider {
        display: none;
    }
}
