/*
    PDF flip-book viewer.

    The first block is page-flip's own stylesheet, vendored.

    It is vendored rather than linked because page-flip 2.0.7 publishes NO dist/css — App.razor
    linked https://cdn.jsdelivr.net/npm/page-flip@2.0.7/dist/css/page-flip.browser.css for months
    and that URL is a 404. The only stylesheet in the package is src/Style/stPageFlip.css, which
    is not a sane thing to hotlink.

    Without these rules the viewer renders NOTHING while looking healthy: .stf__block is the
    element page-flip measures (Render.getBlockHeight() -> distElement.offsetHeight), so a
    statically-positioned block collapses to 0px tall and the stretch branch of
    calculateBoundsRect() clamps the whole book to zero
    (r = h / n; if (r > blockHeight) { r = blockHeight; h = r * n }).
    Flips, events and the page counter all keep working at zero size, which is why this presented
    as "it is not a flip book" rather than as an error.

    Two deliberate differences from the upstream file:
      - `.sft__wrapper` is a typo in the package (s-f-t); it is spelled correctly here, which is
        what lets the wrapper carry the height we hand it.
      - `.stf__wrapper` gets `height: 100%` so the book sizes from the box WE set on the surface
        element. Upstream instead relies on `autoSize` writing a padding-bottom aspect ratio onto
        the wrapper, which derives height from width alone and so cannot fit a landscape
        container — the book overflows vertically and you see a magnified corner of page one.
*/

.stf__parent {
    position: relative;
    display: block;
    box-sizing: border-box;
    transform: translateZ(0);
    -ms-touch-action: pan-y;
    touch-action: pan-y;
}

.stf__wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
}

.stf__parent canvas {
    position: absolute;
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
}

.stf__block {
    position: absolute;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    perspective: 2000px;
}

.stf__item {
    display: none;
    position: absolute;
    transform-style: preserve-3d;
}

.stf__outerShadow,
.stf__innerShadow,
.stf__hardShadow,
.stf__hardInnerShadow {
    position: absolute;
    left: 0;
    top: 0;
}

/* ------------------------------------------------------------------ *
 * Viewer chrome
 * ------------------------------------------------------------------ */

.pdf-flipbook {
    --pdf-toolbar-h: 48px;   /* kept current by pdfFlipbook.js (the toolbar's real height) */
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--qm-bg-dark);
    color: var(--qm-text-primary);
    font-family: var(--qm-font-primary);
    overflow: hidden;
    outline: none;
}

.pdf-flipbook--fullscreen {
    background: #000;
}

/* Status (loading / failed) ---------------------------------------- */

.pdf-flipbook-status {
    position: absolute;
    inset: 0;
    z-index: 6;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px;
    text-align: center;
    background: var(--qm-bg-dark);
    color: var(--qm-text-secondary);
}

.pdf-flipbook-status .q-icon {
    font-size: 40px;
}

.pdf-flipbook-status-progress {
    width: 200px;
    height: 3px;
    border-radius: 2px;
    overflow: hidden;
    background: rgba(var(--qm-primary-rgb), 0.18);
}

.pdf-flipbook-status-progress span {
    display: block;
    height: 100%;
    background: var(--qm-primary);
    transition: width 0.2s linear;
}

.pdf-flipbook-fallback-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    color: var(--qm-primary);
    text-decoration: none;
    font-size: 14px;
}

.pdf-flipbook-fallback-link:hover {
    text-decoration: underline;
}

/* Layout ------------------------------------------------------------ */

.pdf-flipbook-body {
    display: flex;
    flex: 1;
    width: 100%;
    min-height: 0;
    min-width: 0;
}

.pdf-flipbook-main {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

/* Thumbnail rail ---------------------------------------------------- */

.pdf-flipbook-thumbs {
    width: 112px;
    flex-shrink: 0;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 10px;
    background: rgba(var(--qm-primary-rgb), 0.06);
    border-right: 1px solid var(--qm-border);
}

.pdf-flipbook-thumb {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 4px;
    border: 2px solid transparent;
    border-radius: var(--qm-radius-sm, 3px);
    background: none;
    cursor: pointer;
    width: 100%;
}

.pdf-flipbook-thumb img {
    width: 100%;
    display: block;
    border-radius: 2px;
    background: #fff;
}

.pdf-flipbook-thumb span {
    font-size: 11px;
    color: var(--qm-text-secondary);
}

.pdf-flipbook-thumb:hover {
    border-color: var(--qm-primary-light);
}

.pdf-flipbook-thumb--active {
    border-color: var(--qm-primary);
}

.pdf-flipbook-thumb--hit span {
    color: var(--qm-primary);
    font-weight: 700;
}

/* Toolbar ----------------------------------------------------------- */

.pdf-flipbook-toolbar {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 12px;
    flex-shrink: 0;
    background: rgba(var(--qm-primary-rgb), 0.06);
    border-bottom: 1px solid var(--qm-border);
}

.pdf-flipbook-toolbar-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.pdf-flipbook-toolbar-sep {
    width: 1px;
    height: 20px;
    background: var(--qm-border);
}

.pdf-flipbook-zoom-level {
    font-size: 12px;
    color: var(--qm-text-secondary);
    min-width: 44px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.pdf-flipbook-toolbar-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--qm-radius-sm, 3px);
    color: var(--qm-text-secondary);
    text-decoration: none;
}

.pdf-flipbook-toolbar-link:hover {
    background: var(--qm-bg-card-hover);
    color: var(--qm-primary);
}

/* Search ------------------------------------------------------------ */

.pdf-flipbook-search {
    display: flex;
    align-items: center;
    gap: 4px;
}

.pdf-flipbook-search input {
    width: 180px;
    height: 32px;
    padding: 0 10px;
    font-family: inherit;
    font-size: 13px;
    color: var(--qm-text-primary);
    background: var(--qm-bg-card);
    border: 1px solid var(--qm-border);
    border-radius: var(--qm-radius-sm, 3px);
    outline: none;
}

.pdf-flipbook-search input:focus {
    border-color: var(--qm-primary);
}

.pdf-flipbook-search-count {
    font-size: 12px;
    color: var(--qm-text-secondary);
    min-width: 68px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* Stage -------------------------------------------------------------- */

.pdf-flipbook-stage {
    position: relative;
    flex: 1;
    min-height: 0;
    min-width: 0;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    scrollbar-width: thin;
}

.pdf-flipbook-stage--pannable {
    cursor: grab;
}

.pdf-flipbook-stage--panning {
    cursor: grabbing;
}

.pdf-flipbook-surface {
    margin: auto;
    flex-shrink: 0;
}

/*
    One page of the book. page-flip clones this element mid-flip via cloneNode(true), which is why
    the page image is an <img> and not a <canvas> — canvas pixels do NOT survive a clone, so a
    canvas-backed page would turn blank for the duration of every flip animation.
*/
.pdf-flipbook-page {
    position: relative;
    width: 100%;
    height: 100%;
    background: #fff;
    overflow: hidden;
}

.pdf-flipbook-page img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: fill;
}

.pdf-flipbook-page-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.pdf-flipbook-hit {
    position: absolute;
    background: rgba(255, 214, 0, 0.45);
    border-radius: 1px;
}

.pdf-flipbook-hit--current {
    background: rgba(255, 138, 0, 0.6);
}

/* Page controls ------------------------------------------------------ */

.pdf-flipbook-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 10px;
    flex-shrink: 0;
    background: rgba(var(--qm-primary-rgb), 0.06);
    border-top: 1px solid var(--qm-border);
}

.pdf-flipbook-page-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--qm-text-secondary);
}

.pdf-flipbook-page-indicator input {
    width: 54px;
    height: 30px;
    padding: 0 6px;
    text-align: center;
    font-family: inherit;
    font-size: 13px;
    color: var(--qm-text-primary);
    background: var(--qm-bg-card);
    border: 1px solid var(--qm-border);
    border-radius: var(--qm-radius-sm, 3px);
    outline: none;
    font-variant-numeric: tabular-nums;
}

.pdf-flipbook-page-indicator input:focus {
    border-color: var(--qm-primary);
}

/*
    Signage: the screen is unattended, so the chrome fades out once nothing has moved. It is faded
    rather than removed — a passer-by who touches the screen gets the full viewer back, and on a
    wall display the toolbar is the only route to zoom, search and single/two-page.
*/
.pdf-flipbook--signage .pdf-flipbook-toolbar,
.pdf-flipbook--signage .pdf-flipbook-controls,
.pdf-flipbook--signage .pdf-flipbook-thumbs {
    transition: opacity 0.6s ease;
}

.pdf-flipbook--signage.pdf-flipbook--idle .pdf-flipbook-toolbar,
.pdf-flipbook--signage.pdf-flipbook--idle .pdf-flipbook-controls,
.pdf-flipbook--signage.pdf-flipbook--idle .pdf-flipbook-thumbs {
    opacity: 0;
    pointer-events: none;
}

/*
    Scroll mode (phones): pages stacked at fit-to-width, vertical scroll, native-feeling pinch.
    The stage stops centring (a column of pages starts at the top) and lets both axes scroll so a
    zoomed page can be panned. touch-action keeps single-finger pan native while the viewer's own
    pointer handlers take the two-finger pinch.
*/
.pdf-flipbook-stage--scroll {
    display: block;
    overflow: auto;
    touch-action: pan-x pan-y;
    -webkit-overflow-scrolling: touch;
    background: var(--qm-bg-secondary, #ececef);
}

.pdf-flipbook-scroll {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px 0 24px;
    /* Centred when the column is narrower than the stage (a desktop reader who chose Scroll);
       a zoomed column wider than the stage overflows to the right and the stage pans. */
    margin: 0 auto;
}

/* !important on purpose: page-flip positions its pages with inline styles (absolute, left/top,
   transform, clip-path) and its frame loop can write them once more after destroy() when the
   reader switches to the column mid-animation. The column must win regardless. */
.pdf-flipbook-scroll .pdf-flipbook-page {
    position: relative !important;
    display: block !important;
    left: auto !important;
    top: auto !important;
    width: 100% !important;
    height: auto !important;
    transform: none !important;
    clip-path: none !important;
    z-index: auto !important;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
}

.pdf-flipbook-scroll .pdf-flipbook-page img {
    height: auto;
    aspect-ratio: inherit;
}

@media (max-width: 900px) {
    /* Compact chrome: one row of icons, no zoom readout, the search box only as wide as it must
       be, and every control at least 44px — the touch-target floor. */
    .pdf-flipbook-toolbar {
        gap: 4px;
        padding: 6px 8px;
        flex-wrap: nowrap;
        overflow-x: auto;
        justify-content: flex-start;
        scrollbar-width: none;
    }

    .pdf-flipbook-toolbar .q-btn,
    .pdf-flipbook-controls .q-btn {
        min-width: 44px;
        min-height: 44px;
    }

    .pdf-flipbook-zoom-level {
        display: none;
    }

    .pdf-flipbook-search input {
        width: 110px;
    }

    .pdf-flipbook-thumbs {
        width: 78px;
    }

    .pdf-flipbook-controls {
        padding: 6px 10px;
    }

    .pdf-flipbook-page-indicator input {
        min-height: 44px;
    }
}

/* ------------------------------------------------------------------ *
 * Reading tools (plan §44 C1-C4, C9): contents, search hits, shortcuts, reader view.
 * Panels sit just under the toolbar (--pdf-toolbar-h, kept by pdfFlipbook.js) over the page.
 * Signage never draws any of this: the component leaves it out when SignageMode or AutoAdvance is set.
 * ------------------------------------------------------------------ */

.pdf-flipbook-tools {
    position: relative;
}

/* Announces "Link copied" to a screen reader without taking room in the toolbar. */
.pdf-flipbook-live {
    font-size: 12px;
    color: var(--qm-text-secondary);
    white-space: nowrap;
    min-width: 0;
}

.pdf-flipbook-live:empty {
    display: none;
}

.pdf-flipbook-notice {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    font-size: 12px;
    color: var(--qm-text-secondary);
    border-bottom: 1px solid var(--qm-border);
    flex-shrink: 0;
}

.qdoc-contents,
.pdf-flipbook-results,
.pdf-flipbook-help {
    position: absolute;
    top: calc(var(--pdf-toolbar-h, 48px) + 4px);
    z-index: 5;
    display: flex;
    flex-direction: column;
    max-height: calc(100% - var(--pdf-toolbar-h, 48px) - 12px);
    background: var(--qm-bg-card);
    color: var(--qm-text-primary);
    border: 1px solid var(--qm-border);
    border-radius: var(--qm-radius-md, 4px);
    box-shadow: var(--qm-shadow-md, 0 3px 10px rgba(0, 0, 0, 0.18));
    overflow: hidden;
}

.qdoc-contents {
    left: 8px;
    width: min(360px, calc(100% - 16px));
}

.pdf-flipbook-results,
.pdf-flipbook-help {
    right: 8px;
    width: min(400px, calc(100% - 16px));
}

.qdoc-contents__head,
.pdf-flipbook-results__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 8px 6px 12px;
    border-bottom: 1px solid var(--qm-border);
    font-size: 13px;
    flex-shrink: 0;
}

.qdoc-contents__list,
.pdf-flipbook-results__list {
    list-style: none;
    margin: 0;
    padding: 4px;
    overflow-y: auto;
    min-height: 0;
}

.qdoc-contents__link,
.pdf-flipbook-result {
    display: flex;
    align-items: baseline;
    gap: 10px;
    width: 100%;
    padding: 7px 8px;
    text-align: left;
    font: inherit;
    font-size: 13px;
    color: inherit;
    background: none;
    border: 0;
    border-radius: var(--qm-radius-sm, 3px);
    cursor: pointer;
}

.qdoc-contents__link:hover,
.pdf-flipbook-result:hover {
    background: var(--qm-bg-card-hover);
}

.qdoc-contents__link:focus-visible,
.pdf-flipbook-result:focus-visible {
    outline: var(--qm-focus-ring);
    outline-offset: -2px;
}

/* Where the reader is: a bar and the brand's own tint, never colour alone (the entry is also aria-current). */
.qdoc-contents__link--current,
.pdf-flipbook-result--current {
    background: rgba(var(--qm-primary-rgb), 0.1);
    box-shadow: inset 3px 0 0 var(--qm-primary);
    font-weight: 600;
}

.qdoc-contents__title {
    flex: 1;
    min-width: 0;
    overflow-wrap: anywhere;
}

.qdoc-contents__page,
.pdf-flipbook-result__page {
    flex-shrink: 0;
    color: var(--qm-text-secondary);
    font-variant-numeric: tabular-nums;
    font-size: 12px;
}

.qdoc-contents__item--l1 .qdoc-contents__link { padding-left: 20px; }
.qdoc-contents__item--l2 .qdoc-contents__link { padding-left: 32px; font-size: 12.5px; }
.qdoc-contents__item--l3 .qdoc-contents__link { padding-left: 44px; font-size: 12.5px; }
.qdoc-contents__item--l4 .qdoc-contents__link { padding-left: 56px; font-size: 12.5px; }
.qdoc-contents__item--l5 .qdoc-contents__link { padding-left: 68px; font-size: 12.5px; }
.qdoc-contents__item--l0 .qdoc-contents__link { font-weight: 600; }
.qdoc-contents__item--l0 .qdoc-contents__link--current { font-weight: 700; }

.pdf-flipbook-result {
    flex-direction: row;
}

.pdf-flipbook-result__page {
    min-width: 34px;
}

.pdf-flipbook-result__text {
    flex: 1;
    min-width: 0;
    overflow-wrap: anywhere;
}

.pdf-flipbook-result__text mark {
    background: rgba(255, 214, 0, 0.5);
    color: inherit;
    padding: 0 1px;
    border-radius: 1px;
}

.pdf-flipbook-help__list {
    margin: 0;
    padding: 8px 12px 12px;
    display: grid;
    gap: 6px;
    overflow-y: auto;
    font-size: 13px;
}

.pdf-flipbook-help__list > div {
    display: grid;
    grid-template-columns: 96px minmax(0, 1fr);
    gap: 10px;
    align-items: baseline;
}

.pdf-flipbook-help__list dt {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.pdf-flipbook-help__list dd {
    margin: 0;
    color: var(--qm-text-secondary);
}

/* Reader view: the text, reflowed. The host is an empty element Blazor owns; the script fills it. */
.pdf-flipbook-reader-host {
    display: none;
}

.pdf-flipbook-reader-host--open {
    display: block;
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    top: var(--pdf-toolbar-h, 0px);
    z-index: 4;
}

.pdf-flipbook-reader {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--qm-bg-card);
    color: var(--qm-text-primary);
}

.pdf-flipbook-reader-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 12px;
    border-bottom: 1px solid var(--qm-border);
    flex-shrink: 0;
}

.pdf-flipbook-reader-tools {
    display: flex;
    align-items: center;
    gap: 6px;
}

.pdf-flipbook-reader-btn {
    min-width: 44px;
    min-height: 44px;
    padding: 0 12px;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    color: var(--qm-text-primary);
    background: var(--qm-bg-card);
    border: 1px solid var(--qm-border);
    border-radius: var(--qm-radius-sm, 3px);
    cursor: pointer;
}

.pdf-flipbook-reader-btn:hover:not(:disabled) {
    background: var(--qm-bg-card-hover);
}

.pdf-flipbook-reader-btn:disabled {
    opacity: 0.45;
    cursor: default;
}

.pdf-flipbook-reader-btn:focus-visible,
.pdf-flipbook-reader-article:focus-visible {
    outline: var(--qm-focus-ring);
    outline-offset: 2px;
}

.pdf-flipbook-reader-article {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 12px max(16px, 5vw) 40px;
    line-height: 1.6;
    -webkit-overflow-scrolling: touch;
}

.pdf-flipbook-reader-article > section {
    max-width: 44rem;
    margin: 0 auto;
}

.pdf-flipbook-reader-article p {
    margin: 0 0 0.9em;
    overflow-wrap: anywhere;
}

.pdf-flipbook-reader-article h3 {
    margin: 1.1em 0 0.5em;
    font-size: 1.15em;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.pdf-flipbook-reader-pageno {
    margin: 1.4em 0 0.6em;
    padding-top: 0.5em;
    border-top: 1px solid var(--qm-border);
    font-size: 0.7em;
    color: var(--qm-text-secondary);
}

.pdf-flipbook-reader-loading {
    margin: 2em auto;
    text-align: center;
    color: var(--qm-text-secondary);
}

/* Less motion on request: no fades, no smooth scrolling; the script also turns the page-turn into an instant change. */
@media (prefers-reduced-motion: reduce) {
    .pdf-flipbook,
    .pdf-flipbook * {
        transition: none !important;
        animation: none !important;
        scroll-behavior: auto !important;
    }
}

@media (max-width: 900px) {
    .qdoc-contents,
    .pdf-flipbook-results,
    .pdf-flipbook-help {
        left: 6px;
        right: 6px;
        width: auto;
    }

    .qdoc-contents__link,
    .pdf-flipbook-result {
        min-height: 44px;
        align-items: center;
    }

    .qdoc-contents__head .q-btn,
    .pdf-flipbook-results__head .q-btn {
        min-width: 44px;
        min-height: 44px;
    }

    .pdf-flipbook-tools {
        flex-shrink: 0;
    }

    /* Kept for a screen reader ("Link copied"), but out of a phone's crowded toolbar. */
    .pdf-flipbook-live {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }
}
