/* ==========================================================================
   Web QA Digital E-Book Library — World-Class Editorial Design System
   Supports Light Mode ("Editorial Ivory") & Dark Mode ("Midnight Study")
   ========================================================================== */

:root,
[data-theme="light"] {
    /* Core Palette - Light */
    --bg-canvas: #f6f5f1;
    --bg-canvas-accent: radial-gradient(ellipse 80% 50% at 50% -10%, rgba(79, 70, 229, 0.10), transparent 70%),
                        radial-gradient(ellipse 50% 40% at 100% 0%, rgba(217, 119, 6, 0.06), transparent 60%);
    --bg-surface: #ffffff;
    --bg-surface-elevated: #ffffff;
    --bg-surface-subtle: #f1f0eb;
    --bg-glass: rgba(255, 255, 255, 0.86);
    --bg-glass-strong: rgba(255, 255, 255, 0.94);

    /* Borders */
    --border-subtle: rgba(15, 23, 42, 0.08);
    --border-strong: rgba(15, 23, 42, 0.14);
    --border-accent: rgba(79, 70, 229, 0.30);

    /* Typography */
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --text-inverse: #ffffff;

    /* Brand Accents */
    --accent-primary: #4f46e5;
    --accent-primary-hover: #4338ca;
    --accent-primary-soft: rgba(79, 70, 229, 0.10);
    --accent-primary-glow: rgba(79, 70, 229, 0.22);
    --accent-gold: #d97706;
    --accent-gold-soft: rgba(217, 119, 6, 0.12);

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 10px 30px -8px rgba(15, 23, 42, 0.09);
    --shadow-lg: 0 20px 50px -12px rgba(15, 23, 42, 0.14);
    --shadow-book: 0 14px 28px -6px rgba(15, 23, 42, 0.22), 0 4px 10px -2px rgba(15, 23, 42, 0.12);
    --shadow-book-hover: 0 24px 44px -8px rgba(79, 70, 229, 0.28), 0 10px 20px -4px rgba(15, 23, 42, 0.18);

    /* Inputs */
    --input-bg: #ffffff;
    --input-border: rgba(15, 23, 42, 0.14);
    --input-focus-bg: #ffffff;

    /* Table */
    --table-hover: rgba(79, 70, 229, 0.04);
    --table-header-bg: #f8fafc;

    /* Shelf */
    --shelf-shadow: linear-gradient(180deg, rgba(15, 23, 42, 0.06) 0%, transparent 100%);
    color-scheme: light;
}

[data-theme="dark"] {
    /* Core Palette - Dark */
    --bg-canvas: #090d16;
    --bg-canvas-accent: radial-gradient(ellipse 80% 50% at 50% -10%, rgba(99, 102, 241, 0.18), transparent 70%),
                        radial-gradient(ellipse 50% 40% at 100% 0%, rgba(245, 158, 11, 0.08), transparent 60%);
    --bg-surface: #111827;
    --bg-surface-elevated: #161f33;
    --bg-surface-subtle: #0f172a;
    --bg-glass: rgba(15, 23, 42, 0.80);
    --bg-glass-strong: rgba(17, 24, 39, 0.92);

    /* Borders */
    --border-subtle: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.15);
    --border-accent: rgba(129, 140, 248, 0.40);

    /* Typography */
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --text-inverse: #0f172a;

    /* Brand Accents */
    --accent-primary: #6366f1;
    --accent-primary-hover: #818cf8;
    --accent-primary-soft: rgba(99, 102, 241, 0.16);
    --accent-primary-glow: rgba(99, 102, 241, 0.35);
    --accent-gold: #f59e0b;
    --accent-gold-soft: rgba(245, 158, 11, 0.15);

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
    --shadow-md: 0 12px 32px -8px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 24px 60px -12px rgba(0, 0, 0, 0.65);
    --shadow-book: 0 16px 32px -6px rgba(0, 0, 0, 0.65), 0 4px 12px rgba(0, 0, 0, 0.45);
    --shadow-book-hover: 0 26px 50px -8px rgba(99, 102, 241, 0.35), 0 12px 24px rgba(0, 0, 0, 0.6);

    /* Inputs */
    --input-bg: rgba(15, 23, 42, 0.85);
    --input-border: rgba(255, 255, 255, 0.12);
    --input-focus-bg: #0f172a;

    /* Table */
    --table-hover: rgba(99, 102, 241, 0.08);
    --table-header-bg: rgba(15, 23, 42, 0.7);

    /* Shelf */
    --shelf-shadow: linear-gradient(180deg, rgba(0, 0, 0, 0.35) 0%, transparent 100%);
    color-scheme: dark;
}

/* ==========================================================================
   Base Reset & Typography
   ========================================================================== */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Prompt', 'IBM Plex Sans Thai', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-canvas);
    background-image: var(--bg-canvas-accent);
    background-attachment: fixed;
    color: var(--text-primary);
    min-height: 100vh;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    transition: background-color 0.28s ease, color 0.28s ease;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--accent-primary);
    transition: color 0.2s ease;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ==========================================================================
   Navigation Bar
   ========================================================================== */
.ebook-navbar {
    background: var(--bg-glass);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border-bottom: 1px solid var(--border-subtle);
    padding: 12px 0;
    transition: background-color 0.28s ease, border-color 0.28s ease;
    z-index: 1030;
}

.ebook-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: var(--text-primary) !important;
    font-weight: 600;
    font-size: 1.08rem;
    letter-spacing: -0.01em;
}

.ebook-brand-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--accent-primary), #7c3aed);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    box-shadow: 0 6px 16px var(--accent-primary-glow);
    flex-shrink: 0;
}

.ebook-brand-subtitle {
    display: block;
    font-size: 0.72rem;
    font-weight: 400;
    color: var(--text-muted);
    line-height: 1.2;
}

/* Theme Toggle Pill */
.theme-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    border-radius: 999px;
    background: var(--bg-surface-subtle);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    font-size: 0.84rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.22s ease;
}

.theme-toggle-btn:hover {
    border-color: var(--border-accent);
    background: var(--accent-primary-soft);
    color: var(--accent-primary);
    transform: translateY(-1px);
}

.theme-toggle-btn .theme-icon-sun {
    display: none;
    color: #f59e0b;
}
.theme-toggle-btn .theme-icon-moon {
    display: inline-block;
    color: #6366f1;
}

[data-theme="dark"] .theme-toggle-btn .theme-icon-sun {
    display: inline-block;
}
[data-theme="dark"] .theme-toggle-btn .theme-icon-moon {
    display: none;
}

/* Buttons */
.btn-ebook-primary {
    background: linear-gradient(135deg, var(--accent-primary), #6d28d9);
    color: #ffffff !important;
    border: none;
    border-radius: 12px;
    padding: 9px 18px;
    font-weight: 500;
    font-size: 0.9rem;
    box-shadow: 0 6px 18px var(--accent-primary-glow);
    transition: all 0.22s cubic-bezier(0.22, 1, 0.36, 1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    text-decoration: none;
}

.btn-ebook-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 26px var(--accent-primary-glow);
    filter: brightness(1.06);
}

.btn-ebook-ghost {
    background: var(--bg-surface-subtle);
    color: var(--text-primary) !important;
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 8px 16px;
    font-weight: 500;
    font-size: 0.88rem;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    text-decoration: none;
}

.btn-ebook-ghost:hover {
    background: var(--accent-primary-soft);
    border-color: var(--border-accent);
    color: var(--accent-primary) !important;
    transform: translateY(-1px);
}

/* ==========================================================================
   Surfaces, Cards & Forms
   ========================================================================== */
.surface-panel {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 22px;
    box-shadow: var(--shadow-md);
    transition: background-color 0.28s ease, border-color 0.28s ease;
}

.hero-editorial {
    position: relative;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 26px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.hero-editorial::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 12% 18%, var(--accent-primary-soft) 0%, transparent 45%),
        radial-gradient(circle at 88% 82%, var(--accent-gold-soft) 0%, transparent 42%);
    pointer-events: none;
}

.hero-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 999px;
    background: var(--accent-primary-soft);
    color: var(--accent-primary);
    border: 1px solid var(--border-accent);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.hero-stat-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: 14px;
    background: var(--bg-surface-subtle);
    border: 1px solid var(--border-subtle);
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.hero-stat-pill strong {
    color: var(--text-primary);
    font-weight: 700;
}

/* Forms */
.form-control,
.form-select {
    background-color: var(--input-bg) !important;
    border: 1px solid var(--input-border) !important;
    color: var(--text-primary) !important;
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 0.92rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.form-control::placeholder {
    color: var(--text-muted) !important;
    opacity: 0.8;
}

.form-control:focus,
.form-select:focus {
    background-color: var(--input-focus-bg) !important;
    border-color: var(--accent-primary) !important;
    box-shadow: 0 0 0 4px var(--accent-primary-soft) !important;
    color: var(--text-primary) !important;
}

.input-group-text {
    background-color: var(--bg-surface-subtle) !important;
    border: 1px solid var(--input-border) !important;
    color: var(--text-muted) !important;
    border-radius: 12px;
}

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

.form-text {
    color: var(--text-muted) !important;
}

/* ==========================================================================
   Category Bookshelf Tabs — Vibrant Jewel-Tone Editorial Palette
   ========================================================================== */
.shelf-tabs-wrapper {
    display: flex;
    justify-content: center;
    overflow-x: auto;
    padding: 6px 4px 14px;
    scrollbar-width: none;
}
.shelf-tabs-wrapper::-webkit-scrollbar {
    display: none;
}

.shelf-tabs {
    display: inline-flex;
    gap: 10px;
    padding: 8px;
    border-radius: 22px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-md);
}

/* Per-category vibrant color tokens */
.shelf-tab-link {
    --tab-grad: linear-gradient(135deg, #4f46e5, #2563eb);
    --tab-color: #4f46e5;
    --tab-soft: rgba(79, 70, 229, 0.12);
    --tab-border: rgba(79, 70, 229, 0.28);
    --tab-glow: rgba(79, 70, 229, 0.34);

    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 9px 15px 9px 10px;
    border-radius: 15px;
    text-decoration: none;
    color: var(--text-primary);
    background: var(--tab-soft);
    border: 1px solid transparent;
    font-size: 0.88rem;
    font-weight: 600;
    white-space: nowrap;
    transition: all 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.shelf-tab-link[data-tab-color="action_plan"] {
    --tab-grad: linear-gradient(135deg, #4f46e5, #2563eb);
    --tab-color: #4f46e5;
    --tab-soft: rgba(79, 70, 229, 0.11);
    --tab-border: rgba(79, 70, 229, 0.35);
    --tab-glow: rgba(79, 70, 229, 0.36);
}
.shelf-tab-link[data-tab-color="knowledge"] {
    --tab-grad: linear-gradient(135deg, #059669, #0d9488);
    --tab-color: #059669;
    --tab-soft: rgba(5, 150, 105, 0.11);
    --tab-border: rgba(5, 150, 105, 0.35);
    --tab-glow: rgba(5, 150, 105, 0.36);
}
.shelf-tab-link[data-tab-color="risk"] {
    --tab-grad: linear-gradient(135deg, #d97706, #ea580c);
    --tab-color: #d97706;
    --tab-soft: rgba(217, 119, 6, 0.12);
    --tab-border: rgba(217, 119, 6, 0.36);
    --tab-glow: rgba(234, 88, 12, 0.36);
}
.shelf-tab-link[data-tab-color="qa"] {
    --tab-grad: linear-gradient(135deg, #7c3aed, #a855f7);
    --tab-color: #7c3aed;
    --tab-soft: rgba(124, 58, 237, 0.11);
    --tab-border: rgba(124, 58, 237, 0.35);
    --tab-glow: rgba(124, 58, 237, 0.36);
}
.shelf-tab-link[data-tab-color="sar"] {
    --tab-grad: linear-gradient(135deg, #e11d48, #ec4899);
    --tab-color: #e11d48;
    --tab-soft: rgba(225, 29, 72, 0.11);
    --tab-border: rgba(225, 29, 72, 0.35);
    --tab-glow: rgba(225, 29, 72, 0.36);
}
.shelf-tab-link[data-tab-color="annual"] {
    --tab-grad: linear-gradient(135deg, #0284c7, #06b6d4);
    --tab-color: #0284c7;
    --tab-soft: rgba(2, 132, 199, 0.11);
    --tab-border: rgba(2, 132, 199, 0.35);
    --tab-glow: rgba(2, 132, 199, 0.36);
}

[data-theme="dark"] .shelf-tab-link[data-tab-color="action_plan"] { --tab-color: #818cf8; --tab-soft: rgba(99, 102, 241, 0.16); }
[data-theme="dark"] .shelf-tab-link[data-tab-color="knowledge"]   { --tab-color: #34d399; --tab-soft: rgba(16, 185, 129, 0.16); }
[data-theme="dark"] .shelf-tab-link[data-tab-color="risk"]        { --tab-color: #fbbf24; --tab-soft: rgba(245, 158, 11, 0.16); }
[data-theme="dark"] .shelf-tab-link[data-tab-color="qa"]          { --tab-color: #c084fc; --tab-soft: rgba(168, 85, 247, 0.16); }
[data-theme="dark"] .shelf-tab-link[data-tab-color="sar"]         { --tab-color: #fb7185; --tab-soft: rgba(244, 63, 94, 0.16); }
[data-theme="dark"] .shelf-tab-link[data-tab-color="annual"]      { --tab-color: #38bdf8; --tab-soft: rgba(14, 165, 233, 0.16); }

.shelf-tab-icon {
    width: 30px;
    height: 30px;
    border-radius: 10px;
    background: var(--tab-grad);
    color: #ffffff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.84rem;
    box-shadow: 0 4px 10px var(--tab-glow);
    flex-shrink: 0;
    transition: transform 0.25s ease, background 0.25s ease;
}

.shelf-tab-link:hover {
    border-color: var(--tab-border);
    color: var(--tab-color);
    transform: translateY(-2px);
    box-shadow: 0 8px 18px -6px var(--tab-glow);
}

.shelf-tab-link:hover .shelf-tab-icon {
    transform: scale(1.08) rotate(-3deg);
}

.shelf-tab-link.active {
    background: var(--tab-grad);
    color: #ffffff !important;
    border-color: transparent;
    box-shadow: 0 10px 24px -4px var(--tab-glow);
    transform: translateY(-2px);
}

.shelf-tab-link.active .shelf-tab-icon {
    background: rgba(255, 255, 255, 0.24);
    box-shadow: none;
    color: #ffffff;
}

.shelf-tab-count {
    font-size: 0.74rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--bg-surface);
    color: var(--tab-color);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.shelf-tab-link.active .shelf-tab-count {
    background: rgba(255, 255, 255, 0.24);
    color: #ffffff;
    box-shadow: none;
}

/* ==========================================================================
   3D E-Book Cards (Signature Bookshelf Aesthetic)
   ========================================================================== */
.ebook-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 20px;
    padding: 18px;
    height: 100%;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1),
                box-shadow 0.3s cubic-bezier(0.22, 1, 0.36, 1),
                border-color 0.3s ease;
    box-shadow: var(--shadow-sm);
}

.ebook-card:hover {
    transform: translateY(-6px);
    box-shadow: var(--shadow-lg);
    border-color: var(--border-accent);
}

/* 3D Book Cover Container */
.ebook-cover-stage {
    position: relative;
    padding: 12px 16px 16px;
    margin-bottom: 14px;
    border-radius: 14px;
    background: var(--bg-surface-subtle);
    display: flex;
    align-items: center;
    justify-content: center;
    perspective: 1100px;
    cursor: pointer;
    overflow: hidden;
}

.ebook-cover-book {
    position: relative;
    width: 100%;
    max-width: 195px;
    aspect-ratio: 3 / 4.15;
    border-radius: 4px 12px 12px 4px;
    overflow: hidden;
    box-shadow: var(--shadow-book);
    transform: rotateY(-5deg);
    transform-origin: left center;
    transition: transform 0.38s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.38s ease;
    background: linear-gradient(145deg, #1e293b, #0f172a);
}

.ebook-card:hover .ebook-cover-book {
    transform: rotateY(-12deg) translateY(-4px) scale(1.02);
    box-shadow: var(--shadow-book-hover);
}

/* Realistic Book Spine Highlight */
.ebook-cover-book::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 14px;
    background: linear-gradient(
        90deg,
        rgba(0, 0, 0, 0.32) 0%,
        rgba(255, 255, 255, 0.22) 26%,
        rgba(0, 0, 0, 0.14) 55%,
        transparent 100%
    );
    z-index: 3;
    pointer-events: none;
}

/* Subtle glossy sheen */
.ebook-cover-book::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.14) 0%, transparent 45%);
    z-index: 2;
    pointer-events: none;
}

.ebook-cover-book img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Fallback Generated Editorial Book Cover */
.ebook-cover-placeholder {
    width: 100%;
    height: 100%;
    padding: 20px 16px 16px 24px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    background: linear-gradient(155deg, #312e81 0%, #1e1b4b 55%, #0f172a 100%);
    color: #ffffff;
    text-align: left;
}

.ebook-cover-placeholder .placeholder-tag {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #a5b4fc;
    font-weight: 600;
}

.ebook-cover-placeholder .placeholder-title {
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.ebook-cover-placeholder .placeholder-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.65);
    border-top: 1px solid rgba(255, 255, 255, 0.14);
    padding-top: 8px;
}

/* Quick Read Overlay on Hover */
.ebook-read-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.60);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.25s ease;
    z-index: 4;
    color: #fff;
}

.ebook-cover-stage:hover .ebook-read-overlay {
    opacity: 1;
}

.ebook-read-pill {
    padding: 8px 16px;
    border-radius: 999px;
    background: #ffffff;
    color: #0f172a;
    font-size: 0.82rem;
    font-weight: 600;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.ebook-year-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 5;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.82);
    backdrop-filter: blur(6px);
    color: #ffffff;
    font-size: 0.72rem;
    font-weight: 600;
    border: 1px solid rgba(255, 255, 255, 0.16);
}

/* Book Card Info */
.ebook-meta-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--accent-primary-soft);
    color: var(--accent-primary);
    font-size: 0.75rem;
    font-weight: 600;
}

.ebook-title {
    font-size: 0.98rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.5;
    margin: 10px 0 12px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 2.95em;
}

.ebook-card-footer {
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.ebook-downloads {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

/* List View Mode for Library */
.ebook-grid.view-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.ebook-grid.view-list > .col {
    width: 100%;
    max-width: 100%;
    flex: 0 0 100%;
}
.ebook-grid.view-list .ebook-card {
    flex-direction: row;
    align-items: center;
    gap: 20px;
    padding: 16px 20px;
}
.ebook-grid.view-list .ebook-cover-stage {
    width: 110px;
    min-width: 110px;
    margin-bottom: 0;
    padding: 8px;
}
.ebook-grid.view-list .ebook-cover-book {
    max-width: 84px;
}
.ebook-grid.view-list .ebook-card-body {
    flex: 1;
    min-width: 0;
}
.ebook-grid.view-list .ebook-title {
    min-height: auto;
    -webkit-line-clamp: 2;
    margin: 6px 0 8px;
}
.ebook-grid.view-list .ebook-card-footer {
    border-top: none;
    padding-top: 4px;
}

@media (max-width: 576px) {
    .ebook-grid.view-list .ebook-card {
        flex-direction: column;
        align-items: stretch;
    }
    .ebook-grid.view-list .ebook-cover-stage {
        width: 100%;
    }
}

/* ==========================================================================
   World-Class Fullscreen Interactive E-Book PDF Reader
   ========================================================================== */
.ebook-reader-backdrop {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: none;
    flex-direction: column;
    background: #0d111a;
    color: #f8fafc;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.ebook-reader-backdrop.is-open {
    display: flex;
    opacity: 1;
}

/* Reader Paper Themes */
.ebook-reader-backdrop[data-reader-theme="light"] {
    background: #eceae4;
    color: #0f172a;
}
.ebook-reader-backdrop[data-reader-theme="sepia"] {
    background: #2b241d;
    color: #f5ebe0;
}
.ebook-reader-backdrop[data-reader-theme="sepia"] .reader-canvas-page {
    filter: sepia(0.24) contrast(0.96) brightness(0.97);
}

.reader-topbar {
    height: 60px;
    padding: 0 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: rgba(15, 23, 42, 0.92);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(14px);
    flex-shrink: 0;
    z-index: 10;
}

.ebook-reader-backdrop[data-reader-theme="light"] .reader-topbar,
.ebook-reader-backdrop[data-reader-theme="light"] .reader-bottombar {
    background: rgba(255, 255, 255, 0.92);
    border-color: rgba(15, 23, 42, 0.1);
    color: #0f172a;
}

.reader-title-group {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex: 1;
}

.reader-doc-title {
    font-size: 0.95rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.reader-toolbar-group {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: nowrap;
}

.reader-btn {
    height: 36px;
    min-width: 36px;
    padding: 0 11px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.07);
    color: inherit;
    font-size: 0.84rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
    transition: all 0.18s ease;
    text-decoration: none;
}

.ebook-reader-backdrop[data-reader-theme="light"] .reader-btn {
    border-color: rgba(15, 23, 42, 0.12);
    background: rgba(15, 23, 42, 0.05);
}

.reader-btn:hover:not(:disabled) {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: #ffffff;
}

.reader-btn.active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: #ffffff;
}

.reader-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.reader-body {
    flex: 1;
    display: flex;
    min-height: 0;
    position: relative;
    overflow: hidden;
}

/* Thumbnail Drawer */
.reader-sidebar {
    width: 220px;
    background: rgba(15, 23, 42, 0.78);
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    overflow-y: auto;
    padding: 14px;
    display: none;
    flex-direction: column;
    gap: 12px;
    flex-shrink: 0;
}

.ebook-reader-backdrop[data-reader-theme="light"] .reader-sidebar {
    background: rgba(255, 255, 255, 0.86);
    border-right-color: rgba(15, 23, 42, 0.08);
}

.reader-sidebar.is-visible {
    display: flex;
}

.reader-thumb-item {
    cursor: pointer;
    padding: 8px;
    border-radius: 10px;
    border: 2px solid transparent;
    background: rgba(255, 255, 255, 0.04);
    text-align: center;
    transition: all 0.18s ease;
}

.reader-thumb-item:hover {
    border-color: rgba(99, 102, 241, 0.5);
}

.reader-thumb-item.active {
    border-color: var(--accent-primary);
    background: rgba(99, 102, 241, 0.16);
}

.reader-thumb-item canvas {
    width: 100%;
    height: auto;
    border-radius: 4px;
    display: block;
    background: #fff;
}

.reader-thumb-label {
    font-size: 0.74rem;
    margin-top: 6px;
    opacity: 0.8;
}

/* Main Reading Stage */
.reader-stage {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 28px 64px;
    position: relative;
}

.reader-book-spread {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    position: relative;
    transition: transform 0.25s ease;
}

.reader-page-slot {
    position: relative;
    background: #ffffff;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
    line-height: 0;
    transition: transform 0.28s ease, opacity 0.22s ease;
}

.reader-book-spread.is-double .reader-page-slot.slot-left {
    border-radius: 6px 0 0 6px;
}

.reader-book-spread.is-double .reader-page-slot.slot-right {
    border-radius: 0 6px 6px 0;
}

/* Center Book Gutter Shadow in Double-Page E-Book Mode */
.reader-book-spread.is-double .reader-page-slot.slot-left::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 28px;
    background: linear-gradient(90deg, transparent, rgba(0, 0, 0, 0.22));
    pointer-events: none;
}

.reader-book-spread.is-double .reader-page-slot.slot-right::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 28px;
    background: linear-gradient(270deg, transparent, rgba(0, 0, 0, 0.18));
    pointer-events: none;
}

.reader-book-spread.is-single .reader-page-slot {
    border-radius: 8px;
}

.reader-canvas-page {
    display: block;
    max-width: 100%;
    height: auto;
}

/* Floating Prev / Next Arrows */
.reader-nav-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(15, 23, 42, 0.72);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    cursor: pointer;
    z-index: 15;
    backdrop-filter: blur(8px);
    transition: all 0.2s ease;
}

.reader-nav-arrow:hover:not(:disabled) {
    background: var(--accent-primary);
    transform: translateY(-50%) scale(1.08);
}

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

.reader-nav-prev { left: 16px; }
.reader-nav-next { right: 16px; }

/* Page Flip Animation */
@keyframes pageTurnIn {
    0% { opacity: 0.35; transform: scale(0.985); }
    100% { opacity: 1; transform: scale(1); }
}
.reader-book-spread.animating {
    animation: pageTurnIn 0.24s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Loading & Fallback */
.reader-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    background: rgba(9, 13, 22, 0.85);
    backdrop-filter: blur(8px);
    z-index: 20;
    color: #fff;
}

.reader-fallback-iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: #fff;
}

/* Bottom Scrubber Bar */
.reader-bottombar {
    height: 54px;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    background: rgba(15, 23, 42, 0.92);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}

.reader-scrubber {
    width: 260px;
    max-width: 45vw;
    accent-color: var(--accent-primary);
    cursor: pointer;
}

.reader-page-input {
    width: 58px;
    height: 32px;
    text-align: center;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(255, 255, 255, 0.08);
    color: inherit;
    font-size: 0.85rem;
    font-weight: 600;
}

.ebook-reader-backdrop[data-reader-theme="light"] .reader-page-input {
    border-color: rgba(15, 23, 42, 0.16);
    background: rgba(15, 23, 42, 0.05);
}

@media (max-width: 768px) {
    .reader-stage { padding: 14px 12px; }
    .reader-nav-arrow { width: 38px; height: 38px; font-size: 0.95rem; }
    .reader-nav-prev { left: 6px; }
    .reader-nav-next { right: 6px; }
    .reader-btn .btn-label { display: none; }
}

/* ==========================================================================
   Admin Panel, Tables & DataTables Theme Adaptation
   ========================================================================== */
.admin-nav-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px !important;
    border-radius: 11px;
    color: var(--text-secondary) !important;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.admin-nav-link:hover {
    background: var(--bg-surface-subtle);
    color: var(--text-primary) !important;
}

.admin-nav-link.active {
    background: var(--accent-primary-soft) !important;
    color: var(--accent-primary) !important;
    font-weight: 600;
}

.kpi-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 20px;
    padding: 22px;
    box-shadow: var(--shadow-sm);
    transition: transform 0.24s ease, box-shadow 0.24s ease, border-color 0.24s ease;
}

.kpi-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
    border-color: var(--border-accent);
}

.kpi-icon-box {
    width: 46px;
    height: 46px;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

/* Bootstrap Table Theme Override */
.table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--text-primary);
    --bs-table-hover-bg: var(--table-hover);
    --bs-table-hover-color: var(--text-primary);
    --bs-table-border-color: var(--border-subtle);
    color: var(--text-primary) !important;
}

.table thead th {
    background-color: var(--table-header-bg) !important;
    color: var(--text-muted) !important;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
    border-bottom: 1px solid var(--border-subtle) !important;
    padding: 13px 14px;
}

.table tbody td {
    padding: 13px 14px;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-subtle) !important;
}

/* DataTables Theme Adaptation */
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate {
    color: var(--text-secondary) !important;
    font-size: 0.86rem;
}

.dataTables_wrapper .dataTables_length select,
.dataTables_wrapper .dataTables_filter input {
    background-color: var(--input-bg) !important;
    border: 1px solid var(--input-border) !important;
    color: var(--text-primary) !important;
    border-radius: 10px;
    padding: 5px 10px;
}

.page-link {
    background-color: var(--bg-surface) !important;
    border-color: var(--border-subtle) !important;
    color: var(--text-secondary) !important;
    border-radius: 8px !important;
    margin: 0 2px;
}

.page-item.active .page-link {
    background-color: var(--accent-primary) !important;
    border-color: var(--accent-primary) !important;
    color: #ffffff !important;
}

.page-item.disabled .page-link {
    opacity: 0.45;
}

/* Footer */
.ebook-footer {
    margin-top: auto;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-subtle);
    padding: 28px 0;
    color: var(--text-muted);
    font-size: 0.86rem;
}

/* Utility Text Tokens */
.text-ink { color: var(--text-primary) !important; }
.text-ink-secondary { color: var(--text-secondary) !important; }
.text-ink-muted { color: var(--text-muted) !important; }
.border-theme { border-color: var(--border-subtle) !important; }

/* ==========================================================================
   Full-Width Fluid Responsive Layout (Mobile 320px -> 4K / Ultrawide)
   ========================================================================== */
.ebook-grid-fluid {
    display: grid;
    grid-template-columns: repeat(1, minmax(0, 1fr));
    gap: 1.25rem;
}

@media (min-width: 576px) {
    .ebook-grid-fluid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (min-width: 900px) {
    .ebook-grid-fluid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (min-width: 1240px) {
    .ebook-grid-fluid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (min-width: 1600px) {
    .ebook-grid-fluid {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }
}

@media (min-width: 1960px) {
    .ebook-grid-fluid {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }
}

.ebook-grid-fluid.view-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.ebook-grid-fluid.view-list .ebook-card {
    flex-direction: row;
    align-items: center;
    gap: 20px;
    padding: 16px 22px;
}

.ebook-grid-fluid.view-list .ebook-cover-stage {
    width: 112px;
    min-width: 112px;
    margin-bottom: 0;
    padding: 8px;
}

.ebook-grid-fluid.view-list .ebook-cover-book {
    max-width: 86px;
}

.ebook-grid-fluid.view-list .ebook-card-body {
    flex: 1;
    min-width: 0;
}

.ebook-grid-fluid.view-list .ebook-title {
    min-height: auto;
    margin: 6px 0 8px;
}

.ebook-grid-fluid.view-list .ebook-card-footer {
    border-top: none;
    padding-top: 4px;
}

/* Mobile & Small Tablet Polish */
@media (max-width: 767.98px) {
    .ebook-brand {
        font-size: 0.94rem;
        gap: 9px;
    }
    .ebook-brand-icon {
        width: 34px;
        height: 34px;
        font-size: 1rem;
        border-radius: 10px;
    }
    .ebook-brand-subtitle {
        display: none;
    }
    .hero-editorial {
        border-radius: 18px;
    }
    .shelf-tabs-wrapper {
        justify-content: flex-start;
    }
    .shelf-tabs {
        border-radius: 16px;
        padding: 6px;
        gap: 6px;
    }
    .shelf-tab-link {
        padding: 7px 12px 7px 8px;
        font-size: 0.82rem;
    }
    .shelf-tab-icon {
        width: 26px;
        height: 26px;
        font-size: 0.76rem;
    }
}

@media (max-width: 575.98px) {
    .ebook-grid-fluid.view-list .ebook-card {
        flex-direction: column;
        align-items: stretch;
    }
    .ebook-grid-fluid.view-list .ebook-cover-stage {
        width: 100%;
    }
}

/* ==========================================================================
   Executive Colorful Admin Dashboard Components
   ========================================================================== */
.dash-hero-banner {
    position: relative;
    border-radius: 24px;
    padding: 28px 32px;
    background: linear-gradient(125deg, #312e81 0%, #4f46e5 48%, #7c3aed 82%, #ec4899 100%);
    color: #ffffff;
    overflow: hidden;
    box-shadow: 0 20px 45px -12px rgba(79, 70, 229, 0.42);
}

.dash-hero-banner::before {
    content: '';
    position: absolute;
    width: 340px;
    height: 340px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.22) 0%, transparent 70%);
    top: -120px;
    right: -60px;
    pointer-events: none;
}

.dash-hero-banner::after {
    content: '';
    position: absolute;
    width: 220px;
    height: 220px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(251, 191, 36, 0.22) 0%, transparent 70%);
    bottom: -90px;
    left: 22%;
    pointer-events: none;
}

.dash-hero-btn-light {
    background: #ffffff;
    color: #312e81 !important;
    border: none;
    border-radius: 12px;
    padding: 9px 18px;
    font-weight: 600;
    font-size: 0.88rem;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    text-decoration: none;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.2);
    transition: all 0.2s ease;
}

.dash-hero-btn-light:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 26px rgba(15, 23, 42, 0.28);
}

.dash-hero-btn-glass {
    background: rgba(255, 255, 255, 0.16);
    color: #ffffff !important;
    border: 1px solid rgba(255, 255, 255, 0.28);
    backdrop-filter: blur(8px);
    border-radius: 12px;
    padding: 9px 16px;
    font-weight: 500;
    font-size: 0.88rem;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    text-decoration: none;
    transition: all 0.2s ease;
}

.dash-hero-btn-glass:hover {
    background: rgba(255, 255, 255, 0.26);
    transform: translateY(-2px);
}

/* Vibrant Gradient KPI Cards */
.kpi-vibrant {
    position: relative;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 20px;
    padding: 22px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.25s ease, border-color 0.25s ease;
}

.kpi-vibrant::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 4px;
    background: var(--kpi-grad, linear-gradient(90deg, #4f46e5, #2563eb));
}

.kpi-vibrant:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
    border-color: var(--kpi-border, var(--border-accent));
}

.kpi-vibrant .kpi-orb {
    width: 50px;
    height: 50px;
    border-radius: 15px;
    background: var(--kpi-grad);
    color: #ffffff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    box-shadow: 0 8px 18px -4px var(--kpi-glow);
}

.kpi-vibrant.kpi-indigo  { --kpi-grad: linear-gradient(135deg, #4f46e5, #2563eb); --kpi-glow: rgba(79, 70, 229, 0.45); --kpi-border: rgba(79, 70, 229, 0.4); }
.kpi-vibrant.kpi-emerald { --kpi-grad: linear-gradient(135deg, #059669, #10b981); --kpi-glow: rgba(16, 185, 129, 0.45); --kpi-border: rgba(16, 185, 129, 0.4); }
.kpi-vibrant.kpi-amber   { --kpi-grad: linear-gradient(135deg, #d97706, #f59e0b); --kpi-glow: rgba(245, 158, 11, 0.45); --kpi-border: rgba(245, 158, 11, 0.4); }
.kpi-vibrant.kpi-rose    { --kpi-grad: linear-gradient(135deg, #e11d48, #ec4899); --kpi-glow: rgba(236, 72, 153, 0.45); --kpi-border: rgba(236, 72, 153, 0.4); }

/* 6-Category Mini Shelf Cards */
.cat-mini-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px;
    border-radius: 18px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    text-decoration: none;
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
    transition: all 0.24s cubic-bezier(0.22, 1, 0.36, 1);
}

.cat-mini-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
    border-color: var(--cat-accent, var(--accent-primary));
    color: var(--text-primary);
}

.cat-mini-progress {
    height: 6px;
    border-radius: 999px;
    background: var(--bg-surface-subtle);
    overflow: hidden;
}

.cat-mini-progress-bar {
    height: 100%;
    border-radius: 999px;
    background: var(--cat-grad, linear-gradient(90deg, #4f46e5, #2563eb));
}

/* Top 10 Rank Medals */
.rank-badge {
    width: 30px;
    height: 30px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.82rem;
    background: var(--bg-surface-subtle);
    color: var(--text-secondary);
}

.rank-badge.rank-1 { background: linear-gradient(135deg, #f59e0b, #fbbf24); color: #fff; box-shadow: 0 4px 10px rgba(245, 158, 11, 0.4); }
.rank-badge.rank-2 { background: linear-gradient(135deg, #64748b, #94a3b8); color: #fff; box-shadow: 0 4px 10px rgba(100, 116, 139, 0.35); }
.rank-badge.rank-3 { background: linear-gradient(135deg, #b45309, #d97706); color: #fff; box-shadow: 0 4px 10px rgba(180, 83, 9, 0.35); }

.doughnut-center-wrap {
    position: relative;
    height: 300px;
}

.doughnut-center-stat {
    position: absolute;
    top: 43%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    pointer-events: none;
}
