/* TTW Flipbook viewer chrome
   ────────────────────────────────────────────────────────────
   The viewer wraps the react-pageflip canvas with a top bar,
   bottom bar, side nav arrows, and a loading state.
*/

/* === Wrapper & viewer shell ============================================ */

.ttw-flipbook-wrapper {
    margin: 1.5rem auto;
    max-width: 100%;
    box-sizing: border-box;
}

.ttw-flipbook-container {
    width: 100%;
    min-height: 200px;
}

.ttw-viewer {
    --ttw-brand: #F58220;
    --ttw-text: #1c1c1c;
    --ttw-muted: #6b7280;
    --ttw-border: #e5e7eb;
    --ttw-bg: #fff;
    --ttw-stage-bg: #f5f5f0;

    display: flex;
    flex-direction: column;
    background: var(--ttw-stage-bg);
    border: 1px solid var(--ttw-border);
    border-radius: 6px;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--ttw-text);
    /* Default inline height so the stage has room to render. */
    height: 80vh;
    min-height: 600px;
    max-height: 900px;
}

.ttw-viewer-fullscreen {
    position: fixed;
    inset: 0;
    z-index: 999999;
    height: 100vh;
    max-height: none;
    border-radius: 0;
    border: none;
}

/* === Top bar =========================================================== */

.ttw-viewer-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 1.25rem;
    background: var(--ttw-bg);
    border-bottom: 1px solid var(--ttw-border);
    flex-shrink: 0;
    min-height: 56px;
    box-sizing: border-box;
}

.ttw-viewer-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.ttw-viewer-logo {
    height: 28px;
    width: auto;
    display: block;
}

.ttw-viewer-logo-text {
    font-weight: 800;
    font-size: 18px;
    letter-spacing: 0.02em;
    line-height: 1;
}

.ttw-viewer-divider {
    width: 1px;
    height: 24px;
    background: var(--ttw-border);
    flex-shrink: 0;
}

.ttw-viewer-title {
    font-size: 15px;
    font-weight: 500;
    color: var(--ttw-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.ttw-viewer-tools {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-shrink: 0;
}

.ttw-viewer-pages {
    font-size: 13px;
    color: var(--ttw-muted);
    margin-right: 0.5rem;
    font-variant-numeric: tabular-nums;
}

.ttw-viewer-iconbtn {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--ttw-border);
    border-radius: 6px;
    /* Icons inherit colour via currentColor on the SVGs, so setting
       color on the button paints the icon. Brand orange by default. */
    color: var(--ttw-brand);
    cursor: pointer;
    padding: 0;
    transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.05s;
}

.ttw-viewer-iconbtn:hover {
    background: var(--ttw-brand);
    border-color: var(--ttw-brand);
    color: #fff;
}

.ttw-viewer-iconbtn:focus-visible {
    outline: 2px solid var(--ttw-brand);
    outline-offset: 2px;
}

.ttw-viewer-iconbtn:active {
    transform: translateY(1px);
}

/* === Stage (centre) ==================================================== */

.ttw-viewer-stage {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 1.5rem;
    box-sizing: border-box;
}

.ttw-viewer-zoom-wrap {
    transition: transform 0.25s ease;
    transform-origin: center center;
    max-width: 100%;
    max-height: 100%;
}

/* === Side nav arrows =================================================== */

.ttw-viewer-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--ttw-border);
    border-radius: 50%;
    color: var(--ttw-brand);
    cursor: pointer;
    z-index: 5;
    backdrop-filter: blur(4px);
    transition: background 0.15s, color 0.15s, transform 0.15s, opacity 0.15s;
    padding: 0;
}

.ttw-viewer-nav-prev { left: 0.75rem; }
.ttw-viewer-nav-next { right: 0.75rem; }

.ttw-viewer-nav:hover:not(:disabled) {
    background: var(--ttw-brand);
    color: #fff;
    transform: translateY(-50%) scale(1.05);
}

.ttw-viewer-nav:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* === Loading overlay =================================================== */

.ttw-viewer-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--ttw-stage-bg);
    z-index: 10;
    gap: 1rem;
}

.ttw-viewer-loading-book {
    display: flex;
    gap: 4px;
    opacity: 0.5;
}

.ttw-viewer-loading-page {
    width: 180px;
    height: 240px;
    background: #fff;
    border-radius: 2px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.ttw-viewer-loading-spinner {
    position: absolute;
    width: 48px;
    height: 48px;
    border: 4px solid rgba(0, 0, 0, 0.08);
    border-top-color: var(--ttw-brand);
    border-radius: 50%;
    animation: ttw-spin 0.8s linear infinite;
}

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

.ttw-viewer-loading-text {
    color: var(--ttw-muted);
    font-size: 14px;
    margin-top: 60px;
}

/* === Bottom bar ======================================================== */

.ttw-viewer-bottombar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 1.25rem;
    background: var(--ttw-bg);
    border-top: 1px solid var(--ttw-border);
    flex-shrink: 0;
    min-height: 56px;
    box-sizing: border-box;
}

.ttw-viewer-bottom-spacer { flex: 1; }

.ttw-viewer-bottom-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.ttw-viewer-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 1.1rem;
    border: 1px solid transparent;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: opacity 0.15s, transform 0.05s, background 0.15s;
    line-height: 1;
}

.ttw-viewer-btn-ghost {
    background: transparent;
    border-color: var(--ttw-border);
    color: var(--ttw-text);
}

/* Inside the ghost button, the icon (SVG) picks up brand colour while the
   label text stays neutral. Targets the SVG specifically. */
.ttw-viewer-btn-ghost svg {
    color: var(--ttw-brand);
}

.ttw-viewer-btn-ghost:hover {
    background: var(--ttw-brand);
    border-color: var(--ttw-brand);
    color: #fff;
}

.ttw-viewer-btn-ghost:hover svg {
    color: #fff;
}

.ttw-viewer-btn-primary {
    background: var(--ttw-brand);
    border-color: var(--ttw-brand);
    color: #fff;
}

.ttw-viewer-btn-primary:hover {
    opacity: 0.9;
    color: #fff;
}

.ttw-viewer-btn:active { transform: translateY(1px); }

/* === Pages (rendered into stf__block by react-pageflip) ================ */

.ttw-page {
    background: #fff;
    overflow: hidden;
    width: 100%;
    height: 100%;
    box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.1);
}

.ttw-page-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    user-select: none;
    pointer-events: none;
}

.ttw-flipbook-book { margin: 0 auto; }

/* === Mobile ============================================================ */

@media (max-width: 600px) {
    .ttw-viewer { height: 100vh; max-height: none; min-height: 0; border-radius: 0; }
    .ttw-viewer-topbar, .ttw-viewer-bottombar { padding: 0.5rem 0.75rem; min-height: 48px; }
    .ttw-viewer-title { font-size: 14px; }
    .ttw-viewer-pages { font-size: 12px; margin-right: 0.25rem; }
    .ttw-viewer-iconbtn { width: 32px; height: 32px; }
    .ttw-viewer-stage { padding: 0.75rem; }
    .ttw-viewer-nav { width: 36px; height: 36px; }
    .ttw-viewer-nav-prev { left: 0.25rem; }
    .ttw-viewer-nav-next { right: 0.25rem; }
    .ttw-viewer-btn { padding: 0.5rem 0.85rem; font-size: 13px; }
    .ttw-viewer-loading-page { width: 100px; height: 140px; }
}
