/*
 * DEEPTASK Reusable Popup Shell Module.
 * Unified 3-zone dialog layout shared across Edit Order, Payment Ledger, Activity Timeline,
 * and any future modal/dialog:
 *   1. .dt-popup__head  - Centered, uppercase title (15px PC / 13px Tablet / 12px Mobile), no top close button by default.
 *   2. .dt-popup__body  - Smooth independent vertical scroll area.
 *   3. .dt-popup__foot  - Pinned bottom action bar aligned right (e.g. Đóng | Lưu thay đổi / Ghi nhận thanh toán).
 * 100% var(--deeptask-*) color tokens; zero hard-coded colors.
 */

.deeptask-scope .dt-popup:not(dialog),
.deeptask-scope dialog.dt-popup[open] {
    display: flex;
    flex-direction: column;
    overflow: clip;
}

html:has(dialog.dt-popup[open]) {
    overflow: hidden;
}

/* Synchronize Admin modal popup widths & heights with Staff Workspace [data-job-dialog] sizes */
.deeptask-scope #dt-payments-modal .dt-modal__dialog.dt-popup {
    width: min(920px, calc(100vw - 2 * var(--deeptask-viewport-inset)));
    max-height: calc(100dvh - 2 * var(--deeptask-viewport-inset));
    border-radius: var(--deeptask-radius-lg);
}

.deeptask-scope #dt-timeline-modal .dt-modal__dialog.dt-popup {
    width: min(620px, calc(100vw - 2 * var(--deeptask-viewport-inset)));
    border-radius: var(--deeptask-radius-lg);
}

.deeptask-scope #dt-cal-event-modal .dt-modal__dialog.dt-popup {
    width: min(720px, calc(100vw - 2 * var(--deeptask-viewport-inset)));
    border-radius: var(--deeptask-radius-lg);
}

.deeptask-scope #dt-revisions-modal .dt-modal__dialog.dt-popup {
    width: min(540px, calc(100vw - 2 * var(--deeptask-viewport-inset)));
    height: min(640px, calc(100dvh - 2 * var(--deeptask-viewport-inset)));
    max-height: min(640px, calc(100dvh - 2 * var(--deeptask-viewport-inset)));
    border-radius: var(--deeptask-radius-lg);
}

.deeptask-scope .dt-modal__dialog--wide {
    width: min(1040px, calc(100vw - 2 * var(--deeptask-viewport-inset)));
    max-height: calc(100dvh - 2 * var(--deeptask-viewport-inset));
}

.deeptask-scope .dt-popup__body > .dt-notice:not(:last-child),
.deeptask-scope .dt-popup__body > form.dt-card:not(:last-child) {
    margin-bottom: 14px;
}

.deeptask-scope .dt-popup__head {
    position: relative;
    display: flex;
    flex: none;
    align-items: center;
    justify-content: center;
    gap: 12px;
    min-height: 52px;
    padding: 12px 18px;
    border-bottom: 1px solid var(--deeptask-color-border);
    box-sizing: border-box;
}

.deeptask-scope .dt-popup__head--with-close {
    padding-inline: 84px;
}

.deeptask-scope .dt-popup__title {
    margin: 0;
    font-family: var(--deeptask-font-emphasis);
    font-size: var(--deeptask-font-size);
    font-weight: 400;
    line-height: 1.3;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    text-align: center;
    color: var(--deeptask-color-text);
}

.deeptask-scope .dt-popup__head-close {
    position: absolute;
    right: 16px;
}

.deeptask-scope .dt-popup__body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    padding: 16px 18px;
    box-sizing: border-box;
    -webkit-mask-image:
        linear-gradient(to bottom, var(--deeptask-color-transparent) 0, var(--deeptask-color-black) var(--dt-popup-fade-top, 0px), var(--deeptask-color-black) calc(100% - var(--dt-popup-fade-bottom, 0px)), var(--deeptask-color-transparent) 100%),
        linear-gradient(to left, var(--deeptask-color-black) 0, var(--deeptask-color-black) var(--dt-popup-fade-gutter, 0px), var(--deeptask-color-transparent) var(--dt-popup-fade-gutter, 0px));
    -webkit-mask-composite: source-over;
    mask-image:
        linear-gradient(to bottom, var(--deeptask-color-transparent) 0, var(--deeptask-color-black) var(--dt-popup-fade-top, 0px), var(--deeptask-color-black) calc(100% - var(--dt-popup-fade-bottom, 0px)), var(--deeptask-color-transparent) 100%),
        linear-gradient(to left, var(--deeptask-color-black) 0, var(--deeptask-color-black) var(--dt-popup-fade-gutter, 0px), var(--deeptask-color-transparent) var(--dt-popup-fade-gutter, 0px));
    mask-composite: add;
}

.deeptask-scope .dt-popup__foot {
    display: flex;
    flex: none;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 12px 18px;
    border-top: 1px solid var(--deeptask-color-border);
    box-sizing: border-box;
}

.deeptask-scope .dt-popup__foot[hidden] {
    display: none !important;
}

/* Payment history table: fixed 5-row height, hidden scrollbars (X+Y scrollable via wheel/drag/touch), smooth 4-edge fade mask */
.deeptask-scope .dt-payments-table-wrap {
    height: 360px;
    min-height: 360px;
    max-height: 360px;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-width: none;
    -ms-overflow-style: none;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--deeptask-color-border);
    border-radius: var(--deeptask-radius);
    background: var(--deeptask-card-bg);
    -webkit-mask-image:
        linear-gradient(to bottom, var(--deeptask-color-black) 0, var(--deeptask-color-black) calc(100% - var(--dt-popup-fade-bottom, 0px)), var(--deeptask-color-transparent) 100%),
        linear-gradient(to right, var(--deeptask-color-transparent) 0, var(--deeptask-color-black) var(--dt-popup-fade-left, 0px), var(--deeptask-color-black) calc(100% - var(--dt-popup-fade-right, 0px)), var(--deeptask-color-transparent) 100%);
    -webkit-mask-composite: source-in;
    mask-image:
        linear-gradient(to bottom, var(--deeptask-color-black) 0, var(--deeptask-color-black) calc(100% - var(--dt-popup-fade-bottom, 0px)), var(--deeptask-color-transparent) 100%),
        linear-gradient(to right, var(--deeptask-color-transparent) 0, var(--deeptask-color-black) var(--dt-popup-fade-left, 0px), var(--deeptask-color-black) calc(100% - var(--dt-popup-fade-right, 0px)), var(--deeptask-color-transparent) 100%);
    mask-composite: intersect;
}

.deeptask-scope .dt-payments-table-wrap::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

.deeptask-scope .dt-payments-table-wrap.is-dragging {
    cursor: grabbing;
    user-select: none;
}

.deeptask-scope .dt-payments-table {
    width: 100%;
    min-width: 960px;
    border-collapse: separate;
    border-spacing: 0;
}

.deeptask-scope .dt-payments-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--deeptask-color-inset);
    white-space: nowrap;
    border-bottom: 1px solid var(--deeptask-color-border);
}

.deeptask-scope .dt-payments-table tbody td {
    white-space: nowrap;
}

.deeptask-scope .dt-payments-table :is(th, td):nth-child(5) {
    min-width: 300px;
    max-width: 420px;
}

.deeptask-scope .dt-payments-table tbody td:nth-child(5) {
    white-space: normal;
}

.deeptask-scope .dt-payments-table tbody tr:last-child td {
    border-bottom: 0;
}

/* 5-row loading skeleton placeholders (matches .dt-job-placeholder tokens) */
.deeptask-scope .dt-payment-placeholder td {
    vertical-align: middle;
}

.deeptask-scope .dt-payment-placeholder__bar,
.deeptask-scope .dt-payment-placeholder__btn {
    display: block;
    border-radius: var(--deeptask-radius-sm);
}

.deeptask-scope .dt-payment-placeholder__bar {
    max-width: 100%;
    height: 0.8em;
    margin-block: calc((1.45em - 0.8em) / 2);
    background: var(--deeptask-color-border);
    animation: dt-revision-skeleton-pulse 1.5s ease-in-out infinite;
}

.deeptask-scope .dt-payment-placeholder__bar--code { width: min(12ch, 100%); }
.deeptask-scope .dt-payment-placeholder__bar--date { width: min(14ch, 100%); }
.deeptask-scope .dt-payment-placeholder__bar--kind { width: min(13ch, 100%); }
.deeptask-scope .dt-payment-placeholder__bar--amount { width: min(9ch, 100%); }
.deeptask-scope .dt-payment-placeholder__bar--note { width: min(24ch, 100%); }

.deeptask-scope .dt-payment-placeholder__btn {
    width: min(10ch, 100%);
    height: var(--deeptask-control-height);
    border-radius: var(--deeptask-radius);
    background: var(--deeptask-color-inset);
    animation: dt-revision-skeleton-pulse 1.5s ease-in-out infinite;
}

/* Activity timeline & calendar event popups: fixed height + skeleton placeholders */
.deeptask-scope #dt-timeline-modal.dt-popup,
.deeptask-scope #dt-timeline-modal .dt-modal__dialog.dt-popup,
.deeptask-scope #dt-cal-event-modal .dt-modal__dialog.dt-popup {
    height: min(560px, calc(100dvh - 2 * var(--deeptask-viewport-inset)));
    max-height: min(560px, calc(100dvh - 2 * var(--deeptask-viewport-inset)));
}

.deeptask-scope .dt-timeline-placeholder {
    display: grid;
    gap: 8px;
    padding: 12px 14px;
    border: 1px solid var(--deeptask-color-border);
    border-radius: var(--deeptask-radius);
    background: var(--deeptask-color-inset);
}

.deeptask-scope .dt-timeline-placeholder + .dt-timeline-placeholder,
.deeptask-scope .dt-timeline__item + .dt-timeline-placeholder {
    margin-top: 10px;
}

.deeptask-scope .dt-timeline-placeholder__time,
.deeptask-scope .dt-timeline-placeholder__summary {
    display: block;
    border-radius: var(--deeptask-radius-sm);
    background: var(--deeptask-color-border);
}

.deeptask-scope .dt-timeline-placeholder__time {
    width: min(17ch, 55%);
    height: 0.75em;
    margin-block: calc((1.45em - 0.75em) / 2);
}

.deeptask-scope .dt-timeline-placeholder__summary {
    width: 82%;
    height: 0.85em;
    margin-block: calc((1.45em - 0.85em) / 2);
}

.deeptask-scope .dt-timeline-placeholder:nth-child(even) .dt-timeline-placeholder__summary {
    width: 64%;
}

/* Finalized selection list modal (#dt-revisions-modal) */
.deeptask-scope .dt-revision-list {
    display: grid;
    gap: 14px;
}

.deeptask-scope .dt-revision-card {
    display: grid;
    gap: 12px;
    padding: 14px;
    border: 1px solid var(--deeptask-color-border);
    border-radius: var(--deeptask-radius);
    background: var(--deeptask-color-panel);
}

.deeptask-scope .dt-revision-card__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.deeptask-scope .dt-revision-card__title-group {
    display: grid;
    gap: 2px;
    min-width: 0;
}

.deeptask-scope .dt-revision-card__version {
    font-family: var(--deeptask-font-emphasis);
    font-size: var(--deeptask-font-size);
    font-weight: 400;
    color: var(--deeptask-color-text);
    line-height: 1.3;
}

.deeptask-scope .dt-revision-card__time {
    font-size: var(--deeptask-font-size);
    color: var(--deeptask-color-text-muted);
    line-height: 1.35;
}

.deeptask-scope .dt-revision-metrics {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.deeptask-scope .dt-revision-metrics--three {
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
}

.deeptask-scope .dt-revision-metric {
    display: grid;
    gap: 2px;
    padding: 9px 11px;
    border: 1px solid var(--deeptask-color-border);
    border-radius: var(--deeptask-radius-sm);
    background: var(--deeptask-color-inset);
    min-width: 0;
}

.deeptask-scope .dt-revision-metric__label {
    font-size: var(--deeptask-font-size);
    color: var(--deeptask-color-text-muted);
    line-height: 1.3;
}

.deeptask-scope .dt-revision-metric__value {
    font-family: var(--deeptask-font-emphasis);
    font-size: var(--deeptask-font-size);
    font-weight: 400;
    color: var(--deeptask-color-text);
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.deeptask-scope .dt-revision-metric__value--accent {
    color: var(--deeptask-color-primary);
}

.deeptask-scope .dt-revision-block {
    display: grid;
    gap: 4px;
    padding: 10px 12px;
    border: 1px solid var(--deeptask-color-border);
    border-radius: var(--deeptask-radius-sm);
    background: var(--deeptask-color-inset);
}

.deeptask-scope .dt-revision-block__label {
    font-size: var(--deeptask-font-size);
    font-family: var(--deeptask-font-emphasis);
    font-weight: 400;
    color: var(--deeptask-color-text-muted);
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.deeptask-scope .dt-revision-block__text {
    margin: 0;
    font-size: var(--deeptask-font-size);
    line-height: 1.45;
    color: var(--deeptask-color-text);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.deeptask-scope .dt-revision-diff {
    display: grid;
    gap: 4px;
    padding: 10px 12px;
    border: 1px solid var(--deeptask-color-border);
    border-radius: var(--deeptask-radius-sm);
    background: var(--deeptask-color-inset);
    font-size: var(--deeptask-font-size);
    line-height: 1.45;
    color: var(--deeptask-color-text);
}

.deeptask-scope .dt-revision-diff__title {
    font-family: var(--deeptask-font-emphasis);
    color: var(--deeptask-color-text);
}

.deeptask-scope .dt-revision-diff__row {
    color: var(--deeptask-color-text-muted);
    overflow-wrap: anywhere;
}

.deeptask-scope .dt-revision-diff__row strong {
    color: var(--deeptask-color-text);
    font-weight: 400;
    font-family: var(--deeptask-font-emphasis);
}

.deeptask-scope .dt-revision-card__actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
    padding-top: 8px;
    border-top: 1px solid var(--deeptask-color-border);
}

.deeptask-scope .dt-revision-error {
    display: grid;
    justify-items: center;
    gap: 10px;
    padding: 28px 16px;
    text-align: center;
    color: var(--deeptask-color-text-muted);
    font-size: var(--deeptask-font-size);
}

/* Structural skeleton placeholders for #dt-revisions-modal */
.deeptask-scope .dt-revision-skel {
    display: block;
    max-width: 100%;
    border-radius: var(--deeptask-radius-sm);
    background: var(--deeptask-color-border);
    animation: dt-revision-skeleton-pulse 1.5s ease-in-out infinite;
}

.deeptask-scope .dt-revision-skel--version {
    width: min(13ch, 100%);
    height: 0.9em;
    margin-block: calc((1.3em - 0.9em) / 2);
}

.deeptask-scope .dt-revision-skel--time {
    width: min(17ch, 100%);
    height: 0.8em;
    margin-block: calc((1.35em - 0.8em) / 2);
}

.deeptask-scope .dt-revision-skel--badge {
    width: min(14ch, 100%);
    height: var(--deeptask-badge-height);
    border-radius: var(--deeptask-radius-pill);
}

.deeptask-scope .dt-revision-skel--label {
    width: min(8ch, 100%);
    height: 0.78em;
    margin-block: calc((1.3em - 0.78em) / 2);
}

.deeptask-scope .dt-revision-skel--value {
    width: min(6ch, 100%);
    height: 0.9em;
    margin-block: calc((1.3em - 0.9em) / 2);
}

.deeptask-scope .dt-revision-skel--diff-title {
    width: min(18ch, 100%);
    height: 0.85em;
    margin-block: calc((1.45em - 0.85em) / 2);
}

.deeptask-scope .dt-revision-skel--diff-line {
    width: 78%;
    height: 0.82em;
    margin-block: calc((1.45em - 0.82em) / 2);
}

.deeptask-scope .dt-revision-skel--btn {
    width: min(16ch, 100%);
    height: var(--deeptask-control-height);
    border-radius: var(--deeptask-radius);
}

@keyframes dt-revision-skeleton-pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.45;
    }
}

@media (prefers-reduced-motion: reduce) {
    .deeptask-scope .dt-revision-skel,
    .deeptask-scope .dt-payment-placeholder__bar,
    .deeptask-scope .dt-payment-placeholder__btn {
        animation: none;
    }
}

@media (max-width: 767px) {
    .deeptask-scope dialog.dt-popup[open],
    .deeptask-scope #dt-timeline-modal.dt-popup,
    .deeptask-scope #dt-timeline-modal .dt-modal__dialog.dt-popup,
    .deeptask-scope #dt-cal-event-modal .dt-modal__dialog.dt-popup,
    .deeptask-scope #dt-revisions-modal .dt-modal__dialog.dt-popup {
        position: fixed;
        inset: var(--deeptask-viewport-inset);
        margin: auto;
        width: calc(100vw - 2 * var(--deeptask-viewport-inset));
        width: calc(100dvw - 2 * var(--deeptask-viewport-inset));
        max-width: calc(100vw - 2 * var(--deeptask-viewport-inset));
        height: auto;
        max-height: calc(100vh - 2 * var(--deeptask-viewport-inset));
        max-height: calc(100dvh - 2 * var(--deeptask-viewport-inset));
        border: 1px solid var(--deeptask-card-border);
        border-radius: var(--deeptask-radius-lg);
        box-shadow: var(--deeptask-shadow-md);
    }

    .deeptask-scope .dt-popup__head {
        min-height: 48px;
        padding: 10px 14px;
    }

    .deeptask-scope .dt-popup__head--with-close {
        padding-inline: 76px;
    }

    .deeptask-scope .dt-popup__body {
        padding: 12px;
    }

    .deeptask-scope #dt-payments-modal .dt-popup__body {
        display: flex;
        flex-direction: column;
    }

    .deeptask-scope #dt-payments-modal .dt-popup__body > :not(.dt-payments-table-wrap) {
        flex: none;
    }

    .deeptask-scope .dt-payments-table-wrap {
        flex: 1 1 auto;
        height: auto;
        min-height: 220px;
        max-height: none;
    }

    .deeptask-scope .dt-popup__foot {
        padding: 10px 12px max(10px, env(safe-area-inset-bottom));
    }
}
