/* Thanh dưới cho điện thoại (js/mobile_nav.js, 2026-11-02): chỉ < 600 px; máy tính / iPad giữ menu trái. */
.mnav, .mnav-sh { display: none; }
@media (max-width: 600px) {
  :root { --mnav-h: calc(58px + env(safe-area-inset-bottom)); }
  /* menu trái ẩn trên điện thoại ở mọi trang */
  #p1Rail { display: none !important; }

  .mnav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 950; height: var(--mnav-h); display: flex; align-items: stretch;
    padding: 0 4px env(safe-area-inset-bottom); background: #fff; border-top: 1px solid #e2e8f0; box-shadow: 0 -4px 16px rgba(15,23,42,.06);
    font-family: 'Be Vietnam Pro', system-ui, sans-serif; }
  .mnav[hidden] { display: none; }
  /* bảng trượt của Theo dõi (.tdmo-sh nằm trong #tdRoot z 880, thấp hơn thanh): tạm ẩn thanh khi bảng mở */
  body:has(#tdRoot .tdmo-sh:not([hidden])) .mnav { display: none; }
  .mnav button { flex: 1; min-width: 0; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    border: 0; background: none; color: #64748b; font: 500 11px/1.2 'Be Vietnam Pro', system-ui, sans-serif; padding: 4px 0 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
  .mnav button > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .mnav button svg { width: 23px; height: 23px; flex: none; }
  .mnav button.on { color: #0f766e; font-weight: 700; }
  .mnav button.on::before { content: ''; position: absolute; top: 0; width: 28px; height: 3px; border-radius: 0 0 3px 3px; background: #0f766e; }
  .mnav button.back { flex: .75; }
  .mnav button > i { position: absolute; top: 3px; left: calc(50% + 4px); min-width: 17px; height: 17px; border-radius: 9px; background: #dc2626; color: #fff;
    font: 700 10px/17px system-ui, sans-serif; font-style: normal; text-align: center; padding: 0 4px; }
  .mnav-sep { width: 1px; background: #e2e8f0; margin: 12px 2px; flex: none; }

  /* bảng trượt lên (Lập KH / Hệ thống / Thêm) */
  .mnav-sh { display: block; position: fixed; inset: 0; z-index: 1100; background: rgba(15,23,42,0); transition: background .2s; font-family: 'Be Vietnam Pro', system-ui, sans-serif; }
  .mnav-sh[hidden] { display: none; }
  .mnav-sh.open { background: rgba(15,23,42,.42); }
  .mnav-shp { position: absolute; left: 0; right: 0; bottom: 0; max-height: 85vh; overflow-y: auto; background: #fff; border-radius: 22px 22px 0 0;
    padding: 8px 16px calc(16px + var(--mnav-h)); transform: translateY(100%); transition: transform .24s cubic-bezier(.2,.8,.2,1); }
  .mnav-sh.open .mnav-shp { transform: none; }
  .mnav-grip { width: 40px; height: 5px; border-radius: 9px; background: #cbd5e1; margin: 0 auto 10px; }
  .mnav-shc h3 { font-size: 12.5px; color: #64748b; text-transform: uppercase; letter-spacing: .04em; margin: 6px 0 4px; }
  .mnav-it { display: flex; align-items: center; gap: 14px; width: 100%; border: 0; border-top: 1px solid #e5e7eb; background: none; padding: 13px 4px;
    font: 500 15.5px/1.3 'Be Vietnam Pro', system-ui, sans-serif; color: #0f172a; text-align: left; cursor: pointer; }
  .mnav-shc h3 + .mnav-it { border-top: 0; }
  .mnav-it svg { width: 22px; height: 22px; color: #0f766e; flex: none; }
  .mnav-it > i { margin-left: auto; min-width: 20px; height: 20px; border-radius: 10px; background: #dc2626; color: #fff; font: 700 11px/20px system-ui; font-style: normal; text-align: center; padding: 0 5px; }
  .mnav-it.on { color: #0f766e; font-weight: 700; }
  .mnav-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 8px; }
  .mnav-gi { display: flex; flex-direction: column; align-items: center; gap: 6px; border: 1px solid #e5e7eb; background: #f8fafc; border-radius: 14px;
    padding: 12px 4px 10px; font: 500 12.5px/1.25 'Be Vietnam Pro', system-ui, sans-serif; color: #0f172a; text-align: center; cursor: pointer; }
  .mnav-gi svg { width: 24px; height: 24px; color: #0f766e; }
  .mnav-gi.on { border-color: #0f766e; background: #e6f6f4; font-weight: 700; }

  /* nội dung dùng hết bề ngang, chừa đáy cho thanh dưới */
  #tdRoot { inset: 0 0 0 0 !important; }
  body.mnav-on #tdRoot { bottom: var(--mnav-h) !important; }
  /* nút "‹ Lập kế hoạch" đầu các mục Phòng khám: đã có ‹ Menu ở thanh dưới (giữ nút về Danh sách trong hồ sơ BN) */
  body.mnav-on #tdRoot .td-head.hub .td-back:not(.pt):not([data-mback]) { display: none; }
  #dashboardStepContainer.p1 { padding: 0 12px 24px 12px !important; }
  body.mnav-on #dashboardStepContainer.p1 { padding-bottom: calc(24px + var(--mnav-h)) !important; }
  .p1-panel { left: 0; width: 100vw; }
  .tc-dock { left: 8px; }
  body.mnav-on .tc-dock { bottom: calc(8px + var(--mnav-h)); }

  /* Không bao giờ cho trang rộng hơn màn hình: trang tràn ngang thì điện thoại giãn khung trang,
     thanh dưới (fixed) giãn theo -> nút Hệ thống ra ngoài màn (Honor Magic 6, 2026-11-02) */
  html, body { overflow-x: hidden; overflow-x: clip; max-width: 100%; }

  /* hàng ca Lập KH: nhãn "Đang điều trị · Tháng 14/24", "Đã sửa, chưa xuất lại"… xuống dòng thay vì kéo dài hàng */
  .p1-row > * { min-width: 0; }
  .p1-prog-head { flex-wrap: wrap; row-gap: 4px; }
  .p1-prog-head > strong { min-width: 0; }
  .p1-warn { white-space: normal; margin-left: 0; }
  .p1-tag { white-space: normal; max-width: 100%; }

  /* Đang ở Phòng khám (#tdRoot mở): là màn riêng, trang Lập KH bên dưới ẩn + khoá cuộn nền
     (trước: kéo trang thì trang máy tính bên dưới bị kéo theo) */
  html:has(#tdRoot:not([hidden])), body:has(#tdRoot:not([hidden])) { overflow: hidden; }
  body:has(#tdRoot:not([hidden])) #dashboardStepContainer.p1 { display: none !important; }   /* JS đặt style="display: block" */
}
