/**
 * Forma custom PDF viewer (PDF.js canvas + toolbar).
 * Kept separate from styles.css — uses app CSS variables from the shell.
 */

/* —— Modal chrome (PDF viewer modal only) ——
   Sizing lives here only. Load this file after desktop/overrides.css so PDF rules win the cascade.
   Modes: (1) mobile/tablet overlay  (2) desktop centered overlay  (3) desktop floating panel */

.pdf-viewer-modal-content {
    container-type: inline-size;
    container-name: pdfviewermodal;
    display: flex;
    flex-direction: column;
    width: 100%;
}

/* Centered overlay (mobile + desktop backdrop) — not the draggable desktop panel */
#pdfViewerModal.modal:not(.desktop-modal-float) .modal-content.pdf-viewer-modal-content {
    --pdf-viewer-max-width: min(96vw, 900px);
    --pdf-viewer-panel-height: min(92vh, calc(100vh - 1.5rem));
    max-width: var(--pdf-viewer-max-width);
    height: var(--pdf-viewer-panel-height);
    max-height: var(--pdf-viewer-panel-height);
    border-radius: var(--card-radius);
}

@media (min-width: 769px) {
    /* Beats global `.modal-content.large { max-width: 750px }` on wide centered overlay */
    #pdfViewerModal.modal:not(.desktop-modal-float) .modal-content.large.pdf-viewer-modal-content {
        --pdf-viewer-max-width: min(98vw, 1600px);
        --pdf-viewer-panel-height: min(90vh, calc(100vh - 1.5rem));
    }
}

/* Web desktop: floating panel — width from CSS; height from floating-modals.js only (one value) */
@media (min-width: 1024px) {
    body.desktop-side-menu-mode #pdfViewerModal.modal.desktop-modal-float .modal-content.pdf-viewer-modal-content {
        --pdf-viewer-max-width: min(960px, calc(100vw - 48px));
        width: min(920px, calc(100vw - var(--desktop-side-menu-collapsed-width, 84px) - 48px));
        max-width: var(--pdf-viewer-max-width);
        height: auto;
        max-height: none;
        border-radius: var(--card-radius);
    }

    body.desktop-side-menu-mode #pdfViewerModal.modal.desktop-modal-float .pdf-viewer-body {
        flex: 1 1 auto;
        min-height: 0;
    }
}

/* One bar: thumbnail toggle | title (shrinks) | PDF controls + window actions */
#pdfViewerModal .modal-header.pdf-viewer-modal-header {
    --pdf-chrome-hit: 32px;
    --pdf-chrome-gap: 0.22rem;
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.35rem;
    box-sizing: border-box;
    width: 100%;
    min-height: calc(var(--pdf-chrome-hit) + 0.5rem);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-top-left-radius: var(--card-radius);
    border-top-right-radius: var(--card-radius);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    overflow: hidden;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset;
    padding: calc(env(safe-area-inset-top, 0px) + 0.35rem) 0.45rem 0.45rem;
    border-bottom: none;
}

@supports not (overflow-x: clip) {
    #pdfViewerModal .modal-header.pdf-viewer-modal-header {
        overflow-x: hidden;
    }
}

.pdf-viewer-modal-header__start {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
}

.pdf-viewer-modal-header__center {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.pdf-viewer-modal-header__end {
    flex: 0 1 auto;
    min-width: 0;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-end;
    gap: var(--pdf-chrome-gap);
    overflow: hidden;
}

.pdf-viewer-thumbs-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--pdf-chrome-hit, 32px);
    height: var(--pdf-chrome-hit, 32px);
    min-width: var(--pdf-chrome-hit, 32px);
    padding: 0;
    border: none;
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.1s ease;
}

@media (hover: hover) and (pointer: fine) {
    .pdf-viewer-thumbs-toggle-btn:hover {
        background: var(--bg-card);
    }
}

.pdf-viewer-thumbs-toggle-btn:active {
    transform: scale(0.96);
}

.pdf-viewer-thumbs-toggle-btn i {
    pointer-events: none;
}

body.light-theme #pdfViewerModal .modal-header.pdf-viewer-modal-header {
    box-shadow: none;
}

.pdf-viewer-header-title {
    display: block;
    margin: 0;
    padding: 0 0.25rem;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
    color: var(--text-primary);
    font-size: var(--font-size-tertiary);
    font-weight: var(--font-weight-semibold);
    line-height: 1.15;
    letter-spacing: var(--tracking-tight);
}

/* Beat styles.css `.modal-header h3` / iPad media (font-size-default) */
#pdfViewerModal .modal-header.pdf-viewer-modal-header h3.pdf-viewer-header-title,
#pdfViewerModal .modal-header.pdf-viewer-modal-header #pdfViewerTitle {
    font-size: var(--font-size-tertiary);
    line-height: 1.15;
}

.pdf-viewer-header-inline {
    display: inline-flex;
    align-items: center;
    gap: 0.28rem;
    align-self: center;
}

.pdf-viewer-header-menu-wrap {
    display: none;
    position: relative;
    align-items: center;
    align-self: center;
}

.pdf-viewer-header-menu-wrap--empty {
    display: none !important;
}

.pdf-viewer-header-menu {
    position: relative;
}

.pdf-viewer-header-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    min-width: 32px;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.1s ease;
}

@media (hover: hover) and (pointer: fine) {
    .pdf-viewer-header-menu-btn:hover {
        background: var(--bg-card);
    }
}

.pdf-viewer-header-menu-btn:active {
    transform: scale(0.96);
}

.pdf-viewer-header-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 200px;
    max-width: min(280px, 85vw);
    padding: 0.35rem;
    border-radius: 12px;
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    z-index: 50;
}

body.light-theme .pdf-viewer-header-dropdown {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.pdf-viewer-dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    margin: 0;
    padding: 0.55rem 0.65rem;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--text-primary);
    font: inherit;
    font-size: var(--font-size-tertiary);
    text-align: left;
    cursor: pointer;
    transition: background 0.15s ease;
}

@media (hover: hover) and (pointer: fine) {
    .pdf-viewer-dropdown-item:hover {
        background: var(--bg-tertiary);
    }
}

.pdf-viewer-dropdown-item--danger {
    color: #fc8181;
}

body.light-theme .pdf-viewer-dropdown-item--danger {
    color: #e53e3e;
}

.pdf-viewer-dropdown-item i {
    width: 1.1rem;
    text-align: center;
    opacity: 0.95;
}

.pdf-viewer-dropdown-item:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.pdf-viewer-pdf-tools-menu-wrap {
    display: none;
    position: relative;
    align-items: center;
    justify-content: center;
    align-self: center;
}

.pdf-viewer-pdf-tools-dropdown {
    min-width: 220px;
}

.pdf-viewer-dropdown-meta {
    padding: 0.45rem 0.65rem 0.35rem;
    font-size: var(--font-size-tertiary);
    font-weight: var(--font-weight-semibold);
    color: var(--text-secondary);
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 0.25rem;
}

.pdf-viewer-header-fitwidth-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Compact: icon-only page/zoom labels to save header width */
@container pdfviewermodal (max-width: 780px) {
    #pdfViewerModal .modal-header.pdf-viewer-modal-header #pdfCustomViewerPageLabel,
    #pdfViewerModal .modal-header.pdf-viewer-modal-header #pdfCustomViewerZoomLabel {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    #pdfViewerModal .modal-header.pdf-viewer-modal-header .pdf-toolbar-group + .pdf-toolbar-group {
        padding-left: 0.2rem;
        margin-left: 0;
    }
}

/* Narrow: page/zoom menu; fit-width stays as its own header button */
@container pdfviewermodal (max-width: 680px) {
    .pdf-custom-viewer-toolbar--in-modal-header {
        display: none !important;
    }

    .pdf-viewer-pdf-tools-menu-wrap {
        display: inline-flex !important;
        align-items: center;
        align-self: center;
        flex-shrink: 0;
    }

    .pdf-viewer-header-fitwidth-btn {
        display: inline-flex !important;
    }
}

#pdfViewerModal.pdf-viewer-modal--external #pdfCustomViewerToolbar,
#pdfViewerModal.pdf-viewer-modal--external #pdfCustomViewerFitWidth,
#pdfViewerModal.pdf-viewer-modal--external #pdfViewerPdfToolsMenuWrap,
#pdfViewerModal.pdf-viewer-modal--external .pdf-viewer-modal-header__start {
    display: none !important;
}

#pdfViewerModal.pdf-viewer-modal--external .modal-header.pdf-viewer-modal-header {
    flex-wrap: nowrap;
}

#pdfViewerModal.pdf-viewer-modal--external .pdf-viewer-modal-header__center {
    justify-self: start;
}

#pdfViewerModal.pdf-viewer-modal--external .pdf-viewer-header-title {
    text-align: left;
    padding-left: 0;
}

@container pdfviewermodal (max-width: 520px) {
    .pdf-viewer-header-inline {
        display: none !important;
    }

    .pdf-viewer-header-menu-wrap:not(.pdf-viewer-header-menu-wrap--empty) {
        display: inline-flex !important;
        align-items: center;
        align-self: center;
    }
}

.pdf-viewer-delete-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: 0;
    font-size: 0.72rem;
    border-radius: 8px;
}

.pdf-viewer-fullscreen-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    min-width: 32px;
    padding: 0;
    border-radius: 8px;
    font-size: 0.75rem;
}

.pdf-viewer-fullscreen-btn i {
    pointer-events: none;
}

#pdfViewerModal.pdf-viewer-modal--fullscreen .modal-header.pdf-viewer-modal-header {
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-top: none;
    box-shadow: none;
}

.pdf-viewer-body {
    flex: 1;
    min-height: 60vh;
    padding: 0 !important;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.pdf-viewer-external-notice {
    padding: 1rem 1.25rem;
    margin: 0 0 0.75rem 0;
    text-align: center;
    font-size: var(--font-size-tertiary);
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    border-radius: var(--card-radius);
    line-height: 1.45;
}

.pdf-viewer-body--external .pdf-custom-viewer {
    display: none !important;
}

#pdfViewerModal.pdf-viewer-modal--fullscreen {
    align-items: stretch;
    justify-content: stretch;
    padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
}

#pdfViewerModal.pdf-viewer-modal--fullscreen .pdf-viewer-modal-content {
    max-width: none;
    width: 100%;
    height: 100%;
    max-height: none;
    margin: 0;
    border-radius: 0;
    display: flex;
    flex-direction: column;
}

@media (min-width: 1024px) {
    body.desktop-side-menu-mode #pdfViewerModal.pdf-viewer-modal--fullscreen.desktop-modal-float .modal-content.pdf-viewer-modal-content {
        width: 100% !important;
        max-width: none;
        height: 100% !important;
        max-height: none !important;
    }
}

#pdfViewerModal.pdf-viewer-modal--fullscreen .pdf-viewer-body {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

#pdfViewerModal.pdf-viewer-modal--fullscreen .pdf-custom-viewer {
    flex: 1 1 auto;
    min-height: 0;
}

#pdfViewerModal.pdf-viewer-modal--fullscreen .pdf-custom-viewer-main {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

#pdfViewerModal.pdf-viewer-modal--fullscreen .pdf-custom-viewer-thumbs-wrap {
    max-height: 100%;
}

#pdfViewerModal.pdf-viewer-modal--fullscreen .pdf-custom-viewer-scroll {
    flex: 1 1 auto;
    min-height: 0;
}

#pdfViewerModal.pdf-viewer-modal--fullscreen .pdf-viewer-external-notice {
    flex-shrink: 0;
}

/* —— Custom viewer (canvas + controls) —— */
.pdf-custom-viewer {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    background: var(--bg-secondary);
    border-radius: 0 0 var(--card-radius) var(--card-radius);
    overflow: hidden;
}

.pdf-custom-viewer.hidden {
    display: none !important;
}

.pdf-custom-viewer-body {
    display: flex;
    flex-direction: row;
    flex: 1 1 auto;
    min-height: 0;
    min-width: 0;
}

.pdf-custom-viewer-thumbs-wrap {
    flex: 0 0 auto;
    box-sizing: border-box;
    width: 132px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    overflow: hidden;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition:
        width 0.38s cubic-bezier(0.32, 0.72, 0, 1),
        opacity 0.3s ease,
        border-right-width 0.32s ease,
        border-right-color 0.25s ease,
        visibility 0s linear 0s;
}

.pdf-custom-viewer--thumbs-hidden .pdf-custom-viewer-thumbs-wrap {
    width: 0;
    opacity: 0;
    border-right-width: 0;
    border-right-color: transparent;
    pointer-events: none;
    visibility: hidden;
    transition:
        width 0.38s cubic-bezier(0.32, 0.72, 0, 1),
        opacity 0.26s ease 0.04s,
        border-right-width 0.3s ease,
        border-right-color 0.22s ease,
        visibility 0s linear 0.36s;
}

@media (prefers-reduced-motion: reduce) {
    .pdf-custom-viewer-thumbs-wrap,
    .pdf-custom-viewer--thumbs-hidden .pdf-custom-viewer-thumbs-wrap {
        transition-duration: 0.01ms !important;
        transition-delay: 0s !important;
    }
}

.pdf-custom-viewer-thumbs-head {
    flex-shrink: 0;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.35rem 0.45rem 0.4rem;
    border-bottom: 1px solid var(--border-color);
}

.pdf-custom-viewer-thumbs-head-label {
    font-size: 0.68rem;
    font-weight: var(--font-weight-semibold, 600);
    color: var(--text-secondary);
    letter-spacing: 0.02em;
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
}

.pdf-custom-viewer-thumbs-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.pdf-custom-viewer-thumbs {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    padding: 0.5rem 0.4rem 0.75rem;
}

.pdf-custom-viewer-thumb {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    width: 100%;
    margin: 0;
    padding: 0.35rem 0.25rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 0.7rem;
    cursor: pointer;
    box-sizing: border-box;
    transition: border-color 0.12s ease, background 0.12s ease;
}

.pdf-custom-viewer-thumb:hover {
    border-color: var(--accent-primary, #63b3ed);
    color: var(--text-primary);
}

.pdf-custom-viewer-thumb--current {
    border-color: var(--accent-primary, #63b3ed);
    background: var(--bg-card, rgba(99, 179, 237, 0.12));
    color: var(--text-primary);
    box-shadow: 0 0 0 1px rgba(99, 179, 237, 0.35);
}

.pdf-custom-viewer-thumb-preview {
    position: relative;
    width: 100%;
    max-width: 112px;
    margin: 0 auto;
    line-height: 0;
    flex-shrink: 0;
    min-height: 3.25rem;
}

.pdf-custom-viewer-thumb-loading {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 3.25rem;
    border-radius: 2px;
    background: rgba(15, 23, 42, 0.5);
    pointer-events: none;
}

/* Same ring spinner as PDF page picker / job-site loading (`styles.css` .photo-operation-spinner) */
.pdf-custom-viewer-thumb-loading .photo-operation-overlay-content {
    gap: 0;
    color: transparent;
}

.pdf-custom-viewer-thumb-loading .photo-operation-spinner {
    width: 24px;
    height: 24px;
}

body.light-theme .pdf-custom-viewer-thumb-loading {
    background: rgba(255, 255, 255, 0.78);
}

body.light-theme .pdf-custom-viewer-thumb-loading .photo-operation-spinner {
    border: 2px solid rgba(15, 23, 42, 0.22);
    border-top-color: rgba(15, 23, 42, 0.88);
}

.pdf-custom-viewer-thumb-loading.hidden {
    display: none;
}

.pdf-custom-viewer-thumb-canvas {
    display: block;
    margin: 0 auto;
    border-radius: 2px;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

.pdf-custom-viewer-thumb-label {
    font-variant-numeric: tabular-nums;
    font-weight: var(--font-weight-semibold, 600);
    margin-top: 0.15rem;
    line-height: 1.25;
    color: inherit;
    text-align: center;
}

.pdf-custom-viewer-thumb-label.hidden {
    display: none;
}

.pdf-custom-viewer-main {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    position: relative;
}

@media (max-width: 700px) {
    .pdf-custom-viewer-thumbs-wrap {
        display: none;
    }

    #pdfViewerThumbsToggleBtn,
    #pdfViewerPdfToolsDropdownToggleThumbs {
        display: none !important;
    }
}

.pdf-custom-viewer-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.35rem 0.5rem;
    padding: 0.55rem 0.65rem;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.pdf-custom-viewer-toolbar--in-modal-header {
    flex: 0 1 auto;
    min-width: 0;
    display: inline-flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-start;
    gap: 0.12rem 0.2rem;
    padding: 0;
    margin: 0;
    background: transparent;
    border: none;
    align-self: center;
    overflow: hidden;
}

#pdfViewerModal .modal-header.pdf-viewer-modal-header .pdf-viewer-modal-header__end > .pdf-viewer-header-fitwidth-btn,
#pdfViewerModal .modal-header.pdf-viewer-modal-header .pdf-viewer-modal-header__end > .pdf-viewer-header-inline,
#pdfViewerModal .modal-header.pdf-viewer-modal-header .pdf-viewer-modal-header__end > .pdf-viewer-header-menu-wrap,
#pdfViewerModal .modal-header.pdf-viewer-modal-header .pdf-viewer-modal-header__end > .pdf-viewer-pdf-tools-menu-wrap,
#pdfViewerModal .modal-header.pdf-viewer-modal-header .pdf-viewer-modal-header__end > .modal-close {
    flex-shrink: 0;
}

#pdfViewerModal .modal-header.pdf-viewer-modal-header .pdf-toolbar-group {
    gap: 0.12rem;
    padding: 0 0.22rem;
}

#pdfViewerModal .modal-header.pdf-viewer-modal-header .pdf-toolbar-group:first-child {
    padding-left: 0;
    margin-left: 0;
    border-left: none;
}

#pdfViewerModal .modal-header.pdf-viewer-modal-header .pdf-toolbar-group + .pdf-toolbar-group {
    padding-left: 0.35rem;
    margin-left: 0.08rem;
}

#pdfViewerModal .modal-header.pdf-viewer-modal-header .pdf-toolbar-btn {
    width: var(--pdf-chrome-hit, 32px);
    min-width: var(--pdf-chrome-hit, 32px);
    height: var(--pdf-chrome-hit, 32px);
    border-radius: 8px;
    font-size: 0.7rem;
    box-sizing: border-box;
}

#pdfViewerModal .modal-header.pdf-viewer-modal-header .pdf-toolbar-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 1;
    min-height: var(--pdf-chrome-hit, 32px);
    min-width: 2rem;
    max-width: 2.75rem;
    padding: 0 0.08rem;
    font-size: 0.68rem;
    line-height: 1.1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#pdfViewerModal .modal-header.pdf-viewer-modal-header .pdf-viewer-header-fitwidth-btn {
    width: var(--pdf-chrome-hit, 32px);
    min-width: var(--pdf-chrome-hit, 32px);
    height: var(--pdf-chrome-hit, 32px);
    padding: 0;
    border-radius: 8px;
    font-size: 0.7rem;
    box-sizing: border-box;
}

#pdfViewerModal .modal-header.pdf-viewer-modal-header .pdf-viewer-header-menu {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

#pdfViewerModal .modal-header.pdf-viewer-modal-header .pdf-viewer-header-menu-btn,
#pdfViewerModal .modal-header.pdf-viewer-modal-header .pdf-viewer-fullscreen-btn {
    width: var(--pdf-chrome-hit, 32px);
    height: var(--pdf-chrome-hit, 32px);
    min-width: var(--pdf-chrome-hit, 32px);
    min-height: var(--pdf-chrome-hit, 32px);
    border-radius: 8px;
    font-size: 0.72rem;
    box-sizing: border-box;
}

#pdfViewerModal .modal-header.pdf-viewer-modal-header .pdf-viewer-delete-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--pdf-chrome-hit, 32px);
    height: var(--pdf-chrome-hit, 32px);
    min-width: var(--pdf-chrome-hit, 32px);
    min-height: var(--pdf-chrome-hit, 32px);
    padding: 0;
    gap: 0;
    font-size: 0.72rem;
    border-radius: 8px;
    box-sizing: border-box;
}

#pdfViewerModal .modal-header.pdf-viewer-modal-header .pdf-viewer-delete-btn i {
    pointer-events: none;
}

#pdfViewerModal .modal-header.pdf-viewer-modal-header .pdf-viewer-modal-header__end > .modal-close {
    align-self: center;
    flex-shrink: 0;
    width: var(--pdf-chrome-hit, 32px);
    height: var(--pdf-chrome-hit, 32px);
    min-width: var(--pdf-chrome-hit, 32px);
    min-height: var(--pdf-chrome-hit, 32px);
    font-size: 1rem;
    line-height: 1;
    border-radius: 8px;
}

.pdf-toolbar-group {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0 0.35rem;
}

.pdf-toolbar-group + .pdf-toolbar-group {
    border-left: 1px solid var(--border-color);
    padding-left: 0.55rem;
    margin-left: 0.15rem;
}

.pdf-toolbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    height: 38px;
    padding: 0 0.5rem;
    border: none;
    border-radius: 10px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: var(--font-size-tertiary);
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
}

.pdf-toolbar-btn:disabled {
    opacity: 0.38;
    cursor: not-allowed;
}

@media (hover: hover) and (pointer: fine) {
    .pdf-toolbar-btn:hover:not(:disabled) {
        background: var(--bg-card);
    }
}

.pdf-toolbar-btn:active:not(:disabled) {
    transform: scale(0.97);
}

/* Pointer hits the <button>, not nested FA icons — avoids odd multi-target pointer traces and stray hit targets. */
.pdf-custom-viewer-toolbar .pdf-toolbar-btn > i,
.pdf-custom-viewer-toolbar .pdf-toolbar-btn > svg {
    pointer-events: none;
}

.pdf-toolbar-label {
    font-size: var(--font-size-tertiary);
    font-weight: var(--font-weight-medium);
    color: var(--text-primary);
    min-width: 4.5rem;
    text-align: center;
    padding: 0 0.25rem;
}

.pdf-toolbar-zoom {
    min-width: 3.25rem;
}

.pdf-custom-viewer-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--bg-primary);
    /* Native one-finger pan; pinch handled in JS (two-finger). */
    touch-action: pan-x pan-y;
    overscroll-behavior: none;
    overflow-anchor: none;
}

.pdf-custom-viewer-scroll.pdf-custom-viewer-scroll--pinching {
    touch-action: none;
}

/* Pinch scroll math assumes canvas grows from top-left of shell, not flex-centered. */
.pdf-custom-viewer-scroll.pdf-custom-viewer-scroll--pinching .pdf-custom-viewer-canvas-shell {
    justify-content: flex-start;
    align-items: flex-start;
    contain: layout;
}

.pdf-custom-viewer-scroll.pdf-custom-viewer-scroll--pinching .pdf-custom-viewer-canvas {
    will-change: width, height;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

.pdf-custom-viewer-scroll.pdf-custom-viewer-scroll--pannable {
    cursor: grab;
}

.pdf-custom-viewer-scroll.pdf-custom-viewer-scroll--panning {
    cursor: grabbing;
    user-select: none;
}

.pdf-custom-viewer-canvas-zoomwrap {
    display: block;
}

.pdf-custom-viewer-canvas-shell {
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    /* width: max-content so wide canvas grows scrollWidth (full-width shell hid horizontal overflow) */
    width: max-content;
    min-width: 100%;
    margin-left: auto;
    margin-right: auto;
    padding: 1rem 0.75rem 1.25rem;
    /* height follows canvas; JS may raise min-height when pinch anchor needs vertical scroll */
    min-height: 0;
    height: auto;
}

/* Canvas size comes from JS; avoid max-width so zoomed pages can scroll horizontally */
.pdf-custom-viewer-canvas {
    display: block;
    transform-origin: center center;
    flex-shrink: 0;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.18);
    border-radius: 4px;
    background: #fff;
}

body.light-theme .pdf-custom-viewer-canvas {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.pdf-custom-viewer-loading,
.pdf-custom-viewer-error {
    padding: 1.25rem;
    text-align: center;
    font-size: var(--font-size-tertiary);
    color: var(--text-secondary);
}

.pdf-custom-viewer-error {
    color: #fc8181;
}

.pdf-custom-viewer--error .pdf-custom-viewer-scroll {
    display: none;
}
