/* ═══ Giao diện điện thoại kiểu iPhone (≤ 760px) ═══
   Thanh tab dưới đáy, đơn hàng dạng thẻ, hộp thoại trượt từ dưới lên, vùng chạm ≥ 44px. */
.tabbar { display: none; }

@media (max-width: 760px) {
  /* Bỏ thanh icon bên trái → nhường toàn bộ chiều ngang */
  .app-shell { grid-template-columns: minmax(0, 1fr) !important; }
  .rail { display: none !important; }
  .sidebar { inset: 0 auto 0 0 !important; width: min(320px, 86vw) !important; border-radius: 0 20px 20px 0; }
  .mobile-menu-scrim:not([hidden]) { inset-inline-start: 0 !important; background: rgba(0, 0, 0, .28) !important; -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
  main { padding-bottom: calc(76px + env(safe-area-inset-bottom)) !important; }
  .topbar { position: sticky; top: 0; z-index: 30; padding: 0 16px !important; background: rgba(255, 255, 255, .86) !important; -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px); }
  .topbar h1 { font-size: 22px !important; font-weight: 700 !important; }

  /* Thanh tab dưới đáy */
  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 75; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); border-top: 1px solid rgba(0, 0, 0, .08);
    background: rgba(250, 250, 252, .9); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  }
  .tabbar .tab { position: relative; display: grid; justify-items: center; gap: 2px; min-height: 48px; padding: 4px 0 0; border: 0; background: none; color: #8e8e93; font-size: 10.5px; font-weight: 500; cursor: pointer; -webkit-tap-highlight-color: transparent; }
  .tabbar .tab[hidden] { display: none; }
  .tabbar .tab svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
  .tabbar .tab[data-tab="menu"] svg { fill: currentColor; stroke: none; }
  .tabbar .tab.on { color: #0071e3; }
  .tabbar .tab.on svg { stroke-width: 2; }
  .tabbar .tab:active { transform: scale(.94); }
  .tab-badge { position: absolute; top: 0; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: #ff3b30; color: #fff; font-size: 11px; font-weight: 600; line-height: 18px; text-align: center; }
  .tab-badge[hidden] { display: none; }
  .to-top { bottom: calc(86px + env(safe-area-inset-bottom)) !important; }
  .floating { bottom: calc(150px + env(safe-area-inset-bottom)) !important; top: auto !important; }
  .toast { bottom: calc(90px + env(safe-area-inset-bottom)) !important; left: 16px !important; right: 16px !important; text-align: center; border-radius: 14px !important; }

  /* ── Danh sách đơn: mỗi đơn là 1 thẻ ── */
  #ordersView .table-wrap { max-height: none !important; overflow: visible !important; border-radius: 0 !important; background: transparent !important; box-shadow: none !important; }
  #ordersView .orders-table, #ordersView .orders-table tbody { display: block !important; width: 100% !important; min-width: 0 !important; }
  #ordersView .table-wrap .orders-table, #ordersView .table-wrap .orders-table > tbody { max-width: 100% !important; width: 100% !important; min-width: 0 !important; }
  #ordersView .orders-table thead { display: none !important; }
  #ordersView .orders-table tr.ux-row {
    display: grid !important; grid-template-columns: 34px minmax(0, 1fr) auto; grid-template-areas: "chk order status" "chk product product" "chk cust cust" "chk money money";
    gap: 8px 6px; margin: 0 0 10px; padding: 12px 12px 12px 6px; border-radius: 16px; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 14px rgba(0, 0, 0, .04); position: relative; overflow: hidden;
  }
  #ordersView .orders-table tr.ux-row > td { display: block !important; width: auto !important; min-width: 0 !important; padding: 0 !important; border: 0 !important; background: transparent !important; box-shadow: none !important; }
  #ordersView .orders-table tr.ux-row > td:nth-child(1) { display: none !important; }
  #ordersView .orders-table tr.ux-row > td:nth-child(2) { grid-area: chk; align-self: start; padding-top: 2px !important; }
  #ordersView .orders-table tr.ux-row > td:nth-child(3) { grid-area: order; }
  #ordersView .orders-table tr.ux-row > td:nth-child(4) { grid-area: product; }
  #ordersView .orders-table tr.ux-row > td:nth-child(5) { grid-area: cust; }
  #ordersView .orders-table tr.ux-row > td:nth-child(6) { grid-area: status; justify-self: end; }
  #ordersView .orders-table tr.ux-row > td.col-money { grid-area: money; padding: 8px 10px !important; border-radius: 12px; background: #f5f5f7 !important; }
  #ordersView .orders-table tr.ux-row > td:nth-child(n+8) { display: none !important; }
  #ordersView .orders-table tr.ux-row.sla-row-overdue { box-shadow: inset 4px 0 0 #ff3b30, 0 1px 2px rgba(0, 0, 0, .05) !important; }
  #ordersView .orders-table tr.ux-row.sla-row-today { box-shadow: inset 4px 0 0 #ff9500, 0 1px 2px rgba(0, 0, 0, .05) !important; }
  #ordersView .orders-table tr.ux-row.order-row-selected { box-shadow: inset 0 0 0 2px #0071e3 !important; background: #f5f9ff !important; }
  #ordersView .orders-table tr.ux-row > td:nth-child(3):hover { background: transparent !important; }
  #ordersView .orders-table tr.ux-row .ux-money { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  #ordersView .orders-table tr.ux-row .ux-money > div { display: grid !important; gap: 0; text-align: left; }
  #ordersView .orders-table tr.ux-row .ux-money span { font-size: 11px; color: #86868b; }
  #ordersView .orders-table tr.ux-row .ux-money b { font-size: 14px; }
  #ordersView .orders-table tr.ux-row .ux-product, #ordersView .orders-table tr.ux-row .ux-product * { white-space: normal !important; }
  #ordersView .orders-table tr.ux-row .ux-order-id { font-size: 17px !important; }
  #ordersView .orders-table tr.ux-row > td:nth-child(3) .ux-order::after { margin-top: 8px; padding-top: 6px; padding-bottom: 6px; font-size: 12.5px; }
  #ordersView .orders-table tr.ux-row .order-check { width: 30px; height: 30px; }
  #ordersView .orders-table tr.ux-row .order-check span { width: 22px !important; height: 22px !important; }
  /* Chi tiết đơn: toàn chiều ngang, 1 cột */
  #ordersView .orders-table tr.order-detail-row { display: block !important; margin: -6px 0 12px; }
  #ordersView .orders-table tr.order-detail-row > td { display: block !important; width: 100% !important; }
  #ordersView .order-detail-panel { margin: 0 !important; border-radius: 16px !important; }
  #ordersView .order-detail-panel > table, #ordersView .order-detail-panel > table > tbody { display: block !important; min-width: 0 !important; width: 100% !important; }
  #ordersView .order-detail-panel > table > thead { display: none !important; }
  #ordersView .order-detail-panel > table > tbody > tr { display: block !important; margin-bottom: 10px; }
  #ordersView .order-detail-panel > table > tbody > tr > td { display: block !important; width: auto !important; border-right: 0 !important; border-top: 1px solid #f0f0f3 !important; }
  #ordersView .order-detail-panel > table > tbody > tr > td:first-child { border-top: 0 !important; }
  #ordersView .order-detail-panel .vendor-bar { flex-wrap: wrap; }
  #ordersView .order-detail-panel .vendor-bar > span { flex-basis: 100%; }
  #ordersView .order-detail-panel .png-row input, #ordersView .order-detail-panel .png-row button { height: 40px !important; font-size: 15px !important; } /* iOS không phóng to khi gõ (≥ 16px tốt nhất) */
  #ordersView .order-detail-panel input, #ordersView .order-detail-panel textarea, #ordersView .order-detail-panel select { font-size: 16px !important; }
  #ordersView .order-detail-panel .detail-customization > .cz-line { grid-template-columns: minmax(80px, 40%) minmax(0, 1fr); }
  #ordersView .order-detail-panel .cz-line .cz-v { font-size: 15px; }
  #ordersView .order-detail-panel label, #ordersView .order-detail-panel .png-row { width: 100% !important; max-width: 100% !important; min-width: 0 !important; box-sizing: border-box; }
  #ordersView .order-detail-panel .png-row input { flex: 1 1 auto; min-width: 0 !important; width: auto !important; }
  #ordersView .order-detail-panel { overflow-x: hidden; position: static !important; width: 100% !important; max-width: 100% !important; box-sizing: border-box; }
  #ordersView .orders-table tr.order-detail-row, #ordersView .orders-table tr.order-detail-row > td { height: auto !important; max-height: none !important; overflow: visible !important; padding: 0 !important; width: 100% !important; min-width: 0 !important; max-width: 100% !important; box-sizing: border-box; }
  /* Thanh chọn đơn: dính phía trên thanh tab */
  #ordersView .order-selection-bar:not([hidden]) { position: fixed; left: 10px; right: 10px; bottom: calc(72px + env(safe-area-inset-bottom)); z-index: 70; display: flex !important; flex-wrap: wrap; gap: 8px; padding: 10px 12px !important; border: 0 !important; border-radius: 16px !important; background: rgba(29, 29, 31, .92) !important; color: #fff !important; box-shadow: 0 10px 30px rgba(0, 0, 0, .25) !important; -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); }
  #ordersView .order-selection-bar strong { color: #fff !important; flex-basis: 100%; font-size: 13px; }
  #ordersView .order-selection-bar #orderSelectionHint { display: none; }
  #ordersView .order-selection-bar button { height: 36px !important; flex: 1 1 auto; }

  /* Ô nhập: cỡ chữ 16px để iPhone không tự phóng to */
  input, select, textarea { font-size: 16px; }
  #orderSearch { font-size: 16px !important; height: 44px !important; }

  /* ── Hộp thoại: trượt từ dưới lên (bottom sheet) ── */
  dialog[open].dialog, dialog[open].user-manager, dialog[open].vf-dialog, dialog[open].es-dialog, dialog[open].ul-dialog {
    width: 100vw !important; max-width: 100vw !important; max-height: 92dvh !important; margin: auto 0 0 !important;
    border-radius: 22px 22px 0 0 !important; padding-bottom: env(safe-area-inset-bottom) !important; animation: sheetUp .28s cubic-bezier(.2, .8, .2, 1);
  }
  dialog[open].dialog::before, dialog[open].user-manager::before, dialog[open].vf-dialog::before { content: ""; display: block; width: 38px; height: 5px; margin: 8px auto 0; border-radius: 3px; background: #d1d1d6; }
  @keyframes sheetUp { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
  dialog .form-grid { grid-template-columns: 1fr !important; }
  dialog menu { position: sticky; bottom: 0; background: inherit; }

  /* Báo cáo: bảng cuộn ngang mượt, thẻ số 2 cột */
  .report-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 8px !important; }
  .report-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 14px; }
  .report-actionbar { flex-wrap: wrap; gap: 8px !important; }
  .report-tools { flex-wrap: wrap; }
  .report-tools input, .report-tools select { flex: 1 1 140px; }
}

@media (max-width: 760px) and (prefers-reduced-motion: reduce) {
  dialog[open].dialog, dialog[open].user-manager, dialog[open].vf-dialog { animation: none; }
}

/* ═══ Điện thoại (≤ 760px) — rà soát 18/11: gọn kiểu iOS ═══ */
@media (max-width: 760px) {
  /* Ô số liệu: bỏ ô Sales (đã có "Total … items"), 4 ô vận hành thành lưới 2×2 nhỏ */
  #ordersView .order-range-summary { grid-template-columns: 1fr 1fr !important; gap: 8px !important; margin-bottom: 10px !important; }
  #ordersView .order-range-summary > article { display: none !important; }
  #ordersView .order-range-summary .ops-card { min-height: 0 !important; padding: 9px 12px !important; border-radius: 12px !important; gap: 0 8px !important; }
  #ordersView .order-range-summary .ops-card span { font-size: 12.5px !important; line-height: 1.25; }
  #ordersView .order-range-summary .ops-card strong { font-size: 19px !important; }
  #ordersView .order-range-summary .ops-card small { display: none !important; }
  /* Thanh Hạn D+1 + Sắp xếp: 1 hàng cuộn ngang, không xuống 3 dòng */
  #ordersView .sla-bar { flex-wrap: nowrap !important; overflow-x: auto; gap: 6px !important; margin: 8px -16px 6px !important; padding: 0 16px 2px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  #ordersView .sla-bar::-webkit-scrollbar { display: none; }
  #ordersView .sla-bar > * { flex: none; }
  #ordersView .sla-chip { height: 32px !important; padding: 0 10px !important; font-size: 12.5px !important; }
  #ordersView .sla-sort { margin-left: 4px !important; }
  #ordersView .sla-sort button { height: 30px !important; }

  /* Thẻ đơn: cột trạng thái gọn (không đè nhãn hạn), nhãn hạn được xuống dòng */
  #ordersView .orders-table tr.ux-row > td:nth-child(6) { max-width: 116px; text-align: right; }
  #ordersView .orders-table tr.ux-row .ux-status { display: grid; justify-items: end; gap: 3px; }
  #ordersView .orders-table tr.ux-row .ux-status .order-status { white-space: nowrap; }
  #ordersView .orders-table tr.ux-row .ux-status .ux-vendor { max-width: 116px; }
  #ordersView .orders-table tr.ux-row .sla-badge { max-width: 100%; white-space: normal !important; line-height: 1.3 !important; }
  /* Tên sản phẩm tối đa 2 dòng, ảnh 56px */
  #ordersView .orders-table tr.ux-row .ux-product { gap: 10px !important; align-items: flex-start; }
  #ordersView .orders-table tr.ux-row .ux-product img, #ordersView .orders-table tr.ux-row .ux-noimg { width: 56px !important; height: 56px !important; flex: none; border-radius: 10px !important; }
  #ordersView .orders-table tr.ux-row .ux-title { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 14px !important; line-height: 1.35 !important; }
  /* Ô tiền: rộng hết thẻ, 3 cột thẳng hàng */
  #ordersView .orders-table tr.ux-row > td.col-money { justify-self: stretch !important; width: auto !important; }
  #ordersView .orders-table tr.ux-row .ux-money { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; column-gap: 10px !important; }
  #ordersView .orders-table tr.ux-row .ux-money > div { display: grid !important; grid-template-columns: none !important; gap: 1px !important; min-width: 0; }
  #ordersView .orders-table tr.ux-row .ux-money span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #ordersView .orders-table tr.ux-row .ux-money b { white-space: nowrap; }
}
@media (max-width: 760px) {
  /* Chi tiết đơn: SKU 1 dòng (nhãn 70px thay vì 120px), số lượng thẳng hàng, thông báo xuống dòng */
  #ordersView .order-detail-panel .detail-sku > div { grid-template-columns: 70px minmax(0, 1fr) !important; gap: 8px !important; align-items: center; }
  #ordersView .order-detail-panel .detail-sku > div > strong { display: flex !important; flex-wrap: nowrap; align-items: center; gap: 6px; min-width: 0; white-space: nowrap; font-size: 12.5px !important; }
  #ordersView .order-detail-panel .detail-sku .copy-sku { flex: none; width: 26px !important; height: 26px !important; min-height: 0 !important; }
  #ordersView .order-detail-panel .od-qty .detail-qty { align-items: center !important; }
  #ordersView .order-detail-panel .od-qty .dq-label { margin-left: auto; line-height: 28px; }
  #ordersView .order-detail-panel .vendor-bar { flex-wrap: wrap !important; }
  #ordersView .order-detail-panel .vendor-bar > span { white-space: normal !important; flex-basis: 100%; line-height: 1.45; }
  #ordersView .order-detail-panel .od-vendor .vm-list > div, #ordersView .order-detail-panel .od-vendor .fulfill-name { grid-template-columns: 70px minmax(0, 1fr) auto !important; }
}

/* Menu điện thoại: hàng chọn nhóm kiểu iOS + tiêu đề không bị cắt + bỏ mũi tên thu gọn */
.quick-groups { display: none; }
@media (max-width: 760px) {
  .sidebar > .quick-menu { padding-top: env(safe-area-inset-top) !important; }
  .quick-mobile-header { position: sticky; top: 0; z-index: 2; padding: 14px 16px 10px !important; background: inherit; }
  .quick-mobile-header small { font-size: 11px !important; letter-spacing: .06em; color: #86868b; }
  .quick-mobile-header strong { font-size: 20px !important; font-weight: 700 !important; }
  .quick-groups { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; margin: 0 12px 8px; padding: 4px; border-radius: 14px; background: #ececf0; }
  .qg-btn { display: grid; justify-items: center; gap: 2px; min-height: 0 !important; padding: 7px 2px 5px !important; border: 0 !important; border-radius: 10px !important; background: transparent !important; box-shadow: none !important; color: #6e6e73 !important; font: 500 10.5px/1.1 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif !important; cursor: pointer; -webkit-tap-highlight-color: transparent; }
  .qg-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
  .qg-btn span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .qg-btn.on { background: #fff !important; color: #0071e3 !important; box-shadow: 0 1px 3px rgba(0, 0, 0, .12) !important; }
  .collapse { display: none !important; }
}
