/* ==========================================================================
   App Sidebar Layout
   Sinh ra bởi Views/Shared/_Sidebar.cshtml, chỉ áp dụng cho user có ít nhất
   1 role khác CHUYEN_GIA (BDT, QLMH, TDV, BGD, HOD, ADMIN, S_ADMIN...).
   Dùng biến màu thương hiệu khai báo tại brand-colors.css — không hard-code
   màu HEX ngoài các tông trung tính (border/nền/chữ phụ).
   ========================================================================== */
:root {
    --app-sb-w: 268px;
    --app-sb-w-collapsed: 76px;
    --app-sb-transition: .2s cubic-bezier(.4, 0, .2, 1);
    --app-sb-border: #e6e9ec;
    --app-sb-muted: #98a2ae;
    --app-sb-text: #374151;
    --app-sb-hover-bg: rgba(0, 95, 105, .12);
    --app-sb-active-bg: rgba(0, 95, 105, .16);
}

/* ---------- Khung body: header (đã có) + app-body (sidebar + main) ---------- */
.app-body {
    display: flex;
    align-items: flex-start;
}

.app-main {
    flex: 1 1 0%;
    min-width: 0; /* bắt buộc để main content co giãn đúng trong flex row */
}

/* ---------- Floating chevron button (shadcn/ui + Linear + GitHub style) ----------
   Gắn liền vào mép phải sidebar (vị trí tính bằng position:fixed + left theo độ
   rộng sidebar hiện tại), không tách rời ra header — luôn "dính" theo mép sidebar
   kể cả khi mở rộng/thu gọn/đóng-mở trên mobile, tạo liên kết thị giác rõ ràng. */
.app-sidebar-fab {
    position: fixed;
    top: calc(var(--app-header-height, 64px) + 18px);
    left: calc(var(--app-sb-w) - 13px);
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #fff;
    border: 1px solid var(--app-sb-border);
    color: var(--app-sb-text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    line-height: 0;
    cursor: pointer;
    padding: 0;
    box-shadow: 0 1px 3px rgba(15, 23, 42, .1), 0 1px 2px rgba(15, 23, 42, .12);
    z-index: 950;
    transition: left var(--app-sb-transition), background var(--app-sb-transition),
        color var(--app-sb-transition), border-color var(--app-sb-transition), box-shadow var(--app-sb-transition);
}

    .app-sidebar-fab:hover {
        background: var(--brand-primary-light);
        color: var(--brand-primary);
        border-color: var(--brand-primary);
        box-shadow: 0 4px 10px rgba(15, 23, 42, .16);
    }

    .app-sidebar-fab:focus-visible {
        outline: 2px solid var(--brand-primary);
        outline-offset: 2px;
    }

    .app-sidebar-fab i {
        display: block;
        line-height: 1;
    }

/* ---------- Sidebar (desktop mặc định) ---------- */
.app-sidebar {
    width: var(--app-sb-w);
    flex: 0 0 auto;
    background: #fff;
    border-right: 1px solid var(--app-sb-border);
    position: sticky;
    top: var(--app-header-height, 64px);
    height: calc(100vh - var(--app-header-height, 64px));
    overflow: hidden;
    transition: width var(--app-sb-transition);
    z-index: 900;
}

.app-sidebar-scroll {
    width: var(--app-sb-w);
    height: 100%;
    padding: 16px 12px;
    overflow-y: auto;
    overflow-x: hidden;
}

.app-sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .45);
    z-index: 899;
    opacity: 0;
    transition: opacity .2s ease;
}

/* ---------- Section label ---------- */
.app-sidebar-section-label {
    font-size: 12px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #f26f33;
    padding: 14px 12px 6px;
    white-space: nowrap;
}

    .app-sidebar-section-label:first-child {
        padding-top: 2px;
    }

/* ---------- Item / group toggle ---------- */
.app-sidebar-item,
.app-sidebar-group-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 12px;
    border-radius: 9px;
    border: 0;
    background: transparent;
    color: var(--app-sb-text);
    font-size: 14px;
    cursor: pointer;
    white-space: nowrap;
    margin-bottom: 2px;
    transition: var(--app-sb-transition);
    position: relative;
    text-align: left;
    text-decoration: none;
}

.app-sidebar-icon {
    width: 20px;
    height: 20px;
    text-align: center;
    font-size: 15px;
    flex: 0 0 auto;
    color: var(--app-sb-text);
    opacity: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: background var(--app-sb-transition), color var(--app-sb-transition), transform .12s ease;
}

.app-sidebar-item:hover,
.app-sidebar-group-toggle:hover {
    background: var(--app-sb-hover-bg);
    color: var(--brand-primary);
}

    .app-sidebar-item:hover .app-sidebar-icon,
    .app-sidebar-group-toggle:hover .app-sidebar-icon {
        color: var(--brand-primary);
    }

.app-sidebar-item.active {
    background: var(--app-sb-active-bg);
    color: var(--brand-primary);
    font-weight: 600;
}

    .app-sidebar-item.active .app-sidebar-icon {
        color: var(--brand-primary);
    }

.app-sidebar-item:active .app-sidebar-icon,
.app-sidebar-group-toggle:active .app-sidebar-icon {
    transform: scale(.88);
}

.app-sidebar-item:focus-visible,
.app-sidebar-group-toggle:focus-visible {
    outline: 2px solid var(--brand-primary);
    outline-offset: -2px;
    background: var(--app-sb-hover-bg);
    color: var(--brand-primary);
}

.app-sb-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-sb-chevron {
    width: auto;
    flex: 0 0 auto;
    font-size: 11px;
    color: var(--app-sb-muted);
    transition: transform var(--app-sb-transition);
}

.app-sidebar-group.open .app-sb-chevron {
    transform: rotate(180deg);
}

/* ---------- Submenu (accordion, chế độ mở rộng) ---------- */
.app-sidebar-submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height var(--app-sb-transition);
    padding-left: 32px;
}

.app-sidebar-group.open .app-sidebar-submenu {
    max-height: 360px;
}

.app-sidebar-subitem {
    display: block;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13.5px;
    color: var(--app-sb-text);
    margin-bottom: 2px;
    white-space: nowrap;
    text-decoration: none;
    transition: var(--app-sb-transition);
}

    .app-sidebar-subitem:hover {
        background: var(--app-sb-hover-bg);
        color: var(--brand-primary);
    }

    .app-sidebar-subitem.active {
        background: var(--app-sb-active-bg);
        color: var(--brand-primary);
        font-weight: 600;
    }

/* ---------- Tooltip cho icon khi sidebar thu gọn ---------- */
.app-sb-tooltip {
    position: fixed;
    top: 0;
    left: 0;
    background: #20242b;
    color: #fff;
    font-size: 12.5px;
    font-weight: 500;
    padding: 7px 12px;
    border-radius: 8px;
    white-space: nowrap;
    box-shadow: 0 8px 18px rgba(17, 24, 39, .22);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-50%) translateX(-6px);
    transition: opacity .15s ease, transform .15s ease, visibility .15s;
    z-index: 1200;
}

    .app-sb-tooltip.show {
        opacity: 1;
        visibility: visible;
        transform: translateY(-50%) translateX(0);
    }

/* ---------- Flyout menu con khi sidebar thu gọn (group có submenu) ---------- */
.app-sidebar-group {
    position: relative;
}

.app-sidebar-flyout {
    position: fixed;
    top: 0;
    left: 0;
    min-width: 210px;
    background: #fff;
    border: 1px solid var(--app-sb-border);
    border-radius: 12px;
    box-shadow: 0 12px 28px rgba(17, 24, 39, .16);
    padding: 8px;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateX(-6px);
    transition: opacity .15s ease, transform .15s ease, visibility .15s;
    z-index: 1200;
}

    .app-sidebar-flyout.show {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
        transform: translateX(0);
    }

.app-sidebar-flyout-title {
    font-size: 12px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: #f26f33;
    padding: 6px 10px 8px;
    white-space: nowrap;
}

.app-sidebar-flyout-item {
    display: block;
    padding: 9px 10px;
    border-radius: 8px;
    font-size: 13.5px;
    color: var(--app-sb-text);
    white-space: nowrap;
    text-decoration: none;
    transition: var(--app-sb-transition);
}

    .app-sidebar-flyout-item:hover,
    .app-sidebar-flyout-item:focus-visible {
        background: var(--app-sb-hover-bg);
        color: var(--brand-primary);
        outline: none;
    }

/* ==========================================================================
   Desktop (>= 992px): sidebar tĩnh trong luồng flex, thu gọn còn dải icon.
   Main content (.app-main) co giãn tự động vì flex: 1 1 0%.
   ========================================================================== */
@media (min-width: 992px) {
    body.sidebar-collapsed .app-sidebar {
        width: var(--app-sb-w-collapsed);
    }

    body.sidebar-collapsed .app-sidebar-fab {
        left: calc(var(--app-sb-w-collapsed) - 13px);
    }

    body.sidebar-collapsed .app-sidebar-scroll {
        width: var(--app-sb-w-collapsed);
        padding: 16px 12px;
    }

    body.sidebar-collapsed .app-sidebar-section-label {
        height: 1px;
        padding: 0;
        margin: 12px 8px;
        background: var(--app-sb-border);
        overflow: hidden;
        text-indent: -9999px;
    }

    body.sidebar-collapsed .app-sb-label,
    body.sidebar-collapsed .app-sb-chevron {
        display: none;
    }

    body.sidebar-collapsed .app-sidebar-submenu {
        display: none;
    }

    body.sidebar-collapsed .app-sidebar-item:hover,
    body.sidebar-collapsed .app-sidebar-group-toggle:hover,
    body.sidebar-collapsed .app-sidebar-item:focus-visible,
    body.sidebar-collapsed .app-sidebar-group-toggle:focus-visible {
        background: var(--app-sb-hover-bg);
        color: var(--brand-primary);
        outline: none;
        box-shadow: none;
    }

        body.sidebar-collapsed .app-sidebar-item:hover .app-sidebar-icon,
        body.sidebar-collapsed .app-sidebar-group-toggle:hover .app-sidebar-icon,
        body.sidebar-collapsed .app-sidebar-item:focus-visible .app-sidebar-icon,
        body.sidebar-collapsed .app-sidebar-group-toggle:focus-visible .app-sidebar-icon {
            background: transparent;
            color: var(--brand-primary);
        }

    /* Active lúc thu gọn: tô kín toàn bộ khối item (bằng khung item, không chỉ icon-wrap
       bên trong) — cùng độ nổi bật với trạng thái active lúc mở rộng, chỉ khác là ẩn text. */
    body.sidebar-collapsed .app-sidebar-item.active {
        background: var(--brand-primary);
        box-shadow: none;
    }

        body.sidebar-collapsed .app-sidebar-item.active .app-sidebar-icon {
            background: transparent;
            color: var(--brand-white, #fff);
        }
}

/* ==========================================================================
   Mobile / Tablet (< 992px): sidebar chuyển thành overlay trượt từ trái,
   luôn hiển thị đầy đủ nhãn (không có chế độ chỉ-icon) — không phá layout
   nội dung chính vì sidebar ra khỏi luồng flex (position: fixed).
   ========================================================================== */
@media (max-width: 991.98px) {
    .app-sidebar {
        position: fixed;
        top: var(--app-header-height, 64px);
        left: 0;
        height: calc(100vh - var(--app-header-height, 64px));
        transform: translateX(-100%);
        box-shadow: 0 16px 32px rgba(17, 24, 39, .2);
    }

    body.sidebar-mobile-open .app-sidebar {
        transform: translateX(0);
    }

    body.sidebar-mobile-open .app-sidebar-backdrop {
        display: block;
        opacity: 1;
    }

    body.sidebar-mobile-open {
        overflow: hidden;
    }

    /* Sidebar mặc định nằm ngoài màn hình trên mobile — FAB thu về sát mép trái
       màn hình như 1 tab nhỏ để mở, trượt theo mép sidebar khi mở. */
    .app-sidebar-fab {
        left: 10px;
    }

    body.sidebar-mobile-open .app-sidebar-fab {
        left: calc(var(--app-sb-w) - 13px);
    }
}
