/* ============================================================
   ERP PHỐI HỢP - GANTT V2 FINAL
============================================================ */

.erp-ph-gantt-v2 {
    --erp-ph-v2-stt: 55px;
    --erp-ph-v2-noidung: 400px;
    --erp-ph-v2-donvi: 150px;
    --erp-ph-v2-ngay-1: 60px;
    --erp-ph-v2-ngay: 150px;
    --erp-ph-v2-fixed-width: calc(var(--erp-ph-v2-stt) + var(--erp-ph-v2-noidung) + var(--erp-ph-v2-donvi) + var(--erp-ph-v2-ngay-1) + var(--erp-ph-v2-ngay));
    --erp-ph-v2-day-width: 38px;
    --erp-ph-v2-row-height: 42px;

    width: 100%;
    max-width: 100%;
    position: relative;
    overflow: hidden;
    background: #fff;
    font-size: 14px;
}

.erp-ph-gantt-v2 table {
    margin: 0;
    padding: 0;
    border-collapse: separate;
    border-spacing: 0;
    table-layout: fixed;
    border: 1px solid rgba(0, 0, 0, .07);
}

.erp-ph-gantt-v2 th,
.erp-ph-gantt-v2 td {
    box-sizing: border-box;
    border: 1px solid rgba(0, 0, 0, .07);
    padding: 0 6px;
}

/* HEADER */
.erp-ph-gantt-v2__header {
    display: flex;
    width: 100%;
    overflow: hidden;
    background: #fff;
    position: relative;
    z-index: 50;
}

.erp-ph-gantt-v2__header-fixed {
    flex: 0 0 var(--erp-ph-v2-fixed-width);
    width: var(--erp-ph-v2-fixed-width);
    min-width: var(--erp-ph-v2-fixed-width);
    max-width: var(--erp-ph-v2-fixed-width);
    overflow: hidden;
    background: #fff;
    position: relative;
    z-index: 20;
}

.erp-ph-gantt-v2__fixed-table {
    width: var(--erp-ph-v2-fixed-width);
    min-width: var(--erp-ph-v2-fixed-width);
    max-width: var(--erp-ph-v2-fixed-width);
    background: #fff;
}

.erp-ph-gantt-v2__header-timeline {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    background: #fff;
    position: relative;
}

.erp-ph-gantt-v2__timeline-table {
    width: max-content;
    min-width: 1px;
    background: #fff;
}

/* FIXED COLUMNS */
.erp-ph-gantt-v2__col-stt {
    width: var(--erp-ph-v2-stt);
    text-align: center;
    white-space: nowrap;
}

.erp-ph-gantt-v2__col-noidung {
    width: var(--erp-ph-v2-noidung);
    text-align: center;
    white-space: nowrap;
}

.erp-ph-gantt-v2__col-donvi {
    width: var(--erp-ph-v2-donvi);
    text-align: center;
    white-space: nowrap;
}

.erp-ph-gantt-v2__col-ngay {
    width: var(--erp-ph-v2-ngay);
    text-align: center;
    white-space: nowrap;
}

.erp-ph-gantt-v2__col-ngay-1 {
    width: var(--erp-ph-v2-ngay-1);
    text-align: center;
    white-space: nowrap;
}

.erp-ph-gantt-v2__row-month th {
    height: 32px;
    padding: 4px 6px;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
    background: var(--erp-table-bg-th);
}

.erp-ph-gantt-v2__row-weekday th,
.erp-ph-gantt-v2__row-day th {
    height: 25px;
    padding: 0;
    font-size: 11px;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
    background: var(--erp-table-bg-th);
}

.erp-ph-gantt-v2__weekday,
.erp-ph-gantt-v2__day {
    width: var(--erp-ph-v2-day-width);
    min-width: var(--erp-ph-v2-day-width);
    max-width: var(--erp-ph-v2-day-width);
    padding: 0 !important;
    text-align: center;
    white-space: nowrap;
    background: #fff;
}

/* BODY */
.erp-ph-gantt-v2__body-scroll {
    position: relative;
    width: 100%;
    max-width: 100%;
    height: calc(100vh - 265px) !important;
    max-height: calc(100vh - 265px) !important;
    overflow-x: hidden;
    overflow-y: auto;
    background: #fff;
    scrollbar-width: thin;
}

.erp-ph-gantt-v2__body-scroll::-webkit-scrollbar {
    width: 8px;
    height: 0;
}

.erp-ph-gantt-v2__body-table {
    width: max-content;
    min-width: calc(var(--erp-ph-v2-fixed-width) + 1px);
    background: #fff;
}

.erp-ph-gantt-v2__body-table tbody tr {
    height: var(--erp-ph-v2-row-height);
}

/* BODY STICKY COLUMNS */
.erp-ph-gantt-v2__body-table tbody td:nth-child(1) {
    position: sticky;
    left: 0;
    z-index: 20;
    width: var(--erp-ph-v2-stt);
    background: #fff;
}

.erp-ph-gantt-v2__body-table tbody td:nth-child(2) {
    position: sticky;
    left: var(--erp-ph-v2-stt);
    z-index: 20;
    width: var(--erp-ph-v2-noidung);
    background: #fff;
}

.erp-ph-gantt-v2__body-table tbody td:nth-child(3) {
    position: sticky;
    left: calc(var(--erp-ph-v2-stt) + var(--erp-ph-v2-noidung));
    z-index: 20;
    width: var(--erp-ph-v2-donvi);
    background: #fff;
}

.erp-ph-gantt-v2__body-table tbody td:nth-child(4) {
    position: sticky;
    left: calc(var(--erp-ph-v2-stt) + var(--erp-ph-v2-noidung) + var(--erp-ph-v2-donvi));
    z-index: 20;
    width: var(--erp-ph-v2-ngay-1);
    background: #fff;
}

.erp-ph-gantt-v2__body-table tbody td:nth-child(5) {
    position: sticky;
    left: calc(var(--erp-ph-v2-stt) + var(--erp-ph-v2-noidung) + var(--erp-ph-v2-donvi) + var(--erp-ph-v2-ngay-1));
    z-index: 20;
    width: var(--erp-ph-v2-ngay);
    background: #fff;
    /* box-shadow: 5px 0 8px -6px rgba(0, 0, 0, .5); */
}

/* TIMELINE CELLS & BAR */
.erp-ph-gantt-v2__timeline-cell {
    position: relative;
    width: var(--erp-ph-v2-day-width);
    min-width: var(--erp-ph-v2-day-width);
    max-width: var(--erp-ph-v2-day-width);
    height: var(--erp-ph-v2-row-height);
    padding: 0 !important;
    text-align: center;
    border-left: 1px solid rgba(0, 0, 0, .055);
    background: transparent;
    vertical-align: middle;
    overflow: visible !important;
    z-index: 1;
}

.erp-ph-gantt-v2__weekend {
    background: rgba(250, 220, 200, 1) !important;
}

.erp-ph-gantt-v2__timeline-anchor {
    z-index: 10 !important;
}




/* ============================================================
   MILESTONE BADGES (R1, R2, R3) CẮM TRỰC TIẾP TRÊN GANTT BAR
============================================================ */

/* Khung Gantt Bar cần overflow visible để nút R1 nổi bật lên hẳn */
.erp-ph-gantt-v2__gantt-bar {
    position: absolute;
    left: var(--gantt-left);
    top: 50%;
    width: var(--gantt-width);
    height: 10px !important;
    transform: translateY(-50%);
    border-radius: 5px !important;
    background: rgba(18, 118, 8, 0.36) !important;
    overflow: visible !important;
    /* QUAN TRỌNG: Cho phép Badge R1 nổi ra ngoài */
    z-index: 15;
    pointer-events: none;
}

.erp-ph-gantt-v2__gantt-bar-progress {
    position: absolute;
    top: 0;
    left: 0;
    width: var(--gantt-progress);
    height: 100%;
    background: var(--erp-color-3);
    border-radius: inherit;
    transition: width 0.25s ease;
}

/* Badge R1, R2, R3 đặt theo vị trí % hoặc px từ đầu thanh Bar */
.erp-ph-gantt-v2__revision-badge {
    position: absolute;
    top: 50%;
    /* Căn lề trái chính xác theo biến --badge-left được JS tính toán */
    left: var(--badge-left);
    transform: translate(-50%, -50%) !important;

    width: 30px;
    height: 30px;
    line-height: 28px;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 800;
    text-align: center;
    color: #ffffff;

    /* Nổi đè lên trên cả thanh Progress xanh/xám */
    z-index: 30 !important;

    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    user-select: none;
    border: 1.5px solid #ffffff;
    pointer-events: auto;
}

/* Màu sắc các mốc */
.erp-ph-gantt-v2__revision-badge--r1 {
    background-color: #8b5cf6 !important;
}

.erp-ph-gantt-v2__revision-badge--r2 {
    background-color: #f59e0b !important;
}

.erp-ph-gantt-v2__revision-badge--r3 {
    background-color: #ef4444 !important;
}



/* CUSTOM SCROLLBAR */
.erp-ph-gantt-v2__scrollbar-row {
    display: flex;
    width: 100%;
    height: 18px;
    overflow: hidden;
    background: #fff;
}

.erp-ph-gantt-v2__scrollbar-spacer {
    flex: 0 0 var(--erp-ph-v2-fixed-width);
    width: var(--erp-ph-v2-fixed-width);
    height: 18px;
    background: #fff;
}

.erp-ph-gantt-v2__scrollbar {
    flex: 1 1 auto;
    min-width: 0;
    height: 12px;
    /* Đổi thành 12px cho vừa vặn thanh thumb 8px */
    overflow-x: auto;
    overflow-y: hidden;
    cursor: grab;

    /* Hỗ trợ cho Firefox */
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 175, 25, 0.8) #f1f1f1;
}

.erp-ph-gantt-v2__scrollbar:active {
    cursor: grabbing;
}

/* Hỗ trợ cho Webkit (Chrome, Safari, Edge, Brave...) */
.erp-ph-gantt-v2__scrollbar::-webkit-scrollbar {
    height: 8px !important;
    /* Dùng height cho thanh cuộn ngang (thay vì width) */
}

.erp-ph-gantt-v2__scrollbar::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.erp-ph-gantt-v2__scrollbar::-webkit-scrollbar-thumb {
    border-radius: 4px;
    background: rgba(255, 175, 25, 0.8);
    transition: background 0.2s ease;
}

.erp-ph-gantt-v2__scrollbar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 150, 0, 1);
    /* Đậm hơn một chút khi hover */
}

.erp-ph-gantt-v2__scrollbar:active {
    cursor: grabbing;
}

.erp-ph-gantt-v2__scrollbar-inner {
    display: block;
    height: 1px;
    width: 1px;
}

@media (max-width: 768px) {
    .erp-ph-gantt-v2 {
        --erp-ph-v2-stt: 50px;
        --erp-ph-v2-noidung: 220px;
        --erp-ph-v2-donvi: 140px;
        --erp-ph-v2-ngay: 90px;
        --erp-ph-v2-day-width: 36px;
    }

    .erp-ph-gantt-v2__body-scroll {
        height: 60vh;
    }
}

/* ============================================================
   FIXED HEADER ROW - FULL HEIGHT (3 DÒNG)
============================================================ */

/* Tính tổng chiều cao của 3 dòng timeline: 32px + 25px + 25px = 82px */
.erp-ph-gantt-v2__row-fixed-full {
    height: 82px !important;
}

.erp-ph-gantt-v2__row-fixed-full th {
    height: 82px !important;
    vertical-align: middle !important;
    /* Căn giữa nội dung theo chiều dọc */
    text-align: center;
    font-weight: 600;
    background: var(--erp-table-bg-th);
   
    box-sizing: border-box;
}

/* Đảm bảo bảng Fixed chiếm full chiều cao Header */
.erp-ph-gantt-v2__fixed-table {
    height: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

/* ============================================================
   2. BẢNG MÀU BACKGROUND LÂN LƯỢT CHO CÁC THÁNG (MONTH PALETTE)
============================================================ */

/* Tháng Mẫu 0 (Tông xanh dương nhạt) */
.month-bg-4 {
    background-color: rgba(239, 246, 255, 0.6) !important;
}

/* Tháng Mẫu 1 (Tông xanh lá nhạt) */
.month-bg-0 {
    background-color: rgba(240, 253, 244, 0.6) !important;
}

/* Tháng Mẫu 2 (Tông vàng nhạt) */
.month-bg-1 {
    background-color: rgba(254, 252, 232, 0.6) !important;
}

/* Tháng Mẫu 3 (Tông tím nhạt) */
.month-bg-5 {
    background-color: rgba(235, 245, 255, 0.6) !important;
}

/* Tháng Mẫu 4 (Tông cam nhạt) */
.month-bg-3 {
    background-color: rgba(255, 247, 237, 0.6) !important;
}

/* Tháng Mẫu 5 (Tông hồng nhạt) */
.month-bg-2 {
    background-color: rgba(253, 242, 248, 0.6) !important;
}


/* Giữ nguyên màu Weekend nhưng làm đậm hơn một chút để phân biệt */
.erp-ph-gantt-v2__timeline-cell.erp-ph-gantt-v2__weekend {
    filter: brightness(0.8);
}


/* Badge R1, R2, R3 đặt theo vị trí % hoặc px từ đầu thanh Bar */
.erp-ph-gantt-v2__revision-btn {
    /* position: absolute; */
    /* top: 50%;  */
    /* Căn lề trái chính xác theo biến --badge-left được JS tính toán */
    /* left: var(--badge-left); */
    /* transform: translate(-50%, -50%) !important; */

    width: 30px;
    height: 30px;
    line-height: 28px;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 800;
    text-align: center;
    color: #ffffff;
    background-color: var(--erp-color-3);

    /* Nổi đè lên trên cả thanh Progress xanh/xám */
    z-index: 30 !important;

    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    user-select: none;
    border: 1.5px solid #ffffff;
    pointer-events: auto;
}

.erp-ph-gantt-v2__revision-btn-sub {
    /* position: absolute; */
    /* top: 50%;  */
    /* Căn lề trái chính xác theo biến --badge-left được JS tính toán */
    /* left: var(--badge-left); */
    /* transform: translate(-50%, -50%) !important; */

    width: 30px;
    height: 30px;
    line-height: 28px;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 800;
    text-align: center;
    color: #ffffff;
    background-color: var(--erp-color-5);

    /* Nổi đè lên trên cả thanh Progress xanh/xám */
    z-index: 30 !important;

    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    user-select: none;
    border: 1.5px solid #ffffff;
    pointer-events: auto;
}

/* Màu sắc các mốc */
.erp-ph-gantt-v2__revision-btn--1 {
    background-color: #8b5cf6 !important;
}

.erp-ph-gantt-v2__revision-btn--2 {
    background-color: #f59e0b !important;
}

.erp-ph-gantt-v2__revision-btn--3 {
    background-color: #ef4444 !important;
}

/* 1. CSS Ngày Chủ Nhật và Ngày Hiện Tại trên Header */
.erp-ph-gantt-v2__row-weekday th.is-sunday,
.erp-ph-gantt-v2__row-day th.is-sunday {
    color: #dc3545 !important;
    /* Chữ màu đỏ */
    font-weight: bold;
}

.erp-ph-gantt-v2__row-weekday th.is-today,
.erp-ph-gantt-v2__row-day th.is-today {
    color: #0d6efd !important;
    /* Chữ màu xanh */
    font-weight: bold;
}

/* 4. Mầu Progress Công việc Con khác Công việc Cha */
.erp-item-row .erp-ph-gantt-v2__gantt-bar-progress {
    background-color: var(--erp-color-5)!important;
    /* Màu xanh lá cho con (Cha giữ màu mặc định) */
}

.erp-ph-gantt-v2__timeline-anchor {
    position: relative;
    overflow: visible !important;
}