/*
 * App Shell — قافلة الجزيرة (PWA)
 * طبقة تجربة "التطبيق" فوق نظام التصميم الحالي:
 *  - شريط تنقّل سفلي (bottom tab bar) للجوال مع زر مركزي بارز.
 *  - بانر تثبيت التطبيق، ودعم المناطق الآمنة، ووضع standalone.
 * إضافية بالكامل — لا تعدّل سلوك سطح المكتب (السايدبار يبقى كما هو > 1024px).
 */

/* ============================================================
   1) شريط التنقّل السفلي (يظهر فقط على الجوال/اللوحي ≤ 1024px)
   ============================================================ */
.app-tabbar { display: none; }

@media (max-width: 1024px) {
  /* مساحة أسفل المحتوى حتى لا يختفي خلف الشريط */
  body.account-layout .account-content {
    padding-bottom: calc(78px + env(safe-area-inset-bottom, 0px));
  }

  /* إخفاء زر القائمة العائم القديم — استُبدل بتبويب "المزيد" */
  body.account-layout .sidebar-toggle { display: none !important; }

  .app-tabbar {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 900;
    align-items: stretch;
    justify-content: space-around;
    background: rgba(255, 255, 255, 0.92);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    backdrop-filter: saturate(180%) blur(14px);
    border-top: 1px solid var(--border-color, #e5e7eb);
    box-shadow: 0 -6px 24px -12px rgba(0, 0, 0, 0.18);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    height: calc(64px + env(safe-area-inset-bottom, 0px));
  }

  .app-tab {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 8px 4px 6px;
    color: var(--text-muted, #9ca3af);
    text-decoration: none;
    font-size: 0.68rem;
    font-weight: 600;
    font-family: inherit;
    background: none;
    border: none;
    cursor: pointer;
    position: relative;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.2s ease;
  }

  .app-tab svg { width: 23px; height: 23px; stroke-width: 2; transition: transform 0.2s ease; }
  .app-tab span { line-height: 1; }

  .app-tab:active svg { transform: scale(0.88); }

  .app-tab.active { color: var(--primary-dark, #e69500); }

  /* مؤشر التبويب النشط */
  .app-tab.active::before {
    content: '';
    position: absolute;
    top: 0;
    width: 26px; height: 3px;
    border-radius: 0 0 4px 4px;
    background: linear-gradient(90deg, var(--primary, #fea500), var(--primary-dark, #e69500));
  }

  /* الزر المركزي البارز — تسجيل ضمان جديد */
  .app-tab-fab {
    flex: 0 0 auto;
    align-self: center;
    transform: translateY(-16px);
    margin: 0 2px;
  }
  .app-tab-fab .fab-btn {
    width: 58px; height: 58px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--primary, #fea500), var(--primary-dark, #e69500));
    color: #1a1a1a;
    box-shadow: 0 8px 20px rgba(254, 165, 0, 0.45), 0 0 0 5px #fff;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
  }
  .app-tab-fab .fab-btn svg { width: 28px; height: 28px; stroke-width: 2.4; }
  .app-tab-fab:active .fab-btn { transform: scale(0.92); }
  .app-tab-fab .fab-label {
    display: block;
    text-align: center;
    font-size: 0.66rem;
    font-weight: 700;
    color: var(--primary-dark, #e69500);
    margin-top: 2px;
  }
}

/* على الشاشات الصغيرة جداً نخفي نصوص التبويبات الجانبية لإتاحة مساحة أكبر */
@media (max-width: 360px) {
  .app-tab { font-size: 0.62rem; }
}

/* ============================================================
   2) بانر تثبيت التطبيق (Android/Chrome)
   ============================================================ */
.pwa-install-banner {
  position: fixed;
  left: 12px; right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 1200;
  display: none;
  align-items: center;
  gap: 12px;
  background: #1a1a1a;
  color: #fff;
  border-radius: 16px;
  padding: 12px 14px;
  box-shadow: 0 16px 32px -8px rgba(0, 0, 0, 0.45);
  animation: pwaSlideUp 0.35s ease-out;
}
.pwa-install-banner.show { display: flex; }
@media (max-width: 1024px) {
  /* رفع البانر فوق شريط التنقّل */
  .pwa-install-banner { bottom: calc(76px + env(safe-area-inset-bottom, 0px)); }
}
.pwa-install-banner img { width: 42px; height: 42px; border-radius: 10px; background: #fff; padding: 3px; flex: 0 0 auto; }
.pwa-install-banner .pwa-text { flex: 1 1 auto; min-width: 0; }
.pwa-install-banner .pwa-text strong { display: block; font-size: 0.92rem; font-weight: 700; }
.pwa-install-banner .pwa-text small { display: block; font-size: 0.76rem; color: rgba(255,255,255,0.7); margin-top: 1px; }
.pwa-install-banner .pwa-actions { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.pwa-install-banner .pwa-install-btn {
  background: linear-gradient(135deg, var(--primary, #fea500), var(--primary-dark, #e69500));
  color: #1a1a1a; border: none; cursor: pointer;
  font-family: inherit; font-weight: 700; font-size: 0.85rem;
  padding: 9px 14px; border-radius: 10px; white-space: nowrap;
}
.pwa-install-banner .pwa-dismiss {
  background: rgba(255,255,255,0.12); color: #fff; border: none; cursor: pointer;
  width: 34px; height: 34px; border-radius: 9px; display: flex; align-items: center; justify-content: center;
}

@keyframes pwaSlideUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }

/* ============================================================
   3) وضع التطبيق المثبّت (standalone) + المناطق الآمنة
   ============================================================ */
@media (display-mode: standalone) {
  /* منع تحديد النصوص أثناء الاستخدام كتطبيق للإحساس الأصلي */
  .app-tabbar, .sidebar-nav { -webkit-user-select: none; user-select: none; }
  /* احترام المنطقة العلوية الآمنة للهيدر الثابت */
  .header { padding-top: env(safe-area-inset-top, 0px); height: calc(var(--header-height) + env(safe-area-inset-top, 0px)); }
  body.account-layout .account-wrapper,
  body.account-layout .sidebar { top: calc(var(--header-height) + env(safe-area-inset-top, 0px)); }
}

/* دعم iOS للتثبيت اليدوي (Safari لا يدعم beforeinstallprompt) */
.ios-install-hint { display: none; }

/* ============================================================
   4) وضع التطبيق native (Capacitor) — المناطق الآمنة والإحساس الأصلي
   ============================================================ */
html.capacitor-native body.app-native,
html.capacitor-native .app-tabbar,
html.capacitor-native .sidebar-nav {
  -webkit-user-select: none;
  user-select: none;
}
/* منع بانر التثبيت داخل التطبيق (يُحذف برمجياً أيضاً) */
html.capacitor-native .pwa-install-banner { display: none !important; }
/* احترام المنطقة العلوية الآمنة للهيدر الثابت داخل التطبيق */
html.capacitor-native .header {
  padding-top: env(safe-area-inset-top, 0px);
  height: calc(var(--header-height) + env(safe-area-inset-top, 0px));
}
html.capacitor-native body.account-layout .account-wrapper,
html.capacitor-native body.account-layout .sidebar {
  top: calc(var(--header-height) + env(safe-area-inset-top, 0px));
}
/* منع سحب/تكبير غير مرغوب للإحساس الأصلي */
html.capacitor-native { -webkit-text-size-adjust: 100%; }
