/* ====================================================
   MASAR CORE — طبقة الجوال (29/11)
   تُحمَّل بعد styles.css؛ لا تغيّر شيئاً على الشاشات الكبيرة
   ==================================================== */
/* شريط علوي: إخفاء البطاقة الثابتة القديمة متى ظهرت قائمة الحساب الحقيقية (كل الشاشات) */
.topbar-actions:has(#cp-user) > .user-chip { display: none !important; }

@media (max-width: 880px) {
  html, body { overflow-x: hidden; }
  body { -webkit-text-size-adjust: 100%; }

  /* الشريط العلوي: شعار + أيقونات أساسية فقط */
  .topbar { height: calc(var(--topbar-h) + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top); }
  .brand-text, .user-chip, .online-users, .topbar-search kbd { display: none !important; }
  .topbar-actions { gap: 2px; min-width: 0; flex-shrink: 1; }
  .topbar-actions > .icon-btn[data-route="frabo"],
  .topbar-actions > .icon-btn[data-route="calendar"],
  .topbar-actions > .theme-toggle { display: none !important; }
  #cp-user-btn { padding: 0 4px !important; gap: 0 !important; }
  #cp-user-btn > span:not(.avatar), #cp-user-btn > i, #cp-user .cp-hide-sm { display: none !important; }
  #cp-user-menu { position: fixed !important; top: calc(var(--topbar-h) + 6px) !important; left: 8px !important; right: 8px !important; min-width: 0 !important; }

  /* الشريط السفلي يحترم حافة الآيفون */
  .bottom-nav { height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); }
  .content { padding-top: calc(var(--topbar-h) + env(safe-area-inset-top) + 14px) !important; padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + 84px) !important; }

  /* رؤوس الصفحات والأزرار */
  .page-head { flex-direction: column; align-items: stretch !important; }
  .page-head > div:last-child, .page-actions { display: flex; flex-wrap: wrap; gap: 8px; }
  .page-head .btn, .page-actions .btn { flex: 1 1 auto; justify-content: center; }
  .filters-bar { flex-wrap: wrap; }
  .filters-bar > * { min-width: 0; }
  .filters-bar select, .filters-bar input, .filters-bar .select { flex: 1 1 140px; width: auto !important; }

  /* الحقول: 16px يمنع تكبير الشاشة تلقائياً في الآيفون */
  input, select, textarea { font-size: 16px !important; max-width: 100%; }
  .form-grid, .form-grid-2, .form-grid-3 { grid-template-columns: 1fr !important; }
  .field.full, .field { grid-column: auto !important; }

  /* الجداول: تمرير أفقي داخل بطاقتها بدل كسر الصفحة */
  .table-wrap, .card:has(> table), .card:has(> .data-table), .card-body:has(> table), div:has(> table.data-table) { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { max-width: none; }
  .data-table td, .data-table th { white-space: nowrap; }
  .data-table td:first-child, .data-table td:nth-child(2) { white-space: normal; min-width: 140px; }

  /* النوافذ المنبثقة: ملء الشاشة */
  .app-modal { align-items: stretch !important; padding: 0 !important; }
  .app-modal .modal-dialog, .modal-dialog, .modal-dialog.modal-lg, .modal-dialog.lg, .modal-lg {
    width: 100% !important; max-width: 100% !important; min-width: 0 !important;
    height: 100dvh !important; max-height: 100dvh !important; margin: 0 !important; border-radius: 0 !important; border: 0 !important;
  }
  .modal-head { padding-top: calc(12px + env(safe-area-inset-top)) !important; position: sticky; top: 0; z-index: 2; background: var(--bg-2); }
  .modal-body { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px !important; }
  .modal-foot { padding-bottom: calc(12px + env(safe-area-inset-bottom)) !important; flex-wrap: wrap; gap: 8px; }
  .modal-foot .btn { flex: 1 1 auto; justify-content: center; }
  .modal-foot > div, .modal-foot > form { display: flex; flex-wrap: wrap !important; gap: 8px; min-width: 0; max-width: 100%; }
  .modal-foot select { flex: 1 1 160px; }
  body:has(.app-modal.open) #hk-fab, body:has(.app-modal.open) #stk-fab, body:has(.app-modal.open) .bottom-nav, body:has(.lb-ov) #hk-fab, body:has(.lb-ov) #stk-fab { display: none !important; }
  .lb-ov { padding: 0 !important; }
  .lb-ov > div { width: 100vw !important; max-width: 100vw !important; max-height: 100dvh !important; height: 100dvh; border-radius: 0 !important; }

  /* الشبكات المكتوبة داخل الصفحات (style=grid-template-columns) */
  .content [style*="grid-template-columns"], .modal-dialog [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
  .content [style*="repeat(3"], .content [style*="repeat(4"], .content [style*="repeat(5"], .content [style*="repeat(6"],
  .modal-dialog [style*="repeat(3"], .modal-dialog [style*="repeat(4"], .modal-dialog [style*="repeat(5"], .modal-dialog [style*="repeat(6"] { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .content [style*="repeat(7"], .modal-dialog [style*="repeat(7"], .cal-grid { grid-template-columns: repeat(7, minmax(0, 1fr)) !important; }
  .content [style*="min-width:"], .modal-dialog [style*="min-width:"] { min-width: 0 !important; }
  .content [style*="width:"][style*="px"]:not(img):not(.avatar):not(i):not(svg) { max-width: 100%; }
  .grid-2, .grid-3, .grid-3-2, .grid-2-3 { grid-template-columns: 1fr !important; }

  /* التبويبات الكثيرة: تمرير أفقي */
  .tabs, .tk-tabs, .seg, .np-tabs { overflow-x: auto; flex-wrap: nowrap !important; scrollbar-width: none; }
  .tabs::-webkit-scrollbar, .tk-tabs::-webkit-scrollbar { display: none; }
  .tabs > *, .tk-tabs > * { flex: 0 0 auto; }

  /* الأزرار العائمة فوق الشريط السفلي */
  #hk-fab { bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + 14px) !important; left: 14px !important; width: 46px !important; height: 46px !important; font-size: 20px !important; }
  #stk-fab { bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + 14px) !important; left: 68px !important; width: 42px !important; height: 42px !important; }
  #stk-menu { bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + 66px) !important; left: 14px !important; right: 14px !important; }
  .stk { max-width: calc(100vw - 20px) !important; }
  .toast { bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + 70px) !important; left: 12px !important; right: 12px !important; max-width: none !important; justify-content: center; text-align: center; border-radius: 16px !important; transform: translateY(40px) !important; }
  .toast.show { transform: none !important; }

  /* لمس مريح */
  .btn, .icon-btn, .nav-item, .bn-item { min-height: 40px; }
  .nav-item { padding-top: 10px; padding-bottom: 10px; }

  /* نافذة الطباعة والمحرر */
  #mdi-bar, #edbar { overflow-x: auto; flex-wrap: nowrap !important; }
}

@media (max-width: 420px) {
  .content { padding-left: 10px !important; padding-right: 10px !important; }
  .card { border-radius: 14px; }
  .kpi-grid { grid-template-columns: 1fr 1fr !important; }
}

/* بوابة العميل */
@media (max-width: 880px) {
  #cpMain { padding: calc(var(--topbar-h) + env(safe-area-inset-top) + 14px) 12px calc(30px + env(safe-area-inset-bottom)) !important; }
  .cp-hero { padding: 22px 18px !important; }
  .cp-hero h1 { font-size: 22px !important; }
  .cp-hero .stats { gap: 14px !important; }
  .cp-tabs { flex-wrap: nowrap !important; overflow-x: auto; scrollbar-width: none; margin-left: -12px; margin-right: -12px; padding: 0 12px 4px; }
  .cp-tabs::-webkit-scrollbar { display: none; }
  .cp-tabs a { flex: 0 0 auto; }
  .cp-card-grid { grid-template-columns: 1fr 1fr !important; gap: 10px !important; }
  .cp-sec { padding: 14px !important; }
  .cp-row > div[style*="justify-content:space-between"] { flex-direction: column; align-items: flex-start !important; }
}
