:root {
    --emerald: #0d4f3c;
    --emerald-light: #1a7a5e;
    --gold: #c9a227;
    --gold-light: #e8c547;
    --cream: #faf8f3;
    --cream-dark: #f0ebe0;
    --text: #1a2421;
    --text-muted: #5a6b65;
    --white: #ffffff;
    --surface: #ffffff;
    --header-bg: rgba(250, 248, 243, 0.92);
    --border-subtle: rgba(13, 79, 60, 0.06);
    --border-medium: rgba(13, 79, 60, 0.15);
    --nav-hover-bg: rgba(13, 79, 60, 0.06);
    --input-bg: #ffffff;
    --shadow: 0 4px 24px rgba(13, 79, 60, 0.08);
    --shadow-lg: 0 12px 48px rgba(13, 79, 60, 0.12);
    --radius: 12px;
    --radius-lg: 20px;
    --font: 'Outfit', system-ui, sans-serif;
    --font-ar: 'Amiri', 'Traditional Arabic', serif;
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --font-scale: 1;
    --prefs-bg: rgba(13, 79, 60, 0.06);
    --prefs-bg-hover: rgba(13, 79, 60, 0.12);
}

[data-theme="dark"] {
    --emerald: #3cb88a;
    --emerald-light: #5fd4a8;
    --gold: #e8c547;
    --gold-light: #f5d76e;
    --cream: #0f1412;
    --cream-dark: #1a2421;
    --text: #e8ede9;
    --text-muted: #9aab9f;
    --white: #1e2a26;
    --surface: #1e2a26;
    --header-bg: rgba(15, 20, 18, 0.94);
    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-medium: rgba(255, 255, 255, 0.12);
    --nav-hover-bg: rgba(60, 184, 138, 0.12);
    --input-bg: #152019;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.45);
    --prefs-bg: rgba(255, 255, 255, 0.06);
    --prefs-bg-hover: rgba(255, 255, 255, 0.12);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    scroll-behavior: smooth;
    font-size: calc(100% * var(--font-scale, 1));
}

body {
    font-family: var(--font);
    background: var(--cream);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background var(--transition), color var(--transition);
}

body.rtl { font-family: var(--font-ar); }
body.rtl .logo-text strong,
body.rtl h1, body.rtl h2, body.rtl h3 { font-family: var(--font-ar); }

.bg-pattern {
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse 80% 50% at 50% -20%, rgba(26, 122, 94, 0.15), transparent),
        radial-gradient(ellipse 60% 40% at 100% 100%, rgba(201, 162, 39, 0.08), transparent);
    pointer-events: none;
    z-index: -1;
    transition: opacity var(--transition);
}

[data-theme="dark"] .bg-pattern {
    background:
        radial-gradient(ellipse 80% 50% at 50% -20%, rgba(60, 184, 138, 0.12), transparent),
        radial-gradient(ellipse 60% 40% at 100% 100%, rgba(201, 162, 39, 0.05), transparent);
}

.container { width: min(1140px, 92%); margin-inline: auto; }

/* Header */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--header-bg);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-subtle);
    transition: background var(--transition), border-color var(--transition);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 0;
    gap: 1.5rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: var(--text);
}

.logo-icon {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--emerald), var(--emerald-light));
    color: var(--gold-light);
    border-radius: 12px;
    font-size: 1.25rem;
    box-shadow: var(--shadow);
}

.logo-text { display: flex; flex-direction: column; line-height: 1.2; }
.logo-text strong { font-size: 1.05rem; color: var(--emerald); }
.logo-text small { font-size: 0.8rem; color: var(--text-muted); font-family: var(--font-ar); }

.main-nav { display: flex; gap: 0.25rem; }

.main-nav a {
    padding: 0.5rem 1rem;
    text-decoration: none;
    color: var(--text-muted);
    font-weight: 500;
    border-radius: 8px;
    transition: var(--transition);
}

.main-nav a:hover, .main-nav a.active {
    color: var(--emerald);
    background: var(--nav-hover-bg);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

/* Display preferences toolbar */
.prefs-toolbar {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.prefs-text-size {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 2px;
    background: var(--prefs-bg);
    border-radius: 999px;
    border: 1px solid var(--border-medium);
}

.prefs-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    height: 2rem;
    padding: 0 0.4rem;
    border: none;
    border-radius: 999px;
    background: transparent;
    color: var(--emerald);
    font-family: var(--font);
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    line-height: 1;
}

.prefs-btn:hover:not(:disabled) {
    background: var(--prefs-bg-hover);
    color: var(--text);
}

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

.prefs-btn-reset { font-size: 0.9rem; }

.theme-toggle { position: relative; }

.theme-icon {
    display: none;
    font-size: 1rem;
    line-height: 1;
}

[data-theme="light"] .theme-icon-moon,
[data-theme="dark"] .theme-icon-sun {
    display: inline-flex;
}

.admin-sidebar-prefs {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.admin-sidebar-prefs .prefs-toolbar { flex-direction: column; align-items: stretch; }
.admin-sidebar-prefs .prefs-text-size { justify-content: center; }
.admin-sidebar-prefs .prefs-btn { color: rgba(255, 255, 255, 0.9); }
.admin-sidebar-prefs .prefs-btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.12); color: white; }
.admin-sidebar-prefs .prefs-text-size { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.15); }

.login-prefs {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 10;
}

body.rtl .login-prefs {
    right: auto;
    left: 1rem;
}

.lang-switch {
    padding: 0.4rem 0.9rem;
    border: 1px solid var(--border-medium);
    border-radius: 999px;
    text-decoration: none;
    color: var(--emerald);
    font-size: 0.875rem;
    font-weight: 500;
    transition: var(--transition);
}

.lang-switch:hover {
    background: var(--emerald);
    color: var(--white);
    border-color: var(--emerald);
}

.nav-toggle {
    display: none;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
}

.nav-toggle span {
    width: 22px;
    height: 2px;
    background: var(--emerald);
    border-radius: 2px;
    transition: var(--transition);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    text-decoration: none;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary {
    background: linear-gradient(135deg, var(--emerald), var(--emerald-light));
    color: var(--white);
    box-shadow: 0 4px 16px rgba(13, 79, 60, 0.25);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(13, 79, 60, 0.3);
}

.btn-secondary {
    background: var(--surface);
    color: var(--emerald);
    border: 2px solid var(--border-medium);
}

.btn-secondary:hover { border-color: var(--emerald); background: var(--nav-hover-bg); }

.btn-gold {
    background: linear-gradient(135deg, var(--gold), var(--gold-light));
    color: var(--text);
}

.btn-ghost { background: transparent; color: var(--emerald); }
.btn-sm { padding: 0.4rem 0.9rem; font-size: 0.85rem; }
.btn-danger { background: #c0392b; color: white; }

/* Hero */
.hero {
    padding: 4rem 0 5rem;
    text-align: center;
}

.hero-badge {
    display: inline-block;
    padding: 0.35rem 1rem;
    background: rgba(201, 162, 39, 0.15);
    color: var(--emerald);
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
}

.hero h1 {
    font-size: clamp(2rem, 5vw, 3.25rem);
    font-weight: 700;
    color: var(--emerald);
    line-height: 1.2;
    margin-bottom: 1rem;
    max-width: 720px;
    margin-inline: auto;
}

.hero p {
    font-size: 1.15rem;
    color: var(--text-muted);
    max-width: 560px;
    margin: 0 auto 2rem;
}

.hero-actions { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: center; }

/* Sections */
.section { padding: 3.5rem 0; }
.section-header { margin-bottom: 2rem; }
.section-header h2 {
    font-size: 1.75rem;
    color: var(--emerald);
    margin-bottom: 0.35rem;
}
.section-header p { color: var(--text-muted); }

/* Cards grid */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: var(--transition);
    border: 1px solid var(--border-subtle);
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.card-body { padding: 1.5rem; }
.card-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}
.card h3 {
    font-size: 1.15rem;
    color: var(--emerald);
    margin-bottom: 0.75rem;
    line-height: 1.35;
}
.card h3 a { color: inherit; text-decoration: none; }
.card h3 a:hover { color: var(--emerald-light); }
.card p { color: var(--text-muted); font-size: 0.95rem; margin-bottom: 1rem; }
.card-link {
    color: var(--emerald-light);
    font-weight: 600;
    text-decoration: none;
    font-size: 0.9rem;
}
.card-link:hover { color: var(--gold); }

.article-cover-link { display: block; }
.article-cover-thumb {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    display: block;
}
.article-cover-hero {
    width: 100%;
    max-height: 420px;
    object-fit: cover;
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
}

.optional { font-weight: 400; color: var(--text-muted); font-size: 0.85em; }
.cover-preview-wrap { margin-bottom: 0.75rem; }
.cover-preview {
    max-width: 280px;
    width: 100%;
    border-radius: var(--radius);
    border: 1px solid rgba(13, 79, 60, 0.1);
}
.table-thumb {
    width: 48px;
    height: 36px;
    object-fit: cover;
    border-radius: 6px;
}
.table-thumb-placeholder { color: var(--text-muted); }

/* Video card */
.video-thumb {
    aspect-ratio: 16/9;
    background: linear-gradient(135deg, var(--emerald), #0a3d2e);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}
.video-thumb::after {
    content: '▶';
    width: 56px;
    height: 56px;
    background: rgba(255,255,255,0.95);
    color: var(--emerald);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    padding-left: 4px;
    box-shadow: var(--shadow);
}

/* Book card */
.book-cover {
    aspect-ratio: 3/4;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    text-align: center;
    color: white;
}
.book-cover .book-icon { font-size: 3rem; margin-bottom: 1rem; opacity: 0.9; }
.book-cover h4 { font-size: 1.1rem; line-height: 1.4; font-family: var(--font-ar); }

/* Page header */
.page-header {
    padding: 2.5rem 0 1.5rem;
    text-align: center;
}
.page-header h1 { font-size: 2.25rem; color: var(--emerald); }

/* Content page */
.content-page { padding: 2rem 0 4rem; }
.content-article {
    max-width: 760px;
    margin: 0 auto;
    background: var(--surface);
    padding: 2.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    transition: background var(--transition);
}
.content-article h1 { font-size: 2rem; color: var(--emerald); margin-bottom: 0.5rem; }
.content-article .meta { color: var(--text-muted); margin-bottom: 2rem; font-size: 0.9rem; }
.content-article .body {
    font-size: 1.125rem;
    line-height: 1.9;
}
.content-article .body h2, .content-article .body h3 { color: var(--emerald); margin: 1.5rem 0 0.75rem; }
.content-article .body p { margin-bottom: 1rem; }
.content-article .body ul, .content-article .body ol { margin: 1rem 0 1rem 1.5rem; }

/* Video player */
.video-player-wrap {
    max-width: 900px;
    margin: 0 auto 2rem;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    background: #000;
}
.video-player-wrap video { width: 100%; display: block; }
.video-fallback {
    padding: 2rem;
    text-align: center;
    color: var(--text-muted);
    background: var(--surface);
}
.video-fallback a { color: var(--emerald-light); font-weight: 600; }

/* PDF viewer */
.pdf-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: center;
    margin-bottom: 2rem;
}
.pdf-viewer {
    width: 100%;
    height: 80vh;
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    background: var(--white);
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-muted);
}
.empty-state .icon { font-size: 3rem; margin-bottom: 1rem; opacity: 0.5; }

/* Footer */
.site-footer {
    margin-top: auto;
    background: var(--emerald);
    color: rgba(255,255,255,0.85);
    padding: 3rem 0 2rem;
}
.footer-inner { display: grid; gap: 2rem; }
.footer-brand { display: flex; gap: 1rem; align-items: flex-start; }
.footer-brand .logo-icon { background: rgba(255,255,255,0.15); }
.footer-brand strong { color: white; display: block; margin-bottom: 0.35rem; }
.footer-brand p { font-size: 0.9rem; opacity: 0.85; }
.footer-nav { display: flex; gap: 1.5rem; flex-wrap: wrap; }
.footer-nav a { color: rgba(255,255,255,0.8); text-decoration: none; }
.footer-nav a:hover { color: var(--gold-light); }
.footer-copy { font-size: 0.85rem; opacity: 0.6; padding-top: 1.5rem; border-top: 1px solid rgba(255,255,255,0.1); }
.footer-sep { margin: 0 0.5rem; opacity: 0.5; }
.footer-credit {
    color: var(--gold-light);
    text-decoration: none;
    font-weight: 600;
    transition: var(--transition);
}
.footer-credit:hover { color: white; text-decoration: underline; }

/* Admin */
.admin-layout { min-height: 100vh; display: flex; }
.admin-sidebar {
    width: 260px;
    background: var(--emerald);
    color: white;
    padding: 1.5rem;
    flex-shrink: 0;
}
.admin-sidebar h2 { font-size: 1.1rem; margin-bottom: 2rem; color: var(--gold-light); }
.admin-sidebar nav { display: flex; flex-direction: column; gap: 0.25rem; }
.admin-sidebar a {
    color: rgba(255,255,255,0.85);
    text-decoration: none;
    padding: 0.65rem 1rem;
    border-radius: 8px;
    transition: var(--transition);
}
.admin-sidebar a:hover, .admin-sidebar a.active { background: rgba(255,255,255,0.12); color: white; }
.admin-main { flex: 1; padding: 2rem; background: var(--cream-dark); transition: background var(--transition); }
.admin-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem; }
.admin-header h1 { font-size: 1.5rem; color: var(--emerald); }

.admin-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
    border: 1px solid var(--border-subtle);
    transition: background var(--transition);
}

.form-group { margin-bottom: 1.25rem; }
.form-group label { display: block; font-weight: 600; margin-bottom: 0.4rem; color: var(--emerald); font-size: 0.9rem; }
.form-group input, .form-group textarea, .form-group select {
    width: 100%;
    padding: 0.7rem 1rem;
    border: 1px solid var(--border-medium);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.95rem;
    background: var(--input-bg);
    color: var(--text);
    transition: var(--transition);
}
.form-group input:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--emerald-light);
    box-shadow: 0 0 0 3px rgba(26, 122, 94, 0.15);
}
.form-group textarea { min-height: 120px; resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-hint { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.35rem; }

.lang-tabs { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.lang-tab {
    padding: 0.4rem 1rem;
    border: 1px solid var(--border-medium);
    background: var(--surface);
    color: var(--text);
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
}
.lang-tab.active { background: var(--emerald); color: white; border-color: var(--emerald); }
.lang-panel { display: none; }
.lang-panel.active { display: block; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.75rem 1rem; text-align: start; border-bottom: 1px solid var(--cream-dark); }
th { font-weight: 600; color: var(--emerald); font-size: 0.85rem; }
td a { color: var(--emerald-light); }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.alert {
    padding: 1rem 1.25rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    font-weight: 500;
}
.alert-success { background: #d4edda; color: #155724; }
.alert-error { background: #f8d7da; color: #721c24; }

[data-theme="dark"] .alert-success { background: #1a3d2a; color: #8fd4a8; }
[data-theme="dark"] .alert-error { background: #3d1a1a; color: #f0a0a0; }

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}
.login-card {
    width: min(400px, 100%);
    background: var(--surface);
    padding: 2.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-subtle);
    transition: background var(--transition);
}
.login-card h1 { text-align: center; color: var(--emerald); margin-bottom: 0.5rem; font-size: 1.5rem; }
.login-card .subtitle { text-align: center; color: var(--text-muted); margin-bottom: 2rem; font-size: 0.9rem; }
.login-card .logo-icon { margin: 0 auto 1rem; }

.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-published { background: #d4edda; color: #155724; }
.badge-draft { background: #fff3cd; color: #856404; }

[data-theme="dark"] .badge-published { background: #1a3d2a; color: #8fd4a8; }
[data-theme="dark"] .badge-draft { background: #3d3520; color: #e8c547; }

.checkbox-label { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; font-weight: normal; }

.admin-credit {
    text-align: center;
    padding: 1rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}
.admin-credit a {
    color: var(--emerald-light);
    font-weight: 600;
    text-decoration: none;
}
.admin-credit a:hover { text-decoration: underline; }

.compress-progress {
    margin: 1rem 0;
    padding: 1rem;
    background: var(--prefs-bg);
    border-radius: var(--radius);
    border: 1px solid var(--border-medium);
}
.compress-progress-bar {
    height: 8px;
    background: var(--border-subtle);
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}
.compress-progress-bar div {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--emerald), var(--emerald-light));
    border-radius: 999px;
    transition: width 0.2s ease;
}
.compress-progress-text {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 0;
}

@media (max-width: 768px) {
    .nav-toggle { display: flex; }
    .main-nav {
        position: fixed;
        top: 72px;
        left: 0;
        right: 0;
        background: var(--header-bg);
        flex-direction: column;
        padding: 1rem;
        border-bottom: 1px solid var(--border-subtle);
        transform: translateY(-120%);
        opacity: 0;
        transition: var(--transition);
        box-shadow: var(--shadow);
    }
    body.rtl .main-nav { left: 0; right: 0; }
    .main-nav.open { transform: translateY(0); opacity: 1; }
    .form-row { grid-template-columns: 1fr; }
    .admin-layout { flex-direction: column; }
    .admin-sidebar { width: 100%; }
    .content-article { padding: 1.5rem; }
    .header-actions { gap: 0.35rem; }
    .prefs-btn { min-width: 1.75rem; height: 1.75rem; font-size: 0.75rem; }
}
