/* ========================================
   PDF Viewer - Main Stylesheet
   ======================================== */

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

:root {
    --bg-color: #f4f6f8;
    --text-color: #1f2933;
    --border-color: #d1d5db;
    --shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);
    --radius: 8px;
    --font-size: 16px;
    --accent-color: #2563eb;
    --accent-soft: rgba(37, 99, 235, 0.12);
    --page-color: #ffffff;
}

html, body {
    height: 100%;
    font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
    font-size: var(--font-size);
    color: var(--text-color);
    background-color: var(--bg-color);
    direction: ltr;
    line-height: 1.6;
}

.app-spinner {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.6);
    z-index: 2000;
    transition: opacity 0.3s ease;
}

.app-spinner.is-hidden {
    opacity: 0;
    pointer-events: none;
}

.app-spinner__inner {
    text-align: center;
    color: #e0e7ff;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}

.app-spinner__orbit {
    width: 72px;
    height: 72px;
    animation: spinner-rotate 2.4s linear infinite;
}

.app-spinner__arc {
    animation: spinner-dash 1.4s ease-in-out infinite;
}

@keyframes spinner-rotate {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes spinner-dash {
    0% {
        stroke-dashoffset: 180;
    }
    50% {
        stroke-dashoffset: 45;
        transform: rotate(45deg);
    }
    100% {
        stroke-dashoffset: 180;
        transform: rotate(360deg);
    }
}

.accessibility-mode body,
body.accessibility-mode {
    font-size: calc(var(--font-size) * 1.1);
    line-height: 1.85;
    letter-spacing: 0.02em;
}

.accessibility-mode .button,
.accessibility-mode .pill-button,
.accessibility-mode .button--secondary {
    border: 2px solid rgba(15, 23, 42, 0.65);
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35);
}

.library-surface {
    min-height: 100vh;
    background: radial-gradient(120% 120% at 50% 0%, rgba(37, 99, 235, 0.18), transparent),
                linear-gradient(180deg, #f4f6f8 0%, #eef2f7 100%);
}

[data-library-theme="dark"] .library-surface {
    background: radial-gradient(120% 120% at 50% 0%, rgba(59, 130, 246, 0.22), transparent),
                linear-gradient(180deg, #0f172a 0%, #0b1120 100%);
}

[data-library-theme="dark"] body {
    background-color: #0b1120;
    color: #e2e8f0;
}

[data-library-theme="dark"] .collection-section {
    background: rgba(15, 23, 42, 0.75);
    box-shadow: 0 24px 48px rgba(8, 47, 73, 0.65);
}

[data-library-theme="dark"] .document-card {
    background: linear-gradient(160deg, rgba(59, 130, 246, 0.18), rgba(14, 165, 233, 0.15));
}

[data-library-theme="dark"] .pill-button {
    background: rgba(148, 163, 184, 0.14);
    color: #e2e8f0;
}

[data-library-theme="dark"] .pill-button--primary {
    background: linear-gradient(135deg, #60a5fa, #3b82f6);
}

[data-library-theme="sepia"] .library-surface {
    background: linear-gradient(140deg, #f7f1e3 0%, #f3e9d2 100%);
}

[data-library-theme="sepia"] body {
    background-color: #f7f1e3;
    color: #5b4636;
}

.toast {
    position: fixed;
    bottom: 32px;
    right: 32px;
    background: rgba(15, 23, 42, 0.9);
    color: #fff;
    padding: 12px 18px;
    border-radius: 10px;
    opacity: 0;
    pointer-events: none;
    transform: translateY(12px);
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 12000;
}

.toast.toast--error {
    background: rgba(220, 38, 38, 0.9);
}

.toast.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.library-wrapper button,
.library-wrapper a {
    touch-action: manipulation;
}

.document-card {
    cursor: pointer;
}

.document-card a,
.document-card button {
    cursor: pointer;
}

.viewer-banner {
    background: linear-gradient(120deg, rgba(37, 99, 235, 0.15), rgba(14, 165, 233, 0.15));
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    color: #0f172a;
}

.viewer__workspace--public {
    margin-top: 0;
}

/* Authentication Card */
.app {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background: linear-gradient(135deg, #f4f6f8 0%, #e8eef5 100%);
}

.auth-card {
    background: white;
    padding: 40px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    max-width: 400px;
    width: 100%;
}

.auth-card h1 {
    font-size: 28px;
    margin-bottom: 10px;
    color: #1a1612;
}

.auth-card__subtitle {
    color: #666;
    margin-bottom: 20px;
    font-size: 16px;
}

.login-tabs {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin: 20px 0;
    background: rgba(148, 163, 184, 0.12);
    padding: 6px;
    border-radius: 999px;
}

.login-tabs__button {
    border: none;
    background: transparent;
    padding: 10px 16px;
    border-radius: 999px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
    color: #475569;
}

.login-tabs__button.is-active {
    background: white;
    color: #1e293b;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.12);
}

.auth-card__hint {
    font-size: 13px;
    color: #64748b;
    margin-top: 8px;
}

.auth-form.is-hidden {
    display: none;
}

.form__actions {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: flex-end;
    margin-top: 12px;
}

/* Forms */
.form__label {
    display: block;
    margin-bottom: 20px;
}

.form__label span {
    display: block;
    margin-bottom: 5px;
    font-size: 14px;
    font-weight: 500;
    color: #555;
}

.form__label input,
.form__label textarea,
.form__label select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 16px;
    background: white;
    transition: border-color 0.2s;
}

.form__label input:focus,
.form__label textarea:focus,
.form__label select:focus {
    outline: none;
    border-color: #8b7355;
}

input[type="color"] {
    height: 40px;
    cursor: pointer;
}

/* Buttons */
.button {
    display: inline-block;
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.button--primary {
    background: #6b5d4f;
    color: white;
    width: 100%;
    padding: 12px;
}

.button--primary:hover {
    background: #5a4e42;
}

.button--secondary {
    background: #f5f2ed;
    color: #6b5d4f;
}

.button--secondary:hover {
    background: #ebe7e0;
}

.button--icon {
    background: transparent;
    padding: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.button--icon:hover {
    background: rgba(0, 0, 0, 0.05);
}

.button--icon .icon,
.button--icon svg {
    width: 20px;
    height: 20px;
}

.icon {
    display: inline-block;
    width: 20px;
    height: 20px;
}

.icon--sm {
    width: 16px;
    height: 16px;
}

.icon--lg {
    width: 28px;
    height: 28px;
}

.button--icon-text {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: transparent;
}

.button--icon-text:hover {
    background: rgba(0, 0, 0, 0.05);
}

.button--icon-text .icon {
    width: 18px;
    height: 18px;
}

.pill-button .icon,
.button--secondary .icon {
    margin-inline-end: 6px;
}

[dir="rtl"] .pill-button .icon,
[dir="rtl"] .button--secondary .icon {
    margin-inline-end: 0;
    margin-inline-start: 6px;
}

.button.is-disabled,
.button.is-disabled:hover {
    opacity: 0.45;
    cursor: not-allowed;
    background: rgba(15, 23, 42, 0.08);
}

/* Notices */
.notice {
    padding: 12px;
    border-radius: 4px;
    margin-bottom: 20px;
    font-size: 14px;
}

.notice--error {
    background: #fee;
    color: #c33;
    border: 1px solid #fcc;
}

/* Viewer Layout */
.viewer {
    height: 100vh;
    overflow: hidden;
    display: flex;
    background-color: var(--bg-color);
}

.viewer__workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Header */
.viewer__header {
    background: white;
    border-bottom: 1px solid var(--border-color);
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.header__title {
    display: flex;
    align-items: center;
    gap: 20px;
}

.viewer__header h1 {
    font-size: 24px;
    font-weight: 600;
    color: #1a1612;
}

.page-indicator {
    font-size: 14px;
    color: var(--accent-color);
    background: var(--accent-soft);
    padding: 4px 12px;
    border-radius: 20px;
}

.viewer__actions {
    display: flex;
    gap: 10px;
}

.viewer__actions-group {
    display: flex;
    gap: 8px;
}

/* Side Panels */
.viewer-panel {
    position: fixed;
    top: 0;
    height: 100%;
    width: min(360px, 90vw);
    background: white;
    box-shadow: -2px 0 24px rgba(15, 23, 42, 0.18);
    transform: translate3d(110%, 0, 0);
    transition: transform 0.28s ease, opacity 0.28s ease;
    opacity: 0;
    pointer-events: none;
    z-index: 1000;
    overflow-y: auto;
}

.viewer-panel--settings {
    right: 0;
}

.viewer-panel--notes {
    right: 0;
}

.viewer-panel.active {
    transform: translate3d(0, 0, 0);
    opacity: 1;
    pointer-events: auto;
}

.viewer-panel__header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.viewer-panel__header h2 {
    font-size: 20px;
    font-weight: 600;
}

.viewer-panel__close {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #999;
    line-height: 1;
    padding: 0;
}

.viewer-panel__close:hover {
    color: #333;
}

.viewer-panel__body {
    padding: 20px;
}

/* Range Input */
.range-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
}

.range-wrapper input[type="range"] {
    flex: 1;
}

.range-value {
    font-size: 14px;
    color: #666;
    min-width: 40px;
}

/* PDF Viewer */
.book {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    position: relative;
    overflow: auto;
}

.book__inner {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    background: var(--page-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    overflow: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 16px;
}

.book__controls {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 18px;
    pointer-events: none;
    z-index: 10;
}

.nav-button {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    pointer-events: all;
    transition: all 0.2s;
}

.nav-button:hover {
    background: white;
    transform: scale(1.1);
}

.nav-button--prev,
.nav-button--next {
    margin: 0;
}

[dir="rtl"] .book__controls {
    flex-direction: row-reverse;
}

[dir="rtl"] .nav-button--prev svg,
[dir="rtl"] .nav-button--next svg {
    transform: scaleX(-1);
}

/* PDF Container */
.pdf-viewer {
    position: relative;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    min-height: 70vh;
    width: 100%;
    overflow: auto;
}

#pdfCanvas {
    display: block;
    max-width: none;
    background-color: var(--page-color);
    box-shadow: 0 12px 24px rgba(15, 23, 42, 0.08);
    margin: 0 auto;
}

/* Paper Textures */
.book__inner.texture-grain {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><rect width="100" height="100" fill="%23ffffff"/><circle cx="50" cy="50" r="1" fill="%23f5f5f5" opacity="0.5"/></svg>');
}

.book__inner.texture-linen {
    background-image: repeating-linear-gradient(
        90deg,
        transparent,
        transparent 2px,
        rgba(255, 255, 255, 0.1) 2px,
        rgba(255, 255, 255, 0.1) 4px
    );
}

/* Loader */
.loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 18px;
    color: #999;
}

.viewer__error {
    position: absolute;
    bottom: 20px;
    left: 20px;
    right: 20px;
    background: rgba(244, 67, 54, 0.92);
    color: #fff;
    padding: 12px 16px;
    border-radius: 4px;
    text-align: center;
    box-shadow: var(--shadow);
}

/* Notes List */
.notes-list {
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 20px;
}

.note-item {
    background: #f9f8f6;
    padding: 12px;
    margin-bottom: 10px;
    border-radius: 4px;
    position: relative;
}

.note-item__page {
    font-size: 12px;
    color: #999;
    margin-bottom: 5px;
}

.note-item__content {
    font-size: 14px;
    line-height: 1.4;
}

.note-item__delete {
    position: absolute;
    top: 10px;
    left: 10px;
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    font-size: 18px;
}

.note-item__delete:hover {
    color: #c33;
}

.note-form__actions {
    display: flex;
    justify-content: flex-end;
}

.footer-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

/* Footer */
.viewer__footer {
    background: white;
    border-top: 1px solid var(--border-color);
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 15px;
}

#zoomLevel {
    font-size: 14px;
    min-width: 50px;
    text-align: center;
}

/* Responsive */
@media (max-width: 768px) {
    .library-wrapper {
         padding: 24px 16px 48px;
     }
 
    .viewer-panel {
        width: 100%;
    }
    
    .viewer__header h1 {
        font-size: 18px;
    }
    
    .page-indicator {
        display: none;
    }
    
    .book {
        padding: 10px;
    }
    
    .book__inner {
        padding: 12px;
    }
    
    .nav-button {
        width: 35px;
        height: 35px;
    }

    .viewer-panel,
    .viewer__header,
    .viewer__footer {
        padding: 12px;
    }
}

/* Fullscreen Mode */
.viewer.fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
}

.viewer.fullscreen .viewer__header {
    transform: translateY(-100%);
    transition: transform 0.3s;
}

.viewer.fullscreen:hover .viewer__header {
    transform: translateY(0);
}

/* Print Styles */
@media print {
    .viewer__header,
    .viewer__footer,
    .viewer__panel,
    .book__controls {
        display: none;
    }
    
    .book {
        padding: 0;
    }
    
    .book__inner {
        box-shadow: none;
        border-radius: 0;
    }
}

.library-surface.rtl,
.viewer.rtl {
    direction: rtl;
}

.library-surface.ltr,
.viewer.ltr {
    direction: ltr;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.viewer--dark {
    background-color: #0b1120;
    color: #e2e8f0;
}

.viewer--dark .viewer__header,
.viewer--dark .viewer__footer {
    background: rgba(15, 23, 42, 0.85);
    border-color: rgba(148, 163, 184, 0.25);
    color: #e2e8f0;
}

.viewer--dark .page-indicator {
    color: #cbd5f5;
}

.viewer--dark .book__inner {
    background: #111827;
    box-shadow: 0 24px 46px rgba(8, 47, 73, 0.65);
}

.viewer--dark .nav-button {
    background: rgba(30, 41, 59, 0.92);
    border-color: rgba(148, 163, 184, 0.25);
    color: #e2e8f0;
}

.viewer--dark .nav-button:hover {
    background: rgba(51, 65, 85, 0.95);
}

.viewer--dark .button--secondary,
.viewer--dark .pill-button {
    background: rgba(30, 41, 59, 0.75);
    color: #e2e8f0;
}

.viewer--dark .button--secondary:hover,
.viewer--dark .pill-button:hover {
    background: rgba(51, 65, 85, 0.85);
}

.viewer--kindle {
    background: #e8e2d2;
    color: #2f2b26;
}

.viewer--kindle .viewer__header,
.viewer--kindle .viewer__footer {
    background: #f5f1e6;
    border-color: rgba(121, 111, 90, 0.35);
    color: #2f2b26;
}

.viewer--kindle .page-indicator {
    background: rgba(121, 111, 90, 0.12);
    color: #685f4e;
}

.viewer--kindle .book__inner {
    background: #f5f1e6;
    box-shadow: 0 24px 46px rgba(121, 111, 90, 0.25);
}

.viewer--kindle #pdfCanvas {
    box-shadow: 0 14px 30px rgba(121, 111, 90, 0.2);
}

.viewer--kindle .nav-button {
    background: rgba(235, 226, 206, 0.9);
    border-color: rgba(121, 111, 90, 0.4);
    color: #4a4337;
}

.viewer--kindle .nav-button:hover {
    background: rgba(235, 226, 206, 1);
}

.viewer--kindle .button--secondary,
.viewer--kindle .pill-button {
    background: rgba(235, 226, 206, 0.8);
    color: #4a4337;
}

.viewer--kindle .button--secondary:hover,
.viewer--kindle .pill-button:hover {
    background: rgba(213, 202, 178, 0.85);
}
