/* ─────────────────────────────────────────────────────────────────────────────
   Epaper Manager v2.1 — Flipbook Stylesheet
   Farmers Weekly / Citizen sister-site ready
   ─────────────────────────────────────────────────────────────────────────────
   ISOLATION STRATEGY
   All rules are scoped under .epaper-flipbook-wrap so nothing leaks in or out.
   Turn.js internal elements (.turn-page-wrapper, .turn-page) are explicitly
   reset so theme accordion / tab CSS cannot collapse them.
   ───────────────────────────────────────────────────────────────────────────── */

/* ─── Custom Properties ──────────────────────────────────────────────────────── */
.epaper-flipbook-wrap {
    --ep-bg:          #1a1a1a;
    --ep-surface:     #242424;
    --ep-toolbar-bg:  #111111;
    --ep-border:      #333333;
    --ep-accent:      #c8973a;
    --ep-accent-dark: #a07828;
    --ep-text:        #e8e4dc;
    --ep-text-muted:  #888888;
    --ep-white:       #ffffff;
    --ep-shadow:      0 8px 32px rgba(0,0,0,0.6);
    --ep-radius:      4px;
    --ep-toolbar-h:   52px;
    --ep-transition:  0.2s ease;

    /* Layout */
    position: relative;
    width: 100%;
    background: var(--ep-bg);
    border: 1px solid var(--ep-border);
    border-radius: 6px;
    overflow: hidden;
    font-family: 'Helvetica Neue', Arial, sans-serif;
    color: var(--ep-text);
    margin: 32px 0;
    box-shadow: var(--ep-shadow);

    /* Stacking context — keeps us above theme dropdowns, below WP admin bar */
    isolation: isolate;
    z-index: 1;
}

/* Universal reset inside our wrapper — prevents theme inheritance */
.epaper-flipbook-wrap *,
.epaper-flipbook-wrap *::before,
.epaper-flipbook-wrap *::after {
    box-sizing: border-box;
    /* Reset common theme accordion / tab overrides */
    border-collapse: initial;
    list-style: none;
}

/* ─────────────────────────────────────────────────────────────────────────────
   TURN.JS ISOLATION
   These selectors explicitly override anything a theme might inject into
   .turn-page-wrapper or .turn-page (Bootstrap accordion, jQuery UI tabs, etc.)
   ───────────────────────────────────────────────────────────────────────────── */
.epaper-flipbook-wrap .turn-page-wrapper {
    /* Override Bootstrap / jQuery UI accordion */
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    height: auto !important;
    overflow: hidden !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    background: transparent !important;
    /* Keep Turn.js positioning */
    position: absolute !important;
}

.epaper-flipbook-wrap .turn-page {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    background: #fff !important;
    position: absolute !important;
    overflow: hidden !important;
}

/* Gradient shadow that Turn.js injects */
.epaper-flipbook-wrap .gradient {
    background: linear-gradient(to left, rgba(0,0,0,0.18), rgba(0,0,0,0)) !important;
}

/* ─── Toolbar ────────────────────────────────────────────────────────────────── */
.epaper-toolbar {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    height: var(--ep-toolbar-h);
    background: var(--ep-toolbar-bg);
    border-bottom: 1px solid var(--ep-border);
    padding: 0 12px;
    gap: 8px;
    position: relative;
    z-index: 20;
    flex-wrap: nowrap;
}

.epaper-toolbar-left,
.epaper-toolbar-center,
.epaper-toolbar-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.epaper-toolbar-center {
    flex: 1;
    justify-content: center;
}

/* Issue info */
.epaper-title-info {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.epaper-issue-number {
    font-size: 13px;
    font-weight: 700;
    color: var(--ep-accent);
    letter-spacing: 0.03em;
}

.epaper-issue-date {
    font-size: 11px;
    color: var(--ep-text-muted);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* ─── Toolbar buttons ─────────────────────────────────────────────────────────── */
.epaper-toolbar .epaper-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--ep-radius);
    color: var(--ep-text-muted);
    cursor: pointer;
    transition: color var(--ep-transition), background var(--ep-transition), border-color var(--ep-transition);
    text-decoration: none;
    flex-shrink: 0;
    /* Reset any theme button styles */
    box-shadow: none;
    outline: none;
    line-height: 1;
    font-size: 0;
}

.epaper-toolbar .epaper-btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.epaper-toolbar .epaper-btn:hover {
    color: var(--ep-white);
    background: rgba(255,255,255,0.08);
    border-color: var(--ep-border);
}

.epaper-toolbar .epaper-btn.active {
    color: var(--ep-accent);
    background: rgba(200,151,58,0.12);
    border-color: var(--ep-accent);
}

.epaper-toolbar .epaper-download-btn {
    color: var(--ep-accent) !important;
    border-color: var(--ep-accent) !important;
}

.epaper-toolbar .epaper-download-btn:hover {
    background: var(--ep-accent) !important;
    color: #111 !important;
}

/* ─── Page navigation ────────────────────────────────────────────────────────── */
.epaper-nav {
    display: flex;
    align-items: center;
    gap: 4px;
}

.epaper-page-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--ep-text-muted);
    padding: 0 4px;
}

.epaper-flipbook-wrap #epaper-page-input {
    width: 42px;
    height: 28px;
    background: var(--ep-surface);
    border: 1px solid var(--ep-border) !important;
    border-radius: var(--ep-radius);
    color: var(--ep-text);
    font-size: 12px;
    text-align: center;
    outline: none;
    transition: border-color var(--ep-transition);
    -moz-appearance: textfield;
    box-shadow: none !important;
    padding: 0;
}

.epaper-flipbook-wrap #epaper-page-input::-webkit-outer-spin-button,
.epaper-flipbook-wrap #epaper-page-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
}

.epaper-flipbook-wrap #epaper-page-input:focus {
    border-color: var(--ep-accent) !important;
}

.epaper-page-sep {
    font-size: 11px;
    color: var(--ep-text-muted);
}

/* ─── Search panel ───────────────────────────────────────────────────────────── */
.epaper-search-panel {
    background: var(--ep-surface);
    border-bottom: 1px solid var(--ep-border);
    padding: 12px 16px;
}

.epaper-search-inner {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.epaper-flipbook-wrap #epaper-search-input {
    flex: 1;
    height: 36px;
    background: var(--ep-bg);
    border: 1px solid var(--ep-border) !important;
    border-radius: var(--ep-radius);
    color: var(--ep-text);
    font-size: 13px;
    padding: 0 12px;
    outline: none;
    box-shadow: none !important;
    transition: border-color var(--ep-transition);
}

.epaper-flipbook-wrap #epaper-search-input:focus {
    border-color: var(--ep-accent) !important;
}

.epaper-btn-primary {
    height: 36px;
    padding: 0 16px;
    background: var(--ep-accent);
    color: #111;
    border: none;
    border-radius: var(--ep-radius);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--ep-transition);
    white-space: nowrap;
}

.epaper-btn-primary:hover {
    background: var(--ep-accent-dark);
}

.epaper-search-results-count {
    font-size: 12px;
    color: var(--ep-text-muted);
    white-space: nowrap;
}

.epaper-search-results {
    max-height: 220px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.epaper-search-result {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 8px 10px;
    background: var(--ep-bg);
    border-radius: var(--ep-radius);
    cursor: pointer;
    transition: background var(--ep-transition);
}

.epaper-search-result:hover {
    background: rgba(200,151,58,0.1);
}

.result-page {
    font-size: 11px;
    font-weight: 600;
    color: var(--ep-accent);
    white-space: nowrap;
    min-width: 52px;
}

.result-context {
    font-size: 12px;
    color: var(--ep-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.epaper-searching,
.epaper-no-results {
    font-size: 12px;
    color: var(--ep-text-muted);
    margin: 0;
    padding: 6px 0;
}

/* ─── Viewer area ────────────────────────────────────────────────────────────── */
.epaper-viewer-area {
    display: flex !important;
    position: relative;
    min-height: 500px;
}

/* ─── Thumbnails sidebar ─────────────────────────────────────────────────────── */
.epaper-thumbs-sidebar {
    width: 130px;
    flex-shrink: 0;
    background: var(--ep-surface);
    border-right: 1px solid var(--ep-border);
    overflow-y: auto;
    overflow-x: hidden;
    max-height: 80vh;
}

.epaper-thumbs-inner {
    padding: 10px 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.epaper-thumbs-loading {
    font-size: 11px;
    color: var(--ep-text-muted);
    text-align: center;
    padding: 20px 0;
}

.epaper-thumb {
    position: relative;
    cursor: pointer;
    border-radius: 3px;
    overflow: hidden;
    border: 2px solid transparent;
    transition: border-color var(--ep-transition), transform var(--ep-transition);
}

.epaper-thumb img {
    width: 100%;
    display: block;
}

.epaper-thumb-label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    text-align: center;
    background: rgba(0,0,0,0.6);
    color: var(--ep-text-muted);
    font-size: 10px;
    padding: 2px 0;
}

.epaper-thumb:hover {
    border-color: rgba(200,151,58,0.5);
    transform: scale(1.02);
}

.epaper-thumb.active {
    border-color: var(--ep-accent);
}

.epaper-thumb.active .epaper-thumb-label {
    color: var(--ep-accent);
}

/* ─── Flipbook stage ─────────────────────────────────────────────────────────── */
.epaper-stage {
    flex: 1;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 24px 16px 32px;
    overflow: hidden;
    position: relative;
    background:
        radial-gradient(ellipse at 50% 0%, rgba(200,151,58,0.05) 0%, transparent 60%),
        var(--ep-bg);
    min-height: 500px;
}

/* ─── Loading overlay ────────────────────────────────────────────────────────── */
.epaper-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    z-index: 10;
    background: var(--ep-bg);
}

.epaper-loading p {
    font-size: 13px;
    color: var(--ep-text-muted);
    margin: 0;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.epaper-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--ep-border);
    border-top-color: var(--ep-accent);
    border-radius: 50%;
    animation: ep-spin 0.8s linear infinite;
}

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

.epaper-progress-bar {
    width: 200px;
    height: 3px;
    background: var(--ep-border);
    border-radius: 2px;
    overflow: hidden;
}

.epaper-progress-fill {
    height: 100%;
    width: 0;
    background: var(--ep-accent);
    transition: width 0.3s ease;
    border-radius: 2px;
}

/* ─── The flipbook element itself ────────────────────────────────────────────── */
.epaper-flipbook-wrap .epaper-flipbook {
    position: relative !important;
    opacity: 0;
    transition: opacity 0.4s ease;
    transform-origin: top center;
    /* Explicit display so theme cannot collapse it */
    display: block !important;
}

.epaper-flipbook-wrap .epaper-flipbook.epaper-flipbook--visible {
    opacity: 1;
}

/* ─── Individual pages ───────────────────────────────────────────────────────── */
.epaper-flipbook-wrap .epaper-page {
    position: relative !important;
    display: block !important;
    overflow: hidden !important;
    background: #fff !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    /* Prevent theme from treating these as accordion rows */
    height: auto;
}

.epaper-flipbook-wrap .epaper-page img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.epaper-page-num {
    position: absolute;
    bottom: 6px;
    right: 8px;
    font-size: 10px;
    color: #666;
    background: rgba(255,255,255,0.85);
    padding: 1px 5px;
    border-radius: 2px;
    pointer-events: none;
    z-index: 5;
}

/* Loading placeholder */
.epaper-page--loading {
    background: #f0f0f0 !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
}

.ep-page-placeholder-num {
    font-size: 32px;
    color: #ccc;
    font-weight: 700;
}

/* ─── Share dropdown ─────────────────────────────────────────────────────────── */
.epaper-share-wrap {
    position: relative;
}

.epaper-share-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 160px;
    background: var(--ep-surface);
    border: 1px solid var(--ep-border);
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    opacity: 0;
    pointer-events: none;
    transform: translateY(-6px);
    transition: opacity var(--ep-transition), transform var(--ep-transition);
    z-index: 100;
}

.epaper-share-dropdown.open {
    opacity: 1;
    pointer-events: all;
    transform: translateY(0);
}

.epaper-share-dropdown a,
.epaper-share-dropdown button.share-copy {
    display: flex !important;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 14px;
    font-size: 13px;
    color: var(--ep-text);
    text-decoration: none;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background var(--ep-transition);
    text-align: left;
}

.epaper-share-dropdown a:hover,
.epaper-share-dropdown button.share-copy:hover {
    background: rgba(255,255,255,0.06);
}

.epaper-share-dropdown svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

.share-facebook svg { color: #1877f2; }
.share-twitter  svg { color: #1da1f2; }
.share-whatsapp svg { color: #25d366; }
.share-copy     svg { color: var(--ep-text-muted); }

/* ─── Toast ──────────────────────────────────────────────────────────────────── */
.epaper-toast {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: var(--ep-surface);
    color: var(--ep-text);
    border: 1px solid var(--ep-border);
    border-radius: 20px;
    padding: 8px 18px;
    font-size: 13px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 200;
    white-space: nowrap;
}

.epaper-toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ─── Error / Notice ─────────────────────────────────────────────────────────── */
.epaper-error {
    padding: 48px 32px;
    text-align: center;
    color: var(--ep-text-muted);
    font-size: 14px;
    width: 100%;
}

.epaper-notice {
    padding: 16px;
    background: var(--ep-surface);
    border: 1px solid var(--ep-border);
    border-radius: var(--ep-radius);
    color: var(--ep-text-muted);
    font-size: 14px;
    margin: 16px 0;
}

/* ─── Fullscreen ─────────────────────────────────────────────────────────────── */
.epaper--fullscreen {
    position: fixed !important;
    inset: 0 !important;
    z-index: 99999 !important;
    border-radius: 0 !important;
    margin: 0 !important;
    border: none !important;
}

.epaper--fullscreen .epaper-viewer-area {
    height: calc(100vh - var(--ep-toolbar-h));
}

.epaper--fullscreen .epaper-stage {
    flex: 1;
    height: 100%;
    align-items: center;
}

/* ─── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .epaper-toolbar-left { display: none; }
}

@media (max-width: 768px) {
    .epaper-thumbs-sidebar { display: none; }
    .epaper-stage { padding: 12px 8px 20px; }
    .epaper-share-dropdown { right: -60px; }
}

@media (max-width: 480px) {
    #epaper-zoom-in,
    #epaper-zoom-out { display: none; }

    .epaper-toolbar .epaper-btn {
        width: 30px;
        height: 30px;
    }

    .epaper-toolbar {
        padding: 0 8px;
        gap: 4px;
    }
}

/* =============================================================================
   MOBILE LIGHTBOX — full-screen swipeable single-page reader
   ============================================================================= */

/* Prevent body scroll when lightbox is open */
body.ep-lb-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
}

/* Lightbox backdrop */
.ep-lb {
    position: fixed;
    inset: 0;
    z-index: 999999;
    background: #000;
    display: flex;
    flex-direction: column;
    overscroll-behavior: contain;
}

/* Top bar */
.ep-lb-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 52px;
    background: #111;
    border-bottom: 1px solid #222;
    padding: 0 8px;
    flex-shrink: 0;
    z-index: 2;
}

.ep-lb-bar-left,
.ep-lb-bar-right {
    display: flex;
    align-items: center;
    min-width: 52px;
}

.ep-lb-bar-right { justify-content: flex-end; }

.ep-lb-bar-center {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    justify-content: center;
}

.ep-lb-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: transparent;
    border: none;
    border-radius: 4px;
    color: #ccc;
    cursor: pointer;
    padding: 0;
    transition: color 0.15s, background 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.ep-lb-btn svg {
    width: 20px;
    height: 20px;
}

.ep-lb-btn:hover,
.ep-lb-btn:active {
    color: #fff;
    background: rgba(255,255,255,0.1);
}

.ep-lb-page-info {
    font-size: 14px;
    color: #ccc;
    white-space: nowrap;
    min-width: 70px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* Page stage */
.ep-lb-stage {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #111;
    touch-action: pan-y pinch-zoom;
}

/* The page image */
.ep-lb-img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    display: block;
    object-fit: contain;
    opacity: 0;
    transition: opacity 0.2s ease;
    user-select: none;
    -webkit-user-drag: none;
}

.ep-lb-img.visible {
    opacity: 1;
}

/* Spinner */
.ep-lb-spinner {
    position: absolute;
    width: 36px;
    height: 36px;
    border: 3px solid #333;
    border-top-color: #c8973a;
    border-radius: 50%;
    animation: ep-spin 0.8s linear infinite;
}

/* Swipe hint */
.ep-lb-swipe-hint {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: rgba(0,0,0,0.7);
    color: #fff;
    font-size: 13px;
    padding: 8px 18px;
    border-radius: 20px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    white-space: nowrap;
    z-index: 5;
}

.ep-lb-swipe-hint.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Mobile hint on the flipbook stage */
.epaper-mobile-hint {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%) translateY(6px);
    background: rgba(200,151,58,0.92);
    color: #111;
    font-size: 13px;
    font-weight: 600;
    padding: 8px 18px;
    border-radius: 20px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    white-space: nowrap;
    z-index: 10;
}

.epaper-mobile-hint.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Open lightbox button in toolbar */
.epaper-lb-open-btn {
    display: inline-flex;
}

/* On desktop, hide the lightbox open button (it's mainly for mobile) */
@media (min-width: 768px) {
    .epaper-lb-open-btn {
        display: none;
    }
}

/* On mobile, reduce the flipbook to a preview and make it tappable */
@media (max-width: 767px) {
    .epaper-stage {
        cursor: pointer;
    }

    .epaper-flipbook-wrap .epaper-flipbook {
        pointer-events: none; /* prevent Turn.js drag on mobile — use lightbox instead */
    }
}
