/* ============================================================================
   mobile-responsive.css — طبقة تجربة الجوال الاحترافية (Phase 1: الأساس)
   ----------------------------------------------------------------------------
   • تُحمَّل آخر ملف CSS لتفوز في ترتيب التتالي.
   • تعمل فقط ضمن @media — لا تمسّ تصميم الكمبيوتر (> 960px) إطلاقاً.
   • نقطة التحوّل الموحّدة 960px تطابق وضع الدرج ونمط المحادثات الموجودين.
   • النظام يحتفظ بـ "نموذج القشرة" (topbar ثابت + تمرير داخلي) كأنظمة
     لوحات التحكم العالمية — لا نكسره.
   ============================================================================ */

/* طبقة التعتيم خلف الدرج — مخفية على الكمبيوتر دائماً */
#sidebarOverlay { display: none; }

/* ════════════════════════════════════════════════════════════════════
   (A) الجهاز اللوحي + الجوال  ≤ 960px  — وضع الدرج
   ════════════════════════════════════════════════════════════════════ */
@media (max-width: 960px) {

  /* ── (1) القائمة الجانبية: طبقة تعتيم + إغلاق باللمس ──
     الدرج z-index:200 يغطّي الشريط العلوي؛ التعتيم يقفله باللمس.
     يُفعّلها mobile-ux.js عبر إضافة .show */
  #sidebarOverlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    z-index: 150;                 /* تحت الدرج (200)، فوق المحتوى */
    opacity: 0;
    visibility: hidden;
    transition: opacity .3s ease, visibility .3s ease;
  }
  #sidebarOverlay.show { opacity: 1; visibility: visible; }

  /* الدرج: ظل أوضح + احترام المنطقة الآمنة العلوية (notch) */
  .sidebar {
    box-shadow: -8px 0 32px rgba(0, 0, 0, .35);
    padding-top: env(safe-area-inset-top, 0);
  }

  /* ── (2) الشريط العلوي: إخفاء الشعار الموسّط (يتراكب) + تنظيم ── */
  .topbar-brand { display: none !important; }
  .topbar {
    padding-left: max(10px, env(safe-area-inset-left)) !important;
    padding-right: max(10px, env(safe-area-inset-right)) !important;
    gap: 8px !important;
  }
  .topbar-title {
    font-size: 15px;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .menu-btn { padding: 9px !important; }          /* هدف لمس أكبر */
  .menu-btn svg { width: 22px !important; height: 22px !important; }
  .topbar-actions { gap: 6px !important; }
  .tub-info { max-width: 120px; overflow: hidden; }
  .tub-name { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tub-role { font-size: 9px; }

  /* ── (3) أهداف اللمس: حد أدنى مريح للإصبع (≥ 44px) ── */
  .btn, button.btn, .conv-list-icon-btn, .chat-header-icon-btn {
    min-height: 44px;
  }
  .btn, button.btn { padding: 11px 16px; font-size: 14px; }
  input, select, textarea {
    min-height: 44px;
    font-size: 16px !important;   /* 16px يمنع تكبير iOS التلقائي عند التركيز */
  }

  /* ── (4) الجداول: تمرير أفقي ناعم بدل التداخل/الخروج ── */
  .premium-luxury-table,
  .um-audit-table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
  .premium-luxury-table th, .premium-luxury-table td,
  .um-audit-table th, .um-audit-table td { padding: 10px 12px !important; }

  /* ── (5) المساحات والخطوط ── */
  .page { padding: 14px 12px !important; }
  .premium-glass-panel { padding: 14px !important; }
  .page-header { flex-wrap: wrap; gap: 8px; row-gap: 6px; }
  .section-card { padding: 14px !important; }

  /* بانر الترحيب */
  .luxury-welcome-section { padding: 16px !important; }
  .greeting-text h1 { font-size: 19px !important; line-height: 1.35 !important; word-break: break-word; }
  .greeting-text p { font-size: 12px !important; }
  .greeting-emoji { font-size: 24px !important; }

  /* حقول البحث تملأ العرض */
  .search-input { width: 100% !important; box-sizing: border-box; }

  /* شات «عقل السيستم» */
  #page-brain > div { max-width: 100% !important; }

  /* ── (6) فوتر القائمة الجانبية: تصغير قدر الإمكان ──
     على الجوال مساحة الدرج ثمينة؛ نضغط شعار "Created by" والمظهر و Manus AI. */
  .sidebar-footer { padding: 6px 10px env(safe-area-inset-bottom, 8px) !important; }
  .creator-badge { padding: 4px 0 4px !important; gap: 0 !important; }
  .creator-badge img { height: 38px !important; margin: -3px 0 !important; }
  .creator-line { font-size: 8px !important; letter-spacing: 1px !important; }
  .theme-switcher { padding: 0 !important; }
  .theme-label { font-size: 10px !important; margin-bottom: 2px !important; }
  .theme-options { gap: 12px !important; padding: 2px 0 !important; }
  .theme-btn { transform: scale(.8); }
  #themeNameLabel { margin-top: 3px !important; font-size: 9px !important; }
  .version-badge { font-size: 9px !important; padding: 3px 0 !important; }

  /* ── (7) حقل إدخال الدردشة: احترام المنطقة الآمنة السفلية ── */
  .chat-input-area { padding-bottom: max(12px, env(safe-area-inset-bottom)) !important; }

  /* ── (8) عناوين الجداول الفاخرة لا تتزاحم ── */
  .table-header-luxury { flex-wrap: wrap !important; gap: 8px !important; }

  /* ── (9) منع الطفح الأفقي للصفحة (يسبب فراغاً ومحتوى مزاحاً) ── */
  .page { overflow-x: hidden !important; }
  #page-cs, .cs-panel { overflow-x: hidden !important; max-width: 100% !important; }

  /* ── (10) صفحة الإعدادات: تخطيط العمودين يتراصّ ──
     القائمة الفرعية تصير شريط تبويبات أفقي قابل للتمرير، والمحتوى تحتها بكامل العرض. */
  .odoo-settings-body {
    flex-direction: column !important;
    height: auto !important;
    overflow: visible !important;
  }
  .odoo-settings-nav {
    width: 100% !important;
    flex-direction: row !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    padding: 8px !important;
    gap: 6px !important;
    border-left: none !important;
    border-bottom: 1px solid var(--border);
  }
  .odoo-settings-nav .settings-group-title { display: none !important; } /* تكسر الصف الأفقي */
  .setting-nav-item { flex: 0 0 auto !important; white-space: nowrap; }
  .setting-nav-item.active {
    border-right: none !important;
    border-bottom: 3px solid var(--accent) !important;
    border-radius: 10px !important;
  }

  /* ── (11) هَب خدمة العملاء: شريط التبويبات يمرّر أفقياً بدل الطفح ── */
  .cs-tab-bar {
    overflow-x: auto !important;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch;
  }
  .cs-tab-bar > * { flex: 0 0 auto !important; }
}

/* ════════════════════════════════════════════════════════════════════
   (B) الجوال  ≤ 600px
   ════════════════════════════════════════════════════════════════════ */
@media (max-width: 600px) {

  /* الشبكات: عمود واحد */
  .stats-grid,
  .premium-stats-grid { grid-template-columns: 1fr !important; gap: 10px !important; }

  /* المودالات → ورقة سفلية (Bottom Sheet) كأنظمة الجوال الحديثة */
  .modal-overlay,
  .um-modal-overlay {
    align-items: flex-end !important;
    padding: 0 !important;
  }
  .modal,
  .um-modal {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 92vh !important;
    overflow-y: auto !important;
    border-radius: 22px 22px 0 0 !important;
    padding-bottom: env(safe-area-inset-bottom, 0) !important;
    animation: sheetUp .28s cubic-bezier(.34, 1.2, .64, 1) !important;
  }
  @keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

  .page-subtitle { font-size: 12px; }
  .greeting-text h1 { font-size: 17px !important; }

  /* عناصر الصف في القوائم لا تتزاحم */
  .conv-list-title { font-size: 16px !important; }

  /* نماذج بعمودين → عمود واحد على الجوال (نموذج إضافة عميل Odoo وغيره) */
  #manualLeadForm [style*="grid-template-columns"],
  .modal-body [style*="grid-template-columns:1fr 1fr"],
  .modal-body [style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
}

/* ════════════════════════════════════════════════════════════════════
   (C) الهواتف الصغيرة  ≤ 380px
   ════════════════════════════════════════════════════════════════════ */
@media (max-width: 380px) {
  .tub-info { display: none !important; }   /* نبقي الأفاتار فقط */
  .lang-toggle-btn { padding: 6px 8px !important; font-size: 11px !important; }
}
