/* Import Google Fonts for modern Latin and Arabic typography */
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;600;700&family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
    --bg-primary: #0b0f19;
    --bg-secondary: #131a2e;
    --bg-glass: rgba(19, 26, 46, 0.7);
    --border-glass: rgba(255, 255, 255, 0.08);
    --accent-indigo: #6366f1;
    --accent-indigo-glow: rgba(99, 102, 241, 0.4);
    --accent-teal: #0d9488;
    --accent-teal-glow: rgba(13, 148, 136, 0.3);
    --accent-danger: #ef4444;
    --accent-success: #10b981;
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --font-latin: 'Outfit', sans-serif;
    --font-arabic: 'Cairo', sans-serif;
    
    --shadow-premium: 0 20px 40px -15px rgba(0, 0, 0, 0.5);
    --border-radius-lg: 16px;
    --border-radius-md: 10px;
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Base resets & theme styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-primary);
    background-image: 
        radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(13, 148, 136, 0.1) 0px, transparent 50%);
    color: var(--text-primary);
    font-family: var(--font-latin);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* RTL Support class */
body.rtl {
    font-family: var(--font-arabic);
    direction: rtl;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
    background: var(--border-glass);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--accent-indigo);
}

/* App Header styling */
header {
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-glass);
    padding: 1rem 2rem;
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.2);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--accent-indigo), var(--accent-teal));
    border-radius: var(--border-radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: white;
    font-size: 1.25rem;
    box-shadow: 0 0 15px var(--accent-indigo-glow);
}

.logo-text h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    background: linear-gradient(to right, #ffffff, #c7d2fe);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo-text p {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.header-actions {
    display: flex;
    gap: 15px;
    align-items: center;
}

/* Lang toggle & Buttons */
.btn-lang {
    background: transparent;
    border: 1px solid var(--border-glass);
    color: var(--text-primary);
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius-md);
    cursor: pointer;
    font-family: inherit;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: var(--transition-smooth);
}

.btn-lang:hover {
    background: var(--border-glass);
    border-color: var(--text-secondary);
}

/* Main Container Layout */
main {
    flex: 1;
    display: flex;
    align-items: stretch;
    padding: 2rem;
    max-width: 1600px;
    width: 100%;
    margin: 0 auto;
    gap: 2rem;
    min-height: 0;
}

.workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 0;
}

/* Sidebar panel */
.sidebar {
    width: 380px;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-glass);
    border-radius: var(--border-radius-lg);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    box-shadow: var(--shadow-premium);
    height: fit-content;
}

.sidebar-title {
    font-size: 1.15rem;
    font-weight: 600;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-glass);
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Form Controls & Styling */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

select, input[type="number"], input[type="text"] {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-glass);
    color: var(--text-primary);
    padding: 0.75rem;
    border-radius: var(--border-radius-md);
    outline: none;
    font-family: inherit;
    font-size: 0.9rem;
    transition: var(--transition-smooth);
}

select:focus, input[type="number"]:focus, input[type="text"]:focus {
    border-color: var(--accent-indigo);
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.25);
}

.switch-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
}

/* Toggle Switch Styling */
.switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.1);
    transition: .4s;
    border-radius: 24px;
    border: 1px solid var(--border-glass);
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--accent-indigo);
}

input:checked + .slider:before {
    transform: translateX(24px);
}

/* Drag & Drop Area */
.dropzone {
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 2px dashed var(--border-glass);
    border-radius: var(--border-radius-lg);
    padding: 4rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition-smooth);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    min-height: 400px;
    box-shadow: var(--shadow-premium);
}

.dropzone:hover, .dropzone.dragover {
    border-color: var(--accent-indigo);
    background: rgba(99, 102, 241, 0.05);
    box-shadow: 0 0 30px rgba(99, 102, 241, 0.1);
}

.dropzone-icon {
    font-size: 3.5rem;
    color: var(--text-secondary);
    transition: var(--transition-smooth);
}

.dropzone:hover .dropzone-icon {
    color: var(--accent-indigo);
    transform: translateY(-5px);
}

.dropzone-text h3 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
}

.dropzone-text p {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.file-input {
    display: none;
}

/* File Info Box */
.file-info-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-glass);
    border-radius: var(--border-radius-md);
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    max-width: 500px;
    margin-top: 1rem;
}

.file-info-icon {
    font-size: 2rem;
    color: var(--accent-indigo);
}

.file-info-details {
    flex: 1;
    text-align: left;
}

body.rtl .file-info-details {
    text-align: right;
}

.file-info-name {
    font-size: 0.95rem;
    font-weight: 600;
    word-break: break-all;
}

.file-info-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Loading & Rendering State */
.loading-view {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    min-height: 400px;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-glass);
    border-radius: var(--border-radius-lg);
    padding: 3rem;
    box-shadow: var(--shadow-premium);
}

.progress-container {
    width: 100%;
    max-width: 400px;
    background: rgba(255, 255, 255, 0.05);
    height: 10px;
    border-radius: 5px;
    overflow: hidden;
    position: relative;
    border: 1px solid var(--border-glass);
}

.progress-bar {
    width: 0%;
    height: 100%;
    background: linear-gradient(to right, var(--accent-indigo), var(--accent-teal));
    border-radius: 5px;
    transition: width 0.1s ease;
}

.loading-text {
    font-size: 1.1rem;
    font-weight: 500;
}

.loading-subtext {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Viewer Container & Page-Flip Styles */
.viewer-container {
    display: none;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
    flex: 1;              /* fill the remaining height in the main flex area */
    min-height: 0;
    position: relative;
}

.book-viewport {
    background: radial-gradient(circle, #2d3748 0%, #1a202c 100%);
    border-radius: var(--border-radius-lg);
    border: 1px solid var(--border-glass);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    flex: 1;                /* stretch to fill viewer-container height */
    min-height: 300px;
    position: relative;
    overflow: visible;
    box-shadow: var(--shadow-premium);
}

/* Book theme variations */
.book-viewport.theme-dark {
    background: radial-gradient(circle, #1a202c 0%, #0f1319 100%);
}
.book-viewport.theme-light {
    background: radial-gradient(circle, #e2e8f0 0%, #cbd5e1 100%);
}
.book-viewport.theme-wood {
    background: radial-gradient(circle, rgba(139, 69, 19, 0.6) 0%, rgba(54, 25, 0, 0.9) 100%);
}
.book-viewport.theme-leather {
    background: radial-gradient(circle, #4a1c1c 0%, #1f0808 100%);
}

.flipbook-el {
    box-shadow: 0 30px 70px rgba(0,0,0,0.7);
    margin: auto;
}

/* Individual Book Page Styles */
.page {
    background-color: white;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    box-shadow: inset 3px 0 20px rgba(0, 0, 0, 0.1);
}

.page.hard-page {
    box-shadow: 5px 0 15px rgba(0, 0, 0, 0.3);
}

.page-content {
    width: 100%;
    height: 100%;
    position: relative;
}

.page-canvas {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain;
}

.page-num {
    position: absolute;
    bottom: 10px;
    font-size: 0.8rem;
    color: #a0aec0;
    width: 100%;
    text-align: center;
    pointer-events: none;
    z-index: 20;
}

/* Realistic Paper Texture */
.page::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background-image: url('data:image/svg+xml;utf8,<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"><filter id="noiseFilter"><feTurbulence type="fractalNoise" baseFrequency="0.65" numOctaves="3" stitchTiles="stitch"/></filter><rect width="100%" height="100%" filter="url(%23noiseFilter)" opacity="0.05"/></svg>');
    pointer-events: none;
    z-index: 10;
    mix-blend-mode: multiply;
}

/* Inner Spine Shadow to simulate book depth (Permanent when pages are open) */
.page:not(.hard-page)::after {
    content: "";
    position: absolute;
    top: 0; bottom: 0;
    width: 60px; /* Wider for better visibility */
    pointer-events: none;
    z-index: 100; /* Stays above content */
    mix-blend-mode: multiply;
}

/* Page on the right side of the spread */
.page.page-right:not(.hard-page)::after {
    left: 0; /* Shadow on its left edge (spine) */
    background: linear-gradient(to right, rgba(0,0,0,0.3) 0%, rgba(0,0,0,0.05) 40%, transparent 100%);
}

/* Page on the left side of the spread */
.page.page-left:not(.hard-page)::after {
    right: 0; /* Shadow on its right edge (spine) */
    background: linear-gradient(to left, rgba(0,0,0,0.3) 0%, rgba(0,0,0,0.05) 40%, transparent 100%);
}

/* Controls Bar */
.controls-bar {
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-glass);
    border-radius: var(--border-radius-md);
    padding: 0.75rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    box-shadow: var(--shadow-premium);
}

.control-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-ctrl {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-glass);
    color: var(--text-primary);
    width: 40px;
    height: 40px;
    border-radius: var(--border-radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: var(--transition-smooth);
}

.btn-ctrl:hover {
    background: var(--accent-indigo);
    border-color: var(--accent-indigo);
    box-shadow: 0 0 12px var(--accent-indigo-glow);
    transform: translateY(-2px);
}

.btn-ctrl:active {
    transform: translateY(0);
}

.btn-ctrl:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    transform: none;
    background: rgba(255, 255, 255, 0.02);
    border-color: var(--border-glass);
}

.page-indicator {
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0 0.5rem;
    color: var(--text-secondary);
}

/* Action Buttons */
.btn-action {
    padding: 0.75rem 1.5rem;
    border-radius: var(--border-radius-md);
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: var(--transition-smooth);
    border: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-indigo), var(--accent-teal));
    color: white;
    box-shadow: 0 4px 15px var(--accent-indigo-glow);
}

.btn-primary:hover {
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.6);
    transform: translateY(-2px);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-glass);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--border-glass);
    border-color: var(--text-secondary);
}

/* Floating Notification toast */
.toast-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

body.rtl .toast-container {
    left: 2rem;
    right: auto;
}

.toast {
    background: rgba(19, 26, 46, 0.95);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-glass);
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius-md);
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    max-width: 350px;
}

.toast-success {
    border-left: 4px solid var(--accent-success);
}
body.rtl .toast-success {
    border-right: 4px solid var(--accent-success);
    border-left: none;
}

.toast-error {
    border-left: 4px solid var(--accent-danger);
}
body.rtl .toast-error {
    border-right: 4px solid var(--accent-danger);
    border-left: none;
}

.toast-info {
    border-left: 4px solid var(--accent-indigo);
}
body.rtl .toast-info {
    border-right: 4px solid var(--accent-indigo);
    border-left: none;
}

@keyframes slideIn {
    from {
        transform: translateY(100%) scale(0.9);
        opacity: 0;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

/* Footer Section */
footer {
    padding: 2rem;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border-glass);
    margin-top: auto;
}

/* Corner Peek Animations */
@keyframes cornerPulseRight {
    0%   { transform: translateX(0) scale(1); }
    50%  { transform: translateX(-4px) scale(1.05); }
    100% { transform: translateX(0) scale(1); }
}
@keyframes cornerPulseLeft {
    0%   { transform: translateX(0) scale(1); }
    50%  { transform: translateX(4px) scale(1.05); }
    100% { transform: translateX(0) scale(1); }
}
.corner-hint-wrap {
    position: absolute;
    width: 64px;
    height: 64px;
    bottom: 2rem;
    cursor: pointer;
    z-index: 100;
    transition: opacity 0.3s ease;
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.3));
}
.corner-hint-wrap:hover .corner-svg {
    filter: brightness(1.1);
}
.corner-hint-right {
    right: 2rem;
    animation: cornerPulseRight 2s infinite ease-in-out;
}
.corner-hint-left {
    left: 2rem;
    animation: cornerPulseLeft 2s infinite ease-in-out;
}

/* Responsive adjustements */
@media (max-width: 1024px) {
    main {
        flex-direction: column;
        padding: 1rem;
    }
    .sidebar {
        width: 100%;
    }
}
