/* فضاء الكتب — Al-Mahir Book Space */

:root {
    --books-ink: #0c1a14;
    --books-paper: #f4efe6;
    --books-gold: #c4a35a;
    --books-teal: #0f766e;
    --books-teal-soft: rgba(15, 118, 110, 0.12);
    --books-ember: #b45309;
    --books-mist: rgba(12, 26, 20, 0.06);
    --books-radius: 24px;
    --books-ease: cubic-bezier(0.4, 0, 0.2, 1);
}

html.dark {
    --books-ink: #f1f5f9;
    --books-paper: #0b1220;
    --books-gold: #fbbf24;
    --books-teal: #34d399;
    --books-teal-soft: rgba(52, 211, 153, 0.12);
    --books-ember: #fb923c;
    --books-mist: rgba(255, 255, 255, 0.06);
}

.books-body {
    font-family: 'Tajawal', sans-serif;
    background:
        radial-gradient(ellipse 80% 50% at 100% -10%, rgba(15, 118, 110, 0.18), transparent 55%),
        radial-gradient(ellipse 60% 40% at -10% 80%, rgba(196, 163, 90, 0.14), transparent 50%),
        linear-gradient(165deg, #f7f3eb 0%, #eef2f0 45%, #e8ece8 100%);
    color: #1e293b;
    min-height: 100vh;
}

html.dark .books-body {
    background:
        radial-gradient(ellipse 70% 45% at 100% 0%, rgba(52, 211, 153, 0.14), transparent 50%),
        radial-gradient(ellipse 50% 35% at 0% 100%, rgba(251, 191, 36, 0.08), transparent 45%),
        linear-gradient(165deg, #050b14 0%, #07111f 50%, #0b1020 100%);
    color: #e2e8f0;
}

.font-amiri,
.books-display {
    font-family: 'Amiri', 'Noto Naskh Arabic', serif;
}

.books-nav {
    backdrop-filter: blur(14px);
    background: rgba(255, 255, 255, 0.78);
    border-bottom: 1px solid rgba(15, 118, 110, 0.12);
}

html.dark .books-nav {
    background: rgba(7, 17, 31, 0.85);
    border-bottom-color: rgba(148, 163, 184, 0.15);
}

.books-hero {
    position: relative;
    overflow: hidden;
    isolation: isolate;
    min-height: min(72vh, 640px);
    display: flex;
    align-items: flex-end;
    padding: 3.5rem 1.25rem 2.75rem;
}

.books-hero::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: -2;
    background:
        linear-gradient(115deg, rgba(12, 26, 20, 0.88) 0%, rgba(15, 118, 110, 0.55) 48%, rgba(12, 26, 20, 0.35) 100%),
        url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23c4a35a' fill-opacity='0.07'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E"),
        linear-gradient(160deg, #0f3d36, #1a2e28 40%, #2c2416);
    background-size: auto, 60px 60px, auto;
}

.books-hero::after {
    content: '';
    position: absolute;
    inset: auto -10% -40% 30%;
    height: 70%;
    z-index: -1;
    background: radial-gradient(circle, rgba(196, 163, 90, 0.35), transparent 65%);
    animation: booksGlow 8s ease-in-out infinite alternate;
    pointer-events: none;
}

@keyframes booksGlow {
    from { transform: translateY(0) scale(1); opacity: 0.7; }
    to { transform: translateY(-18px) scale(1.08); opacity: 1; }
}

.books-hero-inner {
    max-width: 72rem;
    margin: 0 auto;
    width: 100%;
    color: #f8fafc;
}

.books-brand-mark {
    font-family: 'Amiri', serif;
    font-size: clamp(2.6rem, 7vw, 4.4rem);
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: 0;
    margin: 0 0 0.75rem;
    animation: booksFadeUp 0.8s var(--books-ease) both;
}

.books-hero-lead {
    max-width: 34rem;
    font-size: 1.05rem;
    line-height: 1.85;
    color: rgba(248, 250, 252, 0.88);
    margin: 0 0 1.5rem;
    animation: booksFadeUp 0.9s var(--books-ease) 0.12s both;
}

.books-cta-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    animation: booksFadeUp 1s var(--books-ease) 0.22s both;
}

@keyframes booksFadeUp {
    from { opacity: 0; transform: translateY(18px); }
    to { opacity: 1; transform: translateY(0); }
}

.books-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.85rem 1.4rem;
    border-radius: 16px;
    font-weight: 800;
    font-size: 0.9rem;
    transition: transform 0.25s var(--books-ease), filter 0.25s, background 0.25s;
    border: none;
    cursor: pointer;
    text-decoration: none;
}

.books-btn:hover {
    transform: translateY(-2px);
}

.books-btn-primary {
    background: var(--books-gold);
    color: #1a1408;
}

.books-btn-ghost {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.22);
}

.books-legal-banner {
    max-width: 72rem;
    margin: -1.25rem auto 0;
    padding: 0 1.25rem;
    position: relative;
    z-index: 2;
}

.books-legal-banner .inner {
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(15, 118, 110, 0.2);
    border-radius: 18px;
    padding: 0.9rem 1.15rem;
    display: flex;
    gap: 0.85rem;
    align-items: flex-start;
    box-shadow: 0 16px 40px rgba(12, 26, 20, 0.08);
    font-size: 0.85rem;
    line-height: 1.7;
    color: #334155;
}

html.dark .books-legal-banner .inner {
    background: rgba(15, 27, 46, 0.92);
    border-color: rgba(52, 211, 153, 0.25);
    color: #cbd5e1;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

.books-toolbar {
    max-width: 72rem;
    margin: 1.75rem auto 1rem;
    padding: 0 1.25rem;
    display: grid;
    gap: 0.85rem;
}

.books-search-wrap {
    position: relative;
    display: flex;
    align-items: stretch;
    gap: 0.5rem;
}

.books-search {
    flex: 1;
    width: 100%;
    padding: 1rem 1.15rem;
    border-radius: 18px;
    border: 1px solid rgba(15, 118, 110, 0.18);
    background: rgba(255, 255, 255, 0.9);
    font-weight: 700;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.books-search:focus {
    border-color: var(--books-teal);
    box-shadow: 0 0 0 4px var(--books-teal-soft);
}

html.dark .books-search {
    background: rgba(15, 27, 46, 0.9);
    border-color: rgba(148, 163, 184, 0.2);
    color: #f1f5f9;
}

.books-search-btn {
    flex-shrink: 0;
    width: 3.25rem;
    border-radius: 18px;
    border: 1px solid rgba(15, 118, 110, 0.25);
    background: linear-gradient(145deg, #0f766e, #115e59);
    color: #ecfdf5;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, filter 0.15s ease;
}

.books-search-btn:hover {
    filter: brightness(1.08);
}

.books-search-btn:active {
    transform: scale(0.97);
}

.books-search-btn.is-busy {
    opacity: 0.75;
    pointer-events: none;
}

.books-search-btn.is-busy i::before {
    content: "\f110";
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    animation: books-spin 0.8s linear infinite;
}

@keyframes books-spin {
    to { transform: rotate(360deg); }
}

.books-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.books-chip {
    padding: 0.45rem 0.95rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 800;
    background: rgba(255, 255, 255, 0.75);
    border: 1px solid rgba(15, 118, 110, 0.15);
    color: #475569;
    cursor: pointer;
    transition: all 0.2s var(--books-ease);
}

.books-chip:hover,
.books-chip.is-active {
    background: var(--books-teal);
    color: #fff;
    border-color: transparent;
}

html.dark .books-chip {
    background: rgba(15, 27, 46, 0.7);
    color: #94a3b8;
    border-color: rgba(148, 163, 184, 0.18);
}

html.dark .books-chip.is-active {
    background: var(--books-teal);
    color: #052e2b;
}

.books-grid {
    max-width: 72rem;
    margin: 0 auto 3rem;
    padding: 0 1.25rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1.25rem;
}

.book-tile {
    display: flex;
    flex-direction: column;
    text-align: right;
    text-decoration: none;
    color: inherit;
    background: rgba(255, 255, 255, 0.88);
    border: 1px solid rgba(15, 118, 110, 0.12);
    border-radius: var(--books-radius);
    overflow: hidden;
    transition: transform 0.3s var(--books-ease), box-shadow 0.3s, border-color 0.3s;
    animation: booksFadeUp 0.55s var(--books-ease) both;
}

.book-tile:hover {
    transform: translateY(-5px);
    border-color: var(--books-teal);
    box-shadow: 0 18px 40px rgba(15, 118, 110, 0.12);
}

html.dark .book-tile {
    background: rgba(15, 27, 46, 0.78);
    border-color: rgba(148, 163, 184, 0.14);
}

.book-cover {
    aspect-ratio: 3 / 4;
    background:
        linear-gradient(145deg, rgba(15, 118, 110, 0.85), rgba(12, 26, 20, 0.95)),
        repeating-linear-gradient(-12deg, transparent, transparent 10px, rgba(196, 163, 90, 0.08) 10px, rgba(196, 163, 90, 0.08) 11px);
    background-size: cover;
    background-position: center;
    display: flex;
    align-items: flex-end;
    padding: 1rem;
    color: #fff;
    position: relative;
}

.book-cover::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.55), transparent 45%);
    pointer-events: none;
}

.book-cover-title {
    position: relative;
    z-index: 1;
    font-family: 'Amiri', serif;
    font-size: 1.15rem;
    line-height: 1.35;
    font-weight: 700;
}

.book-meta {
    padding: 1rem 1.1rem 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    flex: 1;
}

.book-meta h3 {
    font-size: 1.05rem;
    font-weight: 800;
    color: #0f172a;
    line-height: 1.4;
}

html.dark .book-meta h3 {
    color: #f8fafc;
}

.book-meta .author {
    font-size: 0.82rem;
    color: #64748b;
    font-weight: 700;
}

.book-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.5rem;
}

.book-tag {
    font-size: 0.68rem;
    font-weight: 800;
    padding: 0.2rem 0.55rem;
    border-radius: 8px;
    background: var(--books-teal-soft);
    color: var(--books-teal);
}

.books-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3rem 1rem;
    color: #64748b;
    font-weight: 700;
}

.books-section-head {
    max-width: 72rem;
    margin: 0.5rem auto 0.75rem;
    padding: 0 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    flex-wrap: wrap;
}

.books-section-head h2 {
    font-family: 'Amiri', serif;
    font-size: 1.75rem;
    font-weight: 700;
}

/* Reader layout */
.reader-shell {
    height: 100vh;
    display: grid;
    grid-template-rows: auto 1fr;
    background: #0b1220;
    color: #e2e8f0;
    overflow: hidden;
}

.reader-shell.night-paper .reader-canvas-wrap {
    background: #0a0a0a;
}

.reader-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.65rem 0.9rem;
    background: rgba(7, 17, 31, 0.95);
    border-bottom: 1px solid rgba(148, 163, 184, 0.15);
    flex-wrap: wrap;
}

.reader-topbar .title-block {
    min-width: 0;
    flex: 1;
}

.reader-topbar h1 {
    font-family: 'Amiri', serif;
    font-size: 1.1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0;
}

.reader-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
}

.reader-icon-btn {
    width: 2.35rem;
    height: 2.35rem;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.2);
    background: rgba(255, 255, 255, 0.04);
    color: #e2e8f0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.reader-icon-btn:hover,
.reader-icon-btn.is-active {
    background: rgba(52, 211, 153, 0.15);
    border-color: rgba(52, 211, 153, 0.4);
    color: #34d399;
}

.reader-workspace {
    display: grid;
    grid-template-columns: 1fr;
    min-height: 0;
}

@media (min-width: 960px) {
    .reader-workspace.has-side {
        grid-template-columns: 1fr 300px;
    }
}

.reader-canvas-wrap {
    position: relative;
    overflow: auto;
    background: #1e293b;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 1.25rem;
    min-height: 0;
}

.reader-canvas-wrap canvas {
    max-width: 100%;
    height: auto !important;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
    background: #fff;
}

.reader-canvas-wrap canvas.hidden,
.reader-frame.hidden {
    display: none !important;
}

.reader-frame {
    width: 100%;
    height: 100%;
    min-height: calc(100vh - 160px);
    border: 0;
    background: #0b1220;
    border-radius: 8px;
}

.cache-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.55rem 0.85rem;
    padding: 0.55rem 0.9rem;
    background: rgba(15, 23, 42, 0.96);
    border-bottom: 1px solid rgba(148, 163, 184, 0.14);
    font-size: 0.78rem;
}

.cache-badge {
    font-weight: 800;
    padding: 0.25rem 0.65rem;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.25);
}

.cache-badge.is-ok {
    color: #052e2b;
    background: #6ee7b7;
    border-color: transparent;
}

.cache-badge.is-busy {
    color: #422006;
    background: #fcd34d;
    border-color: transparent;
}

.cache-badge.is-warn {
    color: #fef3c7;
    background: rgba(245, 158, 11, 0.2);
    border-color: rgba(245, 158, 11, 0.45);
}

.cache-badge.is-err {
    color: #fecaca;
    background: rgba(239, 68, 68, 0.18);
    border-color: rgba(239, 68, 68, 0.4);
}

.cache-badge.is-muted {
    color: #cbd5e1;
    background: rgba(148, 163, 184, 0.12);
}

.cache-detail {
    color: #94a3b8;
    font-weight: 600;
    flex: 1;
    min-width: 120px;
}

.cache-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.cache-btn {
    border: 1px solid rgba(148, 163, 184, 0.25);
    background: rgba(255, 255, 255, 0.05);
    color: #e2e8f0;
    border-radius: 10px;
    padding: 0.35rem 0.65rem;
    font-weight: 800;
    font-size: 0.72rem;
    cursor: pointer;
}

.cache-btn:hover {
    border-color: rgba(52, 211, 153, 0.45);
    color: #6ee7b7;
}

.cache-btn-danger:hover {
    border-color: rgba(248, 113, 113, 0.5);
    color: #fca5a5;
}

.reader-icon-btn.is-disabled {
    opacity: 0.35;
    pointer-events: none;
}

.reader-side {
    border-right: 1px solid rgba(148, 163, 184, 0.15);
    background: rgba(7, 17, 31, 0.98);
    overflow: auto;
    padding: 1rem;
    display: none;
}

.reader-workspace.has-side .reader-side {
    display: block;
}

.reader-side h3 {
    font-size: 0.85rem;
    font-weight: 800;
    color: #94a3b8;
    margin: 0 0 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.reader-side-list {
    list-style: none;
    padding: 0;
    margin: 0 0 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.reader-side-list li {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(148, 163, 184, 0.12);
    border-radius: 12px;
    padding: 0.65rem 0.75rem;
    font-size: 0.8rem;
    line-height: 1.55;
}

.reader-side-list button.linkish {
    background: none;
    border: none;
    color: #34d399;
    font-weight: 800;
    cursor: pointer;
    padding: 0;
}

.reader-status {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 2rem;
    text-align: center;
    background: rgba(15, 23, 42, 0.92);
    z-index: 5;
}

.reader-status.hidden {
    display: none;
}

.reader-status.is-error {
    background: rgba(15, 23, 42, 0.96);
}

.reader-load-card {
    max-width: 22rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.65rem;
}

.reader-load-title {
    font-family: 'Amiri', serif;
    font-size: 1.35rem;
    font-weight: 700;
    color: #e2e8f0;
    margin: 0;
}

.reader-load-sub {
    font-size: 0.82rem;
    font-weight: 600;
    color: #94a3b8;
    margin: 0;
    min-height: 1.2em;
}

.reader-load-bar {
    width: 12rem;
    height: 0.35rem;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.2);
    overflow: hidden;
    margin-top: 0.25rem;
}

.reader-load-bar > span {
    display: block;
    height: 100%;
    width: 15%;
    border-radius: inherit;
    background: linear-gradient(90deg, #34d399, #2dd4bf);
    transition: width 0.35s ease;
}

.reader-more-panel {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.55rem 0.9rem;
    background: rgba(7, 17, 31, 0.98);
    border-bottom: 1px solid rgba(148, 163, 184, 0.12);
}

.reader-more-panel.hidden {
    display: none !important;
}

.format-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    align-items: center;
    margin-inline-end: 0.35rem;
}

.format-picker.hidden {
    display: none !important;
}

.format-chip {
    border: 1px solid rgba(148, 163, 184, 0.28);
    background: rgba(255, 255, 255, 0.04);
    color: #cbd5e1;
    border-radius: 999px;
    padding: 0.22rem 0.55rem;
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.02em;
    cursor: pointer;
}

.format-chip:hover {
    border-color: rgba(52, 211, 153, 0.45);
    color: #6ee7b7;
}

.format-chip.is-active {
    background: rgba(16, 185, 129, 0.22);
    border-color: rgba(52, 211, 153, 0.55);
    color: #a7f3d0;
}

.epub-viewer {
    width: 100%;
    height: 100%;
    min-height: calc(100vh - 160px);
    background: #0b1220;
    border-radius: 8px;
    overflow: hidden;
}

.epub-viewer.hidden {
    display: none !important;
}

.reader-article {
    width: 100%;
    height: 100%;
    min-height: calc(100vh - 160px);
    overflow: auto;
    padding: 1.25rem 1.1rem 2.5rem;
    background: #0b1220;
}

.reader-article.hidden {
    display: none !important;
}

.reader-article-inner {
    max-width: 42rem;
    margin: 0 auto;
    color: #e2e8f0;
    font-family: 'Amiri', serif;
    font-size: 1.15rem;
    line-height: 1.9;
}

.reader-article-inner img {
    max-width: 100%;
    height: auto;
}

.reader-pre {
    max-width: 48rem;
    margin: 0 auto;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.85rem;
    line-height: 1.7;
    color: #cbd5e1;
}

.books-format-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-top: 0.45rem;
}

.books-format-badge {
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 0.03em;
    color: #5eead4;
    border: 1px solid rgba(45, 212, 191, 0.35);
    border-radius: 999px;
    padding: 0.12rem 0.45rem;
    background: rgba(13, 148, 136, 0.12);
}

.reader-find-bar {
    display: none;
    width: 100%;
    gap: 0.5rem;
    align-items: center;
    padding: 0.5rem 0.9rem 0.75rem;
    background: rgba(7, 17, 31, 0.98);
    border-bottom: 1px solid rgba(148, 163, 184, 0.12);
}

.reader-find-bar.is-open {
    display: flex;
    flex-wrap: wrap;
}

.reader-find-bar input {
    flex: 1;
    min-width: 160px;
    padding: 0.55rem 0.85rem;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.25);
    background: rgba(255, 255, 255, 0.06);
    color: #f8fafc;
    outline: none;
}

.admin-panel {
    max-width: 56rem;
    margin: 0 auto;
    padding: 1.5rem 1.25rem 3rem;
}

.admin-card {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(15, 118, 110, 0.15);
    border-radius: 20px;
    padding: 1.25rem;
    margin-bottom: 1rem;
}

html.dark .admin-card {
    background: rgba(15, 27, 46, 0.85);
    border-color: rgba(148, 163, 184, 0.15);
}

.admin-card h3 {
    font-family: 'Amiri', serif;
    font-size: 1.25rem;
    margin: 0 0 0.5rem;
}

.admin-form grid,
.admin-form {
    display: grid;
    gap: 0.75rem;
}

.admin-form label {
    font-size: 0.8rem;
    font-weight: 800;
    color: #64748b;
}

.admin-form input,
.admin-form select,
.admin-form textarea {
    width: 100%;
    padding: 0.7rem 0.9rem;
    border-radius: 12px;
    border: 1px solid rgba(15, 118, 110, 0.2);
    background: #fff;
    font-weight: 600;
}

html.dark .admin-form input,
html.dark .admin-form select,
html.dark .admin-form textarea {
    background: #0f172a;
    border-color: rgba(148, 163, 184, 0.25);
    color: #e2e8f0;
}

.code-block {
    direction: ltr;
    text-align: left;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.72rem;
    background: #0f172a;
    color: #a7f3d0;
    padding: 1rem;
    border-radius: 14px;
    overflow: auto;
    white-space: pre-wrap;
    line-height: 1.55;
}

@media (max-width: 640px) {
    .books-hero {
        min-height: 58vh;
        padding-top: 2.5rem;
    }

    .reader-topbar h1 {
        font-size: 0.95rem;
    }
}
