/* ============================================================
   DesaAI PDF Viewer - Digital Book UX
   ============================================================ */
.aib-pdf {
    --pdf-accent: var(--aib-primary, #7c3aed);
    --pdf-ink: #1e1b4b;
    --pdf-paper: #fffdf8;
    --pdf-paper-edge: #e9e4d8;
    --pdf-desk: #171321;
    --pdf-muted: #a8a1b6;
    --pdf-border: rgba(255, 255, 255, .13);
    --pdf-radius: var(--aib-radius, 18px);
    position: relative;
    width: 100%;
    border-radius: var(--pdf-radius);
    background: radial-gradient(ellipse at 50% 0%, #322743 0%, #171321 55%, #0d0a15 100%);
    color: #f5f3ff;
    overflow: hidden;
    font-family: var(--aib-font, 'Poppins', system-ui, sans-serif);
    box-shadow: 0 22px 60px rgba(15, 10, 25, .35);
    border: 1px solid rgba(255, 255, 255, .06);
}
.aib-pdf * { box-sizing: border-box; }

.aib-pdf-shell { display: flex; flex-direction: column; width: 100%; }

/* ---------- Toolbar ---------- */
.aib-pdf-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: rgba(10, 8, 18, .72);
    border-bottom: 1px solid var(--pdf-border);
    backdrop-filter: blur(10px);
    flex-wrap: wrap;
}
.aib-pdf-title {
    flex: 1 1 180px;
    min-width: 0;
    font-size: .84rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #f5f3ff;
    letter-spacing: .01em;
}
.aib-pdf-group { display: inline-flex; align-items: center; gap: 4px; }
.aib-pdf-btn {
    appearance: none;
    border: 1px solid rgba(255, 255, 255, .14);
    background: rgba(255, 255, 255, .07);
    color: #ece8ff;
    width: 34px;
    height: 34px;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    transition: .16s ease;
    padding: 0;
    text-decoration: none;
}
.aib-pdf-btn:hover:not(:disabled) {
    border-color: var(--pdf-accent);
    background: color-mix(in srgb, var(--pdf-accent) 28%, transparent);
    color: #fff;
    transform: translateY(-1px);
}
.aib-pdf-btn:disabled { opacity: .32; cursor: not-allowed; }
.aib-pdf-btn svg { width: 16px; height: 16px; display: block; }
.aib-pdf-pageinfo {
    min-width: 84px;
    text-align: center;
    font-size: .76rem;
    font-weight: 700;
    color: #cfc8e0;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.aib-pdf-zoom {
    min-width: 52px;
    text-align: center;
    font-size: .72rem;
    font-weight: 700;
    color: #a9a2bb;
    font-variant-numeric: tabular-nums;
}
.aib-pdf-download { text-decoration: none; }

/* ---------- Book stage ---------- */
.aib-pdf-book-stage {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 34px 30px;
    background:
        radial-gradient(ellipse at 50% -10%, rgba(124, 58, 237, .24), transparent 55%),
        radial-gradient(ellipse at 50% 120%, rgba(0, 0, 0, .5), transparent 60%),
        linear-gradient(180deg, #1b1628, #0f0c17);
    overflow: auto;
    min-height: 380px;
}

.aib-pdf-spread {
    position: relative;
    display: flex;
    align-items: stretch;
    justify-content: center;
    width: max-content;
    margin: auto;
    perspective: 2400px;
    transition: width .34s ease, height .34s ease;
    filter: drop-shadow(0 34px 42px rgba(0, 0, 0, .5));
    scrollbar-width: thin;
}
.aib-pdf-spread::before,
.aib-pdf-spread::after {
    content: '';
    position: absolute;
    top: 5px;
    bottom: 5px;
    width: 7px;
    background: repeating-linear-gradient(90deg, var(--pdf-paper-edge) 0 1px, #fbf8f1 1px 3px);
    z-index: -1;
    opacity: .95;
}
.aib-pdf-spread::before { left: -7px; border-radius: 6px 0 0 6px; box-shadow: -2px 4px 10px rgba(0,0,0,.3); }
.aib-pdf-spread::after { right: -7px; border-radius: 0 6px 6px 0; box-shadow: 2px 4px 10px rgba(0,0,0,.3); }
.aib-pdf-spread.is-cover::before { display: none; }
.aib-pdf-spread.is-single::before { display: none; }
.aib-pdf-spread.is-cover::after { width: 9px; }

.aib-pdf-sheet {
    position: relative;
    flex: 0 0 auto;
    background: var(--pdf-paper);
    overflow: hidden;
    border-radius: 4px 10px 10px 4px;
    transition: width .34s ease, height .34s ease;
}
.aib-pdf-sheet-left { border-radius: 10px 4px 4px 10px; }
.aib-pdf-sheet.is-hidden { display: none; }
.aib-pdf-sheet::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        radial-gradient(120% 70% at 50% -10%, rgba(255, 255, 255, .7), transparent 40%),
        linear-gradient(180deg, rgba(0, 0, 0, .02), transparent 8%, transparent 92%, rgba(0, 0, 0, .05));
    mix-blend-mode: multiply;
}
.aib-pdf-page {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--pdf-paper);
}
.aib-pdf-sheet-left .aib-pdf-page { box-shadow: inset -26px 0 34px -30px rgba(15, 23, 42, .5); }
.aib-pdf-sheet-right .aib-pdf-page { box-shadow: inset 26px 0 34px -30px rgba(15, 23, 42, .5); }
.aib-pdf-canvas { display: block; width: 100%; height: 100%; }

.aib-pdf-folio {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 6px;
    text-align: center;
    font-size: .66rem;
    font-weight: 600;
    letter-spacing: .16em;
    color: #8b8478;
    pointer-events: none;
    z-index: 2;
}
.aib-pdf-spread.is-cover .aib-pdf-folio { display: none; }

.aib-pdf-spine {
    position: relative;
    flex: 0 0 18px;
    width: 18px;
    background: linear-gradient(90deg,
        rgba(15, 23, 42, .02),
        rgba(15, 23, 42, .14) 42%,
        rgba(15, 23, 42, .3) 50%,
        rgba(15, 23, 42, .14) 58%,
        rgba(15, 23, 42, .02));
    z-index: 2;
}
.aib-pdf-spine::before,
.aib-pdf-spine::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1px;
    background: rgba(120, 105, 80, .25);
}
.aib-pdf-spine::before { left: 6px; }
.aib-pdf-spine::after { right: 6px; }
.aib-pdf-spread.is-cover .aib-pdf-spine,
.aib-pdf-spread.is-single .aib-pdf-spine { display: none; }

.aib-pdf-ribbon {
    position: absolute;
    top: -3px;
    right: 11%;
    width: 26px;
    height: 72px;
    background: linear-gradient(180deg, var(--pdf-accent), #4c1d95);
    clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 82%, 0 100%);
    z-index: 4;
    display: none;
    filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .35));
}
.aib-pdf-spread.is-cover .aib-pdf-ribbon { display: block; }

.aib-pdf-turn-shadow {
    position: absolute;
    inset: 0;
    z-index: 5;
    pointer-events: none;
    opacity: 0;
    background: linear-gradient(90deg, transparent 25%, rgba(15, 23, 42, .08) 48%, rgba(15, 23, 42, .3) 82%, rgba(15, 23, 42, .42));
}
.aib-pdf-spread.is-turn-next .aib-pdf-turn-shadow { animation: aib-pdf-sweep-next .46s ease; }
.aib-pdf-spread.is-turn-prev .aib-pdf-turn-shadow { animation: aib-pdf-sweep-prev .46s ease; }
@keyframes aib-pdf-sweep-next {
    0% { opacity: 0; transform: translateX(-26%); }
    38% { opacity: 1; }
    100% { opacity: 0; transform: translateX(24%); }
}
@keyframes aib-pdf-sweep-prev {
    0% { opacity: 0; transform: translateX(26%); }
    38% { opacity: 1; }
    100% { opacity: 0; transform: translateX(-24%); }
}
.aib-pdf-spread.is-turn-next .aib-pdf-sheet-right { animation: aib-pdf-flip-next .46s ease; transform-origin: left center; }
.aib-pdf-spread.is-turn-prev .aib-pdf-sheet-left { animation: aib-pdf-flip-prev .46s ease; transform-origin: right center; }
@keyframes aib-pdf-flip-next {
    0% { transform: rotateY(0); }
    45% { transform: rotateY(-9deg); box-shadow: -18px 0 26px rgba(0, 0, 0, .22); }
    100% { transform: rotateY(0); }
}
@keyframes aib-pdf-flip-prev {
    0% { transform: rotateY(0); }
    45% { transform: rotateY(9deg); box-shadow: 18px 0 26px rgba(0, 0, 0, .22); }
    100% { transform: rotateY(0); }
}

/* ---------- Navigation ---------- */
.aib-pdf-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 8;
    width: 46px;
    height: 68px;
    border-radius: 15px;
    border: 1px solid rgba(255, 255, 255, .16);
    background: rgba(18, 14, 28, .55);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: .18s ease;
    padding: 0;
}
.aib-pdf-nav svg { width: 20px; height: 20px; }
.aib-pdf-nav:hover:not(:disabled) {
    background: var(--pdf-accent);
    border-color: var(--pdf-accent);
    box-shadow: 0 10px 26px color-mix(in srgb, var(--pdf-accent) 40%, transparent);
}
.aib-pdf-nav:disabled { opacity: .22; cursor: not-allowed; }
.aib-pdf-nav-prev { left: 8px; }
.aib-pdf-nav-next { right: 8px; }

/* ---------- Footer ---------- */
.aib-pdf-book-foot {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 16px;
    background: rgba(10, 8, 18, .72);
    border-top: 1px solid var(--pdf-border);
}
.aib-pdf-slider {
    flex: 1;
    height: 4px;
    cursor: pointer;
    accent-color: var(--pdf-accent);
    background: transparent;
}
.aib-pdf-hint {
    font-size: .68rem;
    color: #918aa4;
    white-space: nowrap;
    letter-spacing: .02em;
}

/* ---------- Loading / error ---------- */
.aib-pdf-loading,
.aib-pdf-error {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 24px;
    text-align: center;
    background: rgba(13, 10, 21, .82);
    backdrop-filter: blur(3px);
    font-size: .8rem;
    color: #d9d3e8;
}
.aib-pdf-loading[hidden], .aib-pdf-error[hidden] { display: none; }
.aib-pdf-spinner {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, .12);
    border-top-color: var(--pdf-accent);
    animation: aib-pdf-spin .7s linear infinite;
}
@keyframes aib-pdf-spin { to { transform: rotate(360deg); } }
.aib-pdf-error strong { color: #fca5a5; }
.aib-pdf-error a { color: #c4b5fd; font-weight: 700; }

/* ---------- Placeholder ---------- */
.aib-pdf-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    min-height: 320px;
    padding: 46px 28px;
    text-align: center;
    background:
        radial-gradient(ellipse at 50% -10%, rgba(124, 58, 237, .22), transparent 60%),
        linear-gradient(180deg, #1b1628, #0f0c17);
}
.aib-pdf-placeholder-book {
    width: 104px;
    height: 136px;
    border-radius: 4px 12px 12px 4px;
    background: linear-gradient(145deg, #fdfbf5, #eee8db);
    box-shadow: 10px 14px 30px rgba(0, 0, 0, .45), inset 6px 0 10px -6px rgba(0, 0, 0, .25);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    margin-bottom: 8px;
}
.aib-pdf-placeholder-book::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 7px;
    width: 1px;
    background: rgba(120, 105, 80, .25);
}
.aib-pdf-placeholder-book span {
    font-size: 1rem;
    font-weight: 800;
    letter-spacing: .06em;
    color: #b91c1c;
}
.aib-pdf-placeholder h4 { margin: 0; font-size: 1.02rem; font-weight: 800; color: #f5f3ff; }
.aib-pdf-placeholder p { margin: 0; font-size: .82rem; color: #a9a2bb; max-width: 430px; line-height: 1.55; }
.aib-pdf-placeholder button {
    border: 0;
    background: linear-gradient(135deg, #8b5cf6, #6d28d9);
    color: #fff;
    border-radius: 999px;
    padding: 11px 20px;
    font-size: .8rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    box-shadow: 0 10px 26px rgba(109, 40, 217, .4);
    margin-top: 4px;
}
.aib-pdf-placeholder button:hover { filter: brightness(1.06); }

/* ---------- Fullscreen ---------- */
.aib-pdf:fullscreen { border-radius: 0; border: 0; display: flex; flex-direction: column; background: #0d0a15; }
.aib-pdf:fullscreen .aib-pdf-shell { flex: 1; min-height: 0; }
.aib-pdf:fullscreen .aib-pdf-book-stage { flex: 1; max-height: none; }
.aib-pdf:fullscreen .aib-pdf-spread { max-height: calc(100vh - 150px); }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
    .aib-pdf-toolbar { gap: 6px; padding: 8px 10px; }
    .aib-pdf-title { flex-basis: 100%; order: -1; font-size: .8rem; }
    .aib-pdf-pageinfo { min-width: 70px; font-size: .7rem; }
    .aib-pdf-book-stage { padding: 18px 10px; }
    .aib-pdf-nav { width: 36px; height: 54px; border-radius: 12px; }
    .aib-pdf-nav-prev { left: 3px; }
    .aib-pdf-nav-next { right: 3px; }
    .aib-pdf-book-foot { padding: 8px 10px; gap: 8px; }
    .aib-pdf-hint { display: none; }
    .aib-pdf-folio { bottom: 4px; font-size: .6rem; }
}
