/* =========================================================
   Full-screen PDF viewer  —  includes/manual-viewer.php
   Shared by the portal manuals grid (/account/manuals) and
   the public Owner's Manual page, both driven by
   src/js/account-manuals.js.

   Portal pages load account-portal.css, whose :root tokens
   this reuses; every var() carries a fallback so the viewer
   renders identically on public pages, where that sheet
   never loads. Those fallbacks are the LADDER TOKEN the
   portal token now aliases (surfaces.css loads everywhere),
   not a copy of its literal value — a hardcoded copy silently
   goes stale the moment the portal token moves, which is
   exactly what happened when the portal came off its own
   palette. The --tv-cta-ghost-* tokens are global (cta.css
   via head.php).
   ========================================================= */

/*
 * m072224.css loads on every page and carries a global
 *   button { margin-top: 2rem; font-size: 1.25rem; text-transform: uppercase;
 *            letter-spacing: .07rem; color: var(--c4) }
 * so every <button> here has to opt out explicitly (see docs/gotchas.md).
 */
.manual-viewer__btn,
.manual-viewer__dock-btn {
    margin: 0;
    text-transform: none;
    letter-spacing: normal;
}

/* Visually hidden, still read by screen readers — the dock's live region. */
.manual-viewer__sr {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.manual-viewer {
    position: fixed;
    inset: 0;
    /* .navbar sits at 1000000000 — the viewer is full screen, so it must win. */
    z-index: 1000000001;
    display: flex;
    flex-direction: column;
    background: rgba(6, 7, 10, 0.97);
    backdrop-filter: blur(6px);
}

.manual-viewer[hidden] {
    display: none;
}

.manual-viewer__bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.7rem 0.9rem 0.7rem 1.15rem;
    border-bottom: 1px solid var(--portal-divider, var(--tv-line));
    background: rgba(10, 11, 14, 0.92);
}

.manual-viewer__titles {
    flex: 1 1 auto;
    min-width: 0;
}

.manual-viewer__actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex: 0 0 auto;
}

/* Close is a destination, not a sibling of the save actions — set it apart. */
.manual-viewer__btn--close {
    margin-left: 0.35rem;
}

.manual-viewer__btn--close::before {
    content: "";
    position: absolute;
    left: -0.4rem;
    width: 1px;
    height: 1.35rem;
    background: var(--portal-divider, var(--tv-line));
}

.manual-viewer__title {
    font-size: 0.98rem;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.manual-viewer__sub {
    font-size: 0.79rem;
    font-weight: 300;
    color: rgba(255, 255, 255, 0.5);
}

.manual-viewer__btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-width: 2.3rem;
    height: 2.3rem;
    padding: 0 0.85rem;
    border: 1px solid var(--portal-inner-border, var(--tv-line));
    border-radius: var(--portal-radius-btn, 999px);
    background: var(--portal-inner-bg, var(--tv-surface-hover-solid));
    color: var(--portal-text-main, rgba(255, 255, 255, 0.82));
    font-size: 0.8rem;
    font-weight: 500;
    font-family: inherit;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease;
}

.manual-viewer__btn i {
    display: block;
    line-height: 1;
}

.manual-viewer__btn:hover {
    background: var(--tv-surface-hover);
    color: var(--portal-text, rgba(248, 250, 255, 0.94));
    border-color: rgba(255, 255, 255, 0.2);
}

.manual-viewer__btn--primary {
    background: var(--tv-cta-ghost-bg-hover);
    border-color: var(--tv-cta-ghost-border-hover);
    color: #fff;
    box-shadow: var(--tv-cta-ghost-shadow);
    backdrop-filter: var(--tv-cta-ghost-blur);
    -webkit-backdrop-filter: var(--tv-cta-ghost-blur);
}

.manual-viewer__btn--primary:hover {
    background: var(--tv-surface-active);
    border-color: rgba(255, 255, 255, 0.4);
    color: #fff;
}

.manual-viewer__btn:disabled {
    opacity: 0.4;
    cursor: default;
}

/* Square, icon-only. */
.manual-viewer__btn--icon {
    width: 2.3rem;
    padding: 0;
}

/* ── Floating dock (reading controls) ── */

/*
 * Two mirrored triads flanking a divider:
 *   [icon] [readout] [icon]  │  [icon] [readout] [icon]
 * Both readout slots share one width so the halves balance exactly, and the
 * fit label can flip between "Fit page"/"Fit width" without shifting anything.
 */
.manual-viewer__dock {
    --dock-slot: 2.2rem;
    --dock-readout: 5.1rem;

    position: absolute;
    bottom: 1.15rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    max-width: calc(100% - 1.5rem);
    padding: 0.32rem;
    border: 1px solid rgba(255, 255, 255, 0.11);
    border-radius: var(--portal-radius-btn, 999px);
    background: rgba(18, 19, 23, 0.93);
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(12px) saturate(140%);
    -webkit-backdrop-filter: blur(12px) saturate(140%);
}

/* display:flex would otherwise beat the UA [hidden] rule. */
.manual-viewer__dock[hidden] {
    display: none;
}

.manual-viewer__dock-group {
    display: flex;
    align-items: center;
    gap: 0.15rem;
}

.manual-viewer__dock-divider {
    width: 1px;
    height: 1.35rem;
    margin: 0 0.28rem;
    background: rgba(255, 255, 255, 0.13);
}

/*
 * Every dock child is the same fixed-height centred flex box with
 * line-height: 1. Left to their natural line boxes, the text slots and the
 * icon buttons centre on different metrics and the readout floats high.
 */
.manual-viewer__dock-btn,
.manual-viewer__page-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: var(--dock-slot);
    padding: 0;
    line-height: 1;
    font-family: inherit;
}

.manual-viewer__dock-btn {
    width: var(--dock-slot);
    border: none;
    border-radius: var(--portal-radius-btn, 999px);
    background: transparent;
    color: var(--portal-text-main, rgba(255, 255, 255, 0.82));
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.16s ease, color 0.16s ease;
}

.manual-viewer__dock-btn i {
    display: block;
    line-height: 1;
}

.manual-viewer__dock-btn:hover {
    background: var(--tv-surface-active);
    color: var(--portal-text, rgba(248, 250, 255, 0.94));
}

.manual-viewer__dock-btn:active {
    background: var(--tv-cta-ghost-bg-hover);
    color: #fff;
}

/* The two text readouts — identical widths keep the dock mirrored. */
.manual-viewer__dock-btn--wide,
.manual-viewer__page-label {
    width: var(--dock-readout);
    font-size: 0.78rem;
    font-weight: 500;
}

.manual-viewer__page-label {
    color: var(--portal-text-soft, rgba(255, 255, 255, 0.52));
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.manual-viewer__fit-label {
    white-space: nowrap;
}

/*
 * min-height: 0 lets this flex child shrink to the leftover space instead of
 * its content height — without it the stage grows past the viewport and the
 * fit-to-screen measurement reads a stale height.
 */
.manual-viewer__stage {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    /* Bottom padding clears the floating dock. stageBox() reads this computed
       padding, so fit-to-screen sizes pages to the space above the dock. */
    padding: 0.75rem 0.75rem 4.4rem;
    -webkit-overflow-scrolling: touch;
}

.manual-viewer__pages {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    margin: 0 auto;
}

.manual-viewer__page {
    position: relative;
    background: #fff;
    border-radius: 4px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

.manual-viewer__page canvas {
    display: block;
    width: 100%;
    height: auto;
}

.manual-viewer__status {
    padding: 3rem 1rem;
    text-align: center;
    font-size: 0.96rem;
    font-weight: 300;
    color: rgba(255, 255, 255, 0.62);
}

.manual-viewer__spinner {
    width: 1.6rem;
    height: 1.6rem;
    margin: 0 auto 0.85rem;
    border: 2px solid rgba(255, 255, 255, 0.16);
    border-top-color: rgba(255, 255, 255, 0.7);
    border-radius: 50%;
    animation: manual-viewer-spin 0.8s linear infinite;
}

/* account-manuals.css's rescan button also spins on these keyframes. */
@keyframes manual-viewer-spin {
    to {
        transform: rotate(360deg);
    }
}

body.manual-viewer-open {
    overflow: hidden;
}

/* ── Responsive ── */

@media (max-width: 720px) {
    .manual-viewer__bar {
        gap: 0.6rem;
        padding: 0.6rem 0.7rem;
    }

    /* Icons only — the header must stay one row next to a truncated title. */
    .manual-viewer__btn-label {
        display: none;
    }

    .manual-viewer__btn {
        width: 2.3rem;
        padding: 0;
    }

    /* Tighten the whole dock rather than dropping the fit label — it is that
       button's only content, so hiding it would leave an empty square. */
    .manual-viewer__dock {
        --dock-slot: 2.1rem;
        --dock-readout: 4.5rem;
        gap: 0.2rem;
    }

    .manual-viewer__dock-btn--wide,
    .manual-viewer__page-label {
        font-size: 0.73rem;
    }

    .manual-viewer__sub {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}
