/* حصن الزواج — أنماط الهيكل.
 *
 * ⚠️ الألوان رموزٌ على ‎:root‎ لا قيمٌ منثورة: النمط الداكن يُعيد
 * تعريفها في موضعٍ واحد، ولونٌ مكتوبٌ مباشرةً في قاعدةٍ ما يبقى فاتحاً
 * في الداكن بلا أن يشتكي شيء.
 *
 * ⚠️ **والأخضر والذهبيّ مأخوذان من الشعار الرسمي لا مختارَين:**
 * ‎#1C3834‎ هو أكثر لونٍ تكراراً في حصن ‎brand/logo_mark.png‎،
 * و‎#C99D61‎ ذهبيُّ إطاره. وكانا قبل ذلك تخميناً (‎#0E5A4A‎ أخضرَ
 * أفتحَ بدرجتين) فبدت الواجهة قريبةً من الهوية لا منها — وهو فرقٌ
 * يراه صاحب العلامة في أول نظرة ولا يراه من كتب الكود.
 */

:root {
  color-scheme: light dark;

  --bg:        #F6F4EF;
  --surface:   #FFFFFF;
  --border:    #E2DCD0;
  --text:      #1B2320;
  --muted:     #5E6B65;
  --brand:     #1C3834;
  --brand-ink: #FFFFFF;
  --accent:    #A3763C;
  --ok:        #1E7A4A;
  --warn:      #A4562A;

  --radius: 16px;
  --gap: 16px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #0F1513;
    --surface:   #18211E;
    --border:    #2A3A34;
    --text:      #ECF1EE;
    --muted:     #9DAEA7;
    --brand:     #2C5C53;
    --brand-ink: #06120E;
    --accent:    #C99D61;
    --ok:        #4FC08A;
    --warn:      #E0A06A;
  }
}

:root[data-theme="dark"] {
  --bg:        #0F1513;
  --surface:   #18211E;
  --border:    #2A3A34;
  --text:      #ECF1EE;
  --muted:     #9DAEA7;
  --brand:     #2C5C53;
  --brand-ink: #06120E;
  --accent:    #C99D61;
  --ok:        #4FC08A;
  --warn:      #E0A06A;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  /* ⚠️ لا خطّ ويبٍ مُنزَّل: الخطّ الأول في القائمة هو خطّ النظام
   * العربي على كل منصّة. وتنزيل خطٍّ عربي كامل يعني ٣٠٠ كيلوبايت
   * قبل أوّل حرفٍ يظهر — على شبكةٍ بطيئة هو الفرق بين تطبيقٍ يفتح
   * وشاشةٍ بيضاء. */
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Naskh Arabic",
               "Tahoma", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  /* حشوةٌ جانبية ثابتة — لا تمرير أفقي على أضيق هاتف */
  padding: max(24px, env(safe-area-inset-top)) 16px
           max(24px, env(safe-area-inset-bottom));
  min-height: 100vh;
  display: flex;
  justify-content: center;
}

.shell {
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.brand { text-align: center; margin: 8px 0 4px; }
.brand__mark { display: block; margin: 0 auto 12px; height: auto; }
.brand__name { font-size: 1.6rem; margin: 0 0 4px; letter-spacing: -.01em; }
.brand__line { margin: 0; color: var(--muted); font-size: .95rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.card__title { margin: 0 0 6px; font-weight: 700; }
.card__body  { margin: 0; color: var(--muted); font-size: .95rem; }

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 0 0;
  font-size: .9rem;
  color: var(--muted);
}
.status__dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}
.status[data-state="online"]  .status__dot { background: var(--ok); }
.status[data-state="offline"] .status__dot { background: var(--warn); }

.actions { display: flex; flex-direction: column; gap: 10px; }

.btn {
  display: block;
  width: 100%;
  padding: 14px 18px;
  border-radius: 12px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}
.btn--primary { background: var(--brand); color: var(--brand-ink); }
.btn--ghost   { background: transparent; color: var(--text); border-color: var(--border); }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.foot { text-align: center; color: var(--muted); font-size: .85rem; }
.foot p { margin: 0; }

.notice {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin: 0 0 16px;
}

/* الدليل اليدويّ للتثبيت.
 *
 * ⚠️ ظاهرٌ دائماً لا يكشفه فشلُ الزرّ: على iOS لا يظهر زرُّ التثبيت
 * إطلاقاً، وبعض متصفّحات أندرويد تتجاهل ‎prompt()‎ بصمت. فمن لا يجد
 * طريقاً يدوياً يظنّ التطبيق معطَّلاً وهو سليم.
 */
.howto {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 16px;
  font-size: .92rem;
}
.howto > summary {
  cursor: pointer;
  padding: 12px 0;
  font-weight: 600;
  /* ⚠️ ‎list-style‎ وحدها لا تكفي: سفاري يرسم مثلّثه بـ‎::-webkit-details-marker‎
   * ولا يتأثّر بها، فيظهر مؤشّران على iOS دون غيره. */
  list-style: none;
}
.howto > summary::-webkit-details-marker { display: none; }
.howto > summary::after {
  content: '▾';
  float: left;
  color: var(--muted);
}
.howto[open] > summary::after { content: '▴'; }
.howto > summary:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.howto__body { padding-bottom: 10px; color: var(--muted); }
.howto__body p { margin: 0 0 10px; }
.howto__body strong { color: var(--text); }
.howto__note { font-size: .86rem; opacity: .85; }

/* ============================================================
 * التطبيق — البوّابة ثم الرزمة والتبويبات
 * ============================================================
 *
 * ⚠️ **مأخوذٌ عن العينة التي أعدّها صاحب المشروع** (رزمةُ بطاقاتٍ
 * تُسحب، زرّان دائريان، شريطُ تبويباتٍ سفليّ، ورقةٌ للتفاصيل، إعلانُ
 * تطابق) — **شكلاً وحركةً لا ألواناً**. وألوانُ العينة مكتوبةٌ في
 * قواعدها مباشرةً (‎#0a0a0a‎ و‎#d4af37‎)، ونقلُها كما هي يكسر قاعدتين
 * في هذا المستودع معاً: النمطُ الداكن يُعاد تعريفه في موضعٍ واحد،
 * والذهبيُّ الرسميّ ‎#C99D61‎ مقيسٌ من الشعار لا مختار. فالرموز أدناه
 * هي رموز ‎:root‎ نفسها، والشكل هو شكل العينة.
 */

/* ⚠️ **وهذه القاعدة تسبق كلَّ ما تحتها بقرار:** عناصر الشاشة أدناه
 * تُظهَر وتُخفى بسمة `hidden`، وقاعدةٌ مثل `.sheet { display: flex }`
 * **تتغلّب** على `display: none` التي يعطيها المتصفّح للسمة — فتبقى
 * ورقةُ التفاصيل وإعلانُ التطابق مفتوحَين فوق الشاشة من أوّل لحظة،
 * ولا شيء في أي سجلٍّ يشير إلى السبب.
 */
[hidden] { display: none !important; }

/* شاشة الإقلاع — ما يُرى قبل أن تصل النصوص */
.boot {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--bg);
  color: var(--muted);
  text-align: center;
  padding: 24px;
  z-index: 900;
}
.boot .btn { max-width: 260px; }

/* ⚠️ الوضع التطبيقي يُبدّل تخطيط الصفحة كلَّها: البوّابة صفحةٌ تُمرَّر،
 * والتطبيق شاشةٌ ثابتة تُمرَّر أجزاؤها وحدها. وبلا ‎position: fixed‎
 * يقفز التخطيط على أندرويد كلّما ظهرت لوحة المفاتيح أو اختفى شريط
 * العنوان. */
body.is-app {
  padding: 0;
  overflow: hidden;
  position: fixed;
  inset: 0;
  display: block;
}

.app { position: fixed; inset: 0; }

.top {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(52px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 16px 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 10;
}
.top__name  { color: var(--accent); font-size: 1.05rem; }
.top__count { color: var(--muted); font-size: .8rem; }

.view {
  position: fixed;
  top: calc(52px + env(safe-area-inset-top));
  left: 0; right: 0;
  bottom: calc(64px + env(safe-area-inset-bottom));
  overflow: hidden;
}
.view--list {
  overflow-y: auto;
  padding: 14px 16px calc(20px + env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
}
.view--list > * { max-width: 460px; margin-inline: auto; }

/* الرزمة: ثلاثُ بطاقاتٍ لا أكثر — الرابعة لا تُرى ولا تُرسَم */
.view--deck { bottom: calc(168px + env(safe-area-inset-bottom)); padding: 12px; }
.stack { position: absolute; inset: 12px; max-width: 420px; margin: 0 auto; }

.pcard {
  position: absolute;
  inset: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 18px;
  overflow-y: auto;
  z-index: 1;
  /* ⚠️ يمنع المتصفّح من تفسير السحب الأفقي تمريراً للصفحة — وبدونه
   * تسحب البطاقةَ فينتقل التبويب أو تعود الصفحة إلى الخلف. */
  touch-action: pan-y;
}
.pcard--front { z-index: 10; box-shadow: 0 10px 40px rgba(0, 0, 0, .28); }
.pcard--b1 { z-index: 9; transform: scale(.95) translateY(8px);  opacity: .7; pointer-events: none; }
.pcard--b2 { z-index: 8; transform: scale(.90) translateY(16px); opacity: .4; pointer-events: none; }

.pcard__head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.pcard__id    { color: var(--accent); font-weight: 700; font-size: .85rem; }
.pcard__score { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.pcard__badge {
  display: inline-block;
  background: color-mix(in srgb, var(--ok) 15%, transparent);
  color: var(--ok);
  border-radius: 10px;
  padding: 1px 8px;
  font-size: .72rem;
  font-weight: 700;
}

/* الصورة: مموّهةٌ من الوسيط، ولا رابط `getFile` إلى المتصفّح أبداً */
.ava {
  width: 72px; height: 72px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: var(--bg);
  object-fit: cover;
  display: flex; align-items: center; justify-content: center;
  font-size: 30px;
  flex: none;
}
.pcard__note { color: var(--muted); font-size: .72rem; text-align: center; margin: 6px 0 0; }

.pcard__lines { margin: 12px 0 0; }
.pcard__line {
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: .9rem;
  /* النصّ يأتي من البوت سطراً سطراً — والمسافات فيه جزءٌ من معناه */
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.pcard__line:last-child { border-bottom: 0; }
.pcard__hint { text-align: center; color: var(--muted); font-size: .75rem; margin-top: 14px; }

.swipe {
  position: fixed;
  bottom: calc(64px + env(safe-area-inset-bottom));
  left: 0; right: 0;
  height: 104px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  background: var(--bg);
  z-index: 10;
}
.rnd {
  width: 62px; height: 62px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}
.rnd--no  { border-color: var(--warn); color: var(--warn); }
.rnd--yes { border-color: var(--ok);   color: var(--ok); width: 70px; height: 70px; font-size: 30px; }
.rnd:disabled { opacity: .4; }
.rnd:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.tabs {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(64px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 20;
}
.tab {
  flex: 1;
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  font-size: .7rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
}
.tab i { font-size: 19px; font-style: normal; }
.tab.on { color: var(--accent); }
.tab:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }

/* صفٌّ في قائمة (مطابقاتي) */
.row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: start;
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.row__main { flex: 1; min-width: 0; }
.row__name { font-weight: 700; color: var(--accent); }
.row__sub  { color: var(--muted); font-size: .8rem; white-space: pre-wrap; }

.empty { text-align: center; color: var(--muted); padding: 48px 16px; }

/* ورقة التفاصيل وإعلان التطابق */
.sheet {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, .6);
  display: flex;
  align-items: flex-end;
  z-index: 200;
}
.sheet__panel {
  background: var(--surface);
  border-top: 2px solid var(--accent);
  border-radius: 22px 22px 0 0;
  width: 100%;
  max-height: 86vh;
  overflow-y: auto;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
}
.sheet__panel > .btn { margin-top: 14px; }

.pop {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  padding: 24px;
  z-index: 500;
}
.pop__em { font-size: 64px; }
.pop h2  { color: var(--accent); margin: 0; }
.pop p   { color: var(--muted); margin: 0 0 8px; }
.pop .btn { max-width: 300px; }

.toast {
  position: fixed;
  top: calc(64px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%) translateY(-140%);
  background: var(--brand);
  color: var(--brand-ink);
  padding: 10px 20px;
  border-radius: 24px;
  font-size: .85rem;
  font-weight: 600;
  max-width: 88vw;
  text-align: center;
  transition: transform .25s;
  z-index: 600;
}
.toast.on { transform: translateX(-50%) translateY(0); }

/* ⚠️ من يطلب «حركةً أقلّ» في إعدادات نظامه يعنيها: الحركة هنا زينة،
 * وفي بعض الناس دوارٌ حقيقي. */
@media (prefers-reduced-motion: reduce) {
  .toast, .pcard { transition: none !important; }
}

/* حقول النماذج */
.fld { display: block; margin: 0 0 12px; }
.fld > span { display: block; color: var(--muted); font-size: .8rem; margin-bottom: 4px; }
.fld input, .fld select {
  width: 100%;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font: inherit;
  font-size: 1rem;   /* ⚠️ دون 16px يكبّر سفاري الصفحةَ عند التركيز */
}
.fld input:focus, .fld select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.fld__row { display: flex; gap: 10px; }
.fld__row .fld { flex: 1; }
.fld__err { color: var(--warn); font-size: .85rem; margin: 10px 0 0; }

.linkbtn {
  display: block;
  width: 100%;
  margin-top: 12px;
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  font-size: .85rem;
  text-decoration: underline;
  cursor: pointer;
}

/* فاصلٌ بين طريقَي الدخول */
.sep {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: .8rem;
  margin: 14px 0 0;
}
.sep::before, .sep::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* زرُّ مزوّدٍ — رابطٌ لا زرّ، لأنه **ملاحةُ صفحة** إلى نطاقٍ آخر */
.prov {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 13px 16px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.prov i { font-size: 18px; font-style: normal; }
.prov:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.prov[aria-busy="true"] { opacity: .6; pointer-events: none; }
