/* ============================================================
   Document Library — Frontend Styles
   Native PDF viewer modal, clickable book covers, mobile-first
   ============================================================ */

:root {
    --dl-primary:    #2C3E50;
    --dl-accent:     #C0392B;
    --dl-gold:       #F0B429;
    --dl-bg:         #F8F5F0;
    --dl-paper:      #FEFDF9;
    --dl-shadow:     rgba(0,0,0,0.18);
    --dl-text:       #2C3E50;
    --dl-muted:      #7F8C8D;
    --dl-border:     #E8E0D5;
    --dl-radius:     6px;
    --dl-font-serif: 'Georgia', 'Times New Roman', serif;
    --dl-font-sans:  -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ── Library Wrapper ── */
.dl-library {
    font-family: var(--dl-font-sans);
    color: var(--dl-text);
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 16px;
}

/* ── Category Filters ── */
.dl-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 36px;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--dl-border);
}

.dl-filter-btn {
    font-family: var(--dl-font-sans);
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.04em;
    padding: 7px 18px;
    border: 1.5px solid var(--dl-border);
    border-radius: 100px;
    background: white;
    color: var(--dl-muted);
    cursor: pointer;
    transition: all 0.2s ease;
}
.dl-filter-btn:hover,
.dl-filter-btn.active {
    background: var(--dl-primary);
    border-color: var(--dl-primary);
    color: white;
}

/* ── Book Grid ── */
.dl-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 48px 32px;
}
.dl-library[data-columns="2"] .dl-grid { grid-template-columns: repeat(2, 1fr); }
.dl-library[data-columns="4"] .dl-grid { grid-template-columns: repeat(4, 1fr); }
.dl-library[data-columns="1"] .dl-grid { grid-template-columns: 1fr; }

@media (max-width: 900px) {
    .dl-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 36px 24px; }
}
@media (max-width: 560px) {
    .dl-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 24px 16px; }
}
@media (max-width: 380px) {
    .dl-grid { grid-template-columns: 1fr !important; gap: 28px; }
}

/* ── Book Item ── */
.dl-book-item {
    display: flex;
    flex-direction: column;
    transition: transform 0.2s ease;
}
.dl-book-item.dl-hidden { display: none; }

/* ── 3D Book Visual ── */
.dl-book {
    position: relative;
    width: 140px;
    height: 190px;
    margin: 0 auto 20px;
    perspective: 600px;
}

/* Clickable book: pointer cursor + hover hint */
.dl-book-clickable {
    cursor: pointer;
    outline: none;
}
.dl-book-clickable:focus-visible .dl-book-cover {
    outline: 3px solid var(--dl-gold);
    outline-offset: 4px;
}

/* "Read" hint overlay on hover */
.dl-book-open-hint {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(44,62,80,0.85);
    color: white;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 8px;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 5;
    border-radius: 0 0 4px 0;
}
.dl-book-open-hint svg { width: 14px; height: 14px; }
.dl-book-clickable:hover .dl-book-open-hint,
.dl-book-clickable:focus-visible .dl-book-open-hint {
    opacity: 1;
    transform: translateY(0);
}

@media (hover: none) {
    /* Always show hint on touch devices */
    .dl-book-open-hint { opacity: 0.85; transform: translateY(0); }
}

.dl-book-cover {
    position: relative;
    width: 140px;
    height: 190px;
    transform-origin: left center;
    transform: rotateY(-8deg);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 0.35s ease;
    box-shadow:
        6px 6px 20px rgba(0,0,0,0.25),
        2px 2px 8px rgba(0,0,0,0.15);
    border-radius: 2px 5px 5px 2px;
    overflow: hidden;
    background: var(--book-color, #8B5E3C);
}

.dl-book-clickable:hover .dl-book-cover,
.dl-book-clickable:focus-visible .dl-book-cover {
    transform: rotateY(-22deg);
    box-shadow:
        16px 8px 28px rgba(0,0,0,0.30),
        4px 4px 12px rgba(0,0,0,0.18);
}

.dl-cover-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.dl-cover-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    /* Space-between: icon top, text block centred, author pinned bottom */
    justify-content: space-between;
    padding: 16px 12px 14px;
    text-align: center;
    background: linear-gradient(
        160deg,
        var(--book-color, #8B5E3C) 0%,
        color-mix(in srgb, var(--book-color, #8B5E3C) 75%, black) 100%
    );
    box-sizing: border-box;
}

/* Icon sits at the top, small and subtle */
.dl-cover-icon {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    flex-shrink: 0;
}

.dl-cover-icon svg {
    width: 28px;
    height: 32px;
    opacity: 0.35;
    display: block;
    margin: 0 auto;
}

/* Title fills the middle — grows to take available space */
.dl-cover-title {
    font-family: var(--dl-font-serif);
    font-size: 10.5px;
    font-weight: bold;
    color: rgba(255,255,255,0.97);
    line-height: 1.35;
    margin: 0;

    text-shadow: 0 1px 3px rgba(0,0,0,0.45);
    width: 100%;
    text-align: center;
    flex: 1;                     /* stretch to fill remaining height */
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    word-break: break-word;
    hyphens: auto;
}

/* Author pinned at the bottom */
.dl-cover-author {
    font-family: var(--dl-font-serif);
    font-size: 9px;
    color: rgba(255,255,255,0.6);
    font-style: italic;
    margin: 0;
    width: 100%;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 0;
    /* Decorative separator line above author */
    padding-top: 6px;
    border-top: 1px solid rgba(255,255,255,0.2);
}

/* Inner span handles text clamping while outer div handles flex centering */
.dl-cover-title-inner {
    display: -webkit-box;
    -webkit-line-clamp: 5;       /* fits more lines at smaller font */
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
    hyphens: auto;
}


.dl-book-shadow {
    position: absolute;
    bottom: -8px; left: 10px; right: -8px;
    height: 24px;
    background: radial-gradient(ellipse at center, rgba(0,0,0,0.22) 0%, transparent 80%);
    transform: scaleY(0.4);
    transition: transform 0.35s ease, opacity 0.35s ease;
}
.dl-book-clickable:hover .dl-book-shadow {
    transform: scaleY(0.3) translateX(8px);
    opacity: 0.7;
}

/* Featured badge */
.dl-featured-badge {
    position: absolute;
    top: 10px; right: -4px;
    z-index: 10;
    background: var(--dl-gold);
    color: #5a3e00;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: 2px 0 0 2px;
    box-shadow: 2px 2px 6px rgba(0,0,0,0.2);
}
.dl-featured-badge::after {
    content: '';
    position: absolute;
    right: -4px; bottom: -4px;
    border-left: 4px solid #a07a00;
    border-bottom: 4px solid transparent;
}

/* ── Book Info ── */
.dl-book-info { text-align: center; }

.dl-book-title {
    font-family: var(--dl-font-serif);
    font-size: 15px;
    font-weight: bold;
    color: var(--dl-primary);
    margin: 0 0 4px;
    line-height: 1.4;
}

.dl-book-author {
    font-size: 13px;
    color: var(--dl-muted);
    font-style: italic;
    margin: 0 0 8px;
}

.dl-book-meta {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 5px;
    margin-bottom: 10px;
}

.dl-meta-tag {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.06em;
    padding: 2px 7px;
    border-radius: 3px;
    background: var(--dl-bg);
    color: var(--dl-muted);
    border: 1px solid var(--dl-border);
}
.dl-tag-pdf  { background: #FEF2F2; color: #C0392B; border-color: #FECACA; }
.dl-tag-docx { background: #EFF6FF; color: #1D4ED8; border-color: #BFDBFE; }

.dl-book-excerpt {
    font-size: 12px;
    color: var(--dl-muted);
    line-height: 1.5;
    margin: 0 0 14px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ── Action Buttons ── */
.dl-book-actions {
    display: flex;
    gap: 6px;
    justify-content: center;
    flex-wrap: wrap;
}

.dl-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.03em;
    padding: 7px 14px;
    border-radius: var(--dl-radius);
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s ease;
    line-height: 1;
}
.dl-btn svg { width: 13px; height: 13px; flex-shrink: 0; }

.dl-btn-large {
    font-size: 15px;
    padding: 12px 28px;
}
.dl-btn-large svg { width: 17px; height: 17px; }

.dl-btn-read { background: var(--dl-primary); color: white; }
.dl-btn-read:hover { background: #1a252f; transform: translateY(-1px); box-shadow: 0 3px 10px rgba(44,62,80,0.3); }

.dl-btn-download { color: white; text-decoration: none; }
.dl-btn-pdf  { background: var(--dl-accent); }
.dl-btn-pdf:hover  { background: #a93226; transform: translateY(-1px); box-shadow: 0 3px 10px rgba(192,57,43,0.35); color: white; }
.dl-btn-docx { background: #2563EB; }
.dl-btn-docx:hover { background: #1D4ED8; transform: translateY(-1px); box-shadow: 0 3px 10px rgba(37,99,235,0.35); color: white; }

/* ── No Results ── */
.dl-no-results {
    text-align: center;
    color: var(--dl-muted);
    font-style: italic;
    padding: 48px 0;
}

/* ==========================================================
   PDF VIEWER MODAL
   Uses the browser's native PDF renderer (WordPress default)
   ========================================================== */
.dl-reader-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 99999;
    width: 100vw;
    height: 100vh;
    height: 100dvh; /* mobile browser chrome aware */
    background: rgba(15, 12, 8, 0.96);
    backdrop-filter: blur(6px);
    align-items: stretch;
    justify-content: center;
    padding: 0;
    overflow: hidden;
}
.dl-reader-overlay.dl-open {
    display: flex;
    animation: dlFadeIn 0.2s ease;
}
@keyframes dlFadeIn { from { opacity:0 } to { opacity:1 } }

.dl-reader {
    background: var(--dl-paper);
    width: 100%;
    max-width: 100%;
    margin: 0;
    border-radius: 0;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: dlSlideUp 0.25s cubic-bezier(0.34, 1.4, 0.64, 1);
    /* Fill the entire viewport — be explicit about height */
    height: 100vh;
    height: 100dvh;
    flex: 1;
    min-height: 0;
}
@keyframes dlSlideUp { from { transform: translateY(24px); opacity:0 } to { transform:translateY(0); opacity:1 } }

/* Reader header */
.dl-reader-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px;
    background: var(--dl-primary);
    color: white;
    gap: 12px;
    flex-shrink: 0;
}

.dl-reader-title-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}
.dl-reader-book-icon svg { width: 20px; height: 20px; opacity: 0.85; }
.dl-reader-title {
    font-family: var(--dl-font-serif);
    font-size: 16px;
    font-weight: bold;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dl-reader-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.dl-reader-download {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: white;
    text-decoration: none;
    background: rgba(255,255,255,0.15);
    padding: 6px 14px;
    border-radius: 5px;
    transition: background 0.2s;
}
.dl-reader-download:hover { background: rgba(255,255,255,0.25); color: white; }
.dl-reader-download svg { width: 14px; height: 14px; }

.dl-reader-close {
    background: rgba(255,255,255,0.12);
    border: none;
    border-radius: 6px;
    color: white;
    cursor: pointer;
    padding: 6px;
    display: flex;
    align-items: center;
    transition: background 0.2s;
    touch-action: manipulation;
}
.dl-reader-close:hover { background: rgba(255,255,255,0.25); }
.dl-reader-close svg { width: 20px; height: 20px; }

/* Reader body — contains the iframe */
.dl-reader-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #525659; /* matches Chrome PDF viewer background */
    min-height: 0;
    height: 0; /* forces flex child to not overflow, makes iframe take full space */
}

/* Native browser PDF iframe */
.dl-pdf-iframe {
    width: 100%;
    height: 100%;
    flex: 1;
    border: none;
    display: block;
    min-height: 0;
    /* Helps some browsers render PDF centred/fitted to page width */
    background: #525659;
}

/* Mobile fallback panel */
.dl-mobile-fallback {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 24px;
    background: #2a2420;
}

.dl-mobile-fallback-inner {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    max-width: 320px;
}

.dl-mobile-fallback-inner svg {
    width: 64px;
    height: 64px;
}

.dl-mobile-fallback-inner p {
    color: rgba(255,255,255,0.8);
    font-size: 15px;
    line-height: 1.6;
    margin: 0;
}

/* ==========================================================
   RESPONSIVE — MOBILE
   ========================================================== */
@media (max-width: 600px) {
    .dl-reader-title { font-size: 13px; }
    .dl-reader-download span { display: none; }
    .dl-reader-download { padding: 6px 10px; }
    .dl-reader-close { padding: 8px; }
}

@media (max-width: 380px) {
    .dl-book { width: 110px; height: 150px; }
    .dl-book-cover { width: 110px; height: 150px; }
    .dl-book-title { font-size: 13px; }
}
