/* Newsletter PDF viewer. Port of the old assets/css/pdf-viewer.css (icons now inline SVG). */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    background: #fff;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Main container */
#viewer-container {
    position: relative;
    width: 100%;
    height: 100%;
}

/* Pages container. Scrolls when the page is zoomed or fitted to width; the page centres
   itself with auto margins (flex centring would cut off the top/left when it overflows). */
#book {
    z-index: 1;
    width: 100%;
    height: 100%;
    display: flex;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    /* Pinch is handled by the viewer so it can re-render the page sharply. */
    touch-action: pan-x pan-y;
}

/* Navigation arrows. Kept clear of the edges so they never sit on top of a scrollbar. */
.nav-arrow {
    position: absolute;
    top: 50%;
    margin-top: -40px;
    width: 60px;
    height: 80px;
    z-index: 20;
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 22px;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}

/* Always-visible circular badge so the arrow reads on white pages and photos alike. */
.nav-arrow .icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.28);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    transition: background 0.2s, transform 0.1s;
}

.nav-arrow:hover .icon {
    background: rgba(0, 0, 0, 0.55);
}

.nav-arrow:active .icon {
    transform: scale(0.92);
}

.nav-prev {
    left: 12px;
    border-radius: 0;
}

.nav-next {
    right: 12px;
    border-radius: 0;
}

/* Page indicator */
.page-indicator {
    position: absolute;
    bottom: 18px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    color: #6D6E71;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    background: rgba(255, 255, 255, 0.85);
    padding: 3px 12px;
    border-radius: 12px;
    user-select: none;
    pointer-events: none;
}

/* Controls (zoom, fullscreen, download) */
.viewer-controls {
    position: absolute;
    bottom: 18px;
    right: 24px;
    z-index: 20;
    display: flex;
    gap: 6px;
}

.viewer-controls button {
    background: rgba(255, 255, 255, 0.85);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    cursor: pointer;
    color: #6D6E71;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.viewer-controls button:hover {
    background: #96D6D3;
    color: #fff;
}

.viewer-controls button:disabled {
    opacity: 0.4;
    cursor: default;
    background: rgba(255, 255, 255, 0.85);
    color: #6D6E71;
}

/* Loading overlay */
#loading-overlay {
    position: absolute;
    inset: 0;
    z-index: 30;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #fff;
    color: #6D6E71;
    font-size: 14px;
    gap: 12px;
}

#loading-overlay .spinner {
    width: 36px;
    height: 36px;
    border: 3px solid #ddd;
    border-top-color: #96D6D3;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Error overlay */
#error-overlay {
    position: absolute;
    inset: 0;
    z-index: 30;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #fff;
    color: #6D6E71;
    font-size: 16px;
    text-align: center;
    padding: 20px;
    gap: 12px;
}

#error-overlay .icon {
    width: 48px;
    height: 48px;
    color: #ccc;
}

/* Page wrappers (canvas + text layer + annotation layer stacked) */
.pdf-page {
    display: none;
    position: relative;
    flex: none;
    margin: auto;
}

.pdf-page.active {
    display: block;
}

.pdf-page canvas {
    display: block;
    position: relative;
    z-index: 1;
}

/* Text layer — transparent selectable text over the canvas */
.pdf-page .textLayer {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 2;
    overflow: clip;
    opacity: 1;
    line-height: 1;
    text-size-adjust: none;
    forced-color-adjust: none;
    transform-origin: 0 0;
    caret-color: CanvasText;
}

.pdf-page .textLayer span,
.pdf-page .textLayer br {
    color: transparent;
    position: absolute;
    white-space: pre;
    cursor: text;
    transform-origin: 0% 0%;
}

.pdf-page .textLayer ::selection {
    background: rgba(150, 214, 211, 0.4);
}

/* Annotation layer — holds the clickable links */
.pdf-page .annotationLayer {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 3;
    transform-origin: 0 0;
}

.pdf-page .annotationLayer section {
    position: absolute;
    text-align: initial;
    pointer-events: auto;
    box-sizing: border-box;
}

.pdf-page .annotationLayer .linkAnnotation > a {
    position: absolute;
    width: 100%;
    height: 100%;
    display: block;
}

/* Icons (inline SVG, 1em, currentColor) */
.icon svg {
    width: 1em;
    height: 1em;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-linejoin: round;
    display: block;
}
#error-overlay .icon svg {
    width: 100%;
    height: 100%;
}
#btn-fullscreen .icon-compress,
#btn-fullscreen.is-fullscreen .icon-expand {
    display: none;
}
#btn-fullscreen.is-fullscreen .icon-compress {
    display: block;
}

/* Fullscreen */
body.fullscreen {
    background: #2a2a2a;
}

body.fullscreen #viewer-container {
    background: #2a2a2a;
}

body.fullscreen .page-indicator {
    background: rgba(50, 50, 50, 0.85);
    color: #ccc;
}

body.fullscreen .viewer-controls button {
    background: rgba(50, 50, 50, 0.85);
    color: #ccc;
}

body.fullscreen .viewer-controls button:hover {
    background: #96D6D3;
    color: #fff;
}

body.fullscreen .viewer-controls button:disabled {
    background: rgba(50, 50, 50, 0.85);
    color: #ccc;
}

body.fullscreen .nav-arrow:hover .icon {
    background: rgba(255, 255, 255, 0.18);
}

/* Mobile */
@media (max-width: 736px) {
    .nav-arrow {
        width: 40px;
        font-size: 18px;
    }

    .nav-prev {
        left: 0;
    }

    .nav-next {
        right: 0;
    }

    .page-indicator {
        font-size: 12px;
        bottom: 4px;
        padding: 2px 10px;
    }

    .viewer-controls {
        bottom: 4px;
        right: 6px;
    }

    .viewer-controls button {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }
}
