/* ===== 手机端专用查询页（方案 B）≤860px ===== */
@media (min-width: 861px) {
  .mobile-query-shell,
  .mq-bottom-bar {
    display: none !important;
  }
}

@media (max-width: 860px) {
  body.mobile-query-mode #stocktake-banner,
  body.mobile-query-mode .desk-only-toolbar,
  body.mobile-query-mode .desk-only-sheet,
  body.mobile-query-mode #dash-sheet-footer,
  body.mobile-query-mode .mobile-more-btn,
  body.mobile-query-mode .mobile-custom-btn,
  body.mobile-query-mode #sheet-actions,
  body.mobile-query-mode #stab-theme {
    display: none !important;
  }

  body.mobile-query-mode #main-view.sheet-page,
  body.mobile-query-mode #main-view .sheet-card.fill {
    padding: 0 !important;
    margin: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
  }

  .mobile-query-shell {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: max(10px, env(safe-area-inset-top)) 12px 0;
    background:
      radial-gradient(ellipse 90% 55% at 50% -8%, rgba(59, 130, 246, 0.14), transparent 58%),
      linear-gradient(180deg, #0a0d12 0%, #0f141c 100%);
  }

  .mq-sticky-top {
    position: sticky;
    top: 0;
    z-index: 6;
    flex-shrink: 0;
    margin-bottom: 10px;
    padding-bottom: 4px;
    background:
      linear-gradient(180deg, #0a0d12 0%, #0a0d12 72%, rgba(10, 13, 18, 0.94) 100%);
  }

  .mq-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
  }

  .mq-header-brand {
    display: flex;
    align-items: center;
    min-width: 0;
    flex: 1 1 auto;
  }

  .mq-logo-line {
    display: block;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
    font-size: 17px;
    font-weight: 800;
    letter-spacing: 0.02em;
  }

  .mq-logo-name {
    background: linear-gradient(135deg, #93c5fd 0%, #c4b5fd 55%, #f0abfc 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
  }

  .mq-logo-brand {
    font-size: 15px;
    font-weight: 800;
    letter-spacing: 0.08em;
    color: #94a3b8;
  }

  .mq-header-user {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
  }

  .mq-user-chip {
    font-size: 12px;
    color: #cbd5e1;
    max-width: 9em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mq-logout-btn {
    min-height: 34px !important;
    padding: 6px 10px !important;
    font-size: 12px !important;
    border-radius: 999px !important;
    border: 1px solid rgba(148, 163, 184, 0.35) !important;
    background: rgba(30, 41, 59, 0.65) !important;
    color: #e2e8f0 !important;
  }

  .mq-search-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 0;
  }

  .mq-search-field {
    display: flex;
    flex-direction: column;
    gap: 5px;
  }

  .mq-search-field label {
    margin: 0;
    font-size: 12px;
    font-weight: 700;
    color: #94a3b8;
    letter-spacing: 0.04em;
  }

  .mq-search-field input {
    width: 100%;
    min-height: 46px !important;
    padding: 10px 12px !important;
    border-radius: 12px !important;
    border: 1px solid rgba(96, 165, 250, 0.28) !important;
    background: rgba(15, 23, 42, 0.82) !important;
    color: #f1f5f9 !important;
    font-size: 16px !important;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  }

  .mq-search-field input::placeholder {
    color: #64748b;
  }

  .mq-search-field input:focus {
    border-color: rgba(59, 130, 246, 0.75) !important;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2) !important;
    outline: none;
  }

  .mq-result-count {
    margin: 0 0 10px;
    font-size: 13px;
    font-weight: 600;
    color: #94a3b8;
  }

  .mq-results {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(78px + env(safe-area-inset-bottom, 0px));
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .mq-idle {
    margin-top: 8px;
    text-align: center;
    color: #94a3b8;
    font-size: 15px;
    line-height: 1.65;
    padding: 36px 20px;
    border: 1px dashed rgba(148, 163, 184, 0.22);
    border-radius: 16px;
    background: rgba(15, 23, 42, 0.38);
  }

  .mq-idle-hint {
    margin: 8px 0 0;
    font-size: 13px;
    color: #64748b;
  }

  .mq-result-hint {
    margin: 0 0 4px;
    font-size: 13px;
    font-weight: 600;
    color: #94a3b8;
  }

  .mq-empty {
    margin-top: 8px;
    text-align: center;
    color: #94a3b8;
    font-size: 14px;
    line-height: 1.6;
    padding: 24px 16px;
    border: 1px dashed rgba(148, 163, 184, 0.28);
    border-radius: 14px;
    background: rgba(15, 23, 42, 0.45);
  }

  .mq-empty strong {
    display: block;
    font-size: 16px;
    font-weight: 800;
    color: #e2e8f0;
    margin-bottom: 8px;
  }

  .mq-empty-warn {
    border-color: rgba(251, 191, 36, 0.45);
    background: rgba(251, 191, 36, 0.08);
  }

  .mq-empty-warn strong { color: #fbbf24; }

  .mq-empty-info {
    border-color: rgba(96, 165, 250, 0.4);
    background: rgba(59, 130, 246, 0.08);
  }

  .mq-empty-info strong { color: #93c5fd; }

  .mq-loc-status-card {
    margin-bottom: 10px;
    border-style: dashed;
  }

  .mq-loc-status-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
  }

  .mq-loc-status-code {
    font-size: 22px;
    font-weight: 800;
    color: #93c5fd;
    letter-spacing: 0.04em;
  }

  .mq-loc-status-pill {
    flex: 0 0 auto;
    font-size: 12px;
    font-weight: 800;
    padding: 4px 10px;
    border-radius: 999px;
    white-space: nowrap;
  }

  .mq-loc-status-pill.is-empty {
    color: #93c5fd;
    border: 1px solid rgba(96, 165, 250, 0.45);
    background: rgba(59, 130, 246, 0.12);
  }

  .mq-loc-status-pill.is-disabled {
    color: #fbbf24;
    border: 1px solid rgba(251, 191, 36, 0.45);
    background: rgba(251, 191, 36, 0.12);
  }

  .mq-loc-status {
    margin: 0;
    font-size: 14px;
    line-height: 1.55;
    color: #94a3b8;
  }

  .mq-card {
    border-radius: 16px;
    border: 1px solid rgba(96, 165, 250, 0.22);
    background: rgba(17, 23, 34, 0.78);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    padding: 14px;
    -webkit-tap-highlight-color: transparent;
  }

  .mq-card-head {
    margin-bottom: 8px;
  }

  .mq-card-head-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    min-width: 0;
  }

  .mq-card-head-row .mq-model {
    flex: 1 1 auto;
    min-width: 0;
  }

  .mq-card-lock {
    flex: 0 0 auto;
    margin-top: 2px;
  }

  .mq-count-badge {
    flex: 0 0 auto;
    font-size: 11px;
    font-weight: 800;
    line-height: 1.2;
    padding: 4px 8px;
    border-radius: 999px;
    white-space: nowrap;
    margin-top: 2px;
  }

  .mq-count-badge.partial {
    color: #fbbf24;
    border: 1px solid rgba(251, 191, 36, 0.45);
    background: rgba(251, 191, 36, 0.12);
  }

  .mq-count-badge.all {
    color: #4ade80;
    border: 1px solid rgba(34, 197, 94, 0.45);
    background: rgba(34, 197, 94, 0.12);
  }

  .mq-card.mq-card-locked {
    border-color: rgba(34, 197, 94, 0.38) !important;
    box-shadow:
      0 10px 28px rgba(0, 0, 0, 0.28),
      inset 0 0 0 1px rgba(34, 197, 94, 0.16);
  }

  .mq-model {
    margin: 0;
    font-size: 22px;
    font-weight: 800;
    color: #f8fafc;
    line-height: 1.25;
    word-break: break-all;
  }

  .mq-model.mq-model-edit {
    border-radius: 10px;
    padding: 2px 4px;
    margin: -2px -4px;
    border: 1px dashed transparent;
  }

  .mq-model.mq-model-edit:active {
    border-color: rgba(96, 165, 250, 0.45);
    background: rgba(59, 130, 246, 0.08);
  }

  .mq-model-hint {
    margin: 4px 0 0;
    font-size: 11px;
    color: #64748b;
    font-weight: 600;
  }

  .mq-meta {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 14px;
    font-size: 15px;
    color: #e2e8f0;
    line-height: 1.5;
  }

  .mq-meta-row {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px 16px;
  }

  .mq-meta-label {
    color: #94a3b8;
    font-size: 13px;
    font-weight: 600;
    min-width: 2.5em;
  }

  .mq-meta-val {
    min-width: 0;
    word-break: break-word;
  }

  .mq-meta-val.mq-tap-edit {
    border-radius: 8px;
    padding: 2px 6px;
    margin: -2px -6px;
    border: 1px dashed transparent;
  }

  .mq-meta-val.mq-tap-edit:active {
    border-color: rgba(96, 165, 250, 0.45);
    background: rgba(59, 130, 246, 0.08);
  }

  .mq-loc-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .mq-loc-block {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .mq-out-row {
    display: none;
    align-items: stretch;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px dashed rgba(249, 115, 22, 0.45);
    background: rgba(249, 115, 22, 0.08);
    flex-wrap: nowrap;
    width: 100%;
    box-sizing: border-box;
  }

  .mq-card.mq-out-mode .mq-out-row {
    display: flex;
  }

  .mq-card.mq-out-mode .mq-card-out {
    box-shadow: 0 0 0 2px rgba(249, 115, 22, 0.55) !important;
  }

  .mq-out-label {
    flex: 0 0 auto;
    font-size: 13px;
    font-weight: 800;
    color: #fb923c;
    white-space: nowrap;
    align-self: center;
  }

  .mq-out-qty,
  .mq-out-box {
    flex: 1 1 0;
    min-width: 0;
    min-height: 44px !important;
    padding: 8px 6px !important;
    border-radius: 8px !important;
    border: 1px solid rgba(249, 115, 22, 0.35) !important;
    background: rgba(15, 23, 42, 0.75) !important;
    color: #f8fafc !important;
    font-size: 16px !important;
    text-align: center;
  }

  /* 多库位时取消仅显示在最后一行，避免重复 */
  .mq-out-row .mq-out-cancel {
    display: none;
  }

  .mq-loc-block:last-child .mq-out-row .mq-out-cancel {
    display: inline-flex;
  }

  .mq-out-cancel,
  .mq-out-submit {
    flex: 0 0 auto;
    min-width: 48px;
    min-height: 44px !important;
    padding: 0 10px !important;
    font-size: 14px !important;
    font-weight: 800 !important;
    white-space: nowrap;
    border-radius: 8px !important;
    align-items: center;
    justify-content: center;
  }

  .mq-out-submit {
    border: none !important;
    background: linear-gradient(135deg, #f97316 0%, #ea580c 100%) !important;
    color: #fff !important;
  }

  .mq-loc-tile {
    border-radius: 12px;
    border: 1px solid rgba(96, 165, 250, 0.28);
    background: rgba(30, 41, 59, 0.85);
    padding: 10px 12px;
    min-height: 48px;
    display: block;
    width: 100%;
    text-align: left;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
  }

  /* 三列单行：库位号 | 数量 | 盘点开关 */
  .mq-loc-row {
    display: grid;
    grid-template-columns: minmax(3.2em, 28%) minmax(0, 1fr) auto;
    align-items: center;
    column-gap: 8px;
    width: 100%;
    min-width: 0;
  }

  .mq-loc-tile.mq-editable {
    cursor: default;
  }

  .mq-loc-tile.mq-editable:active {
    border-color: rgba(96, 165, 250, 0.45);
    background: rgba(37, 50, 72, 0.95);
  }

  .mq-loc-code {
    display: block;
    font-size: 17px;
    font-weight: 800;
    color: #93c5fd;
    letter-spacing: 0.04em;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mq-loc-code[data-mq-edit-lcode] {
    cursor: pointer;
  }

  .mq-loc-lock {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    flex: 0 0 auto;
    min-width: 0;
  }

  .mq-loc-lock-spacer {
    display: inline-block;
    width: 34px;
    height: 20px;
  }

  .mq-loc-code .inline-edit {
    width: 4.5em;
    max-width: 100%;
    min-height: 38px !important;
    font-size: 16px !important;
    text-align: center;
  }

  .mq-loc-qty {
    display: block;
    font-size: 14px;
    font-weight: 700;
    color: #f1f5f9;
    text-align: right;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mq-loc-qty[data-mq-edit-stock] {
    cursor: pointer;
  }

  .mq-loc-qty .dash-qb-edit {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    width: 100%;
    min-width: 0;
  }

  .mq-loc-qty .dash-qb-sep {
    display: none;
  }

  .mq-loc-qty .dash-qb-field {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 0 1 auto;
    min-width: 0;
  }

  .mq-loc-qty .dash-qb-field .inline-edit {
    width: 4.8em;
    max-width: 42vw;
    min-height: 38px !important;
    font-size: 16px !important;
    text-align: center;
    padding: 6px 4px !important;
  }

  .mq-loc-qty .dash-qb-u {
    font-size: 12px;
    color: #94a3b8;
    font-weight: 600;
    white-space: nowrap;
  }

  .mq-loc-hint {
    margin: 6px 0 0;
    font-size: 11px;
    color: #64748b;
    font-weight: 600;
    text-align: center;
  }

  .mq-loc-empty {
    text-align: center;
    font-size: 13px;
    color: #94a3b8;
    padding: 8px;
    border-radius: 10px;
    border: 1px dashed rgba(100, 116, 139, 0.45);
  }

  .mq-card-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin-top: 12px;
  }

  .mq-card-actions:has(.mq-card-btn:only-child) {
    grid-template-columns: 1fr;
  }

  .mq-card-btn {
    min-height: 44px !important;
    padding: 8px 12px !important;
    border-radius: 10px !important;
    font-size: 15px !important;
    font-weight: 800 !important;
    border: none !important;
    color: #fff !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.22);
  }

  .mq-card-btn.mq-card-in {
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%) !important;
  }

  .mq-card-btn.mq-card-out {
    background: linear-gradient(135deg, #f97316 0%, #ea580c 100%) !important;
  }

  .mq-card-btn.mq-card-btn-ledger {
    background: rgba(30, 41, 59, 0.85) !important;
    border: 1px solid rgba(96, 165, 250, 0.5) !important;
    color: #93c5fd !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18) !important;
  }

  .mq-add-form {
    grid-column: 1 / -1;
    margin-top: 4px;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid rgba(96, 165, 250, 0.28);
    background: rgba(15, 23, 42, 0.65);
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .mq-add-form input {
    min-height: 44px !important;
    font-size: 16px !important;
  }

  .mq-add-inline-row input {
    width: auto !important;
    flex: 1 1 0;
    min-width: 0;
  }

  .mq-add-inline-row .mq-add-cancel,
  .mq-add-inline-row .mq-add-save {
    flex: 0 0 auto;
    min-width: 48px;
    min-height: 44px !important;
    padding: 0 10px !important;
    font-size: 14px !important;
    font-weight: 800 !important;
    white-space: nowrap;
  }

  .mq-add-inline-row {
    display: flex;
    align-items: stretch;
    gap: 8px;
    width: 100%;
  }

  .mq-add-inline-row .mq-add-code {
    flex: 1.15 1 0;
    min-width: 0;
  }

  .mq-add-inline-row .mq-add-qty,
  .mq-add-inline-row .mq-add-box {
    flex: 1 1 0;
    min-width: 0;
    text-align: center;
  }

  .mq-add-qty-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
  }

  .mq-add-qty-field {
    flex: 1 1 0;
    min-width: 0;
    margin: 0;
  }

  .mq-add-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
  }

  .mq-card .inline-edit {
    width: 100%;
    max-width: 100%;
    font-size: 16px !important;
    min-height: 40px;
  }

  .mq-loc-qty .dash-qb-edit {
    width: auto;
    max-width: none;
  }

  .mq-loc-qty.mq-qty-editing {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  .mq-loc-code:has(.inline-edit) {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    flex: 1 1 auto;
    min-width: 0;
  }

  .mq-inline-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
    width: 100%;
    flex-wrap: nowrap;
  }

  .mq-inline-actions button {
    min-height: 36px !important;
    padding: 4px 12px !important;
    font-size: 13px !important;
    font-weight: 700 !important;
    flex: 0 0 auto;
  }

  .mq-bottom-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    background: rgba(10, 14, 22, 0.92);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid rgba(96, 165, 250, 0.22);
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.35);
  }

  body.mobile-query-mode .mq-bottom-bar {
    display: grid !important;
  }

  .mq-bar-btn {
    min-height: 48px !important;
    border-radius: 12px !important;
    font-size: 15px !important;
    font-weight: 800 !important;
    border: none !important;
    color: #fff !important;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  }

  .mq-bar-btn.mq-bar-ledger {
    background: rgba(59, 130, 246, 0.14) !important;
    border: 1px solid rgba(96, 165, 250, 0.35) !important;
    color: #93c5fd !important;
    box-shadow: none !important;
  }

  .mq-bar-in {
    background: linear-gradient(135deg, #059669 0%, #10b981 100%) !important;
  }

  .mq-bar-out {
    background: linear-gradient(135deg, #ea580c 0%, #f97316 100%) !important;
  }

  .mq-bar-tf {
    background: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%) !important;
  }

  body.role-guest.mobile-query-mode .mq-bar-btn.write-action {
    display: none !important;
  }

  body.role-guest.mobile-query-mode .mq-bottom-bar {
    display: grid !important;
    grid-template-columns: 1fr !important;
  }

  body.role-guest.mobile-query-mode .mq-results {
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }
}
