/* Phone layout (≤ 767px). Owner-only phone app: Dashboard, Inbox, Orders + More sheet.
   Everything here is scoped so tablets and desktops are unchanged. See docs/MOBILE_PLAN.md. */

/* ── Bottom sheet (opened only from phone UI) ─────────────────────────────── */
.m-sheet { position: fixed; inset: 0; z-index: 60; display: none; }
.m-sheet.m-sheet-open { display: block; }
.m-sheet-backdrop { position: absolute; inset: 0; background: rgba(2, 6, 23, .55); }
.m-sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 85vh; overflow-y: auto;
  background: #fff; color: #0f172a; border-radius: 18px 18px 0 0;
  padding: 6px 16px calc(16px + env(safe-area-inset-bottom));
  box-shadow: 0 -12px 40px rgba(15, 23, 42, .25);
  animation: m-sheet-up .18s ease-out;
}
.dark .m-sheet-panel { background: #1e293b; color: #e2e8f0; }
@keyframes m-sheet-up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .m-sheet-panel { animation: none; } }
.m-sheet-handle { width: 40px; height: 4px; border-radius: 4px; background: #cbd5e1; margin: 6px auto 8px; }
.dark .m-sheet-handle { background: #475569; }
.m-sheet-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.m-sheet-head h2 { font-size: 1.05rem; font-weight: 700; margin: 0; }
.m-sheet-close { margin-left: auto; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; font-size: 1.5rem; line-height: 1; }
.m-sheet-close:hover { background: rgba(148, 163, 184, .18); }

html.m-sheet-lock, html.m-sheet-lock body { overflow: hidden; }

/* More sheet */
.m-more-list { display: flex; flex-direction: column; }
.m-more-link, .m-more-btn {
  display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 10px 6px;
  border-bottom: 1px solid rgba(148, 163, 184, .25); font-size: 1rem; text-align: left; width: 100%;
  color: inherit; text-decoration: none; background: none;
}
.m-more-link svg, .m-more-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 22px; }
.m-more-link[aria-current="page"] { color: #047857; font-weight: 600; }
.dark .m-more-link[aria-current="page"] { color: #6ee7b7; }
.m-more-btn--danger { color: #dc2626; border-bottom: 0; }
.dark .m-more-btn--danger { color: #fca5a5; }

/* Blocked-page panel (shown by JS only on phones, on pages that are not part of the phone app) */
#mobile-blocked { display: none; }

@media (max-width: 767px) {
  /* The More sheet replaces the long hamburger drawer on phones. */
  #mobile-menu, #mobile-nav, #mobile-nav-backdrop { display: none !important; }

  html.m-blocked, html.m-blocked body { overflow: hidden; }
  html.m-blocked #mobile-blocked {
    display: flex; position: fixed; left: 0; right: 0; top: 52px; bottom: calc(64px + env(safe-area-inset-bottom));
    z-index: 35; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
    padding: 24px; text-align: center; background: #f1f5f9; color: #0f172a;
  }
  html.dark.m-blocked #mobile-blocked { background: #0f172a; color: #e2e8f0; }
  #mobile-blocked .m-blocked-icon { width: 64px; height: 64px; border-radius: 18px; display: grid; place-items: center; background: rgba(16, 185, 129, .14); color: #047857; }
  #mobile-blocked .m-blocked-icon svg { width: 34px; height: 34px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
  #mobile-blocked h1 { font-size: 1.2rem; font-weight: 700; margin: 0; }
  #mobile-blocked p { font-size: .95rem; color: #475569; max-width: 300px; margin: 0; }
  html.dark #mobile-blocked p { color: #94a3b8; }
  #mobile-blocked .m-blocked-actions { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 300px; margin-top: 6px; }
  #mobile-blocked .m-blocked-actions a {
    min-height: 48px; display: flex; align-items: center; justify-content: center; border-radius: 12px;
    font-weight: 600; text-decoration: none; border: 1px solid #cbd5e1; color: inherit; background: #fff;
  }
  html.dark #mobile-blocked .m-blocked-actions a { background: #1e293b; border-color: #334155; }
  #mobile-blocked .m-blocked-actions a.m-primary { background: #047857; border-color: #047857; color: #fff; }

  /* Links inside phone pages that lead to computer-only pages. */
  .m-hide { display: none !important; }
}

/* ── Dashboard (phone) ───────────────────────────────────────────────────── */
.m-only { display: none; }
@media (max-width: 767px) {
  .m-only { display: revert; }
  .m-only.hidden { display: none !important; }
  .business-dashboard { padding: 12px !important; }
  .business-dashboard .ui-page-header { margin-bottom: 10px; flex-wrap: nowrap; align-items: center; }
  .business-dashboard .ui-page-header > :first-child { flex: 1 1 auto; flex-basis: auto; }
  .business-dashboard .ui-page-header .ui-eyebrow { display: none; }
  .business-dashboard .ui-page-actions { width: auto; flex: 0 0 auto; gap: 6px; }
  .business-dashboard .ui-page-actions > * { flex: 0 0 auto; }
  .business-dashboard #last-updated { display: none; }
  .business-dashboard #refresh-btn { min-width: 44px; min-height: 44px; }

  /* Period: one scrollable row of chips; other filters behind the toggle. */
  .dashboard-scope-bar { padding: 10px !important; gap: 8px !important; }
  .dashboard-scope-bar > .dashboard-field:first-child > span { display: none; }
  .dashboard-preset-group { display: flex !important; flex-wrap: nowrap !important; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .dashboard-preset-group::-webkit-scrollbar { display: none; }
  .dashboard-preset { flex: 0 0 auto; min-height: 40px; white-space: nowrap; }
  .dashboard-scope-bar .m-filter-extra { display: none !important; }
  .dashboard-scope-bar.m-filters-open .m-filter-extra { display: flex !important; }
  .dashboard-scope-bar.m-filters-open label.m-filter-extra { display: flex !important; flex-direction: column; }
  .m-filters-toggle { width: 100%; min-height: 40px; border: 1px dashed #94a3b8; border-radius: 10px; font-size: .85rem; font-weight: 600; color: #475569; background: transparent; }
  html.dark .m-filters-toggle { color: #cbd5e1; border-color: #475569; }
  .m-filters-toggle[aria-expanded="true"] span { display: inline-block; transform: rotate(180deg); }
  #dashboard-scope-summary { margin: 6px 2px 10px; }

  /* Sections: tighter spacing; card grids two-up. */
  .business-dashboard .dashboard-section { margin-top: 14px !important; }
  .business-dashboard .dashboard-section-heading p { font-size: .78rem; }
  .business-dashboard .dashboard-financial-grid,
  .business-dashboard .dashboard-operations-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 8px !important; }
  .business-dashboard .dashboard-card-value { font-size: 1.3rem !important; word-break: break-word; }
  .business-dashboard .dashboard-card-note { font-size: .72rem; }
  .business-dashboard .dashboard-financial-grid > .dashboard-card--revenue,
  .business-dashboard .dashboard-financial-grid > .dashboard-card--profit { grid-column: span 2; }
  .business-dashboard .dashboard-analysis-grid { grid-template-columns: minmax(0, 1fr) !important; }

  /* Basket preferences: rows become cards; first 10 unless "Show all". */
  #dashboard-baskets .dashboard-table-toolbar { flex-wrap: wrap; gap: 8px; }
  #dashboard-baskets #basket-summary { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; padding: 10px !important; gap: 8px !important; }
  #dashboard-baskets #basket-summary > div > div:last-child { display: none; }
  #dashboard-baskets .dashboard-table-scroll { overflow: visible; }
  #dashboard-baskets table { min-width: 0 !important; width: 100%; }
  #dashboard-baskets thead { display: none; }
  #dashboard-baskets tbody tr { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px 8px; padding: 10px 12px; border-bottom: 1px solid rgba(148, 163, 184, .3); }
  /* Keep: pattern, orders, units/order, profit/unit, profit/order, details. Full numbers are in "View details". */
  #dashboard-baskets tbody td:nth-child(2), #dashboard-baskets tbody td:nth-child(5),
  #dashboard-baskets tbody td:nth-child(6), #dashboard-baskets tbody td:nth-child(9) { display: none !important; }
  #dashboard-baskets tbody td:first-child span { display: none; }
  #dashboard-baskets tbody td { display: block; padding: 0 !important; border: 0 !important; text-align: left !important; white-space: normal !important; font-size: .85rem; }
  #dashboard-baskets tbody td:first-child, #dashboard-baskets tbody td:last-child { grid-column: 1 / -1; }
  #dashboard-baskets tbody td:last-child { text-align: right !important; }
  #dashboard-baskets tbody td[data-label]::before { content: attr(data-label); display: block; font-size: .7rem; color: #64748b; font-weight: 500; }
  #dashboard-baskets tbody td:last-child button { min-height: 36px; }
  #dashboard-baskets:not(.m-show-all-open) tbody tr:nth-child(n+11) { display: none; }
  .m-show-all { display: block; width: calc(100% - 24px); margin: 10px 12px 14px; min-height: 44px; border-radius: 10px; border: 1px solid #cbd5e1; font-weight: 600; background: transparent; color: inherit; }
  html.dark .m-show-all { border-color: #475569; }

  /* Dialogs opened from the dashboard use the full screen. */
  #basket-detail-dialog, #calculation-dialog, .business-dashboard dialog { width: 100vw !important; max-width: 100vw !important; height: 100dvh; max-height: 100dvh !important; margin: 0; border-radius: 0 !important; }
}
@media (max-width: 767px) {
  .business-dashboard .dashboard-analysis-grid .dashboard-section-heading p { display: none; }
}
@media (max-width: 767px) {
  .dashboard-scope-bar { display: flex !important; flex-direction: column; align-items: stretch; }
  .dashboard-scope-bar > * { min-width: 0; max-width: 100%; }
  .dashboard-scope-bar.m-filters-open #dashboard-range-fields { display: grid !important; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; align-items: end; }
  #dashboard-range-fields label { min-width: 0; }
  .dashboard-scope-bar input, .dashboard-scope-bar select { width: 100%; min-width: 0; font-size: 16px; }
  #dashboard-range-fields #apply-range { grid-column: 1 / -1; min-height: 44px; }
}

/* ── Inbox (phone) ───────────────────────────────────────────────────────── */
@media (max-width: 767px) {
  .inbox-channel-rail .channel-chip { flex: 0 0 auto; }
  .inbox-workspace .ui-eyebrow { display: none; }
}
@media (max-width: 767px) {
  .inbox-workspace #chat-header { flex-wrap: wrap; }
  .inbox-workspace #chat-header.m-controls-open .inbox-thread-controls {
    display: flex !important; order: 10; flex: 1 0 100%; flex-wrap: wrap; gap: 8px; padding: 8px 0 4px;
  }
  .inbox-workspace #chat-header.m-controls-open .inbox-thread-controls label { flex: 1 1 30%; min-width: 0; }
  .inbox-workspace #chat-header.m-controls-open .inbox-thread-controls select { width: 100%; min-height: 40px; font-size: 15px; padding: 0 6px; }
  .inbox-workspace #chat-header.m-controls-open #assign-to-me-btn { flex: 1 0 100%; min-height: 40px; font-size: 14px; }
  .inbox-workspace #thread-menu-panel { min-width: 240px; }
  .inbox-workspace #thread-menu-panel > button, .inbox-workspace #thread-menu-panel > a { min-height: 46px; display: flex; align-items: center; font-size: 14px; }
}

/* Quick replies on phones: a roomy, thumb-sized picker above the keyboard. */
@media (max-width: 767px) {
  #canned-suggest { max-height: 45vh; font-size: .95rem; }
  #canned-suggest .canned-pick, #canned-suggest .canned-all { padding: .7rem .9rem; border-bottom: 1px solid rgba(148, 163, 184, .25); }
  #canned-suggest a { display: inline-block; padding: .5rem .25rem; font-size: .85rem; }
  #quick-image-chip { font-size: .8rem; }
}

/* ── Inbox reply tools (phone) — public/js/inbox-mobile-reply.js ─────────── */
@media (max-width: 767px) {
  /* Reply row: [+] [quick replies] [message] [send]. Template lives in the + menu. */
  #composer #tpl-btn { display: none; }
  #composer #m-quick-btn.m-only { display: grid; color: #047857; border-color: #a7f3d0; background: #ecfdf5; }
  .dark #composer #m-quick-btn.m-only { color: #6ee7b7; border-color: #065f46; background: rgba(6, 95, 70, .35); }
  #m-quick-btn svg { width: 20px; height: 20px; fill: currentColor; }
  #composer > .flex { gap: 6px; }

  /* Favourite quick replies: one swipeable row above the message box. */
  #m-quick-chips:not(.hidden) { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 8px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  #m-quick-chips::-webkit-scrollbar { display: none; }
  .m-quick-chip {
    flex: 0 0 auto; max-width: 62vw; min-height: 36px; padding: 0 14px; border-radius: 18px;
    border: 1px solid #a7f3d0; background: #ecfdf5; color: #065f46; font-size: 14px; font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .dark .m-quick-chip { border-color: #065f46; background: rgba(6, 95, 70, .35); color: #a7f3d0; }

  /* Latest order strip under the chat header. */
  #m-order-strip:not(.hidden) { display: flex; align-items: stretch; gap: 8px; padding: 6px 10px; background: #f8fafc; border-bottom: 1px solid rgba(148, 163, 184, .35); }
  .dark #m-order-strip { background: #0f172a; }
  .m-order-main { flex: 1 1 auto; min-width: 0; min-height: 40px; display: flex; align-items: center; gap: 8px; text-align: left; font-size: 13px; }
  .m-order-no { font-weight: 700; white-space: nowrap; }
  .m-order-status { flex: 0 0 auto; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; background: #e2e8f0; color: #334155; text-transform: capitalize; }
  .m-order-status--delivered { background: #d1fae5; color: #065f46; }
  .m-order-status--shipped, .m-order-status--in_transit, .m-order-status--out_for_delivery { background: #dbeafe; color: #1e40af; }
  .m-order-status--pending, .m-order-status--draft { background: #fef3c7; color: #92400e; }
  .m-order-status--cancelled, .m-order-status--returned, .m-order-status--returned_to_sender { background: #fee2e2; color: #991b1b; }
  .m-order-meta { color: #64748b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .dark .m-order-meta { color: #94a3b8; }
  .m-order-all { flex: 0 0 auto; min-height: 40px; padding: 0 12px; border: 1px solid rgba(148, 163, 184, .5); border-radius: 10px; font-size: 13px; font-weight: 600; }

  /* Tall sheets fill the visible screen, so they stay above the keyboard. */
  .m-sheet-tall { top: var(--m-vv-top, 0); bottom: auto; height: var(--m-vvh, 100%); }
  .m-sheet-tall .m-sheet-panel { max-height: 92%; display: flex; flex-direction: column; overflow: hidden; }

  /* + menu */
  .m-action-list { display: flex; flex-direction: column; }
  .m-action-row { display: flex; align-items: center; gap: 14px; min-height: 58px; padding: 8px 4px; width: 100%; text-align: left; border-bottom: 1px solid rgba(148, 163, 184, .22); cursor: pointer; }
  .m-action-row:last-child { border-bottom: 0; }
  .m-action-row.hidden { display: none; }
  .m-action-icon { flex: 0 0 42px; width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; background: #ecfdf5; color: #047857; }
  .dark .m-action-icon { background: rgba(6, 95, 70, .35); color: #6ee7b7; }
  .m-action-icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .m-action-text { display: flex; flex-direction: column; min-width: 0; }
  .m-action-text b { font-size: 16px; font-weight: 600; }
  .m-action-text small { font-size: 13px; color: #64748b; }
  .dark .m-action-text small { color: #94a3b8; }

  /* Quick replies sheet */
  #m-quick-search { width: 100%; min-height: 46px; padding: 0 14px; border: 1px solid rgba(148, 163, 184, .6); border-radius: 12px; background: transparent; flex: 0 0 auto; }
  .m-quick-hint { margin: 8px 2px 4px; font-size: 12px; color: #64748b; flex: 0 0 auto; }
  .dark .m-quick-hint { color: #94a3b8; }
  .m-quick-list { flex: 1 1 auto; min-height: 120px; overflow-y: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; }
  .m-quick-row { display: flex; align-items: stretch; border-bottom: 1px solid rgba(148, 163, 184, .22); }
  .m-quick-pick { flex: 1 1 auto; min-width: 0; display: flex; gap: 10px; align-items: flex-start; padding: 12px 4px; text-align: left; }
  .m-quick-pick img { flex: 0 0 48px; width: 48px; height: 48px; object-fit: cover; border-radius: 8px; border: 1px solid rgba(148, 163, 184, .4); }
  .m-quick-text { min-width: 0; display: block; }
  .m-quick-text b { font-size: 15px; font-weight: 650; margin-right: 6px; }
  .m-quick-text small { font-size: 12px; color: #64748b; }
  .m-quick-text > span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: 2px; font-size: 14px; line-height: 1.35; color: #475569; white-space: pre-line; }
  .dark .m-quick-text > span, .dark .m-quick-text small { color: #94a3b8; }
  .m-quick-star { flex: 0 0 48px; display: grid; place-items: center; font-size: 24px; color: #94a3b8; }
  .m-quick-star.is-fav { color: #f59e0b; }
  .m-quick-empty { padding: 28px 8px; text-align: center; color: #64748b; font-size: 14px; }
  .m-quick-foot { flex: 0 0 auto; display: flex; align-items: center; gap: 10px; padding-top: 10px; border-top: 1px solid rgba(148, 163, 184, .3); }
  .m-quick-foot-btn { flex: 1 1 auto; min-height: 44px; padding: 0 12px; border-radius: 12px; border: 1px solid #a7f3d0; background: #ecfdf5; color: #065f46; font-size: 14px; font-weight: 600; }
  .m-quick-foot-btn:disabled { border-color: rgba(148, 163, 184, .4); background: transparent; color: #94a3b8; }
  .m-quick-foot-link { flex: 0 0 auto; min-height: 44px; display: grid; place-items: center; padding: 0 10px; font-size: 14px; color: #475569; text-decoration: underline; }
  .dark .m-quick-foot-link { color: #cbd5e1; }
  .m-quick-save { flex: 0 0 auto; margin-top: 10px; padding: 12px; border-radius: 14px; background: #f1f5f9; display: grid; gap: 10px; }
  .m-quick-save.hidden { display: none; }
  #m-quick-sheet.m-saving #m-quick-search, #m-quick-sheet.m-saving .m-quick-hint, #m-quick-sheet.m-saving .m-quick-list, #m-quick-sheet.m-saving .m-quick-foot { display: none; }
  #m-quick-sheet.m-saving .m-quick-save { margin-top: 0; }
  .dark .m-quick-save { background: #0f172a; }
  .m-quick-save-preview { font-size: 13px; color: #475569; max-height: 3.9em; overflow: hidden; white-space: pre-line; }
  .dark .m-quick-save-preview { color: #94a3b8; }
  .m-quick-save label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; }
  .m-quick-save input { min-height: 44px; padding: 0 12px; border: 1px solid rgba(148, 163, 184, .6); border-radius: 10px; background: #fff; font-weight: 400; }
  .dark .m-quick-save input { background: #1e293b; }
  .m-quick-error { color: #b91c1c; font-size: 13px; }
  .m-quick-save-actions { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; }
  .m-quick-save-actions button { min-height: 44px; border-radius: 12px; font-weight: 650; border: 1px solid rgba(148, 163, 184, .6); }
  .m-quick-save-actions button[type="submit"] { background: #047857; border-color: #047857; color: #fff; }

  /* Photo / file preview */
  .m-photo-list { flex: 1 1 auto; min-height: 96px; overflow-y: auto; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; align-content: start; }
  .m-photo-item { position: relative; display: grid; gap: 4px; }
  .m-photo-item img, .m-photo-file { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; border: 1px solid rgba(148, 163, 184, .4); }
  .m-photo-file { display: grid; place-items: center; background: #f1f5f9; color: #475569; font-weight: 700; }
  .m-photo-item span { font-size: 11px; color: #64748b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .m-photo-remove { position: absolute; top: 4px; right: 4px; width: 30px; height: 30px; border-radius: 50%; background: rgba(15, 23, 42, .75); color: #fff; font-size: 18px; line-height: 1; }
  #m-photo-caption { flex: 0 0 auto; width: 100%; margin-top: 10px; padding: 10px 12px; border: 1px solid rgba(148, 163, 184, .6); border-radius: 12px; background: transparent; resize: none; }
  .m-photo-status { flex: 0 0 auto; min-height: 18px; margin: 6px 2px; font-size: 13px; color: #b45309; }
  .m-photo-send { flex: 0 0 auto; min-height: 48px; border-radius: 14px; background: #047857; color: #fff; font-size: 16px; font-weight: 700; }
  .m-photo-send:disabled { opacity: .55; }

  /* Keyboard open: the chat fills exactly the visible screen, so the header and reply box both stay put. */
  body.mobile-chat-open.m-keyboard-open { position: fixed; left: 0; right: 0; top: var(--m-vv-top, 0); height: var(--m-vvh, 100dvh); }
  body.m-keyboard-open #composer { padding-bottom: 7px !important; }
  body.m-keyboard-open #m-order-strip { display: none; }
  body.m-keyboard-open .m-sheet-tall .m-sheet-panel { max-height: 100%; padding-bottom: 12px; }

  /* Reply dialogs (template, payment link, product, buttons, list) open as bottom sheets with readable text. */
  #modal-tpl, #modal-zoho-payment, #modal-buttons, #modal-list, #modal-product { align-items: flex-end; padding: 0; }
  #modal-tpl > div, #modal-zoho-payment > div, #modal-buttons > div, #modal-list > div, #modal-product > div {
    width: 100%; max-width: none; margin: 0; max-height: 90dvh; overflow-y: auto;
    border-radius: 18px 18px 0 0; padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }
  #modal-tpl button, #modal-zoho-payment button, #modal-buttons button, #modal-list button, #modal-product button { min-height: 42px; font-size: 15px; }
  #modal-tpl .text-xs, #modal-product .text-xs, #modal-zoho-payment .text-xs { font-size: 13px; line-height: 1.35; }
  #modal-tpl .text-sm, #modal-product .text-sm { font-size: 15px; }
  body.m-keyboard-open #modal-tpl, body.m-keyboard-open #modal-zoho-payment, body.m-keyboard-open #modal-buttons,
  body.m-keyboard-open #modal-list, body.m-keyboard-open #modal-product { top: 0; bottom: auto; height: 100%; }

  /* Voice note bar and internal notes */
  #recording-bar:not(.hidden) { font-size: 15px; padding: 10px 12px; margin-top: 6px; border-radius: 12px; }
  #recording-bar button { min-height: 40px; padding: 0 14px; border-radius: 10px; font-size: 14px; }
  #inline-notes {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 55; max-height: 70dvh; border-radius: 18px 18px 0 0;
    padding: 14px 14px calc(14px + env(safe-area-inset-bottom)); background: #fefce8; box-shadow: 0 -12px 40px rgba(15, 23, 42, .25);
  }
  .dark #inline-notes { background: #292524; }
  #inline-notes, #inline-notes .text-xs { font-size: 14px; }
  #inline-notes #note-inp { min-height: 44px; padding: 0 12px; }
  #inline-notes #note-go, #inline-notes #note-close { min-height: 44px; padding: 0 16px; font-size: 14px; }
  body.m-keyboard-open #inline-notes { position: absolute; }
}

/* ── Orders (phone) — views/sales-orders.ejs + public/js/orders-mobile.js ─── */
@media (max-width: 767px) {
  /* List: orders first. The page heading and links to computer-only pages go; the four counts become one row. */
  .sales-orders-page .ui-page-header { display: none; }
  .sales-orders-page [aria-label="Operational order summary"] { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .sales-orders-page [aria-label="Operational order summary"] .orders-kpi { min-height: 0; padding: 8px 8px 7px; border-radius: 12px; }
  .sales-orders-page [aria-label="Operational order summary"] .orders-kpi > div:first-child { font-size: 11px; gap: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sales-orders-page [aria-label="Operational order summary"] .orders-kpi > div:last-child { font-size: 19px; margin-top: 2px; }
  .sales-orders-page .orders-finance > summary { padding: 8px 12px; }
  .sales-orders-page .orders-finance #finance-coverage { display: none; }
  .sales-orders-page .orders-panel > div:first-child:has(> .mr-auto > h2) { display: none; }
  /* Filters: search on its own line, then period / status / source side by side. */
  .sales-orders-page .orders-panel > .grid:has(#f-q) { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding: 10px 12px; }
  .sales-orders-page .orders-panel > .grid:has(#f-q) > div:has(#f-q), .sales-orders-page .orders-panel > .grid:has(#f-q) > .orders-more-filters { grid-column: 1 / -1; }
  .sales-orders-page #f-period, .sales-orders-page #f-status-menu > summary, .sales-orders-page #f-source-menu > summary { min-height: 42px; padding: 0 10px; font-size: 14px !important; }
  .sales-orders-page #f-status-menu > div, .sales-orders-page #f-source-menu > div { width: 86vw; max-width: 340px; }
  .sales-orders-page #f-status-menu > div { left: -34vw; right: auto; }
  .sales-orders-page .orders-more-filters > summary { min-height: 38px; padding-block: 6px; font-size: 13px; }
  /* Order cards: who, what status, how much. Bulk ticks, payment refs and admin badges stay on the computer. */
  #mobile-cards .m-oc { margin: 8px 10px; padding: 11px 12px; }
  #mobile-cards .m-oc .row-chk, #mobile-cards .m-oc-source, #mobile-cards .m-oc-payref, #mobile-cards .m-oc-tags, #mobile-cards .m-oc-capi,
  #mobile-cards .m-oc [data-dispatch-date], #mobile-cards .m-oc-flag, #mobile-cards .m-oc [data-del] { display: none; }
  #mobile-cards .m-oc .font-mono.text-xs { font-size: 13px; }
  #mobile-cards .m-oc .font-semibold.text-sm.mt-2 { margin-top: 6px; font-size: 15px; }
  #mobile-cards .m-oc .mt-2\.5 { margin-top: 8px; padding-top: 8px; }
  #mobile-cards .m-oc-actions { margin-top: 8px; }
  #mobile-cards .m-oc-actions [data-edit] { min-height: 40px; }
  /* The + button sits above the tab bar instead of on top of "More". */
  #fab-new { bottom: calc(74px + env(safe-area-inset-bottom)); right: 14px; }

  /* New / edit order: a full-screen form with the fields in the order you need them. */
  #modal { align-items: stretch; overflow: hidden; }
  #modal .m-order-panel { width: 100%; max-width: none; height: 100dvh; max-height: 100dvh; border-radius: 0; display: flex; flex-direction: column; }
  #modal .m-order-body { flex: 1 1 auto; max-height: none; display: flex; flex-direction: column; gap: 12px; padding: 12px 14px 20px; }
  #modal .m-order-body > * { margin-top: 0 !important; }
  #modal .m-order-fields { display: contents; }
  #modal .m-order-fields > * { order: 40; display: none; }
  #modal .m-order-fields input, #modal .m-order-fields select, #modal .m-order-fields textarea, #modal #item-cards input { min-height: 44px; }
  #modal .m-order-fields > label > span:first-child { font-weight: 600; margin-bottom: 3px; }
  #modal .m-order-fields > label:has(#f-customer_phone) { order: 1; display: block; }
  #modal .m-order-fields > #returning-customer:not(.hidden) { order: 1; display: block; }
  #modal .m-order-fields > label:has(#f-customer_name) { order: 2; display: block; }
  #modal .m-order-items { order: 3; padding-top: 12px; }
  #modal .m-order-fields > label:has(#f-saved-address) { order: 4; display: block; }
  #modal .m-order-fields > label:has(#f-saved-address:disabled) { display: none; }
  #modal .m-order-fields > label:has(#f-customer_address) { order: 5; display: block; }
  #modal .m-order-fields > label:has(#f-customer_pincode) { order: 6; display: block; }
  #modal .m-order-fields > label:has(#f-customer_city) { order: 7; display: block; }
  #modal .m-order-fields > label:has(#f-customer_state) { order: 8; display: block; }
  #modal .m-order-fields > label:has(#f-type) { order: 9; display: block; }
  #modal .m-order-fields > label:has(#f-source-edit) { order: 10; display: block; }
  #modal .m-order-fields > label:has(#f-notes) { order: 11; display: block; }
  #modal #m-order-more { order: 30; min-height: 44px; border: 1px dashed rgba(100, 116, 139, .6); border-radius: 12px; font-size: 14px; font-weight: 600; color: #475569; }
  .dark #modal #m-order-more { color: #cbd5e1; }
  /* An existing order: status and tracking first. */
  #modal[data-m-mode="edit"] .m-order-fields > label:has(#f-status-edit) { order: -3; display: block; }
  #modal[data-m-mode="edit"] .m-order-fields > label:has(#f-tracking) { order: -2; display: block; }
  #modal[data-m-mode="edit"] .m-order-fields > label:has(#f-courier) { order: -1; display: block; }
  /* "More details" opens everything else, below the essentials. */
  #modal.m-more .m-order-fields > label, #modal.m-more .m-order-fields > div { display: block; }
  #modal.m-more .m-order-fields > label:has(#f-is-upsell) { display: flex; padding-top: 0; }
  #modal.m-more .m-order-fields > label:has(#f-saved-address:disabled) { display: none; }
  /* Items: big product box with its suggestions; cost rows only under "More details". */
  #modal .m-order-items h3 { font-size: 15px; }
  #modal #add-item { min-height: 40px; padding: 0 12px; }
  #modal #item-cards > div { padding: 10px; border-radius: 12px; }
  #modal #item-cards .relative { scroll-margin-top: 8px; }
  #modal #item-cards .i-sku { font-family: inherit; }
  #modal #item-cards > div > div:has(.i-packing) { display: none; }
  #modal .m-order-items > div:has(> #f-shipping-net), #modal .m-order-items > div:has(> #f-packing-total), #modal .m-order-items > #courier-weight-row { display: none; }
  #modal.m-more #item-cards > div > div:has(.i-packing), #modal.m-more .m-order-items > div:has(> #f-shipping-net), #modal.m-more .m-order-items > div:has(> #f-packing-total) { display: flex; flex-wrap: wrap; }
  #modal .m-order-items > div:has(> #f-shipping-charged) { flex-wrap: wrap; }
  #modal .m-order-items > div:has(> #f-shipping-charged) > span:last-child, #modal.m-more .m-order-items > div > #f-packing-reset { width: 100%; text-align: right; }
  #modal .m-order-items > div > span.flex-1 { text-align: left; }
  /* Save bar stays at the bottom, thumb-sized. */
  #modal .m-order-panel > div:last-child { padding-bottom: calc(10px + env(safe-area-inset-bottom)); gap: 10px; }
  #modal #cancel-btn, #modal #save-btn { min-height: 46px; padding-inline: 18px; font-size: 15px; border-radius: 12px; }
  #modal #save-btn { flex: 1 1 auto; }

  /* Product suggestions: name first, short enough to stay above the keyboard. */
  body .sku-picker-list { max-height: 34vh !important; border-radius: 12px; }
  body .sku-picker-list .sku-picker-option { flex-direction: column-reverse; padding: 10px 12px; font-size: 15px; }
  body .sku-picker-list .sku-picker-option strong { font-size: 11.5px; font-weight: 500; color: #64748b; }
  body .sku-picker-list .sku-picker-option span { color: #0f172a; font-weight: 600; }
  body .sku-picker-list .sku-picker-option span:empty { display: none; }
  body .sku-picker-list .sku-picker-option span:empty + strong, body .sku-picker-list .sku-picker-option strong:only-child { font-size: 15px; font-weight: 600; color: #0f172a; }
  .dark body .sku-picker-list .sku-picker-option span { color: #f1f5f9; }
}
