/* ════════════════════════════════════════════════════════════════
   Dialogs Mobile Optimization — Conservative Version
   ─────────────────────────────────────────────────────────────
   ⚠️ ملاحظات هامة:
   • لا نُعدّل الـ Popup wrapper نهائياً (يكسر daterangepicker)
   • لا نُعدّل overflow على .dxbl-popup أو .rz-dialog
   • نستهدف فقط محتوى الـ dialog الداخلى (.sp-shell, .pay-card, .cpd-shell)

   Dialogs المغطاة:
   ▸ Search Dialogs:    PriceOffer/Orders/Accounts/AccountsFlag/Receipt/ItemQty
   ▸ Payment Popup:     PaymentPopup
   ▸ Confirm Payments:  ConfirmPaymentsDialog
   ════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {

    /* ═══════════════════════════════════════════════════════════
       1) Search Dialog Shell — مساحة كاملة داخل الـ popup
       ═══════════════════════════════════════════════════════════ */
    body .sp-shell {
        height: 100% !important;
        min-height: 100% !important;
        display: flex !important;
        flex-direction: column !important;
        padding: 0 !important;
        margin: 0 !important;
        background: #fff !important;
    }

    /* ─── Header ─── */
    body .sp-head {
        flex-shrink: 0 !important;
        padding: 10px 12px !important;
        gap: 8px !important;
        background: linear-gradient(180deg, var(--fs-tint-2) 0%, #fff 100%) !important;
        border-bottom: 1.5px solid var(--fs-tint-4) !important;
    }

    body .sp-head-top {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        gap: 8px !important;
        flex-wrap: wrap !important;
        margin-bottom: 8px !important;
    }

    /* Search input — touch-friendly */
    body .sp-search-box {
        height: 40px !important;
        border-radius: 10px !important;
        background: #fff !important;
        border: 1.5px solid var(--fs-tint-4) !important;
        padding: 0 10px !important;
        box-shadow: 0 1px 3px rgba(var(--fs-primary-rgb),.08) !important;
    }
    body .sp-search-box:focus-within {
        border-color: var(--fs-primary) !important;
        box-shadow: 0 0 0 3px rgba(var(--fs-primary-rgb),.15) !important;
    }
    body .sp-search-ico {
        width: 16px !important;
        height: 16px !important;
        color: var(--fs-primary) !important;
    }
    body .sp-search {
        flex: 1 !important;
        min-width: 0 !important;
        font-size: 14px !important;
        font-weight: 500 !important;
        height: 38px !important;
        padding: 0 8px !important;
        border: none !important;
        background: transparent !important;
        outline: none !important;
        color: #1f2937 !important;
    }
    body .sp-search::placeholder {
        color: #cbd5e1 !important;
        font-weight: 400 !important;
    }
    body .sp-clear {
        width: 24px !important;
        height: 24px !important;
        border-radius: 50% !important;
        background: #fee2e2 !important;
        color: #dc2626 !important;
        border: none !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        cursor: pointer !important;
        flex-shrink: 0 !important;
    }

    /* Badge — count */
    body .sp-badge {
        font-size: 12px !important;
        font-weight: 700 !important;
        padding: 5px 12px !important;
        border-radius: 999px !important;
        background: var(--fs-tint-2) !important;
        color: var(--fs-primary-ink) !important;
        border: 1px solid var(--fs-tint-4) !important;
        white-space: nowrap !important;
    }
    body .sp-badge b {
        color: var(--fs-primary) !important;
        font-size: 13px !important;
    }
    body .sp-badge-loading {
        background: #dbeafe !important;
        color: #1e40af !important;
        border-color: #bfdbfe !important;
    }
    body .sp-spinner {
        width: 12px !important;
        height: 12px !important;
        border: 2px solid rgba(var(--fs-primary-rgb),.3) !important;
        border-top-color: var(--fs-primary) !important;
        border-radius: 50% !important;
        animation: sp-spin 0.7s linear infinite !important;
        display: inline-block !important;
        margin-inline-end: 4px !important;
    }
    @keyframes sp-spin { to { transform: rotate(360deg); } }

    /* ─── Body — DataGrid container ─── */
    body .sp-body {
        flex: 1 1 auto !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        padding: 0 !important;
        min-height: 0 !important;
    }

    /* RadzenDataGrid — touch-friendly rows */
    body .sp-body .rz-data-grid,
    body .sp-body .rz-grid-table {
        font-size: 13px !important;
    }
    body .sp-body .rz-grid-table thead th {
        padding: 10px 8px !important;
        font-size: 12px !important;
        font-weight: 800 !important;
        background: linear-gradient(180deg, var(--fs-tint-2), #fef3c7) !important;
        color: var(--fs-primary-ink-2) !important;
        border-bottom: 2px solid var(--fs-tint-4) !important;
        white-space: nowrap !important;
    }
    body .sp-body .rz-grid-table tbody td {
        padding: 12px 8px !important;
        font-size: 13px !important;
    }
    body .sp-body .rz-grid-table tbody tr {
        transition: background .12s !important;
    }
    body .sp-body .rz-grid-table tbody tr:active,
    body .sp-body .rz-grid-table tbody tr.rz-selected {
        background: linear-gradient(90deg, rgba(var(--fs-primary-rgb),.12), rgba(var(--fs-primary-rgb),.04)) !important;
    }

    /* Empty state — أوضح */
    body .sp-empty {
        padding: 40px 20px !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 10px !important;
        color: #94a3b8 !important;
        font-size: 14px !important;
        font-weight: 500 !important;
    }
    body .sp-empty svg {
        width: 56px !important;
        height: 56px !important;
        opacity: .5 !important;
    }

    /* ─── Footer — sticky bottom buttons ─── */
    body .sp-foot {
        flex-shrink: 0 !important;
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
        padding: 10px 12px !important;
        background: #fff !important;
        border-top: 1.5px solid var(--fs-tint-4) !important;
        box-shadow: 0 -2px 8px rgba(0,0,0,.06) !important;
    }
    body .sp-btn {
        flex: 1 1 calc(50% - 4px) !important;
        min-height: 44px !important;
        font-size: 13.5px !important;
        font-weight: 700 !important;
        padding: 10px 14px !important;
        border-radius: 10px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 6px !important;
        white-space: nowrap !important;
        border: 1px solid transparent !important;
        cursor: pointer !important;
        transition: transform .12s !important;
    }
    body .sp-btn:active:not(:disabled) {
        transform: scale(.97) !important;
    }
    body .sp-btn:disabled {
        opacity: .5 !important;
        cursor: not-allowed !important;
    }
    body .sp-btn svg {
        width: 14px !important;
        height: 14px !important;
    }
    body .sp-btn-ok {
        background: linear-gradient(135deg, var(--fs-primary), var(--fs-primary-deep)) !important;
        color: #fff !important;
        border-color: transparent !important;
        box-shadow: 0 2px 6px rgba(var(--fs-primary-rgb),.3) !important;
    }
    body .sp-btn-cancel {
        background: #fff !important;
        color: #475569 !important;
        border-color: #cbd5e1 !important;
    }

    /* ═══════════════════════════════════════════════════════════
       2) OrdersSearchDialog Toolbar — Date + Search + Filter
       ⚠️ override flex: 1 على الأزرار حتى لا تكبر فى column container
       ═══════════════════════════════════════════════════════════ */
    body .op-toolbar {
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 8px !important;
        width: 100% !important;
    }
    body .op-date-wrap {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        height: 42px !important;
        min-height: 42px !important;
        max-height: 42px !important;
        border-radius: 10px !important;
        border-width: 1.5px !important;
        flex: 0 0 auto !important;
    }
    body .op-date-input {
        font-size: 14px !important;
        height: 100% !important;
    }

    /* ✦ زر البحث الرئيسى — height ثابت، مش flex grow ✦ */
    body .op-search-btn,
    body .sp-btn.op-search-btn {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        height: 42px !important;
        min-height: 42px !important;
        max-height: 42px !important;
        font-size: 14px !important;
        font-weight: 700 !important;
        padding: 0 14px !important;
        border-radius: 10px !important;
        flex: 0 0 42px !important;       /* ← مش flex: 1 — height ثابت */
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 6px !important;
        line-height: 1 !important;
    }

    /* ✦ Quick filter wrapper — full width touch-friendly ✦ */
    body .op-filter-wrap,
    body .op-filter-wrap.sp-search-box {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        height: 42px !important;
        min-height: 42px !important;
        max-height: 42px !important;
        border-radius: 10px !important;
        border: 1.5px solid var(--fs-tint-4) !important;
        padding: 0 12px !important;
        background: #fff !important;
        display: flex !important;
        align-items: center !important;
        gap: 8px !important;
        flex: 0 0 42px !important;
    }
    body .op-filter-wrap .sp-search,
    body .op-filter-wrap input.sp-search {
        flex: 1 !important;
        min-width: 0 !important;
        height: 38px !important;
        font-size: 14px !important;
        font-weight: 500 !important;
        padding: 0 4px !important;
        border: none !important;
        background: transparent !important;
        outline: none !important;
    }
    body .op-filter-wrap:focus-within {
        border-color: var(--fs-primary) !important;
        box-shadow: 0 0 0 3px rgba(var(--fs-primary-rgb),.15) !important;
    }

    /* ✦ Quick filter العام (مش فى toolbar) — تكست بوكس واضح ✦ */
    body .sp-search-box:not(.op-filter-wrap) {
        height: 42px !important;
        min-height: 42px !important;
        max-height: 42px !important;
        border-radius: 10px !important;
    }
    body .sp-search {
        height: 40px !important;
        font-size: 14px !important;
    }

    /* ✦ Badge العداد بجانب البحث — صغير ✦ */
    body .op-toolbar .sp-badge {
        align-self: flex-start !important;
        font-size: 11.5px !important;
        padding: 4px 10px !important;
    }

    /* ═══════════════════════════════════════════════════════════
       3) PaymentPopup — Card content فقط (مش الـ wrapper)
       ═══════════════════════════════════════════════════════════ */
    body .pay-card {
        width: 100% !important;
        height: 100% !important;
        display: flex !important;
        flex-direction: column !important;
        padding: 0 !important;
        margin: 0 !important;
        overflow: hidden !important;
        background: #fff !important;
    }

    /* Header */
    body .pay-head {
        flex-shrink: 0 !important;
        padding: 12px 14px !important;
        background: linear-gradient(135deg, var(--fs-primary), var(--fs-primary-deep)) !important;
        color: #fff !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        gap: 10px !important;
    }
    body .pay-head-left {
        display: flex !important;
        align-items: center !important;
        gap: 10px !important;
        flex: 1 1 auto !important;
        min-width: 0 !important;
    }
    body .pay-title-icon {
        width: 36px !important;
        height: 36px !important;
        border-radius: 50% !important;
        background: rgba(255,255,255,.25) !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        font-size: 18px !important;
        flex-shrink: 0 !important;
    }
    body .pay-title {
        font-size: 16px !important;
        font-weight: 800 !important;
        color: #fff !important;
        line-height: 1.2 !important;
    }
    body .pay-sub {
        font-size: 11.5px !important;
        color: rgba(255,255,255,.85) !important;
        font-weight: 500 !important;
        margin-top: 2px !important;
    }
    body .pay-close-btn {
        width: 36px !important;
        height: 36px !important;
        border-radius: 50% !important;
        background: rgba(255,255,255,.18) !important;
        color: #fff !important;
        border: none !important;
        font-size: 18px !important;
        flex-shrink: 0 !important;
    }

    /* Amount */
    body .pay-amount {
        flex-shrink: 0 !important;
        margin: 12px !important;
        padding: 14px !important;
        background: linear-gradient(135deg, #fef3c7, #fef9c3) !important;
        border: 1.5px solid #f59e0b !important;
        border-radius: 14px !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 8px !important;
    }
    body .pay-amount-label {
        font-size: 13px !important;
        font-weight: 700 !important;
        color: var(--fs-primary-ink-2) !important;
        display: flex !important;
        align-items: center !important;
        gap: 6px !important;
    }
    body .pay-amount-box .dxbl-spin-edit-input {
        font-size: 22px !important;
        font-weight: 800 !important;
        color: #b45309 !important;
        text-align: center !important;
        background: transparent !important;
        border: none !important;
        height: 40px !important;
    }

    /* Body — scrollable */
    body .pay-body {
        flex: 1 1 auto !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        padding: 0 12px 12px !important;
    }

    /* Method grid — 2 columns على الموبايل */
    body .pay-body .method-grid {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
        margin-bottom: 12px !important;
    }
    body .pay-body .method-btn {
        min-height: 56px !important;
        font-size: 13px !important;
        font-weight: 700 !important;
        padding: 10px !important;
        border-radius: 12px !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 4px !important;
        border: 1.5px solid #e2e8f0 !important;
        background: #fff !important;
        color: #475569 !important;
        cursor: pointer !important;
        transition: all .15s !important;
    }
    body .pay-body .method-btn:active {
        transform: scale(.97) !important;
    }
    body .pay-body .method-btn.method-active {
        background: linear-gradient(135deg, var(--fs-primary), var(--fs-primary-deep)) !important;
        color: #fff !important;
        border-color: transparent !important;
        box-shadow: 0 4px 12px rgba(var(--fs-primary-rgb),.35) !important;
    }
    body .pay-body .method-btn i {
        font-size: 22px !important;
    }

    /* ═══════════════════════════════════════════════════════════
       4) ConfirmPaymentsDialog — Card content
       ═══════════════════════════════════════════════════════════ */
    body .cpd-shell {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
        background: #fff !important;
        border-radius: 16px 16px 0 0 !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
    }

    body .cpd-head {
        padding: 14px 16px !important;
        background: linear-gradient(135deg, var(--fs-primary), var(--fs-primary-deep)) !important;
        color: #fff !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
    }
    body .cpd-title {
        display: flex !important;
        align-items: center !important;
        gap: 10px !important;
        font-size: 15px !important;
        font-weight: 800 !important;
    }
    body .cpd-title-icon {
        width: 32px !important;
        height: 32px !important;
        border-radius: 50% !important;
        background: rgba(255,255,255,.25) !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        font-size: 16px !important;
    }
    body .cpd-close {
        width: 32px !important;
        height: 32px !important;
        border-radius: 50% !important;
        background: rgba(255,255,255,.18) !important;
        color: #fff !important;
        border: none !important;
        font-size: 16px !important;
        cursor: pointer !important;
    }
    body .cpd-sub {
        padding: 10px 16px !important;
        font-size: 13px !important;
        color: #64748b !important;
        background: #f8fafc !important;
        border-bottom: 1px solid #e2e8f0 !important;
    }
    body .cpd-card {
        padding: 12px 16px !important;
        flex: 1 !important;
    }
    body .cpd-row,
    body .cpd-total-row {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        padding: 10px 0 !important;
        border-bottom: 1px solid #f1f5f9 !important;
        gap: 10px !important;
    }
    body .cpd-total-row {
        margin-top: 6px !important;
        padding-top: 14px !important;
        border-top: 2px solid var(--fs-primary) !important;
        border-bottom: none !important;
    }
    body .cpd-name {
        display: flex !important;
        align-items: center !important;
        gap: 8px !important;
        flex: 1 !important;
        min-width: 0 !important;
    }
    body .cpd-badge {
        width: 28px !important;
        height: 28px !important;
        border-radius: 50% !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        background: #f1f5f9 !important;
        color: #64748b !important;
        font-size: 13px !important;
        flex-shrink: 0 !important;
    }
    body .cpd-badge-total {
        background: linear-gradient(135deg, var(--fs-primary), var(--fs-primary-deep)) !important;
        color: #fff !important;
    }
    body .cpd-label {
        font-size: 13px !important;
        font-weight: 600 !important;
        color: #1f2937 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
    body .cpd-val {
        font-size: 14px !important;
        font-weight: 700 !important;
        color: #1f2937 !important;
        white-space: nowrap !important;
    }
    body .cpd-val-total {
        font-size: 17px !important;
        font-weight: 900 !important;
        color: var(--fs-primary) !important;
    }

    body .cpd-foot {
        flex-shrink: 0 !important;
        display: flex !important;
        gap: 8px !important;
        padding: 10px 16px 14px !important;
        background: #fff !important;
        border-top: 1px solid #e2e8f0 !important;
    }
    body .cpd-btn {
        flex: 1 !important;
        min-height: 46px !important;
        font-size: 14px !important;
        font-weight: 700 !important;
        border-radius: 12px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 6px !important;
        border: 1px solid transparent !important;
        cursor: pointer !important;
    }
    body .cpd-btn:active { transform: scale(.97); }
    body .cpd-btn-cancel {
        background: #fff !important;
        color: #475569 !important;
        border-color: #cbd5e1 !important;
    }
    body .cpd-btn-ok {
        background: linear-gradient(135deg, #22c55e, #16a34a) !important;
        color: #fff !important;
        border-color: transparent !important;
        box-shadow: 0 2px 6px rgba(34,197,94,.3) !important;
    }
}

/* ═══════════════════════════════════════════════════════════
   Phones (≤480px) — أصغر شوية
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
    body .sp-head { padding: 8px 10px !important; }
    body .sp-foot { padding: 8px 10px !important; }
    body .sp-btn { font-size: 13px !important; padding: 8px 10px !important; }
    body .sp-search { font-size: 13.5px !important; }
    body .sp-body .rz-grid-table thead th { padding: 8px 6px !important; font-size: 11.5px !important; }
    body .sp-body .rz-grid-table tbody td { padding: 10px 6px !important; font-size: 12.5px !important; }

    body .pay-head { padding: 10px 12px !important; }
    body .pay-title { font-size: 14.5px !important; }
    body .pay-amount { margin: 10px !important; padding: 12px !important; }
    body .pay-amount-box .dxbl-spin-edit-input { font-size: 19px !important; }
    body .pay-body .method-btn { min-height: 50px !important; font-size: 12px !important; }
    body .pay-body .method-btn i { font-size: 19px !important; }

    body .cpd-row, body .cpd-total-row { padding: 8px 0 !important; }
    body .cpd-label { font-size: 12.5px !important; }
    body .cpd-val { font-size: 13px !important; }
    body .cpd-val-total { font-size: 16px !important; }
    body .cpd-btn { font-size: 13px !important; min-height: 42px !important; }
}
