:root {
    --bg: #f5f6f7;
    --surface: #ffffff;
    --surface-muted: #f0f2f4;
    --border: #d8dde3;
    --border-strong: #bcc5cf;
    --text: #111827;
    --text-secondary: #5b6573;
    --accent: #1f2937;
    --accent-soft: #eef1f4;
    --success: #0f766e;
    --warning: #92400e;
    --radius-sm: 0.5rem;
    --radius-md: 0.75rem;
    --radius-lg: 1rem;
    --shadow-sm: 0 8px 24px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 18px 40px rgba(15, 23, 42, 0.06);
}

html {
    scroll-behavior: smooth;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: Inter, "Noto Sans Arabic", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, sans-serif;
    min-height: 100vh;
}

[lang="ar"],
[dir="rtl"] {
    font-family: "Noto Sans Arabic", "Segoe UI", Tahoma, Arial, sans-serif;
    line-height: 1.75;
    text-align: start;
    unicode-bidi: plaintext;
}

[lang="ar"] .display-6,
[lang="ar"] .h3,
[lang="ar"] .h4,
[lang="ar"] .h5,
[dir="rtl"] .display-6,
[dir="rtl"] .h3,
[dir="rtl"] .h4,
[dir="rtl"] .h5 {
    letter-spacing: 0;
}

::selection {
    background: #dbe2ea;
}

.app-shell {
    min-height: 100vh;
}

.navbar {
    backdrop-filter: blur(8px);
}

.brand-mark {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 0.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    letter-spacing: 0.04em;
    font-size: 0.9rem;
}

.brand-title {
    font-weight: 700;
    color: var(--text);
    line-height: 1.1;
}

.nav-link {
    color: var(--text-secondary);
    font-weight: 500;
    border-radius: var(--radius-sm);
    padding-inline: 0.85rem !important;
}

.nav-link.active,
.nav-link:hover,
.nav-link:focus {
    color: var(--text);
    background: var(--accent-soft);
}

.hero-surface,
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.hero-surface {
    padding: clamp(1.5rem, 2vw, 2rem);
}

.panel {
    padding: 1.35rem;
}

.eyebrow,
.section-kicker {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.72rem;
    font-weight: 700;
    margin-bottom: 0.9rem;
}

.display-6,
.h3,
.h4,
.h5 {
    letter-spacing: -0.03em;
}

.lead {
    font-size: 1.04rem;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.9rem;
}

.metric-grid-compact {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.metric-card,
.recent-card {
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1rem;
}

.metric-card {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.metric-value {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.04em;
}

.metric-label {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.compact-list,
.compact-list-numbered {
    color: var(--text-secondary);
    display: grid;
    gap: 0.65rem;
    padding-left: 1.2rem;
}

.compact-list {
    padding-left: 1rem;
}

.compact-list li::marker,
.compact-list-numbered li::marker {
    color: var(--text);
}

.link-arrow,
.back-link {
    color: var(--text);
    font-weight: 600;
    text-decoration: none;
}

.link-arrow:hover,
.back-link:hover {
    color: #000;
}

.form-control,
.form-select {
    border-color: var(--border-strong);
    padding: 0.72rem 0.85rem;
    border-radius: var(--radius-sm);
    background: #fff;
}

.form-control:focus,
.form-select:focus,
.btn:focus,
.nav-link:focus,
.btn-close:focus {
    box-shadow: 0 0 0 0.2rem rgba(31, 41, 55, 0.12);
    border-color: #9aa5b1;
}

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

.btn {
    border-radius: 0.65rem;
    padding: 0.7rem 1rem;
    font-weight: 600;
}

.btn-dark {
    background: var(--accent);
    border-color: var(--accent);
}

.btn-dark:hover,
.btn-dark:focus {
    background: #111827;
    border-color: #111827;
}

.btn-outline-secondary {
    color: var(--text);
    border-color: var(--border-strong);
}

.btn-outline-secondary:hover,
.btn-outline-secondary:focus {
    background: var(--accent-soft);
    color: var(--text);
    border-color: var(--border-strong);
}

.badge {
    border-radius: 999px;
    font-weight: 600;
    letter-spacing: 0.01em;
    padding: 0.55em 0.75em;
}

.text-bg-light {
    background: var(--accent-soft) !important;
    color: var(--text) !important;
    border: 1px solid var(--border);
}

.empty-panel {
    background: var(--surface);
}

.empty-icon {
    width: 3rem;
    height: 3rem;
    border-radius: 1rem;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
}

.table > :not(caption) > * > * {
    padding-block: 0.95rem;
    border-bottom-color: var(--border);
}

.table thead th {
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.reader-panel {
    padding-bottom: 1rem;
}

.reader-frame-wrap {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: #d1d5db;
}

.reader-frame {
    width: 100%;
    min-height: 70vh;
    border: 0;
    background: #fff;
}

.reader-lock,
.summary-box {
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1rem;
}

.summary-box {
    white-space: pre-line;
    line-height: 1.7;
}

.summary-box-muted {
    color: var(--text-secondary);
}

.description-stack {
    display: grid;
    gap: 1rem;
}

.recent-card {
    display: block;
    height: 100%;
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.recent-card:hover,
.recent-card:focus {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--border-strong);
}

.toast {
    min-width: 280px;
    border-radius: 0.85rem;
    overflow: hidden;
}

.toast-stack {
    z-index: 1090;
}

footer a {
    color: var(--text);
}

@media (max-width: 991.98px) {
    .metric-grid {
        grid-template-columns: 1fr;
    }

    .reader-frame {
        min-height: 60vh;
    }
}

/* Flipbook Custom Styles */
#flipbook-wrapper {
    background: #333;
    box-shadow: inset 0 0 30px rgba(0,0,0,0.6);
}

#flipbook .page {
    background-color: #fff;
    /* Soft border for realism */
    border-right: 1px solid #ddd;
}

#flipbook-toolbar button {
    transition: all 0.2s ease;
}

#flipbook-toolbar button:hover {
    transform: scale(1.1);
    color: var(--accent);
}

#flipbook-toolbar button:active {
    transform: scale(0.95);
}

.catalog-card {
    display: grid;
    grid-template-columns: 128px minmax(0, 1fr);
    gap: 1.25rem;
    align-items: stretch;
}

.catalog-card-media {
    display: flex;
}

.catalog-card-cover {
    width: 128px;
    min-width: 128px;
    height: 176px;
    object-fit: cover;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--surface-muted);
    box-shadow: var(--shadow-sm);
}

.catalog-card-cover-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.catalog-card-body {
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.catalog-card-title,
.catalog-card-title-alt {
    overflow-wrap: anywhere;
}

.catalog-card-title-alt {
    font-size: 0.96rem;
}

.catalog-card-badges {
    position: relative;
    z-index: 1;
}

.catalog-card-meta {
    display: grid;
    gap: 0.65rem;
}

.catalog-card-meta > div {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.catalog-card-label {
    min-width: 3.75rem;
    color: var(--text);
    font-weight: 600;
}

@media (max-width: 767.98px) {
    .catalog-card {
        grid-template-columns: 1fr;
    }

    .catalog-card-media {
        justify-content: center;
    }

    .catalog-card-body {
        text-align: start;
    }
}

.topbar-lang-switch {
    border-radius: 999px;
    padding-inline: 0.9rem;
    font-weight: 700;
    line-height: 1.2;
}

.topbar-lang-switch:hover,
.topbar-lang-switch:focus {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
