.fm-preview-doc,
.fe-preview-host {
    width: 100%;
    height: 100%;
    min-height: 320px;
    overflow: auto;
    background: #fff;
}

.invoice-preview-body .fp-pdf-pages,
.inventory-source-invoice-body .fp-pdf-pages {
    width: 100%;
    min-height: 100%;
    padding: 12px;
    box-sizing: border-box;
}

.invoice-preview-body .fp-pdf-page,
.inventory-source-invoice-body .fp-pdf-page {
    display: block;
    max-width: 100%;
    height: auto !important;
    margin: 0 auto 12px;
    background: white;
    box-shadow: 0 2px 8px #0002;
}

.fe-preview-host .fp-pdf-page,
.shared-file-preview-host .fp-pdf-page {
    max-width: 100%;
    height: auto !important;
}

[data-attachment-close] {
    background: transparent !important;
    color: #fff !important;
    font-size: 24px;
    line-height: 1;
    padding: 2px 6px;
    border: 0;
}

/* Keep the window fixed; only the document surface grows when zooming. */
.invoice-preview-window:not([hidden]) { display: flex; flex-direction: column; box-sizing: border-box; }
.invoice-preview-window > .invoice-preview-header,
.invoice-preview-window > .invoice-preview-file-name { flex: 0 0 auto; min-width: 0; max-width: 100%; box-sizing: border-box; }
.invoice-preview-window > .invoice-preview-header > strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.invoice-preview-window > .invoice-preview-header > div { display: flex; align-items: center; flex-shrink: 0; gap: 6px; }
.invoice-preview-window > .invoice-preview-body { flex: 1 1 0; min-width: 0; min-height: 0; width: 100%; height: auto; }

.fp-pdf-view.fp-pdf-view,
.fm-preview-body.fm-preview-body-pdf.fp-pdf-view {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    justify-content: flex-start !important;
    min-width: 0 !important;
    min-height: 0 !important;
    max-width: 100%;
    overflow: hidden !important;
    padding: 0 !important;
    box-sizing: border-box;
}
.fp-pdf-toolbar {
    display: flex; flex: 0 0 auto; flex-wrap: wrap; align-items: center; gap: 6px;
    width: 100%; min-width: 0; padding: 6px 8px; box-sizing: border-box;
    color: #1e293b; background: #f8fafc; border-bottom: 1px solid #cbd5e1;
}
.fp-pdf-toolbar button { min-width: 34px; min-height: 34px; padding: 4px 10px; border: 1px solid #cbd5e1; border-radius: 6px; background: #fff; color: #1e293b; font: inherit; cursor: pointer; touch-action: manipulation; }
.fp-pdf-toolbar button:disabled { opacity: .45; cursor: default; }
.fp-pdf-toolbar output { min-width: 52px; text-align: right; font-variant-numeric: tabular-nums; }
.fp-pdf-view > .fp-pdf-scroll {
    display: block; flex: 1 1 0; width: 100%; max-width: 100%; min-width: 0; min-height: 0;
    overflow: auto !important; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y; background: #e2e8f0;
}
.fp-pdf-view .fp-pdf-scroll > .fp-pdf-pages { max-width: none !important; min-height: 100%; padding: 12px !important; box-sizing: border-box; }
.fp-pdf-view .fp-pdf-scroll .fp-pdf-page { display: block; max-width: none !important; max-height: none !important; margin: 0 auto 12px; }
.inventory-source-invoice-body > [data-source-invoice-pdf] { height: 100%; }
[data-linked-invoice-pdf-pages].fp-pdf-view { height: 65vh; }

@media (max-width: 991.98px) {
    .invoice-preview-window,
    .inventory-source-invoice-window {
        position: fixed !important; left: 0 !important; right: 0 !important;
        top: 56px !important; bottom: 0 !important;
        width: 100vw !important; inline-size: 100vw !important;
        max-width: 100vw !important; max-inline-size: 100vw !important;
        min-width: 0 !important; min-inline-size: 0 !important;
        height: calc(100vh - 56px) !important; height: calc(100dvh - 56px) !important;
        min-height: 0 !important; margin: 0 !important; transform: none !important;
        resize: none !important; box-sizing: border-box; border-radius: 0;
    }
    .invoice-preview-window .invoice-preview-header { cursor: default; }
    .shared-file-preview-modal .modal-dialog,
    #partner-invoice-dialog {
        width: 100vw !important; max-width: 100vw !important; min-width: 0 !important;
        margin-left: 0 !important; margin-right: 0 !important; box-sizing: border-box;
    }
    .shared-file-preview-modal .modal-content,
    .shared-file-preview-modal .modal-body,
    .shared-file-preview-host,
    .inventory-source-invoice-body { min-width: 0 !important; max-width: 100%; overflow: hidden; }
    .inventory-source-invoice-window > div { min-width: 0; overflow-wrap: anywhere; }
}

.shared-file-preview-modal .modal-dialog {
    height: min(90vh, 900px);
}

.shared-file-preview-modal .modal-content,
.shared-file-preview-modal .modal-body,
.shared-file-preview-host {
    min-height: 0;
    height: 100%;
}

.shared-file-preview-modal .modal-content {
    overflow: hidden;
}

.shared-file-preview-host {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #e9ecef;
}

.shared-file-preview-host.is-pdf-preview {
    display: block;
    overflow: auto;
    padding: 0;
    align-items: initial;
    justify-content: initial;
    scroll-padding-top: 0;
}

.shared-file-preview-host.is-pdf-preview .fp-pdf-pages {
    width: 100%;
    min-height: 100%;
    padding: 8px 0 16px;
}

.shared-file-preview-host.is-pdf-preview .fp-pdf-page:first-child {
    margin-top: 0;
}

.shared-file-preview-frame,
.shared-file-preview-media {
    width: 100%;
    height: 100%;
    border: 0;
    background: #fff;
}

.shared-file-preview-image {
    display: block;
    max-width: 100%;
    max-height: 100%;
    margin: auto;
    object-fit: contain;
}

.shared-file-preview-audio {
    width: min(90%, 720px);
}

.shared-file-preview-modal .modal-header {
    min-width: 0;
}

.shared-file-preview-heading {
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
}

.shared-file-preview-title {
    width: 100%;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
}

.shared-file-preview-title > span {
    display: inline-block;
    min-width: max-content;
    white-space: nowrap;
}

.shared-file-preview-title.is-overflowing > span {
    animation: shared-file-title-marquee 7s ease-in-out 1s infinite alternate;
}

@keyframes shared-file-title-marquee {
    from { transform: translateX(var(--shared-preview-title-offset, 0)); }
    to { transform: translateX(0); }
}

.shared-file-preview-actions {
    flex: 0 0 auto;
    position: relative;
    z-index: 2;
    background: var(--bs-modal-bg, #fff);
}

@media (max-width: 767.98px) {
    .shared-file-preview-modal .modal-dialog {
        width: 100%;
        max-width: none;
        height: 100dvh;
        min-height: 100vh;
        margin: 0;
    }

    .shared-file-preview-modal .modal-content {
        border: 0;
        border-radius: 0;
    }

    .shared-file-preview-modal .modal-header {
        position: relative;
        align-items: flex-start;
        flex-wrap: wrap;
        gap: .5rem;
        min-height: 58px;
        padding: .65rem 3.75rem .65rem .75rem;
    }

    .shared-file-preview-title {
        max-width: 100%;
        font-size: 1rem;
        line-height: 1.3;
        text-overflow: clip;
        white-space: nowrap !important;
    }

    .shared-file-preview-heading {
        width: 100%;
        min-width: 0;
    }

    .shared-file-preview-actions {
        position: static;
        width: 100%;
        margin-left: 0 !important;
        flex-wrap: wrap;
    }

    .shared-file-preview-actions .btn:not(.shared-file-preview-close),
    .shared-file-preview-actions a {
        min-height: 38px;
    }

    .shared-file-preview-close {
        position: absolute;
        z-index: 5;
        top: .45rem;
        right: .45rem;
        width: 44px;
        height: 44px;
        margin: 0 !important;
        padding: .8rem;
        border: 1px solid #cbd5e1;
        border-radius: 50%;
        background-color: #fff;
        opacity: 1;
        box-shadow: 0 1px 4px rgba(15, 23, 42, .18);
    }
}

.fm-preview-doc .fp-pdf-page,
.fe-preview-host .fp-pdf-page {
    display: block;
    margin: 0 auto 12px;
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.12);
}

.fm-preview-doc .docx-wrapper,
.fe-preview-host .docx-wrapper {
    padding: 0;
    background: transparent;
}

.fm-preview-body.fm-preview-body-word {
    display: block;
    overflow: hidden;
    padding: 0;
}

.fm-preview-body.fm-preview-body-word .fm-preview-doc {
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

.fp-word-wrap {
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow: auto;
    background: #e8e8ed;
}

.fp-word-page {
    max-width: 816px;
    margin: 0 auto;
    padding: 16px 12px 24px;
}

.fp-word-page .fp-word-html {
    background: #fff;
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.12);
    padding: 32px 40px;
    min-height: 1056px;
}

.fp-word-docx-host {
    max-width: 816px;
    margin: 0 auto;
    padding: 16px 12px 24px;
}

.fp-word-docx-host .docx-wrapper > section.docx {
    background: #fff;
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.12);
    margin: 0 auto 12px;
}

.fp-word-html table,
.fp-word-docx-host table {
    border-collapse: collapse;
    width: 100%;
}

.fp-word-html table td,
.fp-word-html table th,
.fp-word-docx-host table td,
.fp-word-docx-host table th {
    border: 1px solid #747474;
    padding: 4px;
    word-break: break-word;
}

.fp-word-html p,
.fp-word-docx-host p {
    margin: 0.5em 0;
    word-break: break-word;
}

.fp-word-html img,
.fp-word-docx-host img {
    max-width: 100%;
    height: auto;
}

.fm-preview-doc .fp-sheet-wrap,
.fe-preview-host .fp-sheet-wrap {
    overflow: auto;
    max-height: 100%;
}

.fm-preview-doc .fp-sheet-wrap table,
.fe-preview-host .fp-sheet-wrap table {
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.fm-preview-doc .fp-sheet-wrap th,
.fm-preview-doc .fp-sheet-wrap td,
.fe-preview-host .fp-sheet-wrap th,
.fe-preview-host .fp-sheet-wrap td {
    border: 1px solid #cbd5e1;
    padding: 4px 8px;
    white-space: nowrap;
}

.fm-preview-doc .fp-word-html,
.fe-preview-host .fp-word-html {
    line-height: 1.5;
}

.fm-preview-doc .fp-loading,
.fe-preview-host .fp-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    color: #64748b;
}

.fm-preview-doc .fp-error,
.fe-preview-host .fp-error {
    padding: 1rem;
    color: #b91c1c;
    text-align: center;
}

.fm-preview-doc .fp-apryse,
.fe-preview-host .fp-apryse,
.fe-apryse-host {
    width: 100%;
    height: 100%;
    min-height: 480px;
}

.fm-preview-body.fm-preview-body-luckysheet {
    display: block;
    overflow: hidden;
    padding: 0;
}

.fm-preview-body.fm-preview-body-luckysheet .fm-preview-doc {
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

.fm-preview-doc .fp-luckysheet-wrap,
.fe-preview-host .fp-luckysheet-wrap {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 360px;
    overflow: hidden;
    background: #fff;
}

.fm-preview-doc .fp-luckysheet-wrap > [id^="fp-luckysheet-output-"],
.fe-preview-host .fp-luckysheet-wrap > [id^="fp-luckysheet-output-"] {
    position: absolute;
    inset: 0;
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.fm-preview-doc .fp-luckysheet-wrap #luckysheet,
.fe-preview-host .fp-luckysheet-wrap #luckysheet {
    margin: 0;
    padding: 0;
}

/* Preview không có toolbar — tránh vùng 90px làm lệch overlay chọn ô */
.fm-preview-doc .fp-luckysheet-wrap .luckysheet-work-area,
.fe-preview-host .fp-luckysheet-wrap .luckysheet-work-area {
    display: none !important;
    height: 0 !important;
    min-height: 0 !important;
    overflow: hidden !important;
}

.fm-preview-doc .fp-luckysheet-wrap .luckysheet-grid-container,
.fe-preview-host .fp-luckysheet-wrap .luckysheet-grid-container {
    top: 0 !important;
}

.fm-preview-doc .fp-luckysheet-wrap .luckysheet-wa-calculate,
.fe-preview-host .fp-luckysheet-wrap .luckysheet-wa-calculate {
    display: none !important;
}

.fm-preview-doc .fp-luckysheet-wrap #luckysheetloadingdata,
.fm-preview-doc .fp-luckysheet-wrap #luckysheet_info_detail,
.fe-preview-host .fp-luckysheet-wrap #luckysheetloadingdata,
.fe-preview-host .fp-luckysheet-wrap #luckysheet_info_detail {
    display: none;
}

.fm-preview-doc .fp-luckysheet-wrap .luckysheet-sheets-add,
.fe-preview-host .fp-luckysheet-wrap .luckysheet-sheets-add {
    display: none !important;
}

.fm-preview-doc .fp-luckysheet-wrap #luckysheet-sheets-leftscroll,
.fm-preview-doc .fp-luckysheet-wrap #luckysheet-sheets-rightscroll,
.fe-preview-host .fp-luckysheet-wrap #luckysheet-sheets-leftscroll,
.fe-preview-host .fp-luckysheet-wrap #luckysheet-sheets-rightscroll {
    display: none !important;
}

.fm-preview-doc .fp-luckysheet-wrap .luckysheet-grid-window,
.fe-preview-host .fp-luckysheet-wrap .luckysheet-grid-window {
    background: #fff !important;
}

.fm-preview-doc .fp-luckysheet-wrap .luckysheet-grid-window-1,
.fe-preview-host .fp-luckysheet-wrap .luckysheet-grid-window-1 {
    background-color: #fff !important;
}

.fm-preview-doc .fp-luckysheet-wrap .luckysheet-grid-window table td > div,
.fe-preview-host .fp-luckysheet-wrap .luckysheet-grid-window table td > div {
    background-color: #fff;
}

.fm-preview-doc .fp-luckysheet-wrap .luckysheet-rows-h,
.fe-preview-host .fp-luckysheet-wrap .luckysheet-rows-h {
    padding-bottom: 22px;
    border-bottom: 1px solid #dedede;
}

.fm-preview-doc .fp-luckysheet-wrap .luckysheet-scrollbars.luckysheet-scrollbar-y,
.fe-preview-host .fp-luckysheet-wrap .luckysheet-scrollbars.luckysheet-scrollbar-y {
    padding-bottom: 24px;
}

.fm-preview-doc .fp-luckysheet-wrap .luckysheet-scrollbar-y,
.fe-preview-host .fp-luckysheet-wrap .luckysheet-scrollbar-y {
    right: 0 !important;
    left: auto !important;
}

/* Ẩn thanh freeze (vệt đen rgba(0,0,0,.45)) trong chế độ xem */
.fm-preview-doc .fp-luckysheet-wrap .luckysheet-freezebar-vertical-drop,
.fm-preview-doc .fp-luckysheet-wrap .luckysheet-freezebar-horizontal-drop,
.fm-preview-doc .fp-luckysheet-wrap .luckysheet-freezebar-vertical-handle,
.fm-preview-doc .fp-luckysheet-wrap .luckysheet-freezebar-horizontal-handle,
.fe-preview-host .fp-luckysheet-wrap .luckysheet-freezebar-vertical-drop,
.fe-preview-host .fp-luckysheet-wrap .luckysheet-freezebar-horizontal-drop,
.fe-preview-host .fp-luckysheet-wrap .luckysheet-freezebar-vertical-handle,
.fe-preview-host .fp-luckysheet-wrap .luckysheet-freezebar-horizontal-handle {
    display: none !important;
}

.fm-preview-doc .fp-sheetjs-preview .fp-sheet-tab-label,
.fe-preview-host .fp-sheetjs-preview .fp-sheet-tab-label {
    padding: 6px 10px;
    font-size: 0.75rem;
    font-weight: 600;
    color: #334155;
    background: #f1f5f9;
    border-bottom: 1px solid #e2e8f0;
}

.fm-preview-doc .fp-spread-host,
.fe-preview-host .fp-spread-host,
.fe-spread-host {
    width: 100%;
    height: 100%;
    min-height: 480px;
}

.fp-pdf-viewer-frame {
    width: 100%;
    height: 100%;
    min-height: 420px;
    border: 0;
    background: #525659;
}

.fp-pptx-output {
    width: 100%;
    min-height: 320px;
    overflow: auto;
    background: #1e1e1e;
    padding: 0.5rem;
}

.fm-dplayer-host {
    width: 100%;
}

.fm-dplayer-host .dplayer {
    width: 100%;
}

.fm-preview-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    cursor: zoom-in;
}

.fm-preview-doc .fp-sheet-tabs,
.fe-preview-host .fp-sheet-tabs {
    display: flex;
    gap: 0.35rem;
    padding: 0.5rem;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
    flex-wrap: wrap;
}

.fm-preview-doc .fp-sheet-tab,
.fe-preview-host .fp-sheet-tab {
    border: 1px solid #cbd5e1;
    background: #fff;
    border-radius: 6px;
    padding: 0.2rem 0.6rem;
    font-size: 0.75rem;
    cursor: pointer;
}

.fm-preview-doc .fp-sheet-tab.is-active,
.fe-preview-host .fp-sheet-tab.is-active {
    background: #2563eb;
    border-color: #2563eb;
    color: #fff;
}

.fp-viewer-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.fp-viewer-option {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.65rem 0.75rem;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    cursor: pointer;
    margin: 0;
}

.fp-viewer-option:hover {
    background: #f8fafc;
}

.fp-viewer-option input {
    flex: 0 0 auto;
}

.fp-viewer-option-label {
    flex: 1;
    font-size: 0.9375rem;
}

.fp-viewer-default {
    color: #64748b;
    font-size: 0.8125rem;
}

.fm-preview-body.fm-preview-body-pdf,
.fm-preview-body.fm-preview-body-pdf.fm-preview-doc {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0;
    background: #525659;
}

.fm-preview-body.fm-preview-body-pdf .fp-pdf-pages {
    width: 100%;
    min-height: 0;
    padding: 8px 0 16px;
}

.fm-preview-body.fm-preview-body-pdf .fp-pdf-page {
    display: block;
    width: auto;
    max-width: calc(100% - 16px);
    height: auto;
    margin: 8px auto;
}

@media (max-width: 991.98px) {
    .fm-preview-body.fm-preview-body-luckysheet,
    .fm-preview-body.fm-preview-body-pdf,
    .fm-preview-body.fm-preview-body-pdf.fm-preview-doc {
        overflow-y: auto !important;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
        max-height: none;
    }

    .fm-preview-body.fm-preview-body-word,
    .fm-preview-body.fm-preview-body-word.fm-preview-doc {
        overflow-x: auto !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-x pan-y;
        max-height: none;
    }

    .fm-preview-body.fm-preview-body-luckysheet.fm-preview-doc {
        height: auto;
        min-height: 280px;
        overflow-y: auto !important;
    }

    .fm-preview-body.fm-preview-body-word .fm-preview-doc {
        height: auto;
        min-height: 280px;
        overflow-x: auto;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-x pan-y;
    }

    .fm-preview-body.fm-preview-body-luckysheet .fm-preview-doc {
        height: auto;
        min-height: 280px;
        overflow: visible;
    }

    .fp-word-wrap {
        height: auto !important;
        min-height: 0;
        overflow-x: auto !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-x pan-y;
    }

    .fp-word-page,
    .fp-word-docx-host {
        min-height: 0;
    }

    .fp-word-docx-host {
        max-width: none;
        width: max-content;
        min-width: 100%;
    }

    .fp-word-docx-host .docx-wrapper {
        min-width: min-content;
    }

    .fp-word-docx-host .docx-wrapper > section.docx {
        max-width: none;
    }

    .fp-word-docx-host table {
        width: auto;
        max-width: none;
    }

    .fp-word-docx-host table td,
    .fp-word-docx-host table th {
        word-break: normal;
    }

    .fm-preview-doc .fp-luckysheet-wrap,
    .fe-preview-host .fp-luckysheet-wrap {
        min-height: 280px;
        height: auto;
    }

    .fm-preview-body.fm-preview-body-pdf .fp-pdf-page {
        max-width: calc(100vw - 2rem);
    }
}
