:root {
    --primary: #00599a;
    --primary-gradient: linear-gradient(135deg, #007AFF 0%, #0056b3 100%);
    --primary-light: #eef5ff;
    --accent: #007AFF;
    --text-dark: #2d2e2e;
    --text-gray: #6a737d;
    --bg-app: #f8f9fa;
    --border: #e1e4e8;
    --sidebar-w: 280px;
    --sidebar-c: 80px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    /* ---- SIDEBAR (DARK THEME) ---- */
    --sidebar-bg: #12203d;
    --sidebar-bg-alt: #17294c;
    --sidebar-text: #eef1f8;
    --sidebar-text-muted: #8891ab;
    --sidebar-border: rgba(255, 255, 255, 0.07);
    --sidebar-hover: rgba(255, 255, 255, 0.06);
    --sidebar-logo-bg: #2f6fed;
    --sidebar-active-bg: rgba(59, 111, 237, 0.16);
    --sidebar-active-text: #6ea8ff;
    --sidebar-active-bar: #3b6fed;
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Be Vietnam Pro', sans-serif; }
body { background: var(--bg-app); color: var(--text-dark); width: 100vw; height: 100vh; }
img { max-width: 100%; height: auto; display: block; }
.hidden { display: none !important; }

/* AUTH - LOGIN */
.auth-overlay { position: fixed; inset: 0; background: #f4f7f9; display: flex; align-items: center; justify-content: center; z-index: 10000; }
.login-box { background: white; padding: 40px; border-radius: 24px; box-shadow: 0 4px 14px rgba(0, 122, 255, 0.1); text-align: center; width: 520px; }
.login-box img { width: 80px; margin: 0 auto 20px; }
.password-container { position: relative; margin: 20px 0; }
.login-input { width: 100%; padding: 14px; border: 1px solid var(--border); border-radius: 12px; text-align: center; font-size: 16px; outline: none; }
#togglePassword { position: absolute; right: 15px; top: 50%; transform: translateY(-50%); cursor: pointer; color: var(--text-gray); }
.btn-login { width: 100%; background: var(--primary-gradient); color: white; border: none; padding: 14px; border-radius: 12px; font-weight: 600; cursor: pointer; }

/* --- PREMIUM PAGE LOADER --- */
.page-loader {
    position: absolute;
    inset: 0;
    background: rgba(248, 249, 250, 0.8); /* Nền xám nhạt mờ */
    backdrop-filter: blur(4px); /* Hiệu ứng mờ nền cực xịn */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    transition: opacity 0.3s ease;
}

.loader-content { text-align: center; }

.spinner-unime {
    width: 45px;
    height: 45px;
    border: 4px solid #e2e8f0;
    border-top: 4px solid var(--primary); /* Màu xanh chính của bạn */
    border-radius: 50%;
    margin: 0 auto 15px;
    animation: spin 0.8s linear infinite;
}

.loader-content p {
    font-size: 14px;
    font-weight: 600;
    color: var(--primary);
    margin: 0;
    letter-spacing: 0.5px;
}

@keyframes spin { 100% { transform: rotate(360deg); } }

.page-loader.hidden {
    opacity: 0;
    pointer-events: none;
    display: none;
}

/* LAYOUT CHÍNH */
.app-container { display: flex; width: 100vw; height: 100vh; }

/* SIDEBAR - DARK NAVY STYLE */
.sidebar { width: var(--sidebar-w); background: var(--sidebar-bg); border-right: none; display: flex; flex-direction: column; transition: var(--transition); position: relative; overflow: visible !important; z-index: 1001; flex-shrink: 0; }
.sidebar.collapsed { width: var(--sidebar-c); }
.sidebar-toggle { position: absolute; right: -14px; top: 35px; width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--border); background: white; cursor: pointer; z-index: 10002; box-shadow: 0 2px 8px rgba(0,0,0,0.15); display: none !important; align-items: center; justify-content: center; transform: translateY(-50%); color: var(--text-gray); }
.sidebar-toggle:hover { background: var(--primary-gradient); color: white; transform: translateY(-50%) scale(1.1); }
.sidebar.collapsed .sidebar-toggle i { transform: rotate(180deg); }
/* Class để ẩn hoàn toàn Sidebar */
.sidebar.fully-hidden {
    display: none !important;
    width: 0 !important;
    min-width: 0 !important;
}

/* Đảm bảo nội dung chính tự động tràn ra 100% chiều rộng */
.sidebar.fully-hidden ~ .main-content {
    width: 100%;
    margin-left: 0;
}
.sidebar-header { height: 70px; padding: 0 20px; margin-bottom: 20px; display: flex; align-items: center; box-sizing: border-box; }
.user-profile { display: flex; align-items: center; gap: 12px; }
.user-info { display: flex; flex-direction: column; justify-content: center; }
.avatar { width: 42px; height: 42px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; background: var(--sidebar-logo-bg); border-radius: 12px; box-shadow: 0 4px 10px rgba(47, 111, 237, 0.35); overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 12px; }
.avatar i { color: #ffffff; font-size: 19px; }
.app-name { display: block; font-weight: 800; font-size: 20px; color: var(--sidebar-text); white-space: nowrap; line-height: 1.1; margin-bottom: 3px; }
.app-sub { padding-top: 2px; display: block; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--sidebar-text-muted); white-space: nowrap; line-height: 1; }

.sidebar-menu { flex: 1; padding: 4px 14px; overflow-y: auto; overflow-x: hidden; }

/* Nhãn tiêu đề nhóm dạng chữ tĩnh (Tổng quan / UMER Ecosystem / Khác) */
.menu-section-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--sidebar-text-muted);
    padding: 6px 12px 8px;
    margin-top: 4px;
}

.menu-item:hover { background: var(--sidebar-hover); color: var(--sidebar-text); }
.menu-item.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); }
/* FIX QUAN TRỌNG: Ép icon vào khung cố định để chữ luôn thẳng hàng */
.menu-item, 
.group-header {
    display: flex !important;
    flex-direction: row !important; /* Đảm bảo luôn nằm ngang */
    align-items: center !important;
    padding: 10px 12px;
    font-size: 14px;
    font-weight: 600;
    gap: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: 10px;
    margin-bottom: 4px;
    min-height: 42px;
    position: relative;
    text-decoration: none;
    color: var(--sidebar-text-muted);
}
.menu-item i, 
.header-main i {
    width: 22px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 16px;
    color: var(--sidebar-text-muted);
    flex-shrink: 0;
}
.menu-icon {
    width: 24px;
    height: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--sidebar-text-muted);
    flex-shrink: 0;
}
.menu-icon svg { width: 21px; height: 21px; }
.menu-item.active .menu-icon,
.menu-item:hover .menu-icon { color: var(--sidebar-text); }
.menu-item.active .menu-icon { color: var(--sidebar-active-text); }
.header-main { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--sidebar-text-muted); flex: 1; }
/* Ẩn icon trong nhãn nhóm để giống nhãn chữ đơn giản như hình mẫu */
.header-main i { display: none; }
.group-header { cursor: default; padding: 14px 12px 6px; margin-bottom: 2px; }
.group-content { max-height: none !important; overflow: visible !important; margin-left: 0; border-left: none; padding: 0 !important; }
.chevron { display: none !important; }

.sub-item {
    padding-left: 12px !important;
    font-size: 14px;
    font-weight: 600;
    color: var(--sidebar-text-muted);
    position: relative;
    background: transparent;
    border-radius: 10px;
}

/* Bỏ đường kẻ line xám (không có trong giao diện mới) */
.sub-item::before { content: none; }
.sub-item:hover { color: var(--sidebar-text); background: var(--sidebar-hover); }
/* Active cho Menu chính (Báo cáo tiến độ) - nền xanh nhạt + line trái */
.menu-item.active:not(.sub-item) {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    font-weight: 700;
    border-radius: 8px;
    position: relative;
}
.menu-item.active:not(.sub-item)::before {
    content: "";
    position: absolute;
    left: 0;
    top: 6px;
    bottom: 6px;
    width: 3px;
    border-radius: 2px;
    background: var(--sidebar-active-bar);
}
.menu-item.active:not(.sub-item) i { color: var(--sidebar-active-text); }

/* Active cho Menu con (Digital Transformation) - nền xanh nhạt + line trái, đúng theo hình mẫu */
.sub-item.active {
    background: var(--sidebar-active-bg) !important;
    color: var(--sidebar-active-text) !important;
    font-weight: 700;
    border-radius: 8px;
    position: relative;
}
.sub-item.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 6px;
    bottom: 6px;
    width: 3px;
    border-radius: 2px;
    background: var(--sidebar-active-bar);
}
.sub-item.active i { color: var(--sidebar-active-text); }

/* --- FIX KHI SIDEBAR THU GỌN (COLLAPSED) --- */
.sidebar.collapsed .sub-item {
    margin-left: 0;
    padding-left: 12px !important;
}
.sidebar.collapsed .menu-section-label { display: none; }
.sidebar.collapsed .menu-item .menu-label, 
.sidebar.collapsed .header-main .menu-label, 
.sidebar.collapsed .chevron {
    display: none;
}

/* Khi sidebar thu gọn (Collapsed) */
.sidebar.collapsed .menu-item,
.sidebar.collapsed .group-header {
    justify-content: center;
    padding: 12px 0;
    gap: 0;
}
/* Đảm bảo icon LUÔN hiển thị rõ khi thu gọn */
.sidebar.collapsed .menu-icon {
    width: 100%;
    color: var(--sidebar-text-muted);
}
.sidebar.collapsed .menu-item:hover .menu-icon { color: var(--sidebar-text); }
.sidebar.collapsed .menu-item.active .menu-icon { color: var(--sidebar-active-text); }
/* Ẩn thanh line trái khi thu gọn vì không đủ chỗ hiển thị đẹp */
.sidebar.collapsed .menu-item.active::before,
.sidebar.collapsed .sub-item.active::before { display: none; }
.sidebar.collapsed .menu-item.active,
.sidebar.collapsed .sub-item.active { border-radius: 10px; margin: 0 8px 4px; }
/* Nhóm con (sub-item) khi thu gọn cũng nằm giữa icon như menu chính */
.sidebar.collapsed .group-content { display: flex; flex-direction: column; align-items: center; }
.sidebar.collapsed .sub-item { width: 44px; }
.sidebar-footer { padding: 14px; border-top: 1px solid var(--sidebar-border); }
.user-card { display: flex; align-items: center; gap: 10px; padding: 10px; background: var(--sidebar-bg-alt); border-radius: 12px; cursor: pointer; overflow: hidden; }
.user-card:hover { background: var(--sidebar-hover); }
.user-avatar-sm { width: 30px; height: 30px; border-radius: 50%; overflow: hidden; flex-shrink: 0; background: var(--sidebar-logo-bg); display: flex; align-items: center; justify-content: center; }
.user-details { flex: 1; font-size: 13px; font-weight: 600; color: var(--sidebar-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-card > i { color: var(--sidebar-text-muted); }

/* MAIN CONTENT */
.main-content { flex: 1; display: flex; flex-direction: column; height: 100vh; min-width: 0; }
.main-header { align-items: center; height: 70px; background: var(--bg-app); display: flex; align-items: center; justify-content: space-between; padding: 0 30px; border-bottom: 1px solid var(--border); z-index: 100; position: relative; }
.header-divider { width: 1px; height: 24px; background: var(--border); margin: 0 10px; }
.content-area { min-height: calc(100vh - 70px); height: auto !important; overflow-y: auto; }

/* CÁC NÚT BẤM DÀNH CHO SHOT */
/* ÉP Header Actions nằm hàng ngang */
.header-actions { display: flex; align-items: center; gap: 12px; }
.header-left {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 15px;
    flex: 1;
    min-width: 0;
    height: 44px;
}
#dynamic-header-title {
    margin: 0 !important;
        padding: 0 !important;
        font-size: 20px;
        font-weight: 500;
        line-height: 1 !important;
        display: flex;
        align-items: center;
        white-space: nowrap;
        color: #1e293b;
    }
#shot-actions-slot { display: flex; align-items: center; gap: 8px;}
/* CÁC NÚT BẤM DÀNH CHO SHOT */
#shot-actions-slot .btn-action { height: 38px; padding: 0 16px; border-radius: 10px; border: none; font-weight: 600; font-size: 13px; color: white; display: flex; align-items: center; gap: 8px; cursor: pointer; }
.btn-add { background: #28a745; }
.btn-sync { background: var(--primary-gradient); }

/* Nút Menu Global */
.btn-menu-global {
    background: #f1f5f9;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0; /* Chống bị bóp méo nút */
}

.btn-menu-global:hover { background: #e2e8f0; }

/* --- DROPDOWN EXPORT MENU --- */
.export-dropdown {
    position: relative;
    display: inline-block;
}

.btn-dots {
    background: #00000000;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--sidebar-text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-dots:hover {
    background: #e2e8f0;
    color: var(--sidebar-logo-bg);
}

.dropdown-content {
    display: none; /* Mặc định ẩn */
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    background: white;
    min-width: 150px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    border-radius: 10px;
    padding: 6px;
    z-index: 1000;
    border: 1px solid var(--border);
    animation: fadeInDown 0.2s ease;
}

.dropdown-content.show {
    display: block;
}

.dropdown-item {
    width: 100%;
    border: none;
    background: none;
    padding: 10px 14px;
    text-align: left;
    font-size: 13px;
    font-weight: 600;
    color: var(--sidebar-text-muted);
    display: flex;
    align-items: center;
    gap: 10px;
    border-radius: 6px;
    cursor: pointer;
}

.dropdown-item:hover {
    background: #f1f5f9;
    color: var(--sidebar-logo-bg);
}

.dropdown-item i {
    width: 16px;
    font-size: 14px;
}

@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Ẩn dropdown menu trên mobile hoặc các shot không cần thiết */
@media (max-width: 1024px) {
    #exportMenuWrapper { display: none !important; }
}
.content-body { flex: 1; padding: 25px; overflow-y: auto; transition: opacity 0.3s; }

/* ZOOM MODAL - ZOOM IMAGE*/
.modal-preview { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.85); backdrop-filter: blur(8px); z-index: 10000; justify-content: center; align-items: center; backdrop-filter: blur(10px);}
.modal-content { max-width: 95%; max-height: 95%; border-radius: 16px; transform: scale(1); transition: 0.3s; object-fit: contain; cursor: default;}
.modal-preview.active { display: flex; animation: fadeIn 0.3s ease; }
.close-modal { position: absolute; top: 30px; right: 30px; color: white; font-size: 40px; cursor: pointer; }
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
.sidebar.collapsed .user-info, .sidebar.collapsed .menu-item .menu-label, .sidebar.collapsed .header-main .menu-label, .sidebar.collapsed .chevron, .sidebar.collapsed .user-details { display: none; }

.is-exporting #content-area {
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
    padding: 0 !important;
}

.is-exporting .main-content, 
.is-exporting .app-container {
    height: auto !important;
    overflow: visible !important;
}

.is-exporting .sidebar,
.is-exporting .main-header,
.is-exporting .actions,
.is-exporting .btn-trash,
.is-exporting .sidebar-toggle {
    display: none !important;
}

/* ================================================================
   6. RESPONSIVE ENGINE - MOBILE & IPAD (MAX-WIDTH: 1024px)
   ================================================================ */
@media (max-width: 1024px) {
    body { overflow-x: hidden; }
    .app-container { width: 100vw; position: relative; }

    /* SIDEBAR BIẾN THÀNH OVERLAY */
    .sidebar {
        position: fixed;
        left: 0; top: 0; bottom: 0;
        transform: translateX(-100%);
        z-index: 10000;
        width: var(--sidebar-w) !important;
        box-shadow: 15px 0 30px rgba(0,0,0,0.25);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .sidebar.mobile-active { transform: translateX(0); }
    .sidebar-toggle { display: none !important; }

    /* HEADER TỐI ƯU */
    .main-header {
        padding: 0 12px;
        height: 60px;
    }

    .header-left {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 15px;
    flex: 1;
    min-width: 0;
    height: 44px;
    }
    #dynamic-header-title {
        margin: 0 !important;
        padding: 0 !important;
        font-size: 20px;
        font-weight: 500;
        line-height: 1 !important;
        display: flex;
        align-items: center;
        white-space: nowrap;
        color: #1e293b;
    }
    /* NÚT PDF BIẾN THÀNH ICON TRÒN */
    .btn-primary {
        width: 34px; height: 34px; padding: 0;
        justify-content: center; border-radius: 8px;
    }
    .btn-primary span { display: none; }
    .btn-primary i { margin: 0; font-size: 14px; }

    /* LOGIN BOX */
    .login-box { width: 92% !important; padding: 30px 20px !important; }
}

/* LỚP PHỦ MỜ KHI MỞ MENU */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    z-index: 9998; /* Nằm dưới Sidebar (9999) nhưng trên nội dung */
    display: none; /* Mặc định ẩn hoàn toàn */
    pointer-events: none; /* Chắc chắn không chặn click */
}

.sidebar-overlay.active {
    display: block !important;
    pointer-events: auto !important; /* Chỉ nhận click khi đang hiện */
}

/* ================================================================
   RESPONSIVE HEADER ENGINE - MOBILE & IPAD (MAX-WIDTH: 1024px)
   ================================================================ */

@media (max-width: 1024px) {
    /* 1. CẤU HÌNH HEADER MẶC ĐỊNH (1 HÀNG - Cho Shot 1, 5, 8...) */
    .main-header {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
        height: 65px !important;
        min-height: 65px !important;
        padding: 0 15px !important;
        gap: 10px;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    /* 2. CẤU HÌNH HEADER KHI CÓ NÚT ĐIỀU HƯỚNG (2 HÀNG - Cho Shot 6) */
    .main-header.has-nav-actions {
        display: grid !important;
        grid-template-areas: 
            "left-side pdf-btn"
            "nav-slot nav-slot";
        grid-template-columns: 1fr auto; /* Cột trái giãn hết cỡ, cột phải chứa nút PDF */
        height: auto !important;
        min-height: 110px !important;
        gap: 12px 0;
        padding: 10px 15px !important;
    }

    /* ĐỊNH VỊ CÁC THÀNH PHẦN TRONG GRID */
    .header-left { 
        grid-area: left-side; 
        display: flex !important;
        align-items: center !important;
        gap: 10px;
        min-width: 0;
    }

    /* Nút PDF: Luôn sát mép phải hàng 1 */
    #exportPdfBtn { 
        grid-area: pdf-btn; 
        justify-self: end; /* Đẩy sát lề phải */
        width: 40px !important;
        height: 40px !important;
        padding: 0 !important;
        display: flex !important;
        justify-content: center;
        align-items: center;
        border-radius: 10px;
        flex-shrink: 0;
    }
    #exportPdfBtn span { display: none; } /* Ẩn chữ trên mobile */

    /* Slot chứa Roadmap/Usecases: Nằm trọn hàng 2 */
    .header-actions { display: contents !important; } /* Giải phóng slot con */
    
    #shot-actions-slot {
        grid-area: nav-slot;
        width: 100% !important;
        display: flex !important;
        gap: 8px;
        overflow-x: auto; /* Cho phép vuốt ngang hàng 2 */
        padding: 2px 0 8px 0;
        flex-wrap: nowrap;
        -ms-overflow-style: none;
        scrollbar-width: none;
    }
    #shot-actions-slot::-webkit-scrollbar { display: none; }

    /* Ẩn slot hoàn toàn nếu shot không có nút điều hướng */
    .main-header:not(.has-nav-actions) #shot-actions-slot {
        display: none !important;
    }

    /* TỐI ƯU CHỮ TIÊU ĐỀ */
    #dynamic-header-title {
        font-size: 15px;
        font-weight: 800;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 180px; /* Tăng độ rộng tiêu đề */
    }

    /* STYLE NÚT ĐIỀU HƯỚNG TẦNG 2 */
    .btn-nav-scroll {
        height: 34px !important;
        padding: 0 12px !important;
        font-size: 11px !important;
        border-radius: 8px;
        flex-shrink: 0;
        background: #f8fafc;
        border: 1px solid #e2e8f0;
    }
}

/* ================================================================
   XỬ LÝ CUỘN (SCROLL MARGIN) TƯƠNG ỨNG VỚI CHIỀU CAO HEADER
   ================================================================ */
#content-area { scroll-behavior: smooth; }

/* Mặc định cho các Shot 1 hàng (65px + 15px lề) */
.content-section { scroll-margin-top: 80px; }

/* Dành riêng cho Shot có 2 hàng nút (110px + 20px lề) */
.has-nav-actions ~ .content-body .content-section {
    scroll-margin-top: 135px !important;
}

@media (max-width: 1024px) {
    /* Thêm #exportPdfBtn vào để nó đè được style inline */
    #exportPdfBtn {
        display: none !important;
    }
}