/* ==========================================================================
   EVER Sales — lớp điện thoại (≤ 760px), 11/2026. Quy ước: docs/MOBILE-UI-SPEC.md.
   Nạp SAU CÙNG (sau shell.css / medical.css / seasonal-theme.css). Màn ≥ 761px không bị ảnh hưởng.
   Chỉ chứa phần dùng chung (khung, ô nhập, hộp thoại, menu, thanh thao tác). Phần riêng từng trang
   nằm cuối CSS của module, trong khối "@media (max-width: 760px)" có nhãn MOBILE 11/2026.
   ========================================================================== */
@media screen and (max-width: 760px) {
  /* ---------- 1. Bộ màu / kích thước dùng chung ---------- */
  body.sales-shell {
    --m-ink: #25211C; --m-sub: #6F655A; --m-faint: #9A8F82;
    --m-line: #E2D6C4; --m-line-soft: #EFE8DD; --m-wash: #FAF6EF; --m-wash-2: #F5EEE3;
    --m-accent: #9A6A2E; --m-accent-deep: #7E5523; --m-accent-wash: #FAF1E1;
    --m-ok: #1F7A4A; --m-ok-wash: #E7F4EC; --m-warn: #9A5A0B; --m-warn-wash: #FDF1E3; --m-bad: #A3271F; --m-bad-wash: #FBE9E7;
    --m-r: 14px; --m-r-sm: 10px; --m-field-h: 46px; --m-pad: 14px; --m-gutter: 12px;
    --m-tabbar: calc(80px + env(safe-area-inset-bottom, 0px));
    /* Viền xám đậm #85858f của bản máy tính thành viền đồng nhạt cho màn nhỏ */
    --hair: #D9CCB8; --hair-soft: #E8DFD2; --sh-line: #E2D6C4;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
  }
  body.sales-shell #appView { overflow-x: clip; text-wrap: pretty; }
  /* Tránh một từ lẻ rớt xuống dòng cuối; tiêu đề chia dòng cân */
  body.sales-shell #appView :is(h1, h2, h3, h4), body.sales-shell dialog :is(h1, h2, h3, h4) { text-wrap: balance; }
  body.sales-shell dialog, body.sales-shell .overlay { text-wrap: pretty; }

  /* ---------- 2. Thanh đầu + thanh tab ---------- */
  body.sales-shell #appView .appbar { height: 52px; min-height: 52px; padding-top: env(safe-area-inset-top, 0px); }
  body.sales-shell .sh-mword { font-size: 21px; letter-spacing: 3px; }
  body.sales-shell .sh-tabbar { left: 10px; right: 10px; height: 62px; border-color: #E8DFD2; border-radius: 22px; box-shadow: 0 6px 22px #392e2224; }
  body.sales-shell .sh-tab-label { font-size: 10.5px; }
  body.sales-shell .sh-tabbar button:active { background: #F5EEE3; }
  /* Đang nhập form (có thanh Lưu) hoặc bàn phím đang mở: ẩn thanh tab cho rộng chỗ */
  body.sales-shell.m-form .sh-tabbar, body.sales-shell.m-kb .sh-tabbar { display: none; }
  body.sales-shell.m-form #appView { padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
  body.sales-shell.m-kb .toast-host { bottom: 12px !important; }

  /* ---------- 3. Thanh thao tác của form: dính đáy, tràn hai mép ---------- */
  body.sales-shell.m-form #appView :is(.hub-cf-bar, .dk-foot, .xp-foot, .bd-commit, [data-m-actionbar]):not([hidden]) {
    position: fixed !important; z-index: 65; left: 0 !important; right: 0 !important; bottom: 0 !important; top: auto !important;
    width: auto !important; max-width: none !important; margin: 0 !important; box-sizing: border-box;
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px)) !important;
    background: #fff !important; border: 0 !important; border-top: 1px solid var(--m-line) !important; border-radius: 0 !important;
    box-shadow: 0 -6px 20px #392e221a !important;
  }
  body.sales-shell.m-kb.m-form #appView :is(.hub-cf-bar, .dk-foot, .xp-foot, .bd-commit, [data-m-actionbar]) { position: static !important; box-shadow: none !important; }
  body.sales-shell #appView :is(.hub-cf-bar, .dk-foot, .xp-foot, .bd-commit, [data-m-actionbar]) :is(button, .btn) { min-height: 46px; border-radius: 12px; font-size: 15px; }

  /* ---------- 4. Ô nhập: cao 46px, chữ 16px (iOS không tự phóng to), bo 12px ---------- */
  /* :where() giữ độ ưu tiên thấp (#appView + 1 lớp): luật riêng của module (chip lọc 36px…) luôn thắng */
  body.sales-shell #appView :where(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="color"]), select),
  body.sales-shell :where(.overlay, dialog) :where(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="color"]), select) {
    min-height: var(--m-field-h); font-size: 16px; border-radius: 12px; box-sizing: border-box;
  }
  body.sales-shell #appView textarea, body.sales-shell :where(.overlay, dialog) textarea { font-size: 16px; border-radius: 12px; line-height: 1.5; }
  body.sales-shell :is(#appView, .overlay, dialog) :is(input, select, textarea):focus { outline: none; border-color: var(--m-accent) !important; box-shadow: 0 0 0 3px #9A6A2E26 !important; }
  body.sales-shell :is(#appView, .overlay, dialog) input:is([type="checkbox"], [type="radio"]) { width: 20px; height: 20px; accent-color: var(--m-accent); }
  body.sales-shell :is(#appView, .overlay, dialog) input[type="date"], body.sales-shell :is(#appView, .overlay, dialog) input[type="month"], body.sales-shell :is(#appView, .overlay, dialog) input[type="time"] { min-width: 0; -webkit-appearance: none; appearance: none; }
  body.sales-shell :is(#appView, .overlay, dialog) input[type="date"]::-webkit-date-and-time-value,
  body.sales-shell :is(#appView, .overlay, dialog) input[type="month"]::-webkit-date-and-time-value { text-align: left; }
  /* Nhãn trên ô: 13px đậm vừa */
  body.sales-shell #appView .field > label, body.sales-shell .overlay .field > label, body.sales-shell dialog .field > label { font-size: 13px; font-weight: 600; color: var(--m-sub); }

  /* ---------- 5. Hộp thoại: tấm trượt từ dưới lên ---------- */
  body.sales-shell dialog[open]:not(.m-keep) {
    position: fixed; inset: auto 0 0 0; margin: 0; width: 100%; max-width: 100%; max-height: 92dvh; box-sizing: border-box;
    overflow: auto; overscroll-behavior: contain; border: 0; border-radius: 20px 20px 0 0;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    animation: m-sheet-in .22s ease-out;
  }
  body.sales-shell dialog::backdrop { background: #1d17114d; }
  body.sales-shell .overlay:not([hidden]) { display: flex; flex-direction: column; justify-content: flex-end; align-items: stretch !important; padding: 0 !important; }
  body.sales-shell .overlay > .modal { width: 100% !important; max-width: 100% !important; max-height: 92dvh; margin: 0 !important; border-radius: 20px 20px 0 0 !important; overflow: auto; padding-bottom: env(safe-area-inset-bottom, 0px); animation: m-sheet-in .22s ease-out; }

  /* ---------- 6. Menu: tấm lưới biểu tượng theo nhóm (mobile.js dựng lại nội dung) ---------- */
  body.sales-shell .mobile-menu.m-grid {
    left: 0 !important; right: 0 !important; bottom: 0 !important; max-height: 86dvh; overflow: auto; overscroll-behavior: contain;
    padding: 8px 14px calc(92px + env(safe-area-inset-bottom, 0px)); border: 0; border-radius: 22px 22px 0 0; box-shadow: 0 -10px 40px #392e2233;
    animation: m-sheet-in .22s ease-out;
  }
  body.sales-shell .mobile-menu.m-grid::before { content: ""; display: block; width: 40px; height: 4px; margin: 2px auto 8px; border-radius: 2px; background: #DDD2C2; }
  body.sales-shell .mobile-menu.m-grid .mm-title { margin: 14px 2px 8px; color: var(--m-sub); font-size: 12px; font-weight: 700; letter-spacing: .3px; text-transform: uppercase; }
  body.sales-shell .mobile-menu.m-grid .mm-tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  body.sales-shell .mobile-menu.m-grid .mm-tiles > button {
    position: relative; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 6px;
    min-height: 84px; height: auto; padding: 12px 4px 10px; border: 1px solid var(--m-line-soft); border-radius: 14px; background: #fff;
    color: var(--m-ink); font-size: 12.5px; font-weight: 600; line-height: 1.25; text-align: center; white-space: normal; box-shadow: none;
  }
  body.sales-shell .mobile-menu.m-grid .mm-tiles > button[aria-current="true"] { border-color: #E3C79E; background: var(--m-accent-wash); color: #6E4A1C; font-weight: 700; }
  body.sales-shell .mobile-menu.m-grid .mm-tiles > button:active { background: var(--m-wash-2); }
  body.sales-shell .mobile-menu.m-grid .mm-ico { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 11px; background: #FBF6ED; color: #946A2B; }
  body.sales-shell .mobile-menu.m-grid .mm-ico svg { width: 21px; height: 21px; }
  body.sales-shell .mobile-menu.m-grid .mm-tiles .nav-badge { position: absolute; top: 6px; right: 8px; min-width: 18px; height: 18px; margin: 0; padding: 0 5px; box-sizing: border-box; border-radius: 9px; background: #C2362B; color: #fff; font-size: 10px; font-weight: 700; line-height: 18px; }
  body.sales-shell .mobile-menu.m-grid .mm-rows { display: flex; flex-direction: column; margin-top: 4px; border: 1px solid var(--m-line-soft); border-radius: 14px; overflow: hidden; }
  body.sales-shell .mobile-menu.m-grid .mm-rows > button { display: flex; align-items: center; gap: 12px; min-height: 50px; padding: 0 14px; border: 0; border-top: 1px solid var(--m-line-soft); border-radius: 0; background: #fff; color: var(--m-ink); font-size: 15px; font-weight: 500; text-align: left; box-shadow: none; }
  body.sales-shell .mobile-menu.m-grid .mm-rows > button { justify-content: flex-start !important; width: 100%; margin: 0; border-left: 0; border-right: 0; border-bottom: 0; }
  body.sales-shell .mobile-menu.m-grid .mm-rows > button > span { flex: 1 1 auto; text-align: left; }
  body.sales-shell .mobile-menu.m-grid .mm-rows > button:first-child { border-top: 0; }
  body.sales-shell .mobile-menu.m-grid .mm-rows > button svg { width: 20px; height: 20px; flex: 0 0 20px; color: #946A2B; }
  body.sales-shell .mobile-menu.m-grid .mm-rows > button.is-danger { color: var(--m-bad); }
  body.sales-shell .mobile-menu.m-grid .mm-rows > button.is-danger svg { color: var(--m-bad); }
  body.sales-shell.m-menu-open::after { content: ""; position: fixed; inset: 0; z-index: 66; background: #1d17114d; animation: m-fade .18s ease-out; }
  body.sales-shell.m-menu-open .sh-tabbar { z-index: 68; }
  /* Menu nằm trong thanh đầu (lớp xếp chồng z 60): nâng thanh đầu lên trên lớp phủ khi mở menu */
  body.sales-shell.m-menu-open #appView .appbar { z-index: 67; }

  /* ---------- 7. Khối dùng chung ---------- */
  /* Tiêu đề màn */
  #appView .hub-heading h1 { font-size: 20px; font-weight: 800; letter-spacing: -.3px; line-height: 1.25; }
  /* Dải tab ngang: cuộn, không hiện thanh cuộn */
  body.sales-shell #appView [role="tablist"] { scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  body.sales-shell #appView [role="tablist"]::-webkit-scrollbar { display: none; }
  /* Bảng rộng: cuộn ngang trong khung, không đẩy cả trang */
  body.sales-shell #appView .tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
  /* Rê chuột không có trên điện thoại: bỏ nền "hover" dính sau khi chạm */
  @media (hover: none) {
    body.sales-shell #appView .m-nohover:hover { background: inherit; }
  }
  /* Thông báo nổi */
  body.sales-shell .toast-host { left: 12px !important; right: 12px !important; }

  /* ---------- 8. Trang chủ (bảng điều khiển) ---------- */
  #appView .sh-home.shd { gap: 14px; padding: 6px 0 20px; }
  #appView .shd-hello h1 { font-size: 20px; letter-spacing: -.3px; }
  #appView .shd-hello p { font-size: 13px; line-height: 1.35; }
  #appView .shd-actions { margin: 0 -12px; padding: 0 12px; width: auto; box-sizing: content-box; }
  #appView .shd-act { height: 38px; min-height: 38px; padding: 0 14px; border-radius: 19px; font-size: 13.5px; }
  /* Dải số: một hộp, 2 cột, kẻ ngăn (không còn 7 hộp rời) */
  #appView .shd-kpis { gap: 0; padding: 0; border-radius: 12px; background: var(--m-wash); overflow: hidden; }
  #appView .shd-kpi { gap: 1px; min-height: 0; padding: 8px 12px; border: 0; border-radius: 0; background: transparent; }
  #appView .shd-kpi:nth-child(odd) { border-right: 1px solid #EADFCF; }
  #appView .shd-kpi:nth-child(n+3) { border-top: 1px solid #EADFCF; }
  #appView .shd-kpi:last-child:nth-child(odd) { grid-column: auto; }
  #appView .shd-kpi-label { font-size: 12px; }
  #appView .shd-kpi-label svg { width: 13px; height: 13px; flex-basis: 13px; }
  #appView .shd-kpi-val { font-size: 12px; line-height: 1.2; }
  #appView .shd-kpi-val strong { font-size: 17px; line-height: 1.2; }
  #appView .shd-kpi-sub { font-size: 12px; min-height: 0; line-height: 1.3; }
  #appView .sh-home.shd { gap: 12px; }
  #appView .shd-grid { gap: 12px; }
  #appView .shd-panel { padding: 10px 12px 4px; border-color: var(--m-line); border-radius: 14px; }
  #appView .shd-panel-head { margin-bottom: 0; min-height: 32px; align-items: center; }
  #appView .shd-panel-head h2 { font-size: 15px; }
  #appView .shd-panel .sh-row { gap: 10px; padding: 8px 0; }
  #appView .shd-panel .sh-row-ico { flex-basis: 32px; width: 32px; height: 32px; }
  #appView .shd-panel .sh-row-ico svg { width: 17px; height: 17px; }
  #appView .shd-panel .sh-row-btn { height: 32px; min-height: 32px; padding: 0 12px; border-radius: 10px; font-size: 13px; }
  #appView .shd-panel .sh-row-text strong { font-size: 14px; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #appView .shd-panel .sh-row-text > span { font-size: 13px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
  #appView .shd-line { min-height: 48px; gap: 10px; padding: 6px 0; }
  #appView .shd-line .sh-mini-ico { flex-basis: 32px; width: 32px; height: 32px; }
  #appView .sh-date-tile { flex-basis: 36px; width: 36px; height: 40px; }
  #appView .shd-flow { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; margin: 2px 0 8px; }
  #appView .shd-flow-step { padding: 5px 2px 4px; gap: 0; }
  #appView .shd-flow-step strong { font-size: 16px; }
  #appView .shd-facts { gap: 2px 12px; padding-bottom: 8px; }
  #appView .shd-flow-step small { font-size: 11px; }
  #appView .shd-bar { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "name val" "track track"; gap: 3px 12px; padding: 7px 0; }
  #appView .shd-bar-name { grid-area: name; } #appView .shd-bar-val { grid-area: val; } #appView .shd-bar-track { grid-area: track; height: 8px; border-radius: 4px; }
  #appView .shd-bar-fill { border-radius: 4px; }

  /* ---------- 9. Tìm kiếm / Thông báo (toàn màn) ---------- */
  body.sales-shell .sh-panel .shs-field input, body.sales-shell .sh-panel input[type="search"] { min-height: 46px; border-radius: 12px; }

  /* Không có rê chuột: bỏ nền "hover" dính lại sau khi chạm */
  @media (hover: none) {
    #appView .shd-kpi:hover { background: transparent; }
    #appView button.shd-line:hover, #appView .shd-bar:hover { background: transparent; }
    #appView .shd-act:hover { background: #fff; border-color: #E4DACA; }
    #appView .shd-act.is-primary:hover { background: #9A6A2E; border-color: #9A6A2E; }
  }
}

@keyframes m-sheet-in { from { transform: translateY(24px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes m-fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  body.sales-shell dialog[open], body.sales-shell .mobile-menu.m-grid, body.sales-shell .overlay > .modal { animation: none !important; }
}
