/* Layout رئيسي – حديث، نظيف، متوافق W3C. المحتوى ظاهر فوراً ولا يُخفى أسفل. */

:root {
    --primary-color: #3498db;
    --secondary-color: #2c3e50;
    --accent-color: #e74c3c;
    --text-color: #2c3e50;
    --text-light: #7f8c8d;
    --bg-color: #fff;
    --bg-light: #f5f5f5;
    --border-color: #e8e8e8;
    --mtp-bg-from: #eef2ff;
    --mtp-bg-mid: #f5f3ff;
    --mtp-bg-to: #fce7f3;
    --mtp-article-border: rgba(99, 102, 241, 0.25);
    --mtp-article-bg: #fff;
    /* عناوين وقوائم مقالات */
    --mtp-heading: #0f172a;
    --mtp-heading-muted: #334155;
    --mtp-accent: #2563eb;
    --mtp-accent-soft: rgba(37, 99, 235, 0.1);
    --mtp-card-bg: #ffffff;
    --mtp-card-border: #e2e8f0;
    --mtp-card-radius: 14px;
    --mtp-card-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    --mtp-card-shadow-hover: 0 8px 24px rgba(0, 0, 0, 0.08);
    --mtp-section-title-size: 1.25rem;
    --mtp-section-title-weight: 700;
    --mtp-list-title-size: 0.9375rem;
    --mtp-list-title-weight: 600;
}

/* ——— الوضع الليلي ——— */
[data-theme="dark"] {
    --text-color: #e2e8f0;
    --text-light: #94a3b8;
    --bg-color: #0f172a;
    --bg-light: #1e293b;
    --border-color: #334155;
    --mtp-bg-from: #0f172a;
    --mtp-bg-mid: #1e293b;
    --mtp-bg-to: #334155;
    --mtp-article-border: rgba(148, 163, 184, 0.2);
    --mtp-article-bg: #1e293b;
    --mtp-heading: #f1f5f9;
    --mtp-heading-muted: #cbd5e1;
    --mtp-accent: #60a5fa;
    --mtp-accent-soft: rgba(96, 165, 250, 0.15);
    --mtp-card-bg: #1e293b;
    --mtp-card-border: #334155;
    --mtp-card-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    --mtp-card-shadow-hover: 0 8px 24px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] body {
    background: linear-gradient(145deg, var(--mtp-bg-from) 0%, var(--mtp-bg-mid) 40%, var(--mtp-bg-to) 100%);
}

[data-theme="dark"] #page.site {
    background: linear-gradient(165deg, rgba(15, 23, 42, 0.8) 0%, rgba(30, 41, 59, 0.7) 35%, rgba(51, 65, 85, 0.6) 100%);
}

html {
    scroll-behavior: auto;
    direction: rtl;
}

html[dir="ltr"] {
    direction: ltr;
}

body {
    margin: 0;
    padding: 0;
    color: var(--text-color);
    background: linear-gradient(145deg, var(--mtp-bg-from) 0%, var(--mtp-bg-mid) 40%, var(--mtp-bg-to) 100%);
    background-attachment: fixed;
    min-height: 100vh;
    direction: inherit;
    text-align: inherit;
}

body[dir="rtl"] {
    text-align: right;
}

body[dir="ltr"] {
    text-align: left;
}

/* غلاف الصفحة – position نسبة لـ skip-link ولا يخفي المحتوى */
#page.site {
    position: relative;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: visible;
    background: linear-gradient(165deg, rgba(238, 242, 255, 0.6) 0%, rgba(245, 243, 255, 0.5) 35%, rgba(252, 231, 243, 0.4) 100%);
}

/* المحتوى الرئيسي ظاهر فوراً، لا يُدفع أسفل بدون سبب */
.site-main {
    flex: 1 0 auto;
    padding: 1rem 0;
}

.site-main .container {
    padding-top: 0;
}

.container {
    max-width: 1060px;
    width: 100%;
    margin: 0 auto;
    padding: 0 1rem;
}

/* تخطيط تبعاً لوجود سايدبار – يُعالج في القوالب */
@media (min-width: 768px) {
    .site-main {
        padding: 2rem 0;
    }
    .container {
        padding: 0 1.5rem;
    }
}

/* تخطيط الصفحة مع سايدبار */
.site-main.has-sidebar {
    display: block;
}

/* Skip link – وصولية W3C، لا يؤثر على تدفق المحتوى */
.skip-link {
    position: absolute;
    top: -100%;
    right: 1rem;
    z-index: 100000;
    padding: 0.75rem 1rem;
    background: var(--primary-color);
    color: #fff;
    font-weight: 600;
    border-radius: 4px;
}

.skip-link:focus {
    top: 1rem;
}

[dir="ltr"] .skip-link {
    right: auto;
    left: 1rem;
}

/* نصوص قارئ الشاشة */
.screen-reader-text {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.screen-reader-text:focus {
    position: fixed !important;
    top: 0.5rem;
    right: 0.5rem;
    z-index: 100001;
    width: auto;
    height: auto;
    padding: 0.75rem 1rem;
    margin: 0;
    overflow: visible;
    clip: auto;
    background: #fff;
    color: #111;
    font-size: 1rem;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid #e5e7eb;
    white-space: normal;
    border-radius: 4px;
}

[dir="ltr"] .screen-reader-text:focus {
    right: auto;
    left: 0.5rem;
}

/* أرشيف */
.archive-header {
    margin-bottom: 2rem;
    text-align: center;
    padding: 2rem 1rem;
    background: var(--mtp-card-bg);
    border: 1px solid var(--mtp-card-border);
    border-radius: var(--mtp-card-radius);
    box-shadow: var(--mtp-card-shadow);
}

.archive-title {
    font-size: 1.5rem;
    font-weight: var(--mtp-section-title-weight);
    color: var(--mtp-heading);
    margin: 0 0 0.5rem;
    letter-spacing: -0.02em;
}

.archive-description {
    font-size: 1rem;
    color: var(--mtp-heading-muted);
    margin: 0;
}

@media (min-width: 768px) {
    .archive-title {
        font-size: 1.75rem;
    }
}

/* 404 */
.error-404 {
    text-align: center;
    padding: 4rem 1rem;
}

.error-404 .page-title {
    font-size: 6rem;
    font-weight: 700;
    color: var(--primary-color);
    margin: 0 0 1rem;
    line-height: 1;
}

.error-404 .page-description {
    font-size: 1.5rem;
    color: var(--secondary-color);
    margin: 0 0 2rem;
}

.error-404 .page-content {
    max-width: 500px;
    margin: 0 auto;
}

@media (min-width: 768px) {
    .error-404 .page-title {
        font-size: 8rem;
    }
}

/* تنقل المقالات والترقيم */
.posts-navigation,
.post-navigation {
    margin: 2rem 0;
    padding: 1.5rem 0;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
}

.nav-links {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.nav-previous,
.nav-next {
    flex: 1;
    min-width: 0;
}

.nav-previous a,
.nav-next a {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    background: var(--primary-color);
    color: #fff;
    border-radius: 4px;
    font-weight: 500;
}

.nav-previous a:hover,
.nav-next a:hover {
    background: #2980b9;
}

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    margin: 2rem 0;
    flex-wrap: wrap;
}

.pagination .page-numbers {
    display: inline-block;
    padding: 0.5rem 1rem;
    background: var(--bg-light);
    color: var(--text-color);
    border-radius: 4px;
    text-decoration: none;
    min-width: 44px;
    text-align: center;
}

.pagination .page-numbers:hover {
    background: var(--primary-color);
    color: #fff;
}

.pagination .page-numbers.current {
    background: var(--primary-color);
    color: #fff;
}

.pagination .page-numbers.dots {
    background: transparent;
    cursor: default;
}

.pagination .page-numbers.dots:hover {
    background: transparent;
    color: var(--text-color);
}

/* نموذج البحث */
.search-form {
    display: flex;
    gap: 0.5rem;
}

.search-field {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.9375rem;
}

.search-field:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.search-submit {
    padding: 0.75rem 1.5rem;
    background: var(--primary-color);
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
}

.search-submit:hover {
    background: #2980b9;
}

body.menu-open {
    overflow: hidden;
}

/* ——— الوضع الليلي — CSS شامل ——— */
[data-theme="dark"] a {
    color: #60a5fa;
}

[data-theme="dark"] a:hover {
    color: #93c5fd;
}

[data-theme="dark"] .archive-header,
[data-theme="dark"] .error-404,
[data-theme="dark"] .posts-navigation,
[data-theme="dark"] .post-navigation {
    border-color: var(--border-color);
}

[data-theme="dark"] .pagination .page-numbers {
    background: var(--bg-light);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

[data-theme="dark"] .pagination .page-numbers:hover {
    background: var(--mtp-accent);
    color: #fff;
    border-color: var(--mtp-accent);
}

[data-theme="dark"] .search-field {
    background: var(--bg-light);
    border-color: var(--border-color);
    color: var(--text-color);
}

[data-theme="dark"] .search-field:focus {
    outline-color: var(--mtp-accent);
    background: var(--bg-color);
}

[data-theme="dark"] .search-submit {
    background: var(--mtp-accent);
}

[data-theme="dark"] .search-submit:hover {
    background: #3b82f6;
}

/* ——— Floating Action Buttons ——— */
.mtp-floating-actions {
    position: fixed;
    bottom: 2rem;
    left: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    z-index: 1000;
}

.mtp-floating-btn {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: var(--mtp-accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
    border: none;
    cursor: pointer;
    text-decoration: none;
}

.mtp-floating-scroll-top {
    background: var(--bg-color, #fff);
    color: var(--mtp-accent, #2563eb);
    border: 1.5px solid var(--border-color, #e5e7eb);
}

[data-theme="dark"] .mtp-floating-scroll-top {
    background: var(--bg-light, #1e293b);
    border-color: var(--border-color, #1e293b);
    color: var(--text-color, #f1f5f9);
}

/* ——— Stable Sticky Mobile Header ——— */
.mtp-header-wrapper {
    position: sticky;
    top: 0;
    z-index: 9999;
    width: 100%;
}

@media (min-width: 801px) {
    /* Desktop header is not sticky by default */
    .mtp-header-wrapper {
        position: relative;
    }
}
