/* ============================================
   FlippingBook - Premium PDF Viewer
   Design System & Styles
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ---- CSS Custom Properties ---- */
:root {
    /* Colors */
    --bg-primary: #080c14;
    --bg-secondary: #0f1623;
    --bg-card: rgba(255, 255, 255, 0.035);
    --bg-card-hover: rgba(255, 255, 255, 0.065);
    --bg-glass: rgba(255, 255, 255, 0.05);
    --border-glass: rgba(255, 255, 255, 0.08);
    --border-glass-hover: rgba(255, 255, 255, 0.16);

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #4e6070;

    --accent-primary: #0284c7;
    --accent-light: #38bdf8;
    --accent-dark: #0369a1;
    --accent-glow: rgba(2, 132, 199, 0.22);

    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;

    /* Sizing */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 8px 36px rgba(0, 0, 0, 0.55);
    --shadow-glow: 0 0 28px var(--accent-glow);

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.28s ease;
    --transition-slow: 0.5s ease;
}

/* ---- Reset & Base ---- */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ---- Subtle dot grid background ---- */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image:
        radial-gradient(circle, rgba(255, 255, 255, 0.055) 1px, transparent 1px);
    background-size: 28px 28px;
    z-index: -1;
    pointer-events: none;
}

/* ---- Header ---- */
.header {
    padding: 2.5rem 2rem 0.5rem;
    text-align: center;
    position: relative;
}

.header__logo {
    display: inline-flex;
    align-items: center;
    gap: 0.875rem;
    margin-bottom: 0.75rem;
}

.header__icon {
    width: 48px;
    height: 48px;
    background: var(--accent-primary);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    box-shadow: var(--shadow-glow);
    transition: box-shadow var(--transition-normal);
}

.header__icon:hover {
    box-shadow: 0 0 36px rgba(2, 132, 199, 0.4);
}

.header__title {
    font-size: 2rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.025em;
}

.header__title span {
    color: var(--accent-light);
}

.header__subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 400;
    max-width: 480px;
    margin: 0 auto;
    letter-spacing: 0.01em;
}

/* ---- Stats Bar ---- */
.stats-bar {
    display: flex;
    justify-content: center;
    gap: 0;
    padding: 0;
    margin: 1.75rem auto;
    max-width: 420px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 2rem;
    flex: 1;
    transition: background var(--transition-fast);
}

.stat-item:not(:last-child) {
    border-right: 1px solid var(--border-glass);
}

.stat-item__icon {
    color: var(--accent-primary);
    flex-shrink: 0;
    opacity: 0.9;
}

.stat-item__value {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.stat-item__label {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.07em;
    font-weight: 500;
    margin-top: 1px;
}

/* ---- Search Bar ---- */
.search-container {
    max-width: 480px;
    margin: 0 auto 2rem;
    padding: 0 2rem;
}

.search-input {
    width: 100%;
    padding: 0.875rem 1.25rem 0.875rem 3rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
    transition: all var(--transition-normal);
}

.search-input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-glow);
    background: var(--bg-secondary);
}

.search-input::placeholder {
    color: var(--text-muted);
}

.search-wrapper {
    position: relative;
}

.search-wrapper__icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

/* ---- PDF Grid ---- */
.pdf-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.25rem;
    padding: 0 2rem 3rem;
    max-width: 1400px;
    margin: 0 auto;
}

/* ---- PDF Card ---- */
.pdf-card {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    cursor: pointer;
    transition: all var(--transition-normal);
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    gap: 0.875rem;
}

.pdf-card::after {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--accent-primary);
    border-radius: 0;
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.pdf-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-glass-hover);
    transform: translateY(-3px);
    box-shadow: var(--shadow-md), var(--shadow-glow);
}

.pdf-card:hover::after {
    opacity: 1;
}

.pdf-card__thumbnail {
    width: 100%;
    height: 180px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    transition: all var(--transition-normal);
    position: relative;
}

.pdf-card__thumbnail-canvas {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform var(--transition-normal);
    display: none;
}

.pdf-card__thumbnail-loader {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

.loading-spinner-small {
    width: 32px;
    height: 32px;
    border: 2px solid var(--border-glass);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.pdf-card:hover .pdf-card__thumbnail {
    border-color: var(--border-glass-hover);
    box-shadow: var(--shadow-sm);
}

.pdf-card:hover .pdf-card__thumbnail-canvas {
    transform: scale(1.05);
}

.pdf-card__info {
    flex: 1;
    min-width: 0;
}

.pdf-card__name {
    font-size: 0.975rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.4rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

.pdf-card__meta {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.pdf-card__meta-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.pdf-card__actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
}

.pdf-card__share-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem;
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-normal);
    opacity: 0;
    transform: translateY(8px);
}

.pdf-card:hover .pdf-card__share-btn {
    opacity: 1;
    transform: translateY(0);
}

.pdf-card__share-btn:hover {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
    box-shadow: var(--shadow-glow);
}

.pdf-card__action {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    background: var(--accent-primary);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-family: inherit;
    font-size: 0.83rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-normal);
    opacity: 0;
    transform: translateY(8px);
    letter-spacing: 0.01em;
    flex: 1;
}

.pdf-card:hover .pdf-card__action {
    opacity: 1;
    transform: translateY(0);
}

.pdf-card__action:hover {
    background: var(--accent-dark);
    box-shadow: var(--shadow-glow);
}

/* ---- Empty State ---- */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    grid-column: 1 / -1;
}

.empty-state__icon {
    font-size: 4rem;
    margin-bottom: 1.5rem;
    opacity: 0.3;
}

.empty-state__title {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.empty-state__text {
    font-size: 0.95rem;
    color: var(--text-secondary);
    max-width: 380px;
    margin: 0 auto;
}

.empty-state__path {
    display: inline-block;
    margin-top: 1.25rem;
    padding: 0.5rem 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    font-family: 'Courier New', monospace;
    font-size: 0.83rem;
    color: var(--accent-light);
    letter-spacing: 0.02em;
}

/* ---- Animations (Entrance) ---- */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.pdf-card {
    animation: fadeInUp 0.45s ease forwards;
    opacity: 0;
}

.pdf-card:nth-child(1)  { animation-delay: 0.04s; }
.pdf-card:nth-child(2)  { animation-delay: 0.08s; }
.pdf-card:nth-child(3)  { animation-delay: 0.12s; }
.pdf-card:nth-child(4)  { animation-delay: 0.16s; }
.pdf-card:nth-child(5)  { animation-delay: 0.20s; }
.pdf-card:nth-child(6)  { animation-delay: 0.24s; }
.pdf-card:nth-child(7)  { animation-delay: 0.28s; }
.pdf-card:nth-child(8)  { animation-delay: 0.32s; }
.pdf-card:nth-child(9)  { animation-delay: 0.36s; }
.pdf-card:nth-child(10) { animation-delay: 0.40s; }

/* ============================================
   VIEWER PAGE STYLES
   ============================================ */

/* ---- Viewer Header ---- */
.viewer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-glass);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    height: 58px;
}

.viewer-header__left {
    display: flex;
    align-items: center;
    gap: 1rem;
    min-width: 0;
    flex: 1;
}

.viewer-header__back {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 0.875rem;
    background: transparent;
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.83rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
    white-space: nowrap;
    flex-shrink: 0;
}

.viewer-header__back:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
    border-color: var(--border-glass-hover);
}

.viewer-header__divider {
    width: 1px;
    height: 20px;
    background: var(--border-glass);
    flex-shrink: 0;
}

.viewer-header__title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 320px;
}

.viewer-header__center {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.viewer-header__page-info {
    font-size: 0.83rem;
    color: var(--text-secondary);
    font-weight: 500;
    min-width: 90px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.viewer-header__right {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex: 1;
    justify-content: flex-end;
}

/* ---- Viewer Controls ---- */
.btn-control {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0;
    background: transparent;
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.83rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    width: 34px;
    height: 34px;
    flex-shrink: 0;
}

.btn-control:hover {
    background: rgba(255, 255, 255, 0.07);
    color: var(--text-primary);
    border-color: var(--border-glass-hover);
}

.btn-control:disabled {
    opacity: 0.25;
    cursor: not-allowed;
}

.btn-control--accent {
    background: var(--accent-primary);
    border-color: transparent;
    color: white;
}

.btn-control--accent:hover {
    background: var(--accent-dark);
    box-shadow: var(--shadow-glow);
}

/* ---- Viewer Container ---- */
.viewer-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding-top: 58px;
    position: relative;
}

.flipbook-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    width: 100%;
    height: calc(100vh - 58px);
    overflow: hidden;
}

/* ---- Side Navigation Arrows ---- */
.nav-arrow {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    z-index: 50;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-normal);
}

.nav-arrow:hover {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-glow);
    transform: translateY(-50%) scale(1.08);
}

.nav-arrow--prev {
    left: 1.25rem;
}

.nav-arrow--next {
    right: 1.25rem;
}

.nav-arrow:disabled {
    opacity: 0.18;
    cursor: not-allowed;
}

.nav-arrow:disabled:hover {
    transform: translateY(-50%);
    box-shadow: none;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border-color: var(--border-glass);
}

/* ---- Flipbook Element ---- */
.flipbook-container {
    background: transparent;
}

.flipbook-container .stf__parent {
    margin: 0 auto;
}

/* Each page styling */
.page {
    background: white;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.page canvas,
.page img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.page--cover {
    background: #1e293b;
}

/* ---- Loading Overlay ---- */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 200;
    gap: 1.5rem;
    transition: opacity 0.4s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-spinner {
    width: 52px;
    height: 52px;
    border: 2px solid var(--border-glass);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading-text {
    font-size: 0.95rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.loading-progress {
    width: 220px;
    height: 3px;
    background: rgba(255, 255, 255, 0.07);
    border-radius: 2px;
    overflow: hidden;
}

.loading-progress__bar {
    height: 100%;
    background: var(--accent-primary);
    border-radius: 2px;
    transition: width 0.3s ease;
    width: 0%;
}

/* ---- Error State ---- */
.error-state {
    text-align: center;
    padding: 4rem 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.error-state__icon {
    margin-bottom: 1.5rem;
    opacity: 0.85;
}

.error-state__title {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.error-state__text {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.error-state__link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 1.5rem;
    background: var(--accent-primary);
    border-radius: var(--radius-sm);
    color: white;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all var(--transition-normal);
}

.error-state__link:hover {
    background: var(--accent-dark);
    box-shadow: var(--shadow-glow);
    transform: translateY(-2px);
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar {
    width: 5px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-glass);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.18);
}

/* ---- Share Modal ---- */
.share-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-normal), visibility var(--transition-normal);
}

.share-modal.active {
    opacity: 1;
    visibility: visible;
}

.share-modal__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
}

.share-modal__content {
    position: relative;
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.share-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-glass);
}

.share-modal__title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.share-modal__close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.share-modal__close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.share-modal__body {
    padding: 1.5rem;
}

.share-modal__description {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin: 0 0 1rem 0;
}

.share-modal__link-container {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.share-modal__input {
    flex: 1;
    padding: 0.75rem 1rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    outline: none;
    transition: border-color var(--transition-fast);
}

.share-modal__input:focus {
    border-color: var(--accent-primary);
}

.share-modal__copy-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    background: var(--accent-primary);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-normal);
    white-space: nowrap;
}

.share-modal__copy-btn:hover {
    background: var(--accent-dark);
    box-shadow: var(--shadow-glow);
}

.share-modal__success {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.3);
    border-radius: var(--radius-sm);
    color: var(--success);
    font-size: 0.9rem;
    font-weight: 500;
    opacity: 0;
    transform: translateY(-10px);
    transition: all var(--transition-normal);
}

.share-modal__success.show {
    opacity: 1;
    transform: translateY(0);
}

/* ---- Fullscreen mode ---- */
body.fullscreen-mode .viewer-header {
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-normal);
}

body.fullscreen-mode:hover .viewer-header {
    opacity: 1;
    pointer-events: all;
}

body.fullscreen-mode .viewer-container {
    padding-top: 0;
}

body.fullscreen-mode .flipbook-wrapper {
    height: 100vh;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .header {
        padding: 1.75rem 1rem 0.5rem;
    }

    .header__title {
        font-size: 1.5rem;
    }

    .header__subtitle {
        font-size: 0.83rem;
    }

    .stats-bar {
        margin: 1.25rem 1rem;
        max-width: none;
    }

    .stat-item {
        padding: 0.875rem 1.25rem;
        gap: 0.5rem;
    }

    .pdf-grid {
        grid-template-columns: 1fr;
        padding: 0 1rem 2rem;
        gap: 0.875rem;
    }

    .viewer-header {
        padding: 0 0.75rem;
    }

    .viewer-header__title {
        max-width: 140px;
        font-size: 0.8rem;
    }

    .viewer-header__divider {
        display: none;
    }

    .nav-arrow {
        width: 40px;
        height: 40px;
    }

    .nav-arrow--prev { left: 0.5rem; }
    .nav-arrow--next { right: 0.5rem; }

    .viewer-header__center {
        display: none;
    }
}

@media (max-width: 480px) {
    .pdf-card {
        padding: 1.25rem;
    }

    .pdf-card__action {
        opacity: 1;
        transform: translateY(0);
    }
}
