/*
 * ═══════════════════════════════════════════════════════════════
 * POS Mobile Ultimate Fix - الإصلاح الشامل لنقطة البيع على الموبايل
 * ═══════════════════════════════════════════════════════════════
 * يحل جميع مشاكل العرض على الموبايل:
 * ✅ تنسيق الجدول (أعمدة المنتجات، الكمية، السعر)
 * ✅ تحسين شبكة المنتجات (Products Grid)
 * ✅ تصميم متجاوب كامل
 * ═══════════════════════════════════════════════════════════════
 */

/* ═══════════════════════════════════════════════════════════════
 * القسم الأول: تحسين شبكة المنتجات (Products Grid)
 * ═══════════════════════════════════════════════════════════════ */

/* تنسيق عام لشبكة المنتجات */
#product_list_body {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 10px !important;
    padding: 10px !important;
    justify-content: flex-start !important;
}

/* حجم كل منتج */
.product_list {
    flex: 0 0 auto !important;
    width: calc(20% - 10px) !important;
    min-width: 150px !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* صندوق المنتج */
.product_box {
    background: #ffffff !important;
    border-radius: 12px !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
    padding: 12px !important;
    transition: all 0.3s ease !important;
    cursor: pointer !important;
    height: 180px !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-between !important;
    align-items: center !important;
    text-align: center !important;
    border: 1px solid #e9ecef !important;
}

.product_box:hover {
    transform: translateY(-5px) !important;
    box-shadow: 0 8px 16px rgba(52, 152, 219, 0.3) !important;
    border-color: #3498db !important;
}

.product_box:active {
    transform: scale(0.98) !important;
}

/* حاوية الصورة */
.product_box .image-container {
    width: 100% !important;
    height: 100px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    margin-bottom: 8px !important;
    background: #f8f9fa !important;
    border-radius: 8px !important;
    overflow: hidden !important;
}

.product_box .image-container img {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    object-fit: cover !important;
    display: block !important;
}

/* قسم النص */
.product_box .text_div {
    width: 100% !important;
    padding: 5px !important;
}

.product_box .text_div .text {
    font-size: 13px !important;
    font-weight: 600 !important;
    color: #2c3e50 !important;
    line-height: 1.3 !important;
    margin: 0 !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    display: -webkit-box !important;
    -webkit-line-clamp: 2 !important;
    -webkit-box-orient: vertical !important;
    word-break: break-word !important;
    min-height: 32px !important;
}

.product_box .text_div small {
    font-size: 10px !important;
    color: #95a5a6 !important;
    margin-top: 3px !important;
    display: block !important;
}

/* ═══════════════════════════════════════════════════════════════
 * القسم الثاني: تنسيق الجدول للموبايل
 * ═══════════════════════════════════════════════════════════════ */

@media (max-width: 767px) {

    /* جعل الجدول قابل للتمرير أفقياً والعمودي */
    .pos_product_div {
        overflow-x: auto !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        width: 100% !important;
        max-height: 400px !important;
        display: block !important;
        position: relative !important;
        border: 1px solid #dee2e6 !important;
        border-radius: 8px !important;
    }

    /* الجدول */
    table#pos_table {
        width: 100% !important;
        min-width: 625px !important;
        table-layout: fixed !important;
        font-size: 10px !important;
        border-collapse: separate !important;
        border-spacing: 0 !important;
        display: table !important;
    }

    /* رأس الجدول */
    table#pos_table thead {
        position: sticky !important;
        top: 0 !important;
        z-index: 10 !important;
        background: #8D8AA1 !important;
        display: table-header-group !important;
    }

    table#pos_table thead tr {
        display: table-row !important;
        width: 100% !important;
    }

    table#pos_table thead th {
        font-size: 10px !important;
        padding: 10px 4px !important;
        white-space: normal !important;
        color: white !important;
        font-weight: 700 !important;
        text-align: center !important;
        background: #8D8AA1 !important;
        border: 1px solid #7a7791 !important;
        vertical-align: middle !important;
        line-height: 1.2 !important;
        display: table-cell !important;
        word-wrap: break-word !important;
    }

    /* خلايا الجدول */
    table#pos_table tbody td {
        font-size: 11px !important;
        padding: 6px 4px !important;
        vertical-align: middle !important;
        border-bottom: 1px solid #e9ecef !important;
    }

    /* ═══════════════════════════════════════════════════════════
     * أعمدة الجدول - عرض محدد لكل عمود
     * ═══════════════════════════════════════════════════════════ */

    /* عمود المنتج - أكبر عرض */
    table#pos_table thead th:nth-child(1),
    table#pos_table tbody td:nth-child(1) {
        width: 180px !important;
        min-width: 180px !important;
        max-width: 180px !important;
        text-align: right !important;
        padding-right: 6px !important;
        padding-left: 3px !important;
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
    }

    /* عمود الكمية - عرض واضح */
    table#pos_table thead th:nth-child(2),
    table#pos_table tbody td:nth-child(2) {
        width: 130px !important;
        min-width: 130px !important;
        max-width: 130px !important;
        text-align: center !important;
        white-space: nowrap !important;
        padding: 4px 2px !important;
    }

    /* عمود السعر - واضح ومركز */
    table#pos_table thead th:nth-child(3),
    table#pos_table tbody td:nth-child(3) {
        width: 90px !important;
        min-width: 90px !important;
        max-width: 90px !important;
        text-align: center !important;
        padding: 4px 2px !important;
        white-space: nowrap !important;
    }

    /* عمود السعر شامل الضريبة (إذا كان موجوداً) */
    table#pos_table thead th:nth-child(4),
    table#pos_table tbody td:nth-child(4) {
        width: 85px !important;
        min-width: 85px !important;
        max-width: 85px !important;
        text-align: center !important;
        padding: 4px 2px !important;
        white-space: nowrap !important;
    }

    /* عمود المجموع */
    table#pos_table thead th:nth-child(5),
    table#pos_table tbody td:nth-child(5) {
        width: 90px !important;
        min-width: 90px !important;
        max-width: 90px !important;
        text-align: center !important;
        padding: 4px 2px !important;
        white-space: nowrap !important;
    }

    /* عمود الحذف */
    table#pos_table thead th:last-child,
    table#pos_table tbody td:last-child {
        width: 50px !important;
        min-width: 50px !important;
        max-width: 50px !important;
        text-align: center !important;
        padding: 4px 2px !important;
    }

    /* ═══════════════════════════════════════════════════════════
     * مربع الكمية المدمج
     * ═══════════════════════════════════════════════════════════ */

    .pos-qty-container {
        display: inline-flex !important;
        align-items: center !important;
        background: white !important;
        border: 2px solid #dfe4ea !important;
        border-radius: 6px !important;
        overflow: hidden !important;
        max-width: 95px !important;
        margin: 0 auto !important;
    }

    .pos-qty-btn {
        background: #f8f9fa !important;
        border: none !important;
        color: #495057 !important;
        padding: 4px 6px !important;
        cursor: pointer !important;
        font-size: 11px !important;
        min-width: 24px !important;
        width: 24px !important;
        height: 26px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    .pos-qty-minus {
        border-right: 2px solid #dfe4ea !important;
    }

    .pos-qty-minus i {
        color: #dc3545 !important;
        font-size: 9px !important;
    }

    .pos-qty-plus {
        border-left: 2px solid #dfe4ea !important;
    }

    .pos-qty-plus i {
        color: #28a745 !important;
        font-size: 9px !important;
    }

    .pos-qty-input {
        flex: 1 !important;
        border: none !important;
        text-align: center !important;
        font-size: 12px !important;
        font-weight: 600 !important;
        padding: 2px !important;
        background: transparent !important;
        min-width: 30px !important;
        max-width: 45px !important;
        height: 26px !important;
    }

    /* الوحدة بجانب الكمية */
    table#pos_table select.sub_unit {
        font-size: 9px !important;
        padding: 2px 4px !important;
        height: 22px !important;
        max-width: 60px !important;
        margin-left: 4px !important;
        border: 1px solid #dee2e6 !important;
        border-radius: 4px !important;
        display: inline-block !important;
        vertical-align: middle !important;
    }

    /* إخفاء <br> بين الكمية والوحدة */
    table#pos_table td:nth-child(2) br {
        display: none !important;
    }

    /* ═══════════════════════════════════════════════════════════
     * حقول الإدخال (السعر والمجموع)
     * ═══════════════════════════════════════════════════════════ */

    table#pos_table input.pos_unit_price_inc_tax,
    table#pos_table input.pos_line_total {
        font-size: 11px !important;
        padding: 4px !important;
        height: 26px !important;
        text-align: center !important;
        font-weight: 700 !important;
        border: 1px solid #dee2e6 !important;
        border-radius: 4px !important;
        width: 100% !important;
        max-width: 75px !important;
    }

    /* عرض الأسعار */
    table#pos_table .display_currency,
    table#pos_table .pos_line_total_text {
        font-size: 11px !important;
        font-weight: 700 !important;
        color: #2c3e50 !important;
    }

    /* ═══════════════════════════════════════════════════════════
     * زر الحذف
     * ═══════════════════════════════════════════════════════════ */

    table#pos_table .pos_remove_row {
        padding: 4px 6px !important;
        font-size: 11px !important;
        border-radius: 4px !important;
        background: #dc3545 !important;
        color: white !important;
        border: none !important;
    }

    /* ═══════════════════════════════════════════════════════════
     * مؤشر التمرير
     * ═══════════════════════════════════════════════════════════ */

    /* مؤشر التمرير الأفقي */
    .pos_product_div::after {
        content: '↔ مرر لليسار واليمين لرؤية المزيد' !important;
        display: block !important;
        text-align: center !important;
        padding: 6px !important;
        background: #e3f2fd !important;
        color: #1565c0 !important;
        font-size: 10px !important;
        border: 1px solid #90caf9 !important;
        border-radius: 4px !important;
        margin: 5px 0 !important;
        font-weight: 700 !important;
        position: sticky !important;
        bottom: 0 !important;
        z-index: 5 !important;
    }

    /* إخفاء المؤشر بعد التمرير */
    .pos_product_div.scrolled::after {
        display: none !important;
    }

    /* تنسيق Scrollbar للموبايل */
    .pos_product_div::-webkit-scrollbar {
        width: 6px !important;
        height: 6px !important;
    }

    .pos_product_div::-webkit-scrollbar-track {
        background: #f1f1f1 !important;
        border-radius: 3px !important;
    }

    .pos_product_div::-webkit-scrollbar-thumb {
        background: #3498db !important;
        border-radius: 3px !important;
    }

    .pos_product_div::-webkit-scrollbar-thumb:hover {
        background: #2980b9 !important;
    }

    /* للمتصفحات التي تدعم scrollbar-width */
    .pos_product_div {
        scrollbar-width: thin !important;
        scrollbar-color: #3498db #f1f1f1 !important;
    }

    /* ═══════════════════════════════════════════════════════════
     * اسم المنتج
     * ═══════════════════════════════════════════════════════════ */

    table#pos_table td:first-child {
        line-height: 1.3 !important;
        word-break: break-word !important;
        font-size: 11px !important;
    }

    /* ═══════════════════════════════════════════════════════════
     * ارتفاع الصفوف
     * ═══════════════════════════════════════════════════════════ */

    table#pos_table tbody tr {
        min-height: 45px !important;
    }

    /* ═══════════════════════════════════════════════════════════
     * التأكد من ظهور كل الأعمدة
     * ═══════════════════════════════════════════════════════════ */

    table#pos_table th,
    table#pos_table td {
        display: table-cell !important;
        opacity: 1 !important;
        visibility: visible !important;
        box-sizing: border-box !important;
    }

    /* منع التداخل بين الخلايا */
    table#pos_table {
        border-spacing: 0 !important;
    }

    table#pos_table tbody tr {
        display: table-row !important;
    }

    /* تأكيد عدم وجود overflow */
    table#pos_table td * {
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* ═══════════════════════════════════════════════════════════
     * تنسيق الأرقام
     * ═══════════════════════════════════════════════════════════ */

    table#pos_table input[type="text"],
    table#pos_table input[type="number"] {
        direction: ltr !important;
        text-align: center !important;
    }

    /* إخفاء أسهم input number */
    table#pos_table input[type=number]::-webkit-inner-spin-button,
    table#pos_table input[type=number]::-webkit-outer-spin-button {
        -webkit-appearance: none !important;
        margin: 0 !important;
    }

    table#pos_table input[type=number] {
        -moz-appearance: textfield !important;
    }

    /* ═══════════════════════════════════════════════════════════
     * تحسينات إضافية للموبايل
     * ═══════════════════════════════════════════════════════════ */

    /* تصغير مربع البحث */
    .pos-search-container {
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .pos-search-input {
        font-size: 12px !important;
        padding: 8px !important;
        height: 36px !important;
    }

    /* تقليل المسافات */
    .box-body {
        padding: 8px !important;
    }

    .form-group {
        margin-bottom: 8px !important;
    }

    section.content {
        padding: 8px 5px !important;
    }

    /* ═══════════════════════════════════════════════════════════
     * تحسين ظهور الجدول الكبير
     * ═══════════════════════════════════════════════════════════ */

    /* إضافة ظل للإشارة إلى إمكانية التمرير */
    .pos_product_div {
        box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.05) !important;
    }

    /* مساحة للتمرير */
    .pos_product_div {
        margin-bottom: 10px !important;
    }

    /* تأكيد visibility للجدول */
    table#pos_table tbody {
        display: table-row-group !important;
    }

    /* منع الجدول من الاختفاء */
    .pos_product_div,
    .pos_product_div * {
        visibility: visible !important;
        opacity: 1 !important;
    }

    /* ═══════════════════════════════════════════════════════════
     * تنسيق جدول المجاميع أسفل جدول المنتجات
     * ═══════════════════════════════════════════════════════════ */

    /* جدول المجاميع */
    .table-condensed {
        font-size: 10px !important;
        width: 100% !important;
        margin-bottom: 10px !important;
    }

    .table-condensed tr {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 5px !important;
        margin-bottom: 5px !important;
    }

    .table-condensed td {
        flex: 1 1 calc(50% - 5px) !important;
        min-width: 140px !important;
        padding: 6px 8px !important;
        font-size: 10px !important;
        background: #f8f9fa !important;
        border: 1px solid #dee2e6 !important;
        border-radius: 6px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        white-space: nowrap !important;
    }

    .table-condensed td b {
        font-size: 10px !important;
        margin-left: 5px !important;
    }

    .table-condensed td span {
        font-size: 10px !important;
        font-weight: 700 !important;
    }

    .table-condensed td i.fa-edit {
        font-size: 12px !important;
        color: #3498db !important;
        margin: 0 3px !important;
        cursor: pointer !important;
    }

    /* الصف الأول: العدد والمجموع */
    .table-condensed tr:first-child td {
        background: #e3f2fd !important;
        border-color: #90caf9 !important;
        font-weight: 700 !important;
    }

    /* ═══════════════════════════════════════════════════════════
     * تنسيق أزرار الإجراءات (المسودة، الاقتباس، إلخ)
     * ═══════════════════════════════════════════════════════════ */

    .pos-form-actions {
        width: 100% !important;
        padding: 0 !important;
    }

    .pos-form-actions .col-md-12 {
        padding: 0 5px !important;
    }

    /* المجموع الإجمالي */
    .pos-form-actions .col-md-12.text-right {
        background: linear-gradient(135deg, #2ecc71 0%, #27ae60 100%) !important;
        color: white !important;
        padding: 12px 10px !important;
        border-radius: 8px !important;
        margin-bottom: 10px !important;
        font-size: 16px !important;
        font-weight: 700 !important;
        text-align: center !important;
        box-shadow: 0 4px 12px rgba(46, 204, 113, 0.3) !important;
    }

    .pos-form-actions #total_payable {
        font-size: 20px !important;
        font-weight: 900 !important;
        color: white !important;
        margin-right: 8px !important;
    }

    /* جميع الأزرار */
    .pos-form-actions button.btn {
        width: calc(50% - 5px) !important;
        min-height: 50px !important;
        font-size: 12px !important;
        font-weight: 600 !important;
        margin: 2.5px !important;
        padding: 10px 8px !important;
        border-radius: 8px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 6px !important;
        border: none !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;
        transition: all 0.3s ease !important;
        line-height: 1.3 !important;
        text-align: center !important;
    }

    .pos-form-actions button.btn i {
        font-size: 14px !important;
    }

    /* زر المسودة (Draft) */
    .btn-draft,
    button#pos-draft {
        background: linear-gradient(135deg, #95a5a6 0%, #7f8c8d 100%) !important;
        color: white !important;
    }

    .btn-draft:hover {
        background: linear-gradient(135deg, #7f8c8d 0%, #707b7c 100%) !important;
        transform: translateY(-2px) !important;
    }

    /* زر الاقتباس (Quotation) */
    .btn-quotation,
    button#pos-quotation {
        background: linear-gradient(135deg, #9b59b6 0%, #8e44ad 100%) !important;
        color: white !important;
    }

    .btn-quotation:hover {
        background: linear-gradient(135deg, #8e44ad 0%, #7d3c98 100%) !important;
        transform: translateY(-2px) !important;
    }

    /* زر التعليق (Suspend) */
    .btn-suspend {
        background: linear-gradient(135deg, #f39c12 0%, #e67e22 100%) !important;
        color: white !important;
    }

    .btn-suspend:hover {
        background: linear-gradient(135deg, #e67e22 0%, #d35400 100%) !important;
        transform: translateY(-2px) !important;
    }

    /* زر البيع بالآجل (Credit Sale) */
    .btn-payment-credit {
        background: linear-gradient(135deg, #3498db 0%, #2980b9 100%) !important;
        color: white !important;
    }

    .btn-payment-credit:hover {
        background: linear-gradient(135deg, #2980b9 0%, #21618c 100%) !important;
        transform: translateY(-2px) !important;
    }

    /* زر الدفع بالبطاقة (Card) */
    .btn-payment-card {
        background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%) !important;
        color: white !important;
    }

    .btn-payment-card:hover {
        background: linear-gradient(135deg, #c0392b 0%, #a93226 100%) !important;
        transform: translateY(-2px) !important;
    }

    /* زر الدفع المتعدد (Multi-Pay) */
    .btn-multi-pay,
    button#pos-finalize {
        background: linear-gradient(135deg, #16a085 0%, #138d75 100%) !important;
        color: white !important;
    }

    .btn-multi-pay:hover {
        background: linear-gradient(135deg, #138d75 0%, #117a65 100%) !important;
        transform: translateY(-2px) !important;
    }

    /* زر الدفع النقدي (Cash) */
    .btn-payment-cash {
        background: linear-gradient(135deg, #27ae60 0%, #229954 100%) !important;
        color: white !important;
    }

    .btn-payment-cash:hover {
        background: linear-gradient(135deg, #229954 0%, #1e8449 100%) !important;
        transform: translateY(-2px) !important;
    }

    /* زر واتساب */
    button#whatsapp_invoice {
        background: linear-gradient(135deg, #25D366 0%, #128C7E 100%) !important;
        color: white !important;
    }

    button#whatsapp_invoice:hover {
        background: linear-gradient(135deg, #128C7E 0%, #075E54 100%) !important;
        transform: translateY(-2px) !important;
    }

    /* للأزرار ذات العرض الكامل */
    .pos-form-actions button.btn.col-xs-6 {
        width: calc(50% - 5px) !important;
    }

    /* تحسين عرض الأيقونات */
    .pos-form-actions button.btn .fa,
    .pos-form-actions button.btn .fas {
        margin-left: 4px !important;
    }
}

/* ═══════════════════════════════════════════════════════════════
 * شاشات الموبايل الصغيرة جداً (< 480px)
 * ═══════════════════════════════════════════════════════════════ */

@media (max-width: 480px) {

    table#pos_table {
        min-width: 600px !important;
        font-size: 10px !important;
    }

    table#pos_table th:first-child,
    table#pos_table td:first-child {
        min-width: 150px !important;
    }

    .pos-qty-container {
        max-width: 85px !important;
    }

    .pos-qty-input {
        font-size: 11px !important;
        min-width: 25px !important;
    }
}

/* ═══════════════════════════════════════════════════════════════
 * التنسيق المتجاوب لشبكة المنتجات
 * ═══════════════════════════════════════════════════════════════ */

/* شاشات كبيرة جداً */
@media (min-width: 1400px) {
    .product_list {
        width: calc(16.666% - 10px) !important;
    }
}

/* شاشات كبيرة */
@media (min-width: 1200px) and (max-width: 1399px) {
    .product_list {
        width: calc(20% - 10px) !important;
    }
}

/* شاشات متوسطة */
@media (min-width: 992px) and (max-width: 1199px) {
    .product_list {
        width: calc(25% - 10px) !important;
    }
}

/* تابلت */
@media (min-width: 768px) and (max-width: 991px) {
    .product_list {
        width: calc(33.333% - 10px) !important;
    }

    .product_box {
        height: 170px !important;
    }
}

/* موبايل */
@media (max-width: 767px) {
    .product_list {
        width: calc(50% - 10px) !important;
    }

    .product_box {
        height: 160px !important;
        padding: 10px !important;
    }

    .product_box .image-container {
        height: 85px !important;
    }

    .product_box .text_div .text {
        font-size: 12px !important;
        min-height: 30px !important;
    }

    #product_list_body {
        padding: 8px !important;
        gap: 8px !important;
    }
}

/* موبايل صغير جداً */
@media (max-width: 480px) {
    .product_list {
        width: calc(50% - 6px) !important;
    }

    .product_box {
        height: 150px !important;
        padding: 8px !important;
    }

    .product_box .image-container {
        height: 75px !important;
    }

    .product_box .text_div .text {
        font-size: 11px !important;
        -webkit-line-clamp: 2 !important;
    }

    #product_list_body {
        padding: 6px !important;
        gap: 6px !important;
    }
}

/* ═══════════════════════════════════════════════════════════════
 * الوضع الأفقي (Landscape)
 * ═══════════════════════════════════════════════════════════════ */

@media (max-width: 767px) and (orientation: landscape) {
    table#pos_table {
        min-width: 100% !important;
    }

    .pos_product_div::after {
        display: none !important;
    }

    .product_list {
        width: calc(33.333% - 8px) !important;
    }
}

/* ═══════════════════════════════════════════════════════════════
 * تحسينات عامة
 * ═══════════════════════════════════════════════════════════════ */

/* منع اختيار النصوص في صندوق المنتج */
.product_box * {
    user-select: none !important;
    -webkit-user-select: none !important;
}

/* السماح بالنقر على المنتج فقط */
.product_box {
    pointer-events: all !important;
}

.product_box * {
    pointer-events: none !important;
}

/* تحسين الأداء */
table#pos_table {
    will-change: scroll-position !important;
}

.product_box {
    will-change: transform !important;
}

/* ═══════════════════════════════════════════════════════════════
 * نهاية الملف
 * ═══════════════════════════════════════════════════════════════
 * تاريخ الإنشاء: 2025-11-11
 * الإصدار: 1.0.0
 * الحالة: ✅ جاهز للاستخدام
 * ═══════════════════════════════════════════════════════════════ */
