/* =================================================================
   BTW ERP — 3-Layer Chrome
   Layer 1: Handbook Rail (#handbook-rail, 64px, fixed, icon-only)
   Layer 2: Module Sidebar (#sidebar.module-sidebar, 240px/64px)
   Layer 3: Content (#content — unchanged)
   ================================================================= */

:root {
  --chrome-header-height: 64px;
  --chrome-divider: rgba(0,0,0,0.10);
}

[data-theme="dark"] {
  --chrome-divider: rgba(255,255,255,0.10);
}

/* --- LAYOUT OVERRIDE: wrapper is now 3-column --- */
.wrapper {
    display: flex;
    width: 100%;
    align-items: stretch;
    min-height: 100vh;
}

/* ── LAYER 1: HANDBOOK RAIL ── */
#handbook-rail {
    width: 64px;
    min-width: 64px;
    flex-shrink: 0;
    height: 100vh;
    position: sticky;
    top: 0;
    align-self: flex-start;
    background: var(--sidebar-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: 1px 0 0 var(--chrome-divider);
    border-right: 1px solid var(--chrome-divider);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0;
    z-index: 1010;
    gap: 0.25rem;
    overflow: hidden;
}

.rail-logo {
    width: 100%;
    height: var(--chrome-header-height);
    min-height: var(--chrome-header-height);
    max-height: var(--chrome-header-height);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-bottom: 0;
    border-bottom: 1px solid var(--chrome-divider);
    box-sizing: border-box;
    padding: 0;
    line-height: 1;
    font-size: 1rem;
}

.rail-logo + .rail-item {
    margin-top: 0.75rem;
}

.rail-spacer {
    flex: 1;
}

.rail-item {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 1.1rem;
    transition: background 0.18s ease, color 0.18s ease;
    position: relative;
    flex-shrink: 0;
}

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

/* Logout button override — strip browser default button styling */
.rail-item[type="submit"] {
    background: transparent;
    border: none;
    padding: 0;
    cursor: pointer;
}

.rail-item[type="submit"]:hover {
    background: rgba(220, 53, 69, 0.1);
    color: var(--bs-danger);
}

.rail-item.active {
    background: var(--handbook-accent, var(--sidebar-active-bg));
    color: white;
}

/* Tooltip on hover */
.rail-item::after {
    content: attr(title);
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--bg-card);
    color: var(--text-main);
    padding: 5px 11px;
    border-radius: 7px;
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: 0 4px 16px rgba(0,0,0,0.14);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.14s ease;
    z-index: 2000;
}
.rail-item:hover::after { opacity: 1; }

/* ── LAYER 2: MODULE SIDEBAR ── */
#sidebar.module-sidebar {
    min-width: 240px;
    max-width: 240px;
    width: 240px;
    height: 100vh;
    position: sticky;
    top: 0;
    align-self: flex-start;
    background: var(--sidebar-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: 1px 0 0 var(--chrome-divider), 4px 0 24px rgba(0,0,0,0.04);
    border-right: 1px solid var(--chrome-divider);
    transition: min-width 0.28s cubic-bezier(0.4,0,0.2,1),
                max-width 0.28s cubic-bezier(0.4,0,0.2,1),
                width 0.28s cubic-bezier(0.4,0,0.2,1);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Collapsed state (icon-only 64px) */
#sidebar.module-sidebar.module-collapsed {
    min-width: 64px;
    max-width: 64px;
    width: 64px;
}

/* Module sidebar header */
.module-sidebar-header {
    height: var(--chrome-header-height);
    min-height: var(--chrome-header-height);
    max-height: var(--chrome-header-height);
    padding: 0 1rem;
    font-size: 0.95rem;
    font-weight: 800;
    color: var(--text-main);
    display: flex;
    align-items: center;
    flex-shrink: 0;
    border-bottom: 1px solid var(--chrome-divider);
    white-space: nowrap;
    overflow: hidden;
    box-sizing: border-box;
}
.module-sidebar-header i {
    font-size: 1.15rem;
    flex-shrink: 0;
    color: var(--handbook-accent, var(--sidebar-active-text));
}
.module-sidebar-header {
    color: var(--handbook-accent, var(--text-main));
}
.module-sidebar-title {
    overflow: hidden;
    transition: opacity 0.2s ease, width 0.28s ease;
}

/* Hide text labels in collapsed state */
#sidebar.module-sidebar.module-collapsed .module-sidebar-title,
#sidebar.module-sidebar.module-collapsed ul li a span,
#sidebar.module-sidebar.module-collapsed .module-section-label,
#sidebar.module-sidebar.module-collapsed .sidebar-logout-btn span,
#sidebar.module-sidebar.module-collapsed .collapse-label {
    display: none;
}

#sidebar.module-sidebar.module-collapsed ul li a {
    justify-content: center;
    padding: 11px 0;
}

#sidebar.module-sidebar.module-collapsed .module-sidebar-header {
    justify-content: center;
    padding: 0;
    height: var(--chrome-header-height);
    min-height: var(--chrome-header-height);
    max-height: var(--chrome-header-height);
    box-sizing: border-box;
}
#sidebar.module-sidebar.module-collapsed .module-sidebar-header i {
    margin: 0 !important;
}

#sidebar.module-sidebar.module-collapsed .sidebar-logout-btn {
    justify-content: center;
    padding: 11px 0;
}
#sidebar.module-sidebar.module-collapsed .sidebar-logout-btn i {
    margin: 0 !important;
}

#sidebar.module-sidebar.module-collapsed .module-collapse-btn {
    justify-content: center;
}

/* Section labels inside module sidebar */
.module-section-label {
    padding: 0.6rem 1rem 0.25rem;
    font-size: 0.65rem;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--text-muted);
    opacity: 0.6;
}

/* Nav list */
#sidebar.module-sidebar ul.components {
    flex: 1;
    padding: 0.5rem 0.75rem;
    overflow-y: auto;
    margin-bottom: 0;
}

#sidebar.module-sidebar ul li { margin-bottom: 0.2rem; }

#sidebar.module-sidebar ul li a {
    padding: 10px 12px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--sidebar-text);
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    transition: all 0.18s ease;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
}

#sidebar.module-sidebar ul li a i {
    width: 28px;
    text-align: center;
    font-size: 1rem;
    flex-shrink: 0;
}

#sidebar.module-sidebar ul li a:hover {
    background-color: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    transform: translateX(3px);
}
#sidebar.module-sidebar ul li.active a {
    background-color: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    transform: none;
}

/* Collapse button */
.module-collapse-btn {
    color: var(--sidebar-text) !important;
    font-size: 0.9rem;
    font-weight: 600;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    border-radius: 0.5rem;
    text-decoration: none;
    transition: background 0.18s ease, color 0.18s ease;
    border: none;
    background: transparent;
}
.module-collapse-btn:hover {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text) !important;
}

/* Tooltip for collapsed module sidebar items */
#sidebar.module-sidebar.module-collapsed ul li a {
    position: relative;
    overflow: visible;
}
#sidebar.module-sidebar.module-collapsed ul li a i {
    font-size: 1.1rem;
    margin: 0;
    width: auto;
}

/* ── NAVBAR HEADER ── */
.navbar {
    height: var(--chrome-header-height) !important;
    min-height: var(--chrome-header-height) !important;
    max-height: var(--chrome-header-height) !important;
    display: flex !important;
    align-items: center !important;
    padding: 0 1.5rem 0 0 !important;
    box-sizing: border-box !important;
    border-bottom: 1px solid var(--chrome-divider) !important;
}

/* ── BREADCRUMB NAVBAR ── */
.nav-breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-muted);
    overflow: hidden;
}

.nav-breadcrumb .bc-sep {
    opacity: 0.4;
    font-size: 0.75rem;
}

/* Orphaned — breadcrumb simplified to page title only
.nav-breadcrumb .bc-handbook {
    color: var(--handbook-accent, var(--sidebar-active-text));
    display: flex;
    align-items: center;
    gap: 0.3rem;
}
*/

.nav-breadcrumb .bc-page {
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
    font-size: 1.1rem;
    font-weight: 600;
}

/* ── MOBILE OVERRIDES (≤768px) ── */
@media (max-width: 768px) {
    /* Hide handbook rail on mobile — use hamburger only */
    #handbook-rail { display: none; }

    /* Module sidebar becomes full-screen overlay on mobile */
    #sidebar.module-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100dvh;
        z-index: 1100;
        transform: translateX(-100%);
        min-width: 260px;
        max-width: 260px;
        width: 260px;
        transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
    }

    #sidebar.module-sidebar.mobile-open {
        transform: translateX(0);
    }

    /* Override collapsed to not apply on mobile */
    #sidebar.module-sidebar.module-collapsed {
        min-width: 260px;
        max-width: 260px;
        width: 260px;
    }
    #sidebar.module-sidebar.module-collapsed .module-sidebar-title,
    #sidebar.module-sidebar.module-collapsed ul li a span,
    #sidebar.module-sidebar.module-collapsed .module-section-label,
    #sidebar.module-sidebar.module-collapsed .sidebar-logout-btn span,
    #sidebar.module-sidebar.module-collapsed .collapse-label {
        display: inline;
    }
    #sidebar.module-sidebar.module-collapsed ul li a {
        justify-content: flex-start;
        padding: 10px 12px;
    }
    #sidebar.module-sidebar.module-collapsed .module-sidebar-header {
        justify-content: flex-start;
        padding: 0 1rem;
        height: var(--chrome-header-height);
        min-height: var(--chrome-header-height);
        max-height: var(--chrome-header-height);
        box-sizing: border-box;
    }
    #sidebar.module-sidebar.module-collapsed .module-sidebar-header i {
        margin-right: 0.5rem !important;
    }
}
