/**
 * POS (كاشير) — تخطيط الموبايل
 * يُفعَّل مع body.alfaris-pos-mode من pos-mobile-fix.js
 */
@media (max-width: 1023px) {
  body.alfaris-pos-mode {
    overflow: hidden;
    touch-action: manipulation;
  }

  body.alfaris-pos-mode #root {
    min-height: 100dvh;
    height: 100dvh;
    overflow: hidden;
  }

  /* احتياطي قبل تحميل JS — إصلاح صف أفقي يضغط المنتجات */
  body.alfaris-pos-mode [class*="100dvh"][class*="w-screen"] > div[class*="flex-1"][class*="gap-"] {
    flex-direction: column !important;
    overflow: hidden !important;
  }

  body.alfaris-pos-mode [class*="100dvh"] > div[class*="flex-1"] > div[class*="min-w-0"] {
    flex: 1 1 auto !important;
    width: 100% !important;
    min-height: 38dvh !important;
    max-height: 52dvh !important;
    overflow: hidden !important;
  }

  body.alfaris-pos-mode [class*="100dvh"] > div[class*="flex-1"] > div[class*="lg:w-[400px]"],
  body.alfaris-pos-mode [class*="100dvh"] > div[class*="flex-1"] > div[class*="w-[350px]"] {
    width: 100% !important;
    max-width: 100% !important;
    flex: 0 0 auto !important;
    max-height: 42dvh !important;
    min-height: 200px !important;
    overflow-y: auto !important;
    border-top: 1px solid rgba(255, 255, 255, 0.12) !important;
  }

  /* إخفاء شريط التنقل السفلي أثناء الكاشير */
  body.alfaris-pos-mode nav.fixed.bottom-0,
  body.alfaris-pos-mode div.fixed.bottom-0.lg\:hidden {
    display: none !important;
  }

  body.alfaris-pos-mode button.daftrix-ai-fab,
  body.alfaris-pos-mode button.fixed.bottom-5.left-5 {
    display: none !important;
  }

  /* الحاوية الرئيسية للكاشير */
  body.alfaris-pos-mode .alfaris-pos-root {
    height: 100dvh !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    width: 100vw !important;
    overflow: hidden !important;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  /* الهيدر — أزرار أصغر وقابلة للالتفاف */
  body.alfaris-pos-mode .alfaris-pos-root > header {
    flex-shrink: 0;
    padding: 8px 10px !important;
    flex-wrap: wrap !important;
    gap: 6px !important;
    min-height: auto !important;
  }

  body.alfaris-pos-mode .alfaris-pos-root > header button {
    min-height: 40px;
    min-width: 40px;
    padding: 8px 10px !important;
    font-size: 12px !important;
  }

  /* منطقة المنتجات + السلة — عمودي */
  body.alfaris-pos-mode .alfaris-pos-main {
    flex: 1 1 auto !important;
    flex-direction: column !important;
    gap: 8px !important;
    padding: 8px !important;
    min-height: 0 !important;
    overflow: hidden !important;
  }

  body.alfaris-pos-mode .alfaris-pos-products {
    flex: 1 1 auto !important;
    order: 1 !important;
    width: 100% !important;
    max-width: 100% !important;
    min-height: 0 !important;
    min-height: 36dvh !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
  }

  body.alfaris-pos-mode .alfaris-pos-products > div {
    min-height: 0 !important;
    flex: 1 1 auto !important;
    overflow: hidden !important;
  }

  /* شبكة المنتجات — تمرير */
  body.alfaris-pos-mode .alfaris-pos-products .flex-1.overflow-y-auto,
  body.alfaris-pos-mode .alfaris-pos-products [class*="overflow-y-auto"] {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  body.alfaris-pos-mode .alfaris-pos-products .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
    padding-bottom: 12px !important;
  }

  /* بطاقة منتج — لمس أسهل */
  body.alfaris-pos-mode .alfaris-pos-products button.group {
    min-height: 120px;
    touch-action: manipulation;
  }

  /* شريط البحث والباركود — عمودي على الموبايل */
  body.alfaris-pos-mode .alfaris-pos-products .flex.gap-3:first-of-type,
  body.alfaris-pos-mode .alfaris-pos-search-row {
    flex-direction: column !important;
    gap: 8px !important;
  }

  body.alfaris-pos-mode .alfaris-pos-products .relative.w-48,
  body.alfaris-pos-mode .alfaris-pos-products [class*="w-48"] {
    width: 100% !important;
    max-width: 100% !important;
  }

  body.alfaris-pos-mode .alfaris-pos-products input {
    font-size: 16px !important;
    min-height: 44px !important;
  }

  /* السلة — أسفل الشاشة */
  body.alfaris-pos-mode .alfaris-pos-cart {
    flex: 0 0 auto !important;
    order: 2 !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    height: auto !important;
    max-height: 42dvh !important;
    min-height: 220px !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    border-top: 1px solid rgba(255, 255, 255, 0.12) !important;
    border-right: none !important;
    padding-bottom: env(safe-area-inset-bottom, 8px) !important;
  }

  body.alfaris-pos-mode .alfaris-pos-cart button {
    min-height: 44px;
    touch-action: manipulation;
  }

  /* زر الدفع ثابت أسفل السلة */
  body.alfaris-pos-mode .alfaris-pos-cart [class*="دفع"],
  body.alfaris-pos-mode .alfaris-pos-cart button[class*="bg-emerald"] {
    position: sticky;
    bottom: 0;
    z-index: 5;
  }

  /* تبويب سريع منتجات / سلة (يُضاف من JS) */
  body.alfaris-pos-mode .alfaris-pos-tabs {
    display: flex;
    flex-shrink: 0;
    gap: 6px;
    padding: 0 8px 6px;
    order: 0;
  }

  body.alfaris-pos-mode .alfaris-pos-tabs button {
    flex: 1;
    min-height: 44px;
    border-radius: 10px;
    font-weight: 700;
    font-size: 14px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(15, 23, 42, 0.9);
    color: #94a3b8;
  }

  body.alfaris-pos-mode .alfaris-pos-tabs button.active {
    background: #059669;
    color: #fff;
    border-color: #10b981;
  }

  body.alfaris-pos-mode.alfaris-pos-tab-products .alfaris-pos-cart {
    display: none !important;
  }

  body.alfaris-pos-mode.alfaris-pos-tab-cart .alfaris-pos-products {
    display: none !important;
  }

  body.alfaris-pos-mode.alfaris-pos-tab-cart .alfaris-pos-cart {
    flex: 1 1 auto !important;
    max-height: none !important;
    min-height: 0 !important;
  }
}

@media (max-width: 1023px) and (orientation: landscape) {
  body.alfaris-pos-mode .alfaris-pos-main {
    flex-direction: row !important;
  }

  body.alfaris-pos-mode .alfaris-pos-products {
    min-height: 0 !important;
    flex: 1 1 55% !important;
  }

  body.alfaris-pos-mode .alfaris-pos-cart {
    flex: 1 1 45% !important;
    max-height: none !important;
    border-top: none !important;
    border-right: 1px solid rgba(255, 255, 255, 0.12) !important;
  }

  body.alfaris-pos-mode .alfaris-pos-tabs {
    display: none !important;
  }
}