/*
 * =============================================================================
 * GLOBAL STYLES
 * =============================================================================
 */

* {
    font-family: 'Segoe UI', sans-serif !important;
    font-size: 14px;
}

body {
    background: #f8f9fa;
    margin: 0;
}

/*
 * =============================================================================
 * LAYOUT
 * =============================================================================
 */

.layout {
    display: flex;
    min-height: 100vh;
}

.main {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
}

.content {
    flex: 1;
    overflow-x: auto;
    padding: 24px;
}

/*
 * =============================================================================
 * HEADER
 * =============================================================================
 */

.header {
    align-items: center;
    background: #ffffff;
    border-bottom: 1px solid #dee2e6;
    display: flex;
    height: 56px;
    justify-content: space-between;
    padding: 0.75rem 2rem;
    top: 0;
    color: #000;
    z-index: 1000;
}

.toggle-sidebar {
    color: #f5c518;
    cursor: pointer;
    font-size: 20px;
    margin-right: 12px;
}

.user-dropdown {
    font-size: 14px;
    text-decoration: none;
    transition: color 0.2s ease;
}

.user-dropdown:hover {
    color: #C69300;
}

.dropdown-menu {
    border-radius: 12px;
    font-size: 14px;
    min-width: 220px;
}

.dropdown-item {
    transition: background 0.2s ease;
}

.dropdown-item:hover {
    background-color: #fffbe6;
}

/*
 * =============================================================================
 * SEARCH BAR
 * =============================================================================
 */

.header-search {
    position: relative;
    flex-grow: 1;
    margin: 0 1rem;
    display: none;
}

.header-search .input-group {
    border-radius: 0.5rem;
    overflow: hidden;
    height: 40px;
}

.header-search .form-control,
.header-search .input-group-text {
    background-color: rgba(0, 0, 0, 0.05);
    border: none;
    color: #333;
}

.header-search .form-control::placeholder {
    color: #6c757d;
}

.header-search .input-group-text i {
    color: #6c757d;
}

.search-results-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 999;
    background-color: #ffffff;
    border: 1px solid #dee2e6;
    border-top: none;
    border-radius: 0 0 0.5rem 0.5rem;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    max-height: 400px;
    overflow-y: auto;
    display: none;
}

.search-results-dropdown .table {
    margin-bottom: 0;
}

.search-results-dropdown .table th,
.search-results-dropdown .table td {
    white-space: nowrap;
    vertical-align: middle;
}

.search-results-dropdown .table thead {
    top: 0;
    background-color: #f8f9fa;
    z-index: 10;
}

.search-results-dropdown .table-hover tbody tr:hover {
    background-color: #f1f1f1;
    cursor: pointer;
}
/*
 * =============================================================================
 * SIDEBAR
 * =============================================================================
 */

.sidebar {
    background: #fff;
    border-right: 1px solid #eee;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    justify-content: space-between;
    transition: all 0.3s ease;
}

body.sidebar-collapsed .sidebar {
    width: 60px;
}

.sidebar-header {
    align-items: center;
    color: #f5c518;
    display: flex;
    height: 56px;
    justify-content: center;
    margin-left: 7px;
    overflow: hidden;
    padding: 0 10px;
    white-space: nowrap;
}

.sidebar-header img.logo {
    height: 28px;
}

.sidebar-title {
    color: #C69300;
    display: inline;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.1;
}

.sidebar-title small {
    color: #666;
    display: block;
    font-size: 11px;
    font-weight: 500;
}

.sidebar .nav-link {
    align-items: center;
    border-radius: 6px;
    color: #333;
    display: flex;
    font-size: 14px;
    font-weight: 500;
    gap: 10px;
    margin: 2px 12px;
    padding: 10px 12px;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.sidebar .nav-link i {
    color: #f5c518;
    font-size: 18px;
    min-width: 20px;
    text-align: center;
}

.sidebar .nav-link:hover {
    background-color: #fffbe6;
    color: #d72638;
}

.sidebar .nav-link.active {
    background-color: #ffe6e6;
    color: #d72638;
    font-weight: 600;
}

.sidebar span,
.sidebar-footer {
    transition: opacity 0.2s ease;
}

body.sidebar-collapsed .sidebar span,
body.sidebar-collapsed .sidebar-footer {
    display: none !important;
    opacity: 0;
}

body.sidebar-collapsed .sidebar .nav-link {
    justify-content: center;
    padding: 10px 0;
    text-align: center;
}

.sidebar-footer {
    color: #aaa;
    font-size: 12px;
    padding: 10px 0;
    text-align: center;
    white-space: nowrap;
}

/*
 * =============================================================================
 * BUTTONS
 * =============================================================================
 */

.btn-primary {
    background-color: #FFC107 !important;
    border-color: #FFC107 !important;
    color: #000 !important;
}

.btn-primary:hover,
.btn-primary:focus {
    background-color: #e6ac00 !important;
    border-color: #e6ac00 !important;
    color: #000 !important;
}

.btn-outline-primary {
    background-color: transparent !important;
    border-color: #FFC107 !important;
    color: #FFC107 !important;
}

.btn-outline-primary:hover,
.btn-outline-primary:focus {
    background-color: #FFC107 !important;
    border-color: #FFC107 !important;
    color: #000 !important;
}

.btn-secondary {
    background-color: #f8f9fa !important;
    border-color: #ddd !important;
    color: #333 !important;
}

.btn-secondary:hover,
.btn-secondary:focus {
    background-color: #e6e6e6 !important;
    border-color: #ccc !important;
    color: #000 !important;
}

/*
 * =============================================================================
 * QR CODE
 * =============================================================================
 */

.qr-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.qr-wrapper img {
    max-width: 100%;
    width: 100px;
    height: auto;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

/*
 * =============================================================================
 * MODAL SEARCH
 * =============================================================================
 */

#searchModal .form-control {
    font-size: 1.25rem;
    padding: 1rem 1.25rem;
}

#searchModal .btn {
    font-size: 1.25rem;
    padding: 1rem 1.25rem;
}

#searchResults .list-group-item {
    font-size: 1rem;
    padding: 0.75rem 1.25rem;
}

/*
 * =============================================================================
 * MEDIA QUERIES (MOBILE STYLES)
 * =============================================================================
 */

@media (max-width: 1024px) {
    .content {
        font-size: 10px !important;
    }

    .sidebar {
        background: #fff;
        border-right: 1px solid #eee;
        bottom: 0;
        box-shadow: 2px 0 6px rgba(0, 0, 0, 0.1);
        display: flex;
        flex-direction: column;
        left: -240px;
        overflow: hidden;
        position: fixed;
        top: 0;
        width: 240px !important;
        z-index: 1050;
    }

    .sidebar-scroll {
        flex: 1 1 auto;
        max-height: calc(100vh - 56px - 32px);
        overflow-y: auto;
        padding-bottom: 20px;
        -webkit-overflow-scrolling: touch;
    }

    .sidebar.show {
        left: 0;
    }

    .sidebar-backdrop {
        background: rgba(0, 0, 0, 0.2);
        bottom: 0;
        display: none;
        left: 0;
        position: fixed;
        right: 0;
        top: 0;
        z-index: 1040;
    }

    .sidebar-backdrop.show {
        display: block;
    }

    .layout.mobile-open .main {
        opacity: 0.3;
        pointer-events: none;
        user-select: none;
    }

    body.sidebar-collapsed .sidebar .nav-link {
        justify-content: flex-start;
        padding-left: 12px;
    }

    body.sidebar-collapsed .sidebar .nav-link i {
        display: block;
        font-size: 20px;
        margin: 0 auto;
        padding: 6px 0;
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    .qr-wrapper img {
        width: 90px;
    }

    /* Khi sidebar được MỞ trên mobile (class .show) => bắt buộc hiển thị label dù body có sidebar-collapsed */
    body.sidebar-collapsed .sidebar.show span,
    body.sidebar-collapsed .sidebar.show .sidebar-footer,
    .sidebar.show span,
    .sidebar.show .sidebar-footer {
        display: inline !important;
        opacity: 1 !important;
    }

    /* Đảm bảo text không bị căn giữa; icon + text nằm chung hàng khi mở mobile */
    body.sidebar-collapsed .sidebar.show .nav-link,
    .sidebar.show .nav-link {
        justify-content: flex-start !important;
        padding-left: 12px !important;
        text-align: left !important;
    }

    /* Icon giữ khoảng phải để label không dính sát */
    body.sidebar-collapsed .sidebar .nav-link i,
    .sidebar .nav-link i {
        display: inline-block !important;
        min-width: 20px;
        margin-right: 10px !important;
        text-align: center;
    }
}

/* =============================================================================
   CHỈNH SỬA SIDEBAR ĐỂ HỖ TRỢ CUỘN VÀ THU GỌN
   ============================================================================= */

/* 1. Thiết lập chung cho Sidebar */
.sidebar {
    /* height: 100vh; */
    display: flex;
    flex-direction: column;
    background: #fff;
    border-right: 1px solid #eee;
    transition: all 0.3s ease;
    flex-shrink: 0;
    width: 240px; /* Độ rộng mặc định */
}

/* 2. Phần nội dung cuộn - Quan trọng nhất */
.sidebar-scroll {
    flex: 1 1 auto;
    overflow-y: auto;  /* Cho phép cuộn dọc */
    overflow-x: hidden; /* Chặn cuộn ngang */
    -webkit-overflow-scrolling: touch;
}

/* 3. Xử lý thu gọn trên Desktop (Chỉ áp dụng khi màn hình lớn) */
@media (min-width: 1025px) {
    body.sidebar-collapsed .sidebar {
        width: 60px;
    }
    
    body.sidebar-collapsed .sidebar-scroll {
        overflow: visible; /* Để tránh hiện thanh cuộn khi đã thu gọn */
    }

    /* Ẩn thanh cuộn cho đẹp trên Desktop khi đang ở chế độ bình thường */
    .sidebar-scroll::-webkit-scrollbar {
        width: 4px;
    }
    .sidebar-scroll::-webkit-scrollbar-thumb {
        background: #eee;
        border-radius: 10px;
    }
    .sidebar-scroll:hover::-webkit-scrollbar-thumb {
        background: #ccc;
    }
}

/* 4. Xử lý hiển thị trên Mobile (max-width: 1024px) */
@media (max-width: 1024px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        z-index: 1050;
        transform: translateX(-100%); /* Mặc định ẩn sang trái */
        width: 260px !important;      /* Cố định chiều rộng khi mở trên mobile */
    }

    .sidebar.show {
        transform: translateX(0);    /* Hiện ra khi bấm nút toggle */
    }
}