/*
 * PDF reader component – shared by handbook.html and news.html.
 * (toolbar, scrolling stage, loading / "coming soon" / error states)
 * Needs css/index.css tokens (--site-bg, .input) and Bootstrap Icons.
 */

body.hb-lock {
    overflow: hidden;
}

/* ------------------------------------------------------------------ viewer */
.hb-viewer {
    display: flex;
    flex-direction: column;
    width: 90%;
    max-width: 1100px;
    height: clamp(480px, 85vh, 920px);
    margin: 0 auto 4rem;
    border: 1px solid #000;
    border-radius: 0.5rem;
    overflow: hidden;
    background: var(--site-bg, #b6ccd7);
}

.hb-viewer:fullscreen,
.hb-viewer.is-fullscreen {
    width: 100%;
    max-width: none;
    height: 100vh;
    margin: 0;
    border: 0;
    border-radius: 0;
}

.hb-viewer.is-fullscreen {
    position: fixed;
    inset: 0;
    z-index: 100;
}

.hb-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1rem;
    padding: 0.5rem 0.75rem;
    background: #fff;
    border-bottom: 1px solid #000;
}

.hb-group {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.hb-group--end {
    margin-left: auto;
}

/* same look as the outline translate button in the header: black border, fills on hover */
.hb-tool {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    border: 1px solid #000;
    border-radius: 5px;
    background: transparent;
    color: #000;
    font-size: 1rem;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.3s, color 0.3s;
}

.hb-tool:hover:not(:disabled) {
    background: #000;
    color: #fff;
    text-decoration: none;
}

.hb-tool:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.hb-tool:focus-visible,
.input.hb-page-input:focus-visible,
.hb-state .btn:focus-visible {
    outline: 3px solid #000;
    outline-offset: 2px;
}

/* builds on the shared .input from index.css */
.input.hb-page-input {
    width: 4rem;
    min-width: 0;
    height: 2.25rem;
    padding: 0 0.25rem;
    border-color: #000;
    text-align: center;
    font-size: 0.95rem;
}

.hb-info,
.hb-zoom-label {
    font-size: 0.9rem;
    white-space: nowrap;
}

.hb-zoom-label {
    min-width: 3.25rem;
    text-align: center;
}

.hb-notice {
    margin: 0;
    padding: 0.5rem 0.75rem;
    background: #fff7d6;
    border-bottom: 1px solid #000;
    font-size: 0.9rem;
}

.hb-notice:empty {
    display: none;
}

.hb-stage {
    position: relative;
    flex: 1;
    min-height: 0;
    padding: 1rem;
    overflow: auto;
    background: var(--site-bg, #b6ccd7);
    -webkit-overflow-scrolling: touch;
}

.hb-stage:focus-visible {
    outline: 3px solid #000;
    outline-offset: -3px;
}

.hb-pages {
    display: none;
    flex-direction: column;
    align-items: center;
    width: max-content;
    min-width: 100%;
}

.hb-page {
    flex: none;
    margin-bottom: 1rem;
    background: #fff;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}

.hb-page canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.hb-frame {
    display: none;
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    background: #fff;
}

.hb-state {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 2rem;
    background: var(--site-bg, #b6ccd7);
    text-align: center;
}

.hb-state__loading,
.hb-state__error {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.hb-state__error h2 {
    margin: 0;
    font-size: 1.4rem;
    font-weight: 700;
}

.hb-state__error p {
    margin: 0;
    max-width: 420px;
    color: #232323;
}

/* "coming soon" state: shown when a handbook file is not published yet */
.hb-state__soon {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 0.9rem;
    text-align: center;
}

.hb-state__soon h2 {
    margin: 0;
    font-size: 1.6rem;
    font-weight: 700;
}

.hb-state__soon p {
    margin: 0;
    max-width: 460px;
    color: #232323;
}

.hb-soon__art {
    max-width: 100%;
    height: auto;
}

/* viewer modes */
.hb-viewer[data-mode="pdf"] .hb-pages {
    display: flex;
}

.hb-viewer[data-mode="frame"] .hb-frame {
    display: block;
}

.hb-viewer[data-mode="loading"] .hb-state,
.hb-viewer[data-mode="soon"] .hb-state,
.hb-viewer[data-mode="error"] .hb-state {
    display: flex;
}

.hb-viewer[data-mode="loading"] .hb-state__loading,
.hb-viewer[data-mode="error"] .hb-state__error {
    display: flex;
}

.hb-viewer[data-mode="soon"] .hb-state__soon {
    display: flex;
}

.hb-viewer[data-mode="loading"] .hb-toolbar,
.hb-viewer[data-mode="soon"] .hb-toolbar,
.hb-viewer[data-mode="error"] .hb-toolbar {
    display: none;
}

.hb-viewer:not([data-mode="pdf"]) [data-pdf-only] {
    display: none;
}

.hb-spinner {
    width: 2.5rem;
    height: 2.5rem;
    border: 4px solid rgba(0, 0, 0, 0.15);
    border-top-color: #000;
    border-radius: 50%;
    animation: hb-spin 0.9s linear infinite;
}

@keyframes hb-spin {
    to {
        transform: rotate(360deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    .hb-spinner {
        animation-duration: 3s;
    }

    .hb-choice,
    .hb-tool {
        transition: none;
    }
}

@media (max-width: 575.98px) {
    .hb-viewer {
        width: 100%;
        border-left: 0;
        border-right: 0;
        border-radius: 0;
    }

    .hb-stage {
        padding: 0.5rem;
    }

    .hb-group--end {
        margin-left: 0;
    }
}
