/* ============================================
   FlipBook Pro — Main Stylesheet
   ============================================ */

/* --- Google Fonts imported in HTML --- */

/* --- CSS Custom Properties --- */
:root {
    --font-display: 'Syne', sans-serif;
    --font-body: 'DM Sans', sans-serif;

    /* Light theme */
    --bg-primary: #f8f7ff;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-nav: rgba(255,255,255,0.95);
    --border-color: #e8e6f0;
    --text-primary: #1a1a2e;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;

    /* Brand */
    --accent: #4f46e5;
    --accent-light: #818cf8;
    --accent-dark: #3730a3;
    --accent-glow: rgba(79, 70, 229, 0.15);
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08), 0 2px 6px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.1), 0 4px 12px rgba(0,0,0,0.06);
    --shadow-xl: 0 20px 60px rgba(0,0,0,0.12);

    --radius: 12px;
    --radius-lg: 20px;
    --radius-xl: 28px;
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --nav-height: 66px;
}

/* Dark theme */
[data-theme="dark"] {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-card: #1e1e32;
    --bg-nav: rgba(15,15,26,0.95);
    --border-color: #2d2d4a;
    --text-primary: #f1f0ff;
    --text-secondary: #a0a0c0;
    --text-muted: #6b6b8f;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.4);
    --shadow-xl: 0 20px 60px rgba(0,0,0,0.5);
}

/* --- Base Reset & Typography --- */
*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    font-family: var(--font-body);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    font-size: 15px;
    transition: background-color 0.3s ease, color 0.3s ease;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-display);
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

a { color: var(--accent); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--accent-dark); }

/* --- Navbar --- */
.navbar-main {
    background: var(--bg-nav);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    height: var(--nav-height);
    z-index: 1030;
    transition: var(--transition);
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-primary) !important;
    font-family: var(--font-display);
    font-size: 1.2rem;
}

.brand-icon {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-light) 100%);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.1rem;
    box-shadow: 0 4px 12px var(--accent-glow);
}

.nav-link {
    color: var(--text-secondary) !important;
    font-weight: 500;
    padding: 0.5rem 0.85rem !important;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 7px;
    transition: var(--transition);
}
.nav-link:hover, .nav-link.active {
    color: var(--accent) !important;
    background: var(--accent-glow);
}
.nav-link.active { font-weight: 600; }

.btn-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    padding: 0;
}
.btn-icon:hover { background: var(--accent-glow); color: var(--accent); border-color: var(--accent); }

.btn-user {
    height: 38px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    padding: 0 12px;
    font-weight: 500;
    transition: var(--transition);
}
.btn-user:hover { border-color: var(--accent); }

.user-avatar {
    width: 26px;
    height: 26px;
    background: linear-gradient(135deg, var(--accent), var(--accent-light));
    color: white;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.75rem;
    font-family: var(--font-display);
}

/* Dropdown */
.dropdown-menu {
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 8px;
    min-width: 200px;
}
.dropdown-item {
    border-radius: 8px;
    padding: 8px 12px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    transition: var(--transition);
}
.dropdown-item:hover { background: var(--accent-glow); color: var(--accent); }
.dropdown-divider { border-color: var(--border-color); }
.dropdown-header { color: var(--text-primary); font-family: var(--font-display); padding: 8px 12px; }

/* --- Mobile Nav --- */
.offcanvas {
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    width: 280px !important;
}
.mobile-nav-link {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    color: var(--text-secondary);
    border-radius: var(--radius);
    margin-bottom: 4px;
    font-weight: 500;
    transition: var(--transition);
}
.mobile-nav-link:hover { background: var(--accent-glow); color: var(--accent); }

/* --- Main Content --- */
.main-content {
    flex: 1;
    padding: 2rem 0;
}

/* --- Cards --- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}
.card-hover:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
    border-color: var(--accent-light);
}
.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 1.25rem 1.5rem;
    font-family: var(--font-display);
    font-weight: 600;
}
.card-body { padding: 1.5rem; }

/* --- Stat Cards --- */
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}
.stat-icon.accent { background: var(--accent-glow); color: var(--accent); }
.stat-icon.success { background: rgba(16,185,129,0.12); color: var(--success); }
.stat-icon.warning { background: rgba(245,158,11,0.12); color: var(--warning); }
.stat-icon.info { background: rgba(59,130,246,0.12); color: var(--info); }
.stat-label { font-size: 0.8rem; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 4px; }
.stat-value { font-family: var(--font-display); font-size: 1.75rem; font-weight: 800; color: var(--text-primary); line-height: 1; }
.stat-sub { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }

/* --- Flipbook Cards --- */
.flipbook-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: var(--transition);
    cursor: pointer;
}
.flipbook-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-3px); border-color: var(--accent-light); }
.flipbook-thumb {
    aspect-ratio: 3/4;
    background: linear-gradient(135deg, #e8e6ff 0%, #c7d2fe 100%);
    overflow: hidden;
    position: relative;
}
[data-theme="dark"] .flipbook-thumb { background: linear-gradient(135deg, #1e1b4b 0%, #312e81 100%); }
.flipbook-thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.4s ease; }
.flipbook-card:hover .flipbook-thumb img { transform: scale(1.05); }
.flipbook-thumb-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    color: var(--accent-light);
}
.flipbook-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s ease;
}
.flipbook-card:hover .flipbook-overlay { background: rgba(0,0,0,0.5); }
.flipbook-overlay .btn { opacity: 0; transform: translateY(10px); transition: all 0.3s ease 0.05s; }
.flipbook-card:hover .flipbook-overlay .btn { opacity: 1; transform: translateY(0); }
.flipbook-info { padding: 1rem 1.1rem; }
.flipbook-title { font-weight: 600; font-family: var(--font-display); margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.flipbook-meta { font-size: 0.78rem; color: var(--text-muted); display: flex; gap: 8px; align-items: center; }

/* --- Badge visibility --- */
.badge-visibility {
    font-size: 0.68rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 6px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.badge-public { background: rgba(16,185,129,0.12); color: var(--success); }
.badge-private { background: rgba(245,158,11,0.12); color: var(--warning); }
.badge-password { background: rgba(239,68,68,0.12); color: var(--danger); }

/* --- Upload Zone --- */
.upload-zone {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-xl);
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background: var(--bg-card);
    position: relative;
    overflow: hidden;
}
.upload-zone::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 50% 50%, var(--accent-glow) 0%, transparent 70%);
    opacity: 0;
    transition: opacity 0.3s ease;
}
.upload-zone:hover, .upload-zone.drag-over { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-glow); }
.upload-zone:hover::before, .upload-zone.drag-over::before { opacity: 1; }
.upload-icon { font-size: 3.5rem; color: var(--accent); margin-bottom: 1rem; display: block; transition: transform 0.3s ease; }
.upload-zone:hover .upload-icon { transform: translateY(-5px); }
.upload-title { font-family: var(--font-display); font-size: 1.3rem; font-weight: 700; margin-bottom: 0.5rem; }
.upload-subtitle { color: var(--text-muted); margin-bottom: 1.5rem; }
.upload-types { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.upload-type-badge {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 4px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
}

/* Progress */
.upload-progress-bar { height: 8px; border-radius: 4px; background: var(--bg-primary); overflow: hidden; margin-top: 1rem; }
.upload-progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-light)); border-radius: 4px; transition: width 0.3s ease; width: 0%; }

/* --- Forms --- */
.form-control, .form-select {
    background: var(--bg-primary);
    border: 1.5px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-primary);
    padding: 0.625rem 1rem;
    font-family: var(--font-body);
    font-size: 0.9rem;
    transition: var(--transition);
}
.form-control:focus, .form-select:focus {
    background: var(--bg-card);
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-glow);
    color: var(--text-primary);
}
.form-label { font-weight: 600; font-size: 0.875rem; color: var(--text-primary); margin-bottom: 0.5rem; }
.input-group-text { background: var(--bg-primary); border: 1.5px solid var(--border-color); color: var(--text-muted); }
.form-control::placeholder { color: var(--text-muted); }
.form-control[data-theme="dark"]::placeholder { color: var(--text-muted); }

/* --- Buttons --- */
.btn {
    font-family: var(--font-body);
    font-weight: 600;
    border-radius: 10px;
    transition: var(--transition);
    letter-spacing: 0.01em;
}
.btn-primary {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
    border: none;
    box-shadow: 0 4px 14px var(--accent-glow);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 20px var(--accent-glow); background: linear-gradient(135deg, var(--accent-light), var(--accent)); }
.btn-outline-primary { border-color: var(--accent); color: var(--accent); }
.btn-outline-primary:hover { background: var(--accent); border-color: var(--accent); }

/* --- Tables --- */
.table {
    color: var(--text-primary);
    border-color: var(--border-color);
}
.table thead th {
    background: var(--bg-primary);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    border-bottom: 1px solid var(--border-color);
    padding: 0.875rem 1rem;
}
.table tbody td { padding: 1rem; border-bottom: 1px solid var(--border-color); vertical-align: middle; }
.table tbody tr:hover { background: var(--bg-primary); }
.table-responsive { border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border-color); }

/* --- Progress Bar --- */
.progress {
    background: var(--bg-primary);
    border-radius: 20px;
    overflow: hidden;
}
.progress-bar { background: linear-gradient(90deg, var(--accent), var(--accent-light)); }

/* --- Storage Usage --- */
.storage-bar { height: 10px; border-radius: 5px; background: var(--bg-primary); overflow: hidden; }
.storage-fill { height: 100%; border-radius: 5px; background: linear-gradient(90deg, var(--accent), var(--accent-light)); transition: width 1s ease; }
.storage-fill.warning { background: linear-gradient(90deg, var(--warning), #fbbf24); }
.storage-fill.danger { background: linear-gradient(90deg, var(--danger), #f87171); }

/* --- Page Header --- */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}
.page-title { font-family: var(--font-display); font-size: 1.75rem; font-weight: 800; margin: 0; }
.page-subtitle { color: var(--text-muted); margin-top: 4px; }

/* --- Auth Pages --- */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    position: relative;
    overflow: hidden;
    padding: 2rem;
}
.auth-bg-shape {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.3;
}
.auth-bg-shape-1 { width: 500px; height: 500px; background: var(--accent); top: -200px; right: -100px; }
.auth-bg-shape-2 { width: 400px; height: 400px; background: var(--accent-light); bottom: -150px; left: -100px; }
.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 2.5rem;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow-xl);
    position: relative;
    z-index: 1;
    animation: authSlideIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes authSlideIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}
.auth-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 2rem;
    justify-content: center;
}
.auth-logo-icon {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, var(--accent), var(--accent-light));
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.4rem;
    box-shadow: 0 8px 24px var(--accent-glow);
}

/* --- Flipbook Viewer --- */
.viewer-wrapper {
    background: #111;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
.viewer-toolbar {
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(10px);
    padding: 10px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    z-index: 100;
    position: sticky;
    top: 0;
}
.viewer-btn {
    width: 38px;
    height: 38px;
    border-radius: 9px;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.15);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    font-size: 1rem;
}
.viewer-btn:hover { background: rgba(255,255,255,0.2); }
.viewer-btn:disabled { opacity: 0.4; cursor: default; }
.page-indicator {
    color: rgba(255,255,255,0.7);
    font-size: 0.85rem;
    font-weight: 500;
    font-family: var(--font-display);
    white-space: nowrap;
}
#flipbookContainer {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    position: relative;
}
.flipbook-stage {
    position: relative;
    perspective: 2000px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.book {
    position: relative;
    display: flex;
    transform-style: preserve-3d;
}
.book-page {
    background: white;
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    user-select: none;
    position: relative;
}
.book-page img { width: 100%; height: 100%; object-fit: contain; display: block; }
.page-turn {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(135deg, transparent 85%, rgba(0,0,0,0.12) 100%);
}

/* Thumbnail strip */
.thumb-strip {
    background: rgba(0,0,0,0.7);
    padding: 8px;
    display: flex;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: thin;
}
.thumb-item {
    flex-shrink: 0;
    width: 50px;
    cursor: pointer;
    border-radius: 4px;
    overflow: hidden;
    border: 2px solid transparent;
    transition: var(--transition);
    opacity: 0.6;
}
.thumb-item:hover, .thumb-item.active { border-color: var(--accent); opacity: 1; }
.thumb-item img { width: 100%; height: 70px; object-fit: cover; display: block; }

/* --- Status Badges --- */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.status-ready { background: rgba(16,185,129,0.12); color: var(--success); }
.status-processing { background: rgba(245,158,11,0.12); color: var(--warning); }
.status-error { background: rgba(239,68,68,0.12); color: var(--danger); }
.status-dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: currentColor;
    animation: pulse 2s infinite;
}
.status-ready .status-dot { animation: none; }
@keyframes pulse { 0%,100%{opacity:1}50%{opacity:0.3} }

/* --- Empty States --- */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-muted);
}
.empty-state-icon { font-size: 4rem; margin-bottom: 1rem; opacity: 0.4; }
.empty-state h5 { font-family: var(--font-display); color: var(--text-secondary); margin-bottom: 0.5rem; }

/* --- Modal --- */
.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
}
.modal-header { border-bottom: 1px solid var(--border-color); }
.modal-footer { border-top: 1px solid var(--border-color); }

/* --- Alert --- */
.alert { border-radius: var(--radius); border: none; }
.alert-success { background: rgba(16,185,129,0.1); color: var(--success); }
.alert-danger { background: rgba(239,68,68,0.1); color: var(--danger); }
.alert-warning { background: rgba(245,158,11,0.1); color: var(--warning); }
.alert-info { background: rgba(59,130,246,0.1); color: var(--info); }

/* --- Footer --- */
.app-footer {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: 1.25rem 0;
    margin-top: auto;
}
.footer-link { color: var(--text-muted); font-size: 0.85rem; }
.footer-link:hover { color: var(--accent); }

/* --- QR Code --- */
#qrcode canvas, #qrcode img { border-radius: 8px; }

/* --- Copy Share Link --- */
.share-link-input { font-size: 0.85rem; background: var(--bg-primary) !important; }

/* --- Loading Spinner --- */
.spinner-border-sm { width: 1rem; height: 1rem; }

/* --- Processing animation --- */
.processing-pulse {
    animation: processingPulse 2s cubic-bezier(0.4,0,0.6,1) infinite;
}
@keyframes processingPulse { 0%,100%{opacity:1}50%{opacity:.5} }

/* --- Responsive --- */
@media (max-width: 768px) {
    .main-content { padding: 1rem 0; }
    .page-header { margin-bottom: 1.25rem; }
    .page-title { font-size: 1.4rem; }
    .stat-card { padding: 1rem; }
    .stat-value { font-size: 1.4rem; }
    .auth-card { padding: 1.75rem; }
    #flipbookContainer { padding: 0.5rem; }
}

@media (max-width: 576px) {
    .stat-icon { width: 42px; height: 42px; font-size: 1.1rem; }
    .upload-zone { padding: 2rem 1rem; }
}

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* --- Page entry animations --- */
.fade-in { animation: fadeIn 0.4s ease forwards; }
@keyframes fadeIn { from{opacity:0;transform:translateY(12px)}to{opacity:1;transform:translateY(0)} }
.stagger-1 { animation-delay: 0.05s; opacity: 0; }
.stagger-2 { animation-delay: 0.1s; opacity: 0; }
.stagger-3 { animation-delay: 0.15s; opacity: 0; }
.stagger-4 { animation-delay: 0.2s; opacity: 0; }
