/* ============================================================
   ERP PHỐI HỢP - GANTT V2 FINAL
============================================================ */

.erp-ph-gantt-v2 {
    --erp-ph-v2-stt: 55px;
    --erp-ph-v2-noidung: 450px;
    --erp-ph-v2-donvi: 150px;
    --erp-ph-v2-ngay-1: 60px;
    --erp-ph-v2-ngay: 100px;
    --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: var(--erp-color-10) !important;
}

.erp-ph-gantt-v2__revision-badge--r2 {
    background-color: #f59e0b !important;
}

.erp-ph-gantt-v2__revision-badge--r3 {
    background-color: #ef4444 !important;
}

.erp-ph-gantt-v2__revision-badge--ht {
    background-color: rgb(139, 92, 246) !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;
}


/* =========================================================
   TIMELINE
========================================================= */

.erp-cv-timeline {
    position: relative;
    margin-top: 16px;
    padding-left: 4px;
}


/* =========================================================
   ITEM
========================================================= */

.erp-cv-item {
    position: relative;
    padding-bottom: 8px;
}


/* =========================================================
   NODE
========================================================= */

.erp-cv-node {
    position: relative;
    display: flex;
    align-items: center;
    min-height: 54px;
    cursor: pointer;
    user-select: none;
}


/* =========================================================
   ĐƯỜNG NỐI DỌC
   - Dot cao 30px
   - Node cao 54px
   - Tâm node = 27px
   - Đường nối bắt đầu từ giữa dot
========================================================= */

.erp-cv-item:not(:last-child)::before {
    content: "";
    position: absolute;
    left: 15px;
    top: 42px;
    bottom: -12px;
    width: 1px;
    background: var(--erp-color-5);
    z-index: 0;
}


/* =========================================================
   DOT
========================================================= */

.erp-cv-dot {
    position: relative;
    flex: 0 0 30px;
    width: 30px;
    height: 30px;
    border: 1px solid var(--erp-color-5);
    border-radius: 50%;
    transition: all .2s ease;
    background: var(--erp-color-5, #d97706);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 500;
    z-index: 5;
}


/* =========================================================
   KHU VỰC SAU DOT
   TITLE 2/3 + R1/PROCESS 1/3 + ARROW
========================================================= */

.erp-cv-title {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 36px;
    padding: 6px 10px;
    border-radius: 6px;
    transition: background .2s ease;
}


/* TITLE */

.erp-cv-title b,
.erp-cv-title strong {
    display: block;
    min-width: 0;
    color: var(--erp-color-5, #495057);
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}


/* HOVER TITLE */

.erp-cv-node:hover .erp-cv-title {
    background: #f5f7fa;
}


/* =========================================================
   PROCESS BAR CÔNG VIỆC CON
========================================================= */

.erp-cv-progress {
    flex: 0 0 33.333%;
    max-width: 33.333%;
    min-width: 220px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}

/* Milestone R1/R2/R3 + Ngày */
.erp-cv-progress-milestone {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.erp-cv-progress-date {
    font-size: 12px;
    color: #6c757d;
    white-space: nowrap;
}

/* Process Container */
.erp-cv-process {
    flex: 1;
    min-width: 80px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Thanh Nền */
.erp-cv-process-bar {
    position: relative;
    flex: 1;
    height: 8px;
    background: #e9ecef;
    border-radius: 20px;
    overflow: hidden;
}

/* Thanh Tiến Độ */
.erp-cv-process-progress {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 0%;
    background: var(--erp-color-3, #d97706);
    border-radius: 20px;
    transition: width 0.4s ease;
}

/* Percent Text */
.erp-cv-process-percent {
    flex: 0 0 auto;
    min-width: 34px;
    font-size: 11px;
    font-weight: 600;
    text-align: right;
    color: var(--erp-color-3, #d97706);
}


/* MOBILE */
@media (max-width: 768px) {

    .erp-cv-progress {
        flex: 0 0 auto;
        max-width: none;
        min-width: 160px;
    }

    .erp-cv-progress-date {
        display: none;
    }

    .erp-cv-process-percent {
        font-size: 10px;
    }

}


/* =========================================================
   MŨI TÊN
   LUÔN NẰM CUỐI HÀNG
========================================================= */

.erp-cv-arrow {
    flex: 0 0 28px;

    display: flex;
    align-items: center;
    justify-content: center;

    width: 28px;
    height: 28px;

    margin-left: 8px;

    color: #8c96a3;

    transition: transform .2s ease;
}


/* =========================================================
   DETAIL - MẶC ĐỊNH ĐÓNG
========================================================= */

.erp-cv-detail {
    display: grid;
    grid-template-rows: 0fr;

    margin-left: 40px;

    opacity: 0;

    transition:
        grid-template-rows .25s ease,
        opacity .2s ease;
}


.erp-cv-detail-inner {
    min-height: 0;
    overflow: hidden;
}


/* =========================================================
   OPEN
========================================================= */

.erp-cv-item.is-open .erp-cv-detail {
    grid-template-rows: 1fr;
    opacity: 1;
}


.erp-cv-item.is-open .erp-cv-arrow {
    transform: rotate(180deg);
}


/* =========================================================
   DOT OPEN
========================================================= */

.erp-cv-item.is-open .erp-cv-dot {
    border-color: var(--erp-color-3, #0d6efd);
    background: var(--erp-color-3, #0d6efd);
}


.erp-cv-item.is-open .erp-cv-dot::after {
    background: #fff;
}


/* =========================================================
   DETAIL CONTENT
========================================================= */

.erp-cv-info {
    margin-top: 4px;
    margin-bottom: 8px;

    padding: 10px 14px;

    /* font-size: 14px;
    line-height: 1.6; */
}


.erp-cv-info strong {
    color: #495057;
}


/* =========================================================
   CONTENT TINY MCE
========================================================= */

.erp-cv-content {
    max-width: 100%;
    overflow-x: auto;
    overflow-wrap: break-word;
}


.erp-cv-content p {
    padding-bottom: 6px;
    margin-bottom: 0;
}


.erp-cv-content img {
    max-width: 100%;
    height: auto;
}

.erp-cv-content table {
    max-width: 100%;
    font-size: 14px;
    border-collapse: collapse;
    border: 1px solid rgba(0, 0, 0, 0.3);
}

.erp-cv-content table th,
.erp-cv-content table td {
    border: 1px solid rgba(0, 0, 0, 0.3);
    padding: 3px 6px;
}


/* =========================================================
   MOBILE
========================================================= */

@media (max-width: 768px) {

    .erp-cv-title {
        flex: 1;

        min-width: 0;

        margin-left: 8px;
        padding: 6px 8px;
    }


    .erp-cv-title b,
    .erp-cv-title strong {
        font-size: 14px;
    }


    /* R1 + PROCESS vẫn giữ bên phải,
       nhưng nhỏ gọn hơn */

    .erp-cv-progress {
        flex: 0 0 35%;
        gap: 5px;
    }


    .erp-cv-progress .erp-btn-tron {
        transform: scale(.9);
    }


    .erp-cv-process-text {
        min-width: 28px;
        font-size: 11px;
    }


    .erp-cv-process-bar {
        height: 5px;
    }


    .erp-cv-arrow {
        flex: 0 0 24px;

        width: 24px;
        height: 24px;

        margin-left: 4px;
    }


    .erp-cv-detail {
        margin-left: 38px;
    }


    .erp-cv-info {
        padding: 8px 10px;
        font-size: 13px;
    }
}