/* =========================================================
   الأربعين النووية — نظام تصميم عصري بسيط (Minimal)
   RTL · وضع فاتح/داكن · تصميم متجاوب
   ========================================================= */

/* ---- الخطوط ---- */
:root {
  --font-ui: "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-matn: "Amiri", "Noto Naskh Arabic", "Times New Roman", serif;

  /* المقاسات المتجاوبة */
  --step-0: clamp(1rem, 0.95rem + 0.3vw, 1.125rem);
  --step-1: clamp(1.15rem, 1.05rem + 0.5vw, 1.35rem);
  --step-2: clamp(1.35rem, 1.2rem + 0.8vw, 1.7rem);
  --step-3: clamp(1.7rem, 1.4rem + 1.4vw, 2.4rem);
  --step-4: clamp(2.1rem, 1.6rem + 2.5vw, 3.2rem);

  --container: 820px;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px -12px rgba(0,0,0,.12);
  --shadow-lg: 0 12px 40px -16px rgba(0,0,0,.22);
  --ring: 0 0 0 3px var(--accent-soft);
  --transition: .22s cubic-bezier(.4,0,.2,1);
}

/* ---- الوضع الفاتح ---- */
:root {
  --bg: #f7f5ef;
  --bg-grad-1: #f9f7f1;
  --bg-grad-2: #f1ede3;
  --surface: #ffffff;
  --surface-2: #faf8f3;
  --border: #e7e1d3;
  --border-strong: #d8cfba;
  --text: #26221c;
  --text-soft: #5c5648;
  --text-mute: #8a8271;
  --accent: #0f766e;          /* أخضر زيتوني هادئ */
  --accent-2: #b58a2e;        /* ذهبي */
  --accent-soft: rgba(15,118,110,.14);
  --accent-ink: #0b5a54;
  --matn-bg: #f4f1e8;
  --matn-border: #e0d8c4;
  --highlight: #0b5a54;       /* لون الكلمات المميزة داخل النص */
  --sacred: #b58a2e;
}

/* ---- الوضع الداكن ---- */
:root[data-theme="dark"] {
  --bg: #14181b;
  --bg-grad-1: #171c20;
  --bg-grad-2: #10141a;
  --surface: #1b2126;
  --surface-2: #20272d;
  --border: #2b333a;
  --border-strong: #3a444c;
  --text: #eef1f2;
  --text-soft: #b9c0c4;
  --text-mute: #8b959b;
  --accent: #4dd8c8;
  --accent-2: #e6c168;
  --accent-soft: rgba(77,216,200,.16);
  --accent-ink: #7fe6da;
  --matn-bg: #1e252b;
  --matn-border: #313b42;
  --highlight: #6fe0d3;
  --sacred: #e6c168;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px -12px rgba(0,0,0,.6);
  --shadow-lg: 0 12px 40px -16px rgba(0,0,0,.7);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14181b; --bg-grad-1: #171c20; --bg-grad-2: #10141a;
    --surface: #1b2126; --surface-2: #20272d;
    --border: #2b333a; --border-strong: #3a444c;
    --text: #eef1f2; --text-soft: #b9c0c4; --text-mute: #8b959b;
    --accent: #4dd8c8; --accent-2: #e6c168; --accent-soft: rgba(77,216,200,.16);
    --accent-ink: #7fe6da; --matn-bg: #1e252b; --matn-border: #313b42;
    --highlight: #6fe0d3; --sacred: #e6c168;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px -12px rgba(0,0,0,.6);
    --shadow-lg: 0 12px 40px -16px rgba(0,0,0,.7);
  }
}

/* ---- تصفير ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

body {
  font-family: var(--font-ui);
  font-size: var(--step-0);
  line-height: 1.85;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 100% -10%, var(--accent-soft), transparent 60%),
    linear-gradient(180deg, var(--bg-grad-1), var(--bg-grad-2));
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

img { max-width: 100%; display: block; }
a { color: var(--accent-ink); text-decoration: none; }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 6px; }

.container { width: min(100% - 2rem, var(--container)); margin-inline: auto; }

/* ---- الترويسة ---- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in oklab, var(--surface) 82%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.site-header .bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding-block: .7rem;
}
.brand { display: flex; align-items: center; gap: .7rem; color: var(--text); }
.brand .mark {
  flex: none; display: grid; place-items: center; width: 44px; height: 44px;
  border-radius: 13px; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-ink));
  box-shadow: 0 4px 14px -4px var(--accent-soft), inset 0 1px 0 rgba(255,255,255,.15);
}
:root[data-theme="dark"] .brand .mark { color: #08201d; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .brand .mark { color: #08201d; } }
.brand .mark svg { width: 25px; height: 25px; }
.brand .name { font-weight: 700; font-size: 1.12rem; letter-spacing: -.01em; line-height: 1.2; }
.brand .name span { display: block; font-size: .72rem; font-weight: 500; color: var(--text-mute); margin-top: 1px; }

.actions { display: flex; align-items: center; gap: .5rem; }
.theme-toggle, .icon-btn {
  display: inline-grid; place-items: center;
  width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid var(--border-strong); background: var(--surface-2);
  color: var(--text-soft); cursor: pointer; transition: var(--transition);
}
.theme-toggle:hover, .icon-btn:hover { color: var(--accent-ink); border-color: var(--accent); transform: translateY(-1px); }
.theme-toggle svg, .icon-btn svg { width: 20px; height: 20px; }

/* ---- نافذة البحث المنبثقة ---- */
.search-overlay {
  position: fixed; inset: 0; z-index: 100; display: none;
  padding: clamp(1rem, 8vh, 6rem) 1rem 1rem;
  background: color-mix(in oklab, #000 45%, transparent);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
.search-overlay.open { display: block; animation: fade .2s ease; }
.search-modal {
  width: min(100%, 640px); margin-inline: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  overflow: hidden; display: flex; flex-direction: column;
  max-height: min(70vh, 640px);
}
.search-modal .field { position: relative; border-bottom: 1px solid var(--border); }
.search-modal .field svg { position: absolute; inset-inline-end: 1.1rem; top: 50%; transform: translateY(-50%);
  width: 20px; height: 20px; color: var(--text-mute); pointer-events: none; }
.search-modal input {
  width: 100%; font-family: inherit; font-size: 1.1rem; color: var(--text);
  padding: 1.1rem 3.2rem 1.1rem 1.2rem; border: 0; background: transparent;
}
.search-modal input:focus { outline: none; box-shadow: none; }
.search-modal input::placeholder { color: var(--text-mute); }
.search-results { overflow-y: auto; overscroll-behavior: contain; }
.search-hint { padding: 1.4rem; text-align: center; color: var(--text-mute); font-size: .95rem; }
.result {
  display: block; width: 100%; text-align: start; padding: .9rem 1.2rem;
  border: 0; border-bottom: 1px solid var(--border); background: transparent;
  cursor: pointer; transition: background .12s; color: var(--text); font-family: inherit;
}
.result:last-child { border-bottom: 0; }
.result:hover, .result.active { background: var(--accent-soft); }
.result .r-head { display: flex; align-items: center; gap: .6rem; margin-bottom: .25rem; }
.result .r-num {
  flex: none; display: grid; place-items: center; min-width: 26px; height: 26px; padding: 0 .3rem;
  border-radius: 8px; font-size: .8rem; font-weight: 700; font-variant-numeric: tabular-nums;
  color: var(--accent-ink); background: var(--accent-soft);
}
.result .r-title { font-weight: 700; font-size: 1rem; }
.result .r-tag { margin-inline-start: auto; font-size: .72rem; color: var(--text-mute);
  border: 1px solid var(--border-strong); border-radius: 999px; padding: .1rem .55rem; }
.result .r-snippet { font-size: .9rem; line-height: 1.7; color: var(--text-soft);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.result mark { background: transparent; color: var(--accent-ink); font-weight: 700; }
.search-foot { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap;
  padding: .6rem; border-top: 1px solid var(--border); font-size: .78rem; color: var(--text-mute); }
.search-foot kbd { font-family: inherit; background: var(--surface-2); border: 1px solid var(--border-strong);
  border-radius: 6px; padding: .05rem .4rem; font-size: .75rem; }
body.no-scroll { overflow: hidden; }
.theme-toggle .sun { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: block; }
:root[data-theme="dark"] .theme-toggle .moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .moon { display: none; }
}

/* ---- الصفحة الرئيسية ---- */
.hero { text-align: center; padding: clamp(2.5rem, 6vw, 4.5rem) 0 1.5rem; }
.hero .kicker {
  display: inline-block; font-size: .8rem; font-weight: 600; letter-spacing: .08em;
  color: var(--accent-ink); background: var(--accent-soft);
  padding: .35rem .9rem; border-radius: 999px; margin-bottom: 1.1rem;
}
.hero h1 {
  font-family: var(--font-matn); font-size: var(--step-4); font-weight: 700;
  line-height: 1.25; color: var(--text); letter-spacing: -.01em;
}
.hero p { color: var(--text-soft); font-size: var(--step-1); max-width: 46ch; margin: 1rem auto 0; }

.search {
  position: relative; max-width: 480px; margin: 2rem auto 0;
}
.search input {
  width: 100%; font-family: inherit; font-size: 1rem; color: var(--text);
  padding: .9rem 3rem .9rem 1.1rem; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--surface);
  box-shadow: var(--shadow); transition: var(--transition);
}
.search input::placeholder { color: var(--text-mute); }
.search input:focus { border-color: var(--accent); box-shadow: var(--ring); }
.search svg { position: absolute; inset-inline-end: 1rem; top: 50%; transform: translateY(-50%);
  width: 20px; height: 20px; color: var(--text-mute); pointer-events: none; }

/* ---- شبكة الأحاديث ---- */
.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 1rem; padding: 2rem 0 3rem;
}
.card {
  display: flex; align-items: center; gap: 1rem;
  padding: 1.1rem 1.2rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); transition: var(--transition);
}
.card:hover { transform: translateY(-3px); border-color: var(--accent); box-shadow: var(--shadow-lg); }
.card .num {
  flex: none; display: grid; place-items: center; width: 48px; height: 48px;
  border-radius: 14px; font-weight: 700; font-size: 1.15rem;
  color: var(--accent-ink); background: var(--accent-soft);
  font-variant-numeric: tabular-nums;
}
.card .meta { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.card .meta .id { display: block; font-size: .8rem; color: var(--text-mute); font-weight: 600; }
.card .meta .title { display: block; font-size: 1.05rem; font-weight: 600; color: var(--text); line-height: 1.4; }
.card[hidden] { display: none; }
.no-results { text-align: center; color: var(--text-mute); padding: 2rem; grid-column: 1/-1; }

/* ---- صفحة الحديث ---- */
.page-nav { display: flex; align-items: center; gap: .5rem; padding-top: 1.5rem; font-size: .9rem; color: var(--text-mute); }
.page-nav a { color: var(--text-soft); }
.page-nav a:hover { color: var(--accent-ink); }

.hadith-head { text-align: center; padding: 1.5rem 0 .5rem; }
.hadith-head .id {
  display: inline-block; font-size: .85rem; font-weight: 600; letter-spacing: .05em;
  color: var(--accent-ink); background: var(--accent-soft);
  padding: .3rem .9rem; border-radius: 999px;
}
.hadith-head h1 {
  font-family: var(--font-matn); font-size: var(--step-3); font-weight: 700;
  color: var(--text); margin-top: .8rem; line-height: 1.3;
}

.head-actions { display: flex; justify-content: center; margin-top: 1rem; }
.share-btn {
  display: inline-flex; align-items: center; gap: .5rem; cursor: pointer;
  font-family: inherit; font-size: .92rem; font-weight: 600; color: var(--text-soft);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 999px; padding: .55rem 1.1rem; transition: var(--transition);
}
.share-btn:hover { color: var(--accent-ink); border-color: var(--accent); transform: translateY(-1px); box-shadow: var(--shadow); }
.share-btn svg { width: 17px; height: 17px; }

/* ---- التبويبات ---- */
.tabs {
  display: flex; gap: .3rem; padding: .35rem; margin: 1.5rem 0;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1 0 auto; display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .65rem 1rem; border: 0; border-radius: 999px; cursor: pointer;
  font-family: inherit; font-size: .95rem; font-weight: 600; white-space: nowrap;
  color: var(--text-soft); background: transparent; transition: var(--transition);
}
.tab:hover { color: var(--accent-ink); }
.tab[aria-selected="true"] { color: #fff; background: var(--accent); box-shadow: var(--shadow); }
:root[data-theme="dark"] .tab[aria-selected="true"] { color: #08201d; }
.tab svg { width: 18px; height: 18px; }

.panel { animation: fade .3s ease; }
.panel[hidden] { display: none; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---- بطاقة المحتوى ---- */
.sheet {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: clamp(1.3rem, 3vw, 2.2rem);
}

/* المتن */
.matn {
  font-family: var(--font-matn); font-size: var(--step-2); line-height: 2.2;
  text-align: justify; color: var(--text);
  background: var(--matn-bg); border: 1px solid var(--matn-border);
  border-inline-start: 4px solid var(--accent-2);
  border-radius: var(--radius-sm); padding: clamp(1.1rem, 3vw, 1.8rem);
}
.matn p { margin-block: .6rem; }
.matn p:first-child { margin-top: 0; }
.matn p:last-child { margin-bottom: 0; }
.matn .said { color: var(--highlight); font-weight: 700; }   /* النص النبوي/القرآني المُقتبس */
.sacred { color: var(--sacred); font-family: var(--font-matn); }
.isnad { display: block; margin-top: 1rem; padding-top: .9rem; border-top: 1px dashed var(--matn-border);
  font-family: var(--font-ui); font-size: .95rem; line-height: 1.9; color: var(--text-soft); }

/* الشرح + ترجمة الراوي */
.prose { font-size: var(--step-1); line-height: 2.05; text-align: justify; color: var(--text-soft); }
.prose p { margin-bottom: 1.1rem; }
.prose p:last-child { margin-bottom: 0; }
.prose .said { color: var(--highlight); font-weight: 700; font-family: var(--font-matn); }
.prose b { color: var(--highlight); font-weight: 700; }

/* الوسائط */
.media h3 {
  font-size: 1.05rem; font-weight: 700; color: var(--text); margin: 1.4rem 0 .7rem;
  display: flex; align-items: center; gap: .5rem;
}
.media h3:first-child { margin-top: 0; }
.media h3 svg { width: 20px; height: 20px; color: var(--accent); }
.media audio { width: 100%; height: 44px; }
.video-wrap {
  position: relative; aspect-ratio: 16 / 9; border-radius: var(--radius-sm);
  overflow: hidden; background: #000; border: 1px solid var(--border);
}
.video-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* التنقل بين الأحاديث */
.hadith-foot {
  display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; margin: 1.8rem 0 1rem;
}
.nav-btn {
  display: flex; align-items: center; gap: .6rem; padding: .9rem 1.1rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-weight: 600; transition: var(--transition); box-shadow: var(--shadow);
}
.nav-btn:hover { border-color: var(--accent); color: var(--accent-ink); transform: translateY(-2px); }
.nav-btn.disabled { opacity: .4; pointer-events: none; }
.nav-btn .dir { color: var(--text-mute); font-size: .8rem; display: block; }
.nav-btn svg { width: 18px; height: 18px; flex: none; }
.nav-btn.next { justify-content: flex-start; }
.nav-btn.prev { justify-content: flex-end; text-align: end; }

.index-link {
  display: inline-flex; align-items: center; gap: .5rem; margin: 0 auto 1rem;
  padding: .7rem 1.4rem; border-radius: 999px; font-weight: 600;
  color: var(--accent-ink); background: var(--accent-soft); transition: var(--transition);
}
.index-link:hover { background: var(--accent); color: #fff; }
:root[data-theme="dark"] .index-link:hover { color: #08201d; }
.center { display: flex; justify-content: center; }

/* ---- التذييل ---- */
.site-footer {
  border-top: 1px solid var(--border); margin-top: 2rem;
  background: color-mix(in oklab, var(--surface) 60%, transparent);
}
.site-footer .inner { padding: 2rem 0; text-align: center; }
.site-footer ul { list-style: none; display: flex; flex-wrap: wrap; justify-content: center; gap: .5rem 1.4rem; margin-bottom: 1rem; }
.site-footer a { color: var(--text-soft); font-weight: 500; }
.site-footer a:hover { color: var(--accent-ink); text-decoration: underline; }
.site-footer p { color: var(--text-mute); font-size: .9rem; line-height: 1.8; }

/* 404 */
.notfound { text-align: center; padding: clamp(3rem, 10vw, 6rem) 0; }
.notfound .code { font-family: var(--font-matn); font-size: clamp(4rem, 15vw, 8rem); font-weight: 700; color: var(--accent); line-height: 1; }
.notfound h1 { font-size: var(--step-2); margin: 1rem 0; color: var(--text); }
.notfound p { color: var(--text-soft); margin-bottom: 1.5rem; }

@media (max-width: 520px) {
  .tab span { display: none; }
  .tab { flex: 1; padding: .6rem; }
  .hadith-foot { grid-template-columns: 1fr; }
  .brand .name span { display: none; }
}
