/* ============================================
   PDF Flipbook — Styles
   ============================================ */

/* --- Reset & Base --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-surface: rgba(255, 255, 255, 0.08);
    --bg-surface-hover: rgba(255, 255, 255, 0.15);
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0b0;
    --accent: #4a9eff;
    --accent-hover: #6bb3ff;
    --border: rgba(255, 255, 255, 0.1);
    --shadow: rgba(0, 0, 0, 0.3);
    --header-height: 90px;
    --footer-height: 52px;
    --transition-fast: 0.15s ease;
    --transition-normal: 0.2s ease;
}

/* --- Light Theme Override --- */
[data-theme="light"] {
    --bg-primary: #f0f2f5;
    --bg-secondary: #ffffff;
    --bg-surface: rgba(0, 0, 0, 0.06);
    --bg-surface-hover: rgba(0, 0, 0, 0.1);
    --text-primary: #1a1a2e;
    --text-secondary: #555566;
    --accent: #2b7de9;
    --accent-hover: #1a6bd6;
    --border: rgba(0, 0, 0, 0.12);
    --shadow: rgba(0, 0, 0, 0.1);
}

/* --- Theme Toggle Icons & Assets --- */
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: block; }

[data-theme="dark"] .theme-dark { display: block; }
[data-theme="dark"] .theme-light { display: none !important; }
[data-theme="light"] .theme-light { display: block; }
[data-theme="light"] .theme-dark { display: none !important; }

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* iOS rubber-band fix */
body {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

/* --- Utility --- */
.hidden {
    display: none !important;
}

/* --- Layout --- */
body {
    display: flex;
    flex-direction: column;
}

/* --- Header --- */
#top-bar {
    height: var(--header-height);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    z-index: 100;
}

.top-bar-left-spacer {
    flex: 1;
}

.top-bar-center {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
}

.logo-client {
    height: 32px;
    object-fit: contain;
}

.logo-header {
    height: 80px;
    max-width: 400px;
    object-fit: contain;
}

/* btn-theme sizing handled in round icon buttons section */

.top-bar-right {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

/* --- Buttons (glassmorphism base) --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, rgba(74, 158, 255, 0.1), rgba(140, 80, 255, 0.06));
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow:
        0 0 0 1px rgba(74, 158, 255, 0.15),
        0 2px 8px rgba(0, 0, 0, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.btn:hover {
    background: linear-gradient(135deg, rgba(74, 158, 255, 0.2), rgba(140, 80, 255, 0.12));
    box-shadow:
        0 0 0 1px rgba(74, 158, 255, 0.3),
        0 4px 12px rgba(74, 158, 255, 0.12),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0) scale(0.96);
    box-shadow:
        0 0 0 1px rgba(74, 158, 255, 0.2),
        0 1px 4px rgba(0, 0, 0, 0.2);
}

.btn svg {
    filter: drop-shadow(0 0 2px rgba(74, 158, 255, 0.25));
    transition: filter 0.3s ease;
}

.btn:hover svg {
    filter: drop-shadow(0 0 4px rgba(74, 158, 255, 0.45));
}

/* Light theme buttons */
[data-theme="light"] .btn {
    background: linear-gradient(135deg, rgba(43, 125, 233, 0.08), rgba(100, 60, 200, 0.04));
    box-shadow:
        0 0 0 1px rgba(43, 125, 233, 0.15),
        0 2px 8px rgba(0, 0, 0, 0.06),
        inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

[data-theme="light"] .btn:hover {
    background: linear-gradient(135deg, rgba(43, 125, 233, 0.16), rgba(100, 60, 200, 0.08));
    box-shadow:
        0 0 0 1px rgba(43, 125, 233, 0.3),
        0 4px 12px rgba(43, 125, 233, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

[data-theme="light"] .btn svg {
    filter: drop-shadow(0 0 2px rgba(43, 125, 233, 0.2));
}

[data-theme="light"] .btn:hover svg {
    filter: drop-shadow(0 0 4px rgba(43, 125, 233, 0.4));
}

/* --- Open PDF Button (animated glassmorphism) --- */
#btn-load-pdf {
    position: relative;
    padding: 12px 24px;
    border-radius: 14px;
    border: none;
    background: linear-gradient(135deg, rgba(74, 158, 255, 0.2), rgba(140, 80, 255, 0.15), rgba(74, 158, 255, 0.1));
    background-size: 200% 200%;
    animation: btn-shimmer 4s ease infinite;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    font-weight: 600;
    font-size: 14px;
    letter-spacing: 0.5px;
    color: #e8f0ff;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow:
        0 0 0 1px rgba(74, 158, 255, 0.3),
        0 4px 12px rgba(0, 0, 0, 0.25),
        0 0 20px rgba(74, 158, 255, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    overflow: hidden;
    z-index: 1;
}

#btn-load-pdf::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(135deg, rgba(74, 158, 255, 0.3), rgba(140, 80, 255, 0.2), rgba(255, 100, 180, 0.15));
    background-size: 200% 200%;
    animation: btn-shimmer 4s ease infinite;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: -1;
}

#btn-load-pdf:hover::before {
    opacity: 1;
}

#btn-load-pdf:hover {
    transform: translateY(-2px);
    box-shadow:
        0 0 0 1px rgba(74, 158, 255, 0.5),
        0 8px 24px rgba(74, 158, 255, 0.25),
        0 0 40px rgba(74, 158, 255, 0.12),
        inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

#btn-load-pdf:active {
    transform: translateY(0) scale(0.96);
    box-shadow:
        0 0 0 1px rgba(74, 158, 255, 0.4),
        0 2px 6px rgba(0, 0, 0, 0.3);
}

#btn-load-pdf svg {
    filter: drop-shadow(0 0 3px rgba(74, 158, 255, 0.4));
    transition: filter 0.3s ease;
}

#btn-load-pdf:hover svg {
    filter: drop-shadow(0 0 6px rgba(74, 158, 255, 0.6));
}

@keyframes btn-shimmer {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* Light theme */
[data-theme="light"] #btn-load-pdf {
    background: linear-gradient(135deg, rgba(43, 125, 233, 0.15), rgba(100, 60, 200, 0.1), rgba(43, 125, 233, 0.08));
    background-size: 200% 200%;
    color: #1a3a5c;
    box-shadow:
        0 0 0 1px rgba(43, 125, 233, 0.25),
        0 4px 12px rgba(0, 0, 0, 0.08),
        0 0 20px rgba(43, 125, 233, 0.06),
        inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

[data-theme="light"] #btn-load-pdf::before {
    background: linear-gradient(135deg, rgba(43, 125, 233, 0.25), rgba(100, 60, 200, 0.15), rgba(220, 80, 150, 0.1));
    background-size: 200% 200%;
}

[data-theme="light"] #btn-load-pdf:hover {
    box-shadow:
        0 0 0 1px rgba(43, 125, 233, 0.4),
        0 8px 24px rgba(43, 125, 233, 0.15),
        0 0 40px rgba(43, 125, 233, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

[data-theme="light"] #btn-load-pdf svg {
    filter: drop-shadow(0 0 3px rgba(43, 125, 233, 0.3));
}

[data-theme="light"] #btn-load-pdf:hover svg {
    filter: drop-shadow(0 0 6px rgba(43, 125, 233, 0.5));
}

/* --- Round icon buttons (nav, zoom, theme) --- */
.btn-nav, .btn-zoom, .btn-theme {
    padding: 8px;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-nav:hover, .btn-zoom:hover, .btn-theme:hover {
    box-shadow:
        0 0 0 1px rgba(74, 158, 255, 0.35),
        0 4px 14px rgba(74, 158, 255, 0.15),
        0 0 20px rgba(74, 158, 255, 0.06),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

[data-theme="light"] .btn-nav:hover,
[data-theme="light"] .btn-zoom:hover,
[data-theme="light"] .btn-theme:hover {
    box-shadow:
        0 0 0 1px rgba(43, 125, 233, 0.3),
        0 4px 14px rgba(43, 125, 233, 0.1),
        0 0 20px rgba(43, 125, 233, 0.05),
        inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

/* --- Main Content --- */
#main-content {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bg-logo {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 85%;
    height: 85%;
    object-fit: contain;
    opacity: 0.15;
    pointer-events: none;
    z-index: 0;
}

/* --- Drop Zone --- */
#drop-zone {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

.drop-zone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 48px 64px;
    border: 2px dashed var(--border);
    border-radius: 16px;
    color: var(--text-secondary);
    transition: border-color var(--transition-normal), background var(--transition-normal);
}

#drop-zone.drag-over .drop-zone-content {
    border-color: var(--accent);
    background: rgba(74, 158, 255, 0.08);
}

.drop-zone-content p {
    font-size: 18px;
}

.drop-zone-hint {
    font-size: 14px !important;
    opacity: 0.6;
}

/* --- Loading Overlay --- */
#loading-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    background: var(--bg-primary);
    z-index: 60;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

#loading-overlay p {
    color: var(--text-secondary);
    font-size: 16px;
}

/* --- Flipbook Wrapper --- */
#flipbook-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
    z-index: 1;
}

#flipbook-container {
    will-change: transform;
    transition: transform 0.2s ease;
    transform-origin: center center;
}

#flipbook-container.dragging {
    transition: none;
    cursor: grabbing;
}

#flipbook-container.zoomed {
    cursor: grab;
}

/* Block StPageFlip mouse/touch interactions when zoomed — panning only */
.zoom-locked .stf__wrapper {
    pointer-events: none;
}

/* --- Flipbook Pages --- */
.flipbook-page {
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.flipbook-page canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
    object-fit: contain;
}

.flipbook-page .page-spinner {
    position: absolute;
    width: 32px;
    height: 32px;
    border: 2px solid #ddd;
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* --- Footer --- */
#bottom-bar {
    height: var(--footer-height);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    z-index: 100;
}

.footer-section {
    display: flex;
    align-items: center;
    gap: 8px;
}

.footer-left {
    flex: 1;
    justify-content: flex-start;
}

.footer-center {
    flex: 0;
    white-space: nowrap;
}

.footer-right {
    flex: 1;
    justify-content: flex-end;
}

#page-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 14px;
    color: var(--text-secondary);
    padding: 4px 4px;
    user-select: none;
}

#page-current {
    width: 42px;
    padding: 4px 6px;
    border: 1px solid rgba(74, 158, 255, 0.15);
    border-radius: 8px;
    background: linear-gradient(135deg, rgba(74, 158, 255, 0.06), rgba(140, 80, 255, 0.03));
    color: var(--text-secondary);
    font-size: 14px;
    font-family: inherit;
    text-align: center;
    outline: none;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    -moz-appearance: textfield;
}

#page-current::-webkit-outer-spin-button,
#page-current::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

#page-current:focus {
    border-color: rgba(74, 158, 255, 0.5);
    background: linear-gradient(135deg, rgba(74, 158, 255, 0.15), rgba(140, 80, 255, 0.08));
    color: var(--text-primary);
    box-shadow: 0 0 12px rgba(74, 158, 255, 0.15);
}

#page-current:hover:not(:focus) {
    border-color: rgba(74, 158, 255, 0.3);
    background: linear-gradient(135deg, rgba(74, 158, 255, 0.1), rgba(140, 80, 255, 0.05));
}

[data-theme="light"] #page-current {
    border-color: rgba(43, 125, 233, 0.15);
    background: linear-gradient(135deg, rgba(43, 125, 233, 0.05), rgba(100, 60, 200, 0.02));
}

[data-theme="light"] #page-current:focus {
    border-color: rgba(43, 125, 233, 0.5);
    background: linear-gradient(135deg, rgba(43, 125, 233, 0.12), rgba(100, 60, 200, 0.06));
    box-shadow: 0 0 12px rgba(43, 125, 233, 0.1);
}

[data-theme="light"] #page-current:hover:not(:focus) {
    border-color: rgba(43, 125, 233, 0.25);
    background: linear-gradient(135deg, rgba(43, 125, 233, 0.08), rgba(100, 60, 200, 0.04));
}

#zoom-level {
    font-size: 13px;
    color: var(--text-secondary);
    min-width: 48px;
    text-align: center;
    user-select: none;
    padding: 4px 8px;
    border-radius: 8px;
    background: linear-gradient(135deg, rgba(74, 158, 255, 0.06), rgba(140, 80, 255, 0.03));
    border: 1px solid rgba(74, 158, 255, 0.1);
}

[data-theme="light"] #zoom-level {
    background: linear-gradient(135deg, rgba(43, 125, 233, 0.05), rgba(100, 60, 200, 0.02));
    border-color: rgba(43, 125, 233, 0.1);
}

.footer-brand-link {
    text-decoration: none;
    color: inherit;
    opacity: 0.85;
    transition: opacity var(--transition-normal);
}

.footer-brand-link:hover {
    opacity: 1;
}

.footer-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
}

.footer-credit {
    font-size: 9px;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 1px;
    white-space: nowrap;
    opacity: 0.6;
    margin-top: 4px;
}

.logo-footer {
    margin-top: -5px;
}

.logo-footer {
    height: 42px;
    object-fit: contain;
    opacity: 0.7;
}

.logo-creator {
    height: 28px;
    object-fit: contain;
    opacity: 0.7;
}

/* --- Responsive --- */

/* Tablet */
@media (max-width: 1024px) {
    .btn span {
        display: none;
    }

    #btn-load-pdf {
        padding: 10px;
    }
}

/* Mobile */
@media (max-width: 768px) {
    :root {
        --header-height: 72px;
        --footer-height: 46px;
    }

    .logo-header {
        height: 65px;
        max-width: 340px;
    }

    #top-bar, #bottom-bar {
        padding: 0 8px;
    }

    /* Move zoom controls to overlay bottom-right on mobile */
    #zoom-controls {
        position: fixed;
        bottom: calc(var(--footer-height) + 8px);
        right: 8px;
        z-index: 99;
        background: var(--bg-secondary);
        border-radius: 12px;
        padding: 4px;
        border: 1px solid var(--border);
        box-shadow: 0 2px 12px var(--shadow);
    }

    #top-bar {
        justify-content: center;
    }

    .top-bar-left-spacer {
        display: none;
    }

    .top-bar-right:not(.hidden) {
        position: fixed;
        bottom: calc(var(--footer-height) + 8px);
        right: 8px;
    }

    .top-bar-center {
        flex: unset;
    }

    .btn-nav, .btn-zoom {
        width: 34px;
        height: 34px;
    }

    .btn-theme {
        width: 34px;
        height: 34px;
    }

    #page-indicator {
        font-size: 13px;
        padding: 4px 4px;
    }

    #page-current {
        width: 36px;
        font-size: 13px;
    }

    #zoom-level {
        font-size: 11px;
        min-width: 36px;
        padding: 2px 4px;
    }

    .footer-credit {
        font-size: 8px;
    }

    .logo-footer {
        height: 30px;
    }

    .logo-creator {
        height: 22px;
    }
}

/* Small mobile */
@media (max-width: 480px) {
    :root {
        --header-height: 62px;
        --footer-height: 42px;
    }

    .logo-header {
        height: 55px;
        max-width: 286px;
    }

    .btn-nav, .btn-zoom {
        width: 30px;
        height: 30px;
    }

    .btn-nav svg, .btn-zoom svg {
        width: 16px;
        height: 16px;
    }

    .btn-theme {
        width: 30px;
        height: 30px;
    }

    .footer-credit {
        font-size: 7px;
        letter-spacing: 0.5px;
    }

    .logo-footer {
        height: 22px;
    }
}

/* Short viewports (landscape mobile) */
@media (max-height: 500px) {
    :root {
        --header-height: 44px;
        --footer-height: 38px;
    }

    .logo-header {
        height: 34px;
        max-width: 180px;
    }

    .footer-brand {
        gap: 0;
    }

    .footer-credit {
        font-size: 6px;
        letter-spacing: 0.5px;
        margin-top: 1px;
    }

    .logo-footer {
        height: 20px;
        margin-top: -2px;
    }
}
