/* Suppress transitions on first paint to avoid sidebar flash */
html.no-transition #sidebar,
html.no-transition #main-content,
html.no-transition #topbar { transition: none !important; }

/* =============================================
   CSS VARIABLES - Light / Dark
============================================= */
:root {
    --primary:        #2563eb;
    --primary-dark:   #1d4ed8;
    --primary-light:  #eff6ff;
    --primary-muted:  rgba(37, 99, 235, 0.12);

    --sidebar-w:          260px;
    --sidebar-collapsed-w: 65px;
    --topbar-h:           60px;
    --radius:             0px;
    --transition:         0.25s ease;
}

/* LIGHT */
[data-theme="light"], [data-theme="auto"] {
    --bg:             #f1f5f9;
    --surface:        #ffffff;
    --surface-2:      #f8fafc;
    --border:         #e2e8f0;
    --text:           #1e293b;
    --text-muted:     #64748b;
    --sidebar-bg:     #ffffff;
    --sidebar-text:   #475569;
    --sidebar-active-bg:   var(--primary-light);
    --sidebar-active-text: var(--primary);
    --sidebar-hover-bg:    #f8fafc;
    --topbar-bg:      #ffffff;
    --shadow:         0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md:      0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.05);
}

/* DARK */
[data-theme="dark"] {
    --bg:             #0f172a;
    --surface:        #1e293b;
    --surface-2:      #162032;
    --border:         #334155;
    --text:           #f1f5f9;
    --text-muted:     #94a3b8;
    --sidebar-bg:     #1e293b;
    --sidebar-text:   #94a3b8;
    --sidebar-active-bg:   var(--primary-muted);
    --sidebar-active-text: #60a5fa;
    --sidebar-hover-bg:    rgba(255,255,255,0.04);
    --topbar-bg:      #1e293b;
    --shadow:         0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
    --shadow-md:      0 4px 6px rgba(0,0,0,0.3), 0 2px 4px rgba(0,0,0,0.2);

    /* Bootstrap variable overrides */
    --bs-body-bg:                  #0f172a;
    --bs-body-color:               #f1f5f9;
    --bs-dropdown-bg:              #1e293b;
    --bs-dropdown-color:           #f1f5f9;
    --bs-dropdown-border-color:    #334155;
    --bs-dropdown-link-color:      #f1f5f9;
    --bs-dropdown-link-hover-color:#f1f5f9;
    --bs-dropdown-link-hover-bg:   #162032;
    --bs-dropdown-divider-bg:      #334155;
    --bs-table-bg:                 transparent;
    --bs-table-color:              #f1f5f9;
    --bs-table-border-color:       #334155;
    --bs-table-striped-bg:         rgba(255,255,255,0.03);
    --bs-table-hover-bg:           rgba(255,255,255,0.04);
    --bs-table-active-bg:          rgba(255,255,255,0.06);
    --bs-modal-bg:                 #1e293b;
    --bs-modal-color:              #f1f5f9;
    --bs-modal-header-border-color:#334155;
    --bs-modal-footer-border-color:#334155;
    --bs-border-color:             #334155;
    --bs-secondary-bg:             #162032;
    --bs-tertiary-bg:              #0f172a;
    --bs-heading-color:            #f1f5f9;
    --bs-link-color:               #60a5fa;
    --bs-link-hover-color:         #93c5fd;
    --bs-form-valid-color:         #4ade80;
    --bs-form-invalid-color:       #f87171;
    --bs-secondary-color:          #94a3b8;
    --bs-tertiary-color:           #64748b;
}

/* AUTO = follow OS */
@media (prefers-color-scheme: dark) {
    [data-theme="auto"] {
        --bg:             #0f172a;
        --surface:        #1e293b;
        --surface-2:      #162032;
        --border:         #334155;
        --text:           #f1f5f9;
        --text-muted:     #94a3b8;
        --sidebar-bg:     #1e293b;
        --sidebar-text:   #94a3b8;
        --sidebar-active-bg:   var(--primary-muted);
        --sidebar-active-text: #60a5fa;
        --sidebar-hover-bg:    rgba(255,255,255,0.04);
        --topbar-bg:      #1e293b;
        --shadow:         0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
        --shadow-md:      0 4px 6px rgba(0,0,0,0.3), 0 2px 4px rgba(0,0,0,0.2);

        /* Bootstrap variable overrides */
        --bs-body-bg:                  #0f172a;
        --bs-body-color:               #f1f5f9;
        --bs-dropdown-bg:              #1e293b;
        --bs-dropdown-color:           #f1f5f9;
        --bs-dropdown-border-color:    #334155;
        --bs-dropdown-link-color:      #f1f5f9;
        --bs-dropdown-link-hover-color:#f1f5f9;
        --bs-dropdown-link-hover-bg:   #162032;
        --bs-dropdown-divider-bg:      #334155;
        --bs-table-bg:                 transparent;
        --bs-table-color:              #f1f5f9;
        --bs-table-border-color:       #334155;
        --bs-table-striped-bg:         rgba(255,255,255,0.03);
        --bs-table-hover-bg:           rgba(255,255,255,0.04);
        --bs-table-active-bg:          rgba(255,255,255,0.06);
        --bs-modal-bg:                 #1e293b;
        --bs-modal-color:              #f1f5f9;
        --bs-modal-header-border-color:#334155;
        --bs-modal-footer-border-color:#334155;
        --bs-border-color:             #334155;
        --bs-secondary-bg:             #162032;
        --bs-tertiary-bg:              #0f172a;
        --bs-heading-color:            #f1f5f9;
        --bs-link-color:               #60a5fa;
        --bs-link-hover-color:         #93c5fd;
        --bs-form-valid-color:         #4ade80;
        --bs-form-invalid-color:       #f87171;
        --bs-secondary-color:          #94a3b8;
        --bs-tertiary-color:           #64748b;
    }
}

/* =============================================
   BOOTSTRAP DARK MODE — direct overrides
============================================= */
[data-theme="dark"] .table > :not(caption) > * > * {
    background-color: transparent;
    color: #f1f5f9;
    border-color: #334155;
}
/* Table headers: always show dark surface, never transparent */
[data-theme="dark"] .table > thead > tr > th {
    background-color: #162032 !important;
    color: #94a3b8 !important;
    border-color: #334155 !important;
}
/* Bootstrap .table-light in dark mode */
[data-theme="dark"] .table-light,
[data-theme="dark"] thead.table-light > tr > th,
[data-theme="dark"] .table > thead.table-light {
    --bs-table-bg: #162032;
    --bs-table-color: #94a3b8;
    background-color: #162032 !important;
    color: #94a3b8 !important;
    border-color: #334155 !important;
}
/* card headers */
[data-theme="dark"] .card-header { background-color: #162032 !important; border-color: #334155; color: #94a3b8; }
[data-theme="dark"] .table-hover > tbody > tr:hover > * { background-color: rgba(255,255,255,0.04); }
[data-theme="dark"] .table { border-color: #334155; }
[data-theme="dark"] .modal-content { background-color: #1e293b; color: #f1f5f9; border-color: #334155; }
[data-theme="dark"] .modal-header, [data-theme="dark"] .modal-footer { border-color: #334155; }
[data-theme="dark"] .btn-close { filter: invert(1); }
[data-theme="dark"] .form-control, [data-theme="dark"] .form-select { background-color: #162032; color: #f1f5f9; border-color: #334155; }
[data-theme="dark"] .form-control:focus, [data-theme="dark"] .form-select:focus { background-color: #162032; color: #f1f5f9; border-color: #2563eb; }
[data-theme="dark"] .form-control::placeholder { color: #64748b; }
[data-theme="dark"] .card { background-color: #1e293b; border-color: #334155; }

@media (prefers-color-scheme: dark) {
    [data-theme="auto"] .table > :not(caption) > * > * { background-color: transparent; color: #f1f5f9; border-color: #334155; }
    [data-theme="auto"] .table > thead > tr > th { background-color: #162032 !important; color: #94a3b8 !important; border-color: #334155 !important; }
    [data-theme="auto"] .table-light,
    [data-theme="auto"] thead.table-light > tr > th,
    [data-theme="auto"] .table > thead.table-light { --bs-table-bg: #162032; background-color: #162032 !important; color: #94a3b8 !important; border-color: #334155 !important; }
    [data-theme="auto"] .card-header { background-color: #162032 !important; border-color: #334155; color: #94a3b8; }
    [data-theme="auto"] .table-hover > tbody > tr:hover > * { background-color: rgba(255,255,255,0.04); }
    [data-theme="auto"] .table { border-color: #334155; }
    [data-theme="auto"] .modal-content { background-color: #1e293b; color: #f1f5f9; border-color: #334155; }
    [data-theme="auto"] .modal-header, [data-theme="auto"] .modal-footer { border-color: #334155; }
    [data-theme="auto"] .btn-close { filter: invert(1); }
    [data-theme="auto"] .form-control, [data-theme="auto"] .form-select { background-color: #162032; color: #f1f5f9; border-color: #334155; }
    [data-theme="auto"] .form-control:focus, [data-theme="auto"] .form-select:focus { background-color: #162032; color: #f1f5f9; border-color: #2563eb; }
    [data-theme="auto"] .form-control::placeholder { color: #64748b; }
    [data-theme="auto"] .card { background-color: #1e293b; border-color: #334155; }
}

/* Un-stamped pages (system = dark, no [data-theme] attribute) */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) .table > thead > tr > th { background-color: #162032 !important; color: #94a3b8 !important; border-color: #334155 !important; }
    :root:not([data-theme]) .table-light,
    :root:not([data-theme]) thead.table-light > tr > th { --bs-table-bg: #162032; background-color: #162032 !important; color: #94a3b8 !important; }
    :root:not([data-theme]) .card-header { background-color: #162032 !important; border-color: #334155; color: #94a3b8; }
    :root:not([data-theme]) .card { background-color: #1e293b; border-color: #334155; }
}

/* =============================================
   BASE
============================================= */
*, *::before, *::after {
    box-sizing: border-box;
    border-radius: 0 !important;
}

/* العناصر الدائرية الوحيدة في التطبيق */
.topbar-avatar,
.profile-dropdown-avatar,
.notif-dot,
.notif-avatar,
.notif-avatar-img,
.notif-unread-dot,
.submenu .nav-link::before {
    border-radius: 50% !important;
}

body {
    font-family: 'Cairo', 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    transition: background var(--transition), color var(--transition);
}

/* =============================================
   SIDEBAR
============================================= */
#sidebar {
    width: var(--sidebar-w);
    height: 100vh;
    background: var(--sidebar-bg);
    border-left: 1px solid var(--border);
    position: fixed;
    top: 0;
    right: 0;
    z-index: 1040;
    display: flex;
    flex-direction: column;
    transition: transform var(--transition), width var(--transition), background var(--transition), border-color var(--transition);
    box-shadow: var(--shadow);
    overflow: hidden;
}

/* LOGO */
.sidebar-brand {
    height: var(--topbar-h);
    padding: 0 18px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-brand .logo-box {
    width: 34px;
    height: 34px;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1rem;
    flex-shrink: 0;
}

.sidebar-brand .brand-name {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.3px;
}

.sidebar-brand .brand-name span {
    color: var(--primary);
}

/* NAV SCROLL */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border); }

/* SECTION LABEL */
.nav-label {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    padding: 14px 10px 5px;
}

/* NAV ITEM */
.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    color: var(--sidebar-text);
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    transition: all var(--transition);
    margin-bottom: 1px;
    white-space: nowrap;
}

.sidebar-nav .nav-link .nav-icon {
    width: 18px;
    text-align: center;
    font-size: 1rem;
    flex-shrink: 0;
}

.sidebar-nav .nav-link .arrow {
    margin-right: auto;
    font-size: 0.7rem;
    color: var(--text-muted);
    transition: transform var(--transition);
}

.sidebar-nav .nav-link:hover {
    background: var(--sidebar-hover-bg);
    color: var(--text);
}

.sidebar-nav .nav-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    font-weight: 600;
    border-right: 3px solid var(--primary);
}

.sidebar-nav .nav-link[aria-expanded="true"] {
    background: var(--sidebar-hover-bg);
    color: var(--text);
}

.sidebar-nav .nav-link[aria-expanded="true"] .arrow {
    transform: rotate(-90deg);
}

/* SUBMENU */
.submenu .nav-link {
    padding-right: 40px;
    font-size: 0.84rem;
    font-weight: 400;
    color: var(--text-muted);
    position: relative;
}

.submenu .nav-link::before {
    content: '';
    position: absolute;
    right: 22px;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--border);
    transition: background var(--transition);
}

.submenu .nav-link:hover::before,
.submenu .nav-link.active::before {
    background: var(--primary);
}

.submenu .nav-link:hover,
.submenu .nav-link.active {
    color: var(--text);
}

.submenu .nav-link.active {
    color: var(--sidebar-active-text);
    font-weight: 600;
    background: var(--sidebar-active-bg);
}

/* =============================================
   OVERLAY (mobile)
============================================= */
#sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1039;
    backdrop-filter: blur(2px);
}

/* =============================================
   MAIN CONTENT
============================================= */
#main-content {
    margin-right: var(--sidebar-w);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-right var(--transition);
}

/* TOPBAR */
.topbar {
    height: var(--topbar-h);
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: var(--shadow);
    transition: background var(--transition), border-color var(--transition);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.page-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}

/* HAMBURGER (mobile) */
#menu-toggle {
    display: none;
    background: none;
    border: 1px solid var(--border);
    width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    color: var(--text);
    cursor: pointer;
    font-size: 1.1rem;
    margin-left: 10px;
    transition: background var(--transition);
}

#menu-toggle:hover { background: var(--sidebar-hover-bg); }

/* COLLAPSE BUTTON (desktop topbar) */
#collapse-btn {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
    flex-shrink: 0;
    transition: all var(--transition);
}

#collapse-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

#collapse-btn i {
    transition: transform var(--transition);
}

.sidebar-collapsed #collapse-btn i {
    transform: rotate(180deg);
}

/* TOPBAR ICON BUTTONS */
.topbar-btn {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
    transition: all var(--transition);
    position: relative;
}

.topbar-btn:hover {
    background: var(--sidebar-hover-bg);
    color: var(--text);
}

/* PROFILE AVATAR (topbar) */
.topbar-avatar {
    width: 36px;
    height: 36px;
    background: var(--primary);
    border: 2px solid var(--primary);
    color: #fff;
    font-weight: 700;
    font-size: 0.82rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition);
    border-radius: 50% !important;
}

.topbar-avatar:hover {
    opacity: 0.85;
}

/* PROFILE DROPDOWN */
.profile-dropdown {
    min-width: 240px;
    padding: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0;
    box-shadow: var(--shadow-md);
    margin-top: 6px !important;
}

.profile-dropdown-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--surface-2);
}

.profile-dropdown-avatar {
    width: 40px;
    height: 40px;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: 50% !important;
}

.profile-dropdown-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
}

.profile-dropdown-info strong {
    font-size: 0.88rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profile-dropdown-info span {
    font-size: 0.76rem;
    color: var(--primary);
    font-weight: 500;
}

.profile-dropdown-info small {
    font-size: 0.72rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profile-dropdown .dropdown-divider {
    border-color: var(--border);
    margin: 0;
}

.profile-dropdown .dropdown-item {
    color: var(--text);
    font-size: 0.85rem;
    padding: 9px 16px;
    display: flex;
    align-items: center;
    gap: 9px;
    transition: background var(--transition);
    border-radius: 0;
}

.profile-dropdown .dropdown-item i {
    width: 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.profile-dropdown .dropdown-item:hover {
    background: var(--sidebar-hover-bg);
    color: var(--text);
}

.profile-dropdown .dropdown-item.text-danger:hover {
    background: #fef2f2;
    color: #ef4444 !important;
}

[data-theme="dark"] .profile-dropdown .dropdown-item.text-danger:hover {
    background: rgba(239, 68, 68, 0.1);
}

.notif-dot {
    width: 7px;
    height: 7px;
    background: #ef4444;
    border-radius: 50%;
    position: absolute;
    top: 5px;
    left: 5px;
    border: 2px solid var(--topbar-bg);
}

/* THEME SWITCHER */
.theme-switcher {
    display: flex;
    align-items: center;
    background: var(--surface-2);
    border: 1px solid var(--border);
    overflow: hidden;
    height: 36px;
}

.theme-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    transition: all var(--transition);
}

.theme-btn.active {
    background: var(--primary);
    color: #fff;
}

.theme-btn:hover:not(.active) {
    background: var(--sidebar-hover-bg);
    color: var(--text);
}

/* CONTENT */
.content-area {
    flex: 1;
    padding: 24px;
}

/* SUPER ADMIN NAV ITEM */
.nav-superadmin-divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--border), transparent);
    margin: 8px 16px;
}

.nav-superadmin {
    color: #a78bfa !important;
    position: relative;
}

.nav-superadmin:hover {
    background: rgba(167, 139, 250, 0.1) !important;
    color: #c4b5fd !important;
}

.nav-superadmin.active {
    background: rgba(167, 139, 250, 0.15) !important;
    color: #c4b5fd !important;
}

.nav-superadmin .nav-icon {
    color: #a78bfa;
}

/* FOOTER */
.app-footer {
    padding: 12px 24px;
    border-top: 1px solid var(--border);
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.78rem;
    color: var(--text-muted);
    transition: background var(--transition), border-color var(--transition);
    gap: 12px;
}

.footer-db {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
    color: var(--text-muted);
}

.footer-db i {
    color: var(--primary);
    font-size: 0.85rem;
}

@media (max-width: 576px) {
    .app-footer { flex-direction: column; gap: 6px; text-align: center; }
    .footer-db { justify-content: center; }
}

/* =============================================
   SIDEBAR COLLAPSED
============================================= */
.sidebar-collapsed #sidebar {
    width: var(--sidebar-collapsed-w);
    overflow: visible;
}

.sidebar-collapsed .sidebar-nav {
    overflow-y: auto;
    overflow-x: visible;
}

.sidebar-collapsed #main-content {
    margin-right: var(--sidebar-collapsed-w);
}

.sidebar-collapsed .sidebar-brand .brand-name,
.sidebar-collapsed .nav-label,
.sidebar-collapsed .sidebar-nav .nav-link span,
.sidebar-collapsed .sidebar-nav .nav-link .arrow {
    display: none;
}

.sidebar-collapsed .sidebar-nav .nav-link {
    justify-content: center;
    padding: 10px 0;
    border-right: none;
}

.sidebar-collapsed .sidebar-nav .nav-link.active {
    border-right: 3px solid var(--primary);
}

.sidebar-collapsed .sidebar-nav .nav-link .nav-icon {
    width: auto;
    font-size: 1.15rem;
}

.sidebar-collapsed .submenu {
    display: none !important;
}

/* =============================================
   RESPONSIVE
============================================= */

/* Tablet */
@media (max-width: 992px) {
    :root { --sidebar-w: 240px; }
}

/* Mobile */
@media (max-width: 768px) {
    :root { --sidebar-w: 260px; }

    #sidebar {
        transform: translateX(100%);
        overflow: hidden;
    }

    #sidebar.open {
        transform: translateX(0);
        box-shadow: -4px 0 20px rgba(0,0,0,0.15);
    }

    #sidebar-overlay.show {
        display: block;
    }

    #main-content {
        margin-right: 0 !important;
    }

    #menu-toggle {
        display: flex;
    }

    #collapse-btn {
        display: none;
    }

    .sidebar-collapsed #sidebar {
        width: var(--sidebar-w);
        overflow: hidden;
    }

    .content-area {
        padding: 16px;
    }

    .topbar {
        padding: 0 14px;
    }
}

/* Small mobile — collapse to single cycling button */
@media (max-width: 480px) {
    .theme-switcher {
        background: transparent;
        border: none;
        height: auto;
    }
    .theme-btn { display: none; }
    .theme-btn.active { display: flex; }
}

/* LANGUAGE BUTTON */
.lang-btn .lang-label {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: var(--primary);
}

/* =============================================
   BOTTOM NAVIGATION BAR
============================================= */
#bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(56px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 1035;
    align-items: stretch;
    box-shadow: 0 -2px 10px rgba(0,0,0,.07);
    transition: background var(--transition), border-color var(--transition);
}

.bn-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.6rem;
    font-weight: 600;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px 2px 4px;
    transition: color 0.15s;
    position: relative;
    font-family: inherit;
    letter-spacing: 0.01em;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.bn-item i {
    font-size: 1.3rem;
    line-height: 1;
    transition: transform 0.15s;
}

.bn-item.active           { color: var(--primary); }
.bn-item.active i         { transform: translateY(-2px); }
.bn-item:not(.active):hover { color: var(--text); }

.bn-badge {
    position: absolute;
    top: 5px;
    left: calc(50% + 5px);
    width: 8px;
    height: 8px;
    background: #ef4444;
    border-radius: 50% !important;
    border: 1.5px solid var(--surface);
    pointer-events: none;
}

/* =============================================
   QUICK ACTIONS PANEL
============================================= */
#qa-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1033;
    background: rgba(0,0,0,.35);
}
#qa-overlay.show { display: block; }

#quick-actions-panel {
    position: fixed;
    bottom: calc(56px + env(safe-area-inset-bottom, 0px));
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 2px solid var(--primary);
    z-index: 1034;
    display: none;
    grid-template-columns: repeat(4, 1fr);
    transform: translateY(100%);
    transition: transform .25s cubic-bezier(.4,0,.2,1);
    box-shadow: 0 -6px 24px rgba(0,0,0,.18);
}
#quick-actions-panel.show {
    display: grid;
    transform: translateY(0);
}
.qa-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 16px 6px;
    color: var(--text);
    text-decoration: none;
    font-size: 0.65rem;
    font-weight: 600;
    border-inline-end: 1px solid var(--border);
    transition: background .15s, color .15s;
    -webkit-tap-highlight-color: transparent;
}
.qa-item:last-child { border-inline-end: none; }
.qa-item:active { background: var(--surface-2); }
.qa-item i { font-size: 1.5rem; color: var(--primary); }

.bn-plus i { color: var(--primary); font-size: 1.5rem !important; }
.bn-plus.active i { transform: rotate(45deg); }
.bn-plus i { transition: transform .25s ease; }

/* =============================================
   SIDEBAR MOBILE FOOTER
============================================= */
.sidebar-mobile-footer {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    flex-shrink: 0;
    transition: background var(--transition), border-color var(--transition);
}

.sidebar-mobile-footer .theme-switcher {
    height: 34px;
}

.sidebar-mobile-footer .theme-btn {
    width: 34px;
    height: 34px;
}

/* =============================================
   MOBILE ENHANCEMENTS
============================================= */
/* ── Bottom nav + FAB repositioning (tablets & phones) ── */
@media (max-width: 768px) {
    #bottom-nav { display: flex; }

    .content-area {
        padding-bottom: calc(16px + 56px + env(safe-area-inset-bottom, 0px)) !important;
    }

    #back-to-top {
        bottom: calc(56px + env(safe-area-inset-bottom, 0px) + 46px + 14px);
        left: 12px;
    }

    .page-header { padding: 8px 12px; }
    .page-title  { font-size: 0.85rem; }
}

/* ── Sidebar mobile footer + topbar cleanup (phones only) ── */
@media (max-width: 640px) {
    .sidebar-mobile-footer              { display: flex; }
    /* hide lang/theme from topbar only — sidebar footer keeps its own copies */
    .topbar .lang-btn,
    .topbar .theme-switcher             { display: none !important; }
    /* ensure sidebar footer's theme-switcher is always visible inside it */
    .sidebar-mobile-footer .theme-switcher { display: flex !important; }
}

/* Extra-small phones: trim further */
@media (max-width: 380px) {
    .content-area  { padding: 10px; padding-bottom: calc(10px + 56px + env(safe-area-inset-bottom, 0px)) !important; }
    .topbar        { padding: 0 10px; }
    .page-title    { font-size: 0.78rem; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* =============================================
   LTR OVERRIDES (English)
============================================= */
[dir="ltr"] #sidebar {
    right: auto;
    left: 0;
    border-left: none;
    border-right: 1px solid var(--border);
}

[dir="ltr"] #main-content {
    margin-right: 0;
    margin-left: var(--sidebar-w);
}

[dir="ltr"] .sidebar-nav .nav-link.active {
    border-right: none;
    border-left: 3px solid var(--primary);
}

[dir="ltr"] .sidebar-nav .nav-link .arrow {
    margin-right: 0;
    margin-left: auto;
}

[dir="ltr"] .submenu .nav-link {
    padding-right: 12px;
    padding-left: 40px;
}

[dir="ltr"] .submenu .nav-link::before {
    right: auto;
    left: 22px;
}

[dir="ltr"] .notif-dot {
    left: auto;
    right: 5px;
}

[dir="ltr"] .sidebar-collapsed #main-content {
    margin-right: 0;
    margin-left: var(--sidebar-collapsed-w);
}

[dir="ltr"] .sidebar-collapsed .sidebar-nav .nav-link.active {
    border-right: none;
    border-left: 3px solid var(--primary);
}

/* Mobile LTR */
@media (max-width: 768px) {
    [dir="ltr"] #sidebar {
        left: 0;
        right: auto;
        transform: translateX(-100%);
    }

    [dir="ltr"] #sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0,0,0,0.15);
    }

    [dir="ltr"] #main-content {
        margin-left: 0 !important;
    }

    [dir="ltr"] #back-to-top {
        left: auto;
        right: 12px;
    }

    [dir="ltr"] .bn-badge {
        left: auto;
        right: calc(50% + 5px);
    }
}

/* =============================================
   CHAT FAB — hide since chat moved to sidebar
============================================= */

/* =============================================
   MOBILE RESPONSIVE TABLES
============================================= */
@media (max-width: 768px) {
    /* Wrap all DataTables in scroll container */
    .dataTables_wrapper,
    .table-responsive-auto {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Prevent filter form rows from overflowing */
    .card .row.g-3 > [class*="col-md"] {
        min-width: 0;
    }

    /* Activity log filter inputs */
    .card .row.g-3 .col-md-2,
    .card .row.g-3 .col-md-3 {
        flex: 0 0 50%;
        max-width: 50%;
    }
    .card .row.g-3 .col-md-1 {
        flex: 0 0 100%;
        max-width: 100%;
    }
}
@media (max-width: 480px) {
    .card .row.g-3 .col-md-2,
    .card .row.g-3 .col-md-3 {
        flex: 0 0 100%;
        max-width: 100%;
    }
}

/* ── Dark mode: Bootstrap nav-tabs full fix ── */
[data-theme="dark"] .nav-tabs {
    --bs-nav-tabs-border-color: #334155;
    --bs-nav-tabs-link-active-bg: #1e293b;
    --bs-nav-tabs-link-active-color: #f1f5f9;
    --bs-nav-tabs-link-active-border-color: #334155 #334155 #1e293b;
    border-bottom-color: #334155;
}
[data-theme="dark"] .nav-tabs .nav-link {
    color: #94a3b8 !important;
    border-color: transparent;
}
[data-theme="dark"] .nav-tabs .nav-link:hover {
    background-color: #162032 !important;
    border-color: #334155 #334155 transparent;
    color: #cbd5e1 !important;
}
[data-theme="dark"] .nav-tabs .nav-link.active,
[data-theme="dark"] .nav-tabs .nav-item.show .nav-link {
    background-color: #1e293b !important;
    color: #f1f5f9 !important;
    border-color: #334155 #334155 #1e293b !important;
}
[data-theme="dark"] .tab-content {
    color: #e2e8f0;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .nav-tabs {
        --bs-nav-tabs-border-color: #334155;
        --bs-nav-tabs-link-active-bg: #1e293b;
        --bs-nav-tabs-link-active-color: #f1f5f9;
        --bs-nav-tabs-link-active-border-color: #334155 #334155 #1e293b;
        border-bottom-color: #334155;
    }
    :root:not([data-theme="light"]) .nav-tabs .nav-link {
        color: #94a3b8 !important;
        border-color: transparent;
    }
    :root:not([data-theme="light"]) .nav-tabs .nav-link:hover {
        background-color: #162032 !important;
        border-color: #334155 #334155 transparent;
        color: #cbd5e1 !important;
    }
    :root:not([data-theme="light"]) .nav-tabs .nav-link.active,
    :root:not([data-theme="light"]) .nav-tabs .nav-item.show .nav-link {
        background-color: #1e293b !important;
        color: #f1f5f9 !important;
        border-color: #334155 #334155 #1e293b !important;
    }
    :root:not([data-theme="light"]) .tab-content {
        color: #e2e8f0;
    }
}
