/* =====================================================================
 *  mobile.css — واجهة الجوال
 *  ---------------------------------------------------------------------
 *  ⚠️ يُحمَّل **بعد** style.css عمداً. سببه أن style.css فيه قواعد
 *     قديمة للجوال بـ !important تكسر الواجهة، ولا نقدر نعدّلها من
 *     داخله بأمان لأن نسختك على الجهاز قديمة (٨٧٥ بايت) والنسخة
 *     الحيّة على السيرفر ١٠٣٠٣ بايت — فلو استبدلناه لضاع فرق كبير.
 *
 *     فنُصلح هنا بملف مستقل: لو احتجت يوماً ترجع للسابق احذف سطر
 *     استدعائه من index.php ولا شي غيره يتغيّر.
 *
 *  🖥️ الكمبيوتر والآيباد لا يتغيّر فيهما شيء — كل ما هنا داخل
 *     @media للجوال وحده.
 * ===================================================================== */

@media (max-width: 640px) {

  /* ==================================================================
   *  ١) 🐞 أكبر مشكلة: كل الشبكات كانت تنهار لعمود واحد
   * ------------------------------------------------------------------
   *  في style.css:
   *      .grid-cols-2, .grid-cols-3, .grid-cols-4
   *          { grid-template-columns: 1fr !important; }
   *
   *  كُتبت قديماً بنيّة «الجوال عمود واحد»، ونتيجتها أن الزبون يشوف
   *  قطعتين ونصف في الشاشة كاملة ثم يسحب ويسحب. وشراء المجوهرات
   *  مقارنة بالعين: الزبون يبغى يشوف القطع **جنب بعض** ليختار.
   *  فنرجّع عمودين — وهو ما تفعله كل متاجر المجوهرات على الجوال.
   * ================================================================== */
  .grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .grid-cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .grid-cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .grid-cols-1 { grid-template-columns: minmax(0, 1fr) !important; }

  /* فجوة أصغر فتتسع القطعتان بلا خنق */
  .gap-4 { gap: 0.625rem !important; }
  .gap-6 { gap: 0.75rem !important; }
  .gap-3 { gap: 0.5rem !important; }

  /* 🧱 بطاقات التصنيفات ثلاثة في الصف — وهذا ما يجعل الصفحة
     الرئيسية «مليانة» على الجوال. وهي بطاقات صغيرة باسم فقط، فثلاثة
     منها تُقرأ بوضوح؛ أما بطاقات القطع فتبقى عمودين لأن فيها صورة
     وسعراً وزرّ سلة. */
  body .cat-tiles { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; gap: .5rem !important; }
  body .cat-tiles .h-40 { height: 6.75rem !important; }
  body .cat-tiles h3 { font-size: 12px !important; line-height: 1.25 !important; }
  body .cat-tiles .p-4 { padding: .5rem !important; }

  /* النماذج والجداول تبقى عموداً واحداً — عمودان فيها خنق لا تنظيم */
  body form .grid-cols-2,
  body .grid-cols-2:has(> label),
  body .grid-cols-2:has(> div > label),
  body #admin-dashboard-container .grid-cols-2 { grid-template-columns: minmax(0, 1fr) !important; }

  /* ==================================================================
   *  ٢) 🐞 حجم الخط المفروض على كل عنصر
   * ------------------------------------------------------------------
   *  كان في style.css:  p, span, div { font-size: 0.95rem !important; }
   *  وهذا يطبّق ١٥ بكسل على **كل** span وdiv في الصفحة، فيُلغي كل
   *  المقاسات الصغيرة المقصودة: «شامل الضريبة والتوصيل» والنجوم
   *  وشارات الخصم وأرقام التتبّع — كلها تطلع بحجم النص العادي
   *  فتزدحم الشاشة ويضيع التمييز بين المهم والثانوي.
   *
   *  فنُعيد الحجم الأساسي للجسم وحده، ونترك المقاسات الصغيرة تعمل.
   * ================================================================== */
  body { font-size: 15px !important; }
  p, span, div { font-size: inherit !important; }

  .text-\[9px\]  { font-size: 9px !important; }
  .text-\[10px\] { font-size: 10px !important; }
  .text-\[11px\] { font-size: 11px !important; }
  .text-xs       { font-size: 12px !important; }
  .text-sm       { font-size: 13.5px !important; }
  .text-base     { font-size: 15px !important; }
  .text-lg       { font-size: 17px !important; }
  .text-xl       { font-size: 19px !important; }
  .text-2xl      { font-size: 22px !important; }
  .text-3xl      { font-size: 26px !important; }
  h1 { font-size: 22px !important; }
  h2 { font-size: 19px !important; }

  /* ==================================================================
   *  ٣) شريط أسعار الذهب
   * ------------------------------------------------------------------
   *  كان يُخفي كل العيارات ويعرض **الأونصة** وحدها. والأونصة آخر ما
   *  يهم زبون التجزئة — هو يسأل «كم عيار ٢١ اليوم؟» بالجرام.
   *  فنعرض ٢١ و١٨ بالجرام، والباقي يظهر بضغطة على الشريط.
   * ================================================================== */
  #main-ticker { height: 38px !important; }
  body { padding-top: 38px !important; }

  body #gold-prices-container {
    flex-direction: row !important;
    justify-content: flex-start !important;
    gap: 14px !important;
    padding: 0 !important;
    overflow-x: auto;
    scrollbar-width: none;
  }
  body #gold-prices-container::-webkit-scrollbar { display: none; }

  /* العيارات التي يسأل عنها الزبون فعلاً */
  body .price-item { display: none !important; width: auto !important; padding: 0 !important; border: none !important; }
  body .price-item[data-karat="21"],
  body .price-item[data-karat="18"] { display: flex !important; }
  body .price-item { font-size: 11.5px !important; gap: 5px !important; }
  body .price-value { font-size: 12px !important; }

  /* وعند التمدد يظهر الكل عموداً */
  body #main-ticker.expanded { height: auto !important; padding-bottom: 8px; }
  body #main-ticker.expanded #gold-prices-container { flex-direction: column !important; align-items: stretch !important; gap: 0 !important; padding: 4px 14px !important; }
  body #main-ticker.expanded .price-item {
    display: flex !important; justify-content: space-between;
    padding: 7px 0 !important; border-bottom: 1px solid rgba(255,255,255,.07) !important;
  }

  /* ==================================================================
   *  ٤) 📱 شريط التنقّل السفلي
   * ------------------------------------------------------------------
   *  السلة والبحث والحساب كانت في أعلى الصفحة — وأعلى الشاشة أبعد
   *  نقطة عن الإبهام في الجوال. وبعد ما صار الموقع يُثبَّت كتطبيق،
   *  غيابُ شريط سفلي يجعله يبدو موقعاً داخل إطار لا تطبيقاً.
   *
   *  ويحترم مساحة الإيماءات في الآيفون (safe-area).
   * ================================================================== */
  body #mobile-tabbar { display: flex !important; }
  body { padding-bottom: calc(62px + env(safe-area-inset-bottom, 0px)) !important; }

  /* الأزرار العائمة ترتفع فوق الشريط فلا تتراكب معه */
  body #whatsapp-floating-btn { bottom: calc(76px + env(safe-area-inset-bottom, 0px)) !important; }
  body #sbc-floating-btn      { bottom: calc(144px + env(safe-area-inset-bottom, 0px)) !important; }

  /* شارة «متجر موثق» كانت تغطي بطاقة قطعة — نُصغّرها ونُبعدها */
  /* شارة «متجر موثق» — صغيرة وهي ساكنة فلا تغطي قطعة
     ⚠️ ولا نقصّها بـ overflow:hidden: شاشة التحقق تفتح **داخل**
        الإطار نفسه، والقصّ يُخفي الشهادة التي وُضعت الشارة لأجلها. */
  body #sbc-floating-btn { transform: scale(.62); transform-origin: bottom left; opacity: .92; }

  /* ولما تتمدّد (يكبّر المصدرُ الإطارَ لعرض الشهادة) نرفع عنها
     التصغير ونوسّطها في الشاشة بخلفية معتمة — فتُقرأ كاملة بدل أن
     تطلع نصفها خارج الجوال. الكلاس يضعه sbcWatchSeal في store.js. */
  body #sbc-floating-btn.sbc-open {
    transform: none !important;
    opacity: 1 !important;
    top: 50% !important;
    left: 50% !important;
    right: auto !important;
    bottom: auto !important;
    margin: 0 !important;
    translate: -50% -50%;
    z-index: 130 !important;
  }
  body #sbc-floating-btn.sbc-open iframe {
    max-width: calc(100vw - 32px) !important;
    max-height: 72vh !important;
  }
  body #sbc-seal-backdrop {
    position: fixed; inset: 0; z-index: 129;
    background: rgba(0,0,0,.55);
    backdrop-filter: blur(2px);
  }

  /* ==================================================================
   *  ٥) بطاقة القطعة — أنحف لتتسع في عمودين
   * ================================================================== */
  body #catalog-grid .h-44,
  body #account-favorites-grid .h-44 { height: 9.5rem !important; }
  body .line-clamp-2 { -webkit-line-clamp: 2; }

  /* ==================================================================
   *  ٦) مسافات أقل بين الأقسام — الشاشة ضيقة والفراغ يُكلّف سحباً
   * ================================================================== */
  body .py-8  { padding-top: 1.25rem !important; padding-bottom: 1.25rem !important; }
  body .mt-16 { margin-top: 2rem !important; }
  body .mt-14 { margin-top: 1.75rem !important; }
  body .mb-6  { margin-bottom: 1rem !important; }

  /* ==================================================================
   *  ٧) تحديد النص — كان ممنوعاً في كل الصفحة
   * ------------------------------------------------------------------
   *  مُنع لحماية الصور، لكنه منع الزبون من نسخ **رقم تتبّع شحنته**
   *  أو رقم طلبه أو عنوان الفرع. فنسمح بما يحتاج النسخ تحديداً.
   * ================================================================== */
  body .select-all, body .font-mono, body [dir="ltr"] {
    -webkit-user-select: text !important;
    user-select: text !important;
    -webkit-touch-callout: default !important;
  }

  /* نوافذ المتجر تملأ الشاشة من الأسفل — أقرب للإبهام */
  body #cart-sidebar > div { max-height: 92vh !important; }
}

/* ==================================================================
 *  شريط التنقّل السفلي — مخفي خارج الجوال، ومخفي في لوحة التحكم
 * ================================================================== */
#mobile-tabbar { display: none; }

body:has(#admin-dashboard-container:not(.hidden)) #mobile-tabbar { display: none !important; }
body:has(#admin-dashboard-container:not(.hidden)) { padding-bottom: 0 !important; }

.tabbar-link {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 7px 0 calc(7px + env(safe-area-inset-bottom, 0px));
  color: #94a3b8;
  font-size: 10px;
  font-weight: 700;
  background: none;
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color .15s ease;
}
.tabbar-link svg { width: 21px; height: 21px; }
.tabbar-link.active { color: #A37215; }
.tabbar-link:active { color: #D6A74A; }

#mobile-tabbar .tab-badge {
  position: absolute;
  top: 2px;
  transform: translateX(10px);
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: #D6A74A;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

@media print { #mobile-tabbar { display: none !important; } }

/* =====================================================================
 *  🖼️ مكبّر الصور في الجوال
 *  ---------------------------------------------------------------------
 *  🐞 العلّة: في style.css قاعدة للجوال تقول:
 *
 *        .fixed.inset-0 .bg-white { width: 92% !important; … }
 *
 *     نيّتها «كرت النافذة المنبثقة يكون 92% من عرض الشاشة». لكنها
 *     تصطاد **أي** عنصر فيه bg-white داخل أي شاشة كاملة — والصور
 *     والمصغّرات والأزرار كلها فيها bg-white. فصارت كل مصغّرة عرضها
 *     92% من الشاشة، فتنزل وحدها في سطر: «الصور تحت بعض». والصورة
 *     الكبيرة طلعت برّا حدود الشاشة، وطولها دفع زر الإغلاق (×) فوق
 *     حدّ الشاشة فاختفى.
 *
 *     ما نعدّل style.css (نسختك على الكمبيوتر قديمة جداً ورفعها يمسح
 *     شغلاً كثيراً على السيرفر)، فنصحّحها من هنا — وهذا الملف يُحمّل
 *     بعدها فتعديله هو الأخير.
 * ===================================================================== */
@media (max-width: 640px) {

    /* القاعدة للكروت لا للصور والأزرار: نرجّع هذولا لمقاسهم الطبيعي */
    body .fixed.inset-0 img.bg-white,
    body .fixed.inset-0 button.bg-white,
    body .fixed.inset-0 a.bg-white,
    body .fixed.inset-0 span.bg-white,
    body .fixed.inset-0 .pz-btn {
        width: auto !important;
        margin: 0 !important;
    }

    /* الصورة الكبيرة: داخل حدود الشاشة، وطولها يسيب مكاناً للشريط
       والمصغّرات حتى يبقى زر الإغلاق وما تحته ظاهراً بلا تمرير. */
    body #prod-zoom-host #pz-main {
        width: auto !important;
        max-width: 100% !important;
        max-height: 58vh !important;
        margin: 0 auto !important;
    }

    /* المصغّرات: صف أفقي يُسحب بالإصبع — لا عمود تحت بعضه */
    body #prod-zoom-host .pz-thumb {
        width: 3rem !important;
        height: 3rem !important;
        max-height: none !important;
        margin: 0 !important;
        flex: 0 0 auto !important;
    }
    body #prod-zoom-host #pz-thumbs {
        flex-wrap: nowrap !important;
        justify-content: flex-start !important;
        -webkit-overflow-scrolling: touch;
    }

    /* زر الإغلاق والأسهم: مقاسهم ثابت مهما قالت قواعد أخرى */
    body #prod-zoom-host .pz-btn {
        width: 2.5rem !important;
        height: 2.5rem !important;
        flex: 0 0 auto !important;
        border-radius: 999px !important;
    }
}

/* =====================================================================
 *  🏷️ الشعار في النص — الجوال فقط
 *  ---------------------------------------------------------------------
 *  شريط الهيدر موزّع بـ justify-between على أربعة عناصر: زر القائمة،
 *  والشعار، وروابط الكمبيوتر، ومجموعة الأيقونات. وفي الجوال تختفي روابط
 *  الكمبيوتر (عرضها صفر) وتبقى الأطراف غير متساوية: الأيقونات ١٢٨ بكسل
 *  في جهة وزر القائمة ٢٨ في الجهة الثانية. فـ justify-between يوزّع
 *  الفراغ بالتساوي بين العناصر لا حول الأوسط — فيزيح الشعار ٥٠ بكسل عن
 *  نص الشاشة ويبان مايل.
 *
 *  الحل: نخرج الشعار من التوزيع ونثبّته في نص الشريط تماماً. والأطراف
 *  تبقى مكانها فما يتداخل شي (الأيقونات تنتهي عند ١٤٤ والشعار يبدأ من
 *  ١٦٠). وعلى الكمبيوتر ما يتغيّر شي — القاعدة للجوال وحده.
 * ===================================================================== */
@media (max-width: 767px) {
    body #nav-row { position: relative; }
    body #nav-row > #nav-logo {
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        margin: 0 !important;
        pointer-events: auto;
    }
}
