/* Royal Bali SPA 櫃台：手機與平板版面
 *
 * 只放「螢幕變小、用手指操作」時的調整，接在 styles.css、shell.css 之後載入。
 * 電腦版的樣式在 styles.css；BETA 標示、雲端登入頁、網路中斷提示、加入主畫面提示在 shell.css（這裡不改它們）。
 *
 * 這個檔案的每一條規則都包在 @media 裡：寬度 1200px 以上、用滑鼠的電腦一條都不會套用。
 * 改完請跑 `node tools/check-mobile.mjs`：它會逐個尺寸檢查，並在電腦尺寸把這個檔案關掉再比一次。
 *
 * 可以用的變數與 class（public/js/device.js 設定）：
 *   --vvh            目前看得到的畫面高度（px，鍵盤跳出來會變小）；沒有時用 100dvh
 *   --vvt            iOS 鍵盤把頁面往上推的距離（px）；沒有時用 0
 *   body.kb-open     螢幕鍵盤正開著
 *   body.pwa         從主畫面圖示開啟（全螢幕，沒有瀏覽器網址列）
 *   body.touch       有觸控螢幕的裝置（觸控筆電也算，所以這裡的尺寸調整改用 pointer: coarse 判斷）
 *   body.beta        雲端 BETA 測試版（頂列上面多一條 #beta-strip）
 * 這個檔案設定、給 shell.css 用的變數：
 *   --bottom-nav-h   手機底部分頁列的高度（只在手機寬度設定）
 *
 * 分段：
 *   一、手指操作（pointer: coarse）：按鈕與欄位至少 44px 高、輸入欄字體 16px
 *   二、對話框貼齊看得到的高度（手指操作，或寬度 1199px 以下）
 *   三、寬度 1199px 以下：頂列收窄
 *   四、平板 701–1199px：開單、預約表單的欄位排成兩列
 *   五、寬度 900px 以下：頂列兩排
 *   六、手機 700px 以下：底部分頁列、單欄、表格變卡片、對話框滿版
 *   七、橫放的手機（高度 500px 以下）
 *
 * 表格在手機上怎麼顯示：
 *   儲存格有 data-label 的表格 → 一列一張卡片，data-label 是欄位名稱（public/js 裡加在 td 上）。
 *   沒有 data-label 的表格 → 在自己的區塊（.table-wrap）裡左右捲。
 */

/* ==================================================================
 * 一、手指操作：可以點的東西至少 44px 高，輸入欄字體 16px
 *     範圍限定在頁面內容（main）、對話框（#modal-root）和頂列，不動 shell.css 的登入頁與提示。
 * ================================================================== */
@media (pointer: coarse) {
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  body { -webkit-tap-highlight-color: rgba(15, 92, 85, .14); }
  /* 連點按鈕時不要把畫面放大 */
  button, a, select, summary, label, input { touch-action: manipulation; }

  :where(main, #modal-root, #update-bar) .btn { min-height: 44px; }
  :where(main, #modal-root) .btn.small { min-height: 44px; padding: 6px 12px; }
  :where(main, #modal-root) .btn.big { min-height: 48px; }
  :where(main, #modal-root) .icon-btn { width: 44px; height: 44px; flex: none; }
  /* 文字連結（單號、客人、「換人」）：整塊 44px 高，才點得準 */
  :where(main, #modal-root) .link { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 0 .3em; min-height: 44px; text-align: left; }
  :where(main, #modal-root) .dur-btn { min-height: 44px; padding: 6px 14px; }
  :where(main, #modal-root) .chip { display: inline-flex; align-items: center; min-height: 44px; padding: 6px 16px; }
  :where(main, #modal-root) .roster-cell { min-height: 44px; min-width: 68px; }
  :where(main, #modal-root) summary { min-height: 44px; padding-top: 11px; padding-bottom: 11px; }
  :where(main, #modal-root) .cat-block > summary { align-items: center; }
  .date-nav .btn { min-width: 44px; }
  .who-btn { min-height: 44px; padding: 4px 12px; }

  /* iOS：輸入欄字體小於 16px，一點就自動放大畫面 */
  :where(main, #modal-root) input[type="text"], :where(main, #modal-root) input[type="tel"], :where(main, #modal-root) input[type="date"],
  :where(main, #modal-root) input[type="time"], :where(main, #modal-root) input[type="number"], :where(main, #modal-root) input[type="search"],
  :where(main, #modal-root) input[type="password"], :where(main, #modal-root) input[type="email"],
  :where(main, #modal-root) select, :where(main, #modal-root) textarea {
    min-height: 44px; font-size: 16px;
  }
  /* styles.css 沒有幫查詢欄和密碼欄畫外框：手指操作時補上，和其他欄位一樣 */
  :where(main, #modal-root) input[type="search"], :where(main, #modal-root) input[type="password"], :where(main, #modal-root) input[type="email"] {
    padding: 6px 9px; border: 1px solid #bdb5a8; border-radius: 6px; background: #fff; min-width: 0;
    -webkit-appearance: none; appearance: none;
  }
  :where(main, #modal-root) input[type="date"], :where(main, #modal-root) input[type="time"] { max-width: 100%; }
  :where(main, #modal-root) input[type="checkbox"], :where(main, #modal-root) input[type="radio"] { width: 22px; height: 22px; flex: none; }
  .check { min-height: 44px; gap: 8px; }
  .check-cell { min-width: 44px; min-height: 44px; align-items: center; }
  .ho-choice { min-height: 44px; }
  input.cap-custom, .staff-bar .cap-switch input.cap-custom { width: 88px; flex-basis: 88px; padding: 6px 8px; }
  .dur-custom input { width: 88px; }
  select.sel-gender { width: 88px; }
  .section-head h3 { flex: none; }

  /* 電腦版的單列表單：最後一欄放 44px 的移除鍵 */
  .item-row-main { grid-template-columns: 24px 1.2fr 168px 2fr 128px 62px 44px; }
  .oi-row { grid-template-columns: 24px 1.6fr 1.3fr 1fr 128px 104px 104px 54px 44px; }

  /* 時段表：手指點一下空白時段就直接開新增預約，不需要滑鼠移過去的「＋ 10:15」提示（點完會殘留在畫面上） */
  .slot-hover { display: none !important; }
  /* 「已收款」旁邊原本滑鼠移過去才看得到的說明，直接顯示 */
  .view-schedule .table td.actions > span[title]::after { content: "：" attr(title); }
  /* 預約明細的「修改」按不下去的原因，原本只寫在滑鼠移過去的提示裡：手指操作時直接顯示在按鈕列上面 */
  .modal-footer { position: relative; }
  #bk-edit:disabled[title]:not([title=""]) { opacity: 1; color: #9aa3a0; background: #f4f2ee; border-color: var(--line-soft); }
  #bk-edit:disabled[title]:not([title=""])::after {
    content: "不能修改：" attr(title); position: absolute; left: 0; right: 0; bottom: 100%;
    padding: 6px 14px; background: #fff6e0; color: #5a3600; border-top: 1px solid #e2b877;
    font-size: .84rem; font-weight: 400; line-height: 1.4; text-align: left; white-space: normal;
  }
  /* 手指點過的按鈕不要一直留著滑鼠移過去的顏色（看起來像被選起來） */
  :where(main, #modal-root) .btn:hover:not(:disabled) { border-color: var(--line); color: inherit; }
  :where(main, #modal-root) .btn.primary:hover:not(:disabled) { background: var(--brand); border-color: var(--brand); color: #fff; }
  :where(main, #modal-root) .btn.accent:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); color: #fff; }
  :where(main, #modal-root) .btn.danger:hover:not(:disabled) { background: var(--danger); border-color: var(--danger); color: #fff; }
  :where(main, #modal-root) .btn.danger-outline:hover:not(:disabled) { background: #fff; border-color: #e3b5b1; color: var(--danger); }
  :where(main, #modal-root) .chip:hover { border-color: var(--line); color: inherit; }
  :where(main, #modal-root) .dur-btn:not(.active):not(.base):hover { border-color: #bdb5a8; }
  :where(main, #modal-root) .icon-btn:hover { background: transparent; color: var(--muted); }
  .btn:active:not(:disabled), .dur-btn:active, .chip:active, .icon-btn:active, .roster-cell:active:not(:disabled) { filter: brightness(.93); }
  /* 從主畫面圖示開啟時沒有「另開視窗」這回事 */
  body.pwa #board-popout { display: none; }
  /* 對話框開著時，底下的頁面不跟著捲 */
  body:has(#modal-root > .overlay) { overflow: hidden; }
}

/* ==================================================================
 * 二、對話框貼齊看得到的高度：內容區自己捲，底部按鈕列固定看得到（螢幕鍵盤不會擋住確認按鈕）
 * ================================================================== */
@media (pointer: coarse), (max-width: 1199px) {
  .overlay {
    top: var(--vvt, 0px); bottom: auto; height: var(--vvh, 100dvh);
    padding: max(10px, 3vh) 12px; overflow: hidden;
  }
  .modal { display: flex; flex-direction: column; max-height: 100%; min-height: 0; }
  .modal-head, .modal-footer { flex: none; }
  .modal-body { flex: 1 1 auto; min-height: 0; overflow-x: hidden; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
  .modal-footer { flex-wrap: wrap; }
  body.kb-open .overlay { padding-top: 6px; padding-bottom: 6px; }
  /* 程式更新提示固定在底部：鍵盤開著時它在鍵盤後面，不用替它留空間 */
  body.kb-open.has-update .overlay { padding-bottom: 6px; }
  .sched-scroll { max-height: calc(100dvh - 250px); }
}

/* ==================================================================
 * 三、寬度 1199px 以下（平板橫向以下）：頂列收窄，主選單放不下時可以左右滑
 * ================================================================== */
@media (max-width: 1199px) {
  .topbar {
    gap: 12px;
    padding-left: max(12px, env(safe-area-inset-left, 0px)); padding-right: max(12px, env(safe-area-inset-right, 0px));
  }
  .brand-sub, .clock { display: none; }
  .tabs { flex: 1 1 auto; min-width: 0; gap: 2px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs a { flex: none; padding: 0 12px; white-space: nowrap; }
  .topbar-right { flex: none; gap: 8px; }
  .th-code, .th-name { white-space: nowrap; }
  .section-head h3 { flex: none; }
  /* 收款面板「應收」那一行：金額（含折扣說明）用掉右邊整排，不要擠在窄欄裡換行 */
  .pay-line > strong { grid-column: 2 / -1; }
  .who-btn .who-shift { display: none; }
  /* 連線狀態只留圓點；斷線時才把字顯示出來 */
  .sync:not(.down) { font-size: 0; gap: 0; }
  .sync::before { width: 10px; height: 10px; }
  main { padding: 14px max(12px, env(safe-area-inset-right, 0px)) 40px max(12px, env(safe-area-inset-left, 0px)); }
  .legend-hint { margin-left: 0; }
  .table-wrap { -webkit-overflow-scrolling: touch; }
  /* 抽成比例表、班表左右捲的時候，師傅那一欄固定在左邊 */
  .table.matrix th[scope="row"], .roster-table th.roster-name, .roster-table thead th:first-child {
    position: sticky; left: 0; z-index: 1; background: var(--panel);
  }
}

/* ==================================================================
 * 四、平板 701–1199px：開單的每一項排成兩列（上：療程、實際師傅、客人點名；下：開始、定價、本次價格、刷保險）
 * ================================================================== */
@media (min-width: 701px) and (max-width: 1199px) {
  .oi-row { grid-template-columns: 24px minmax(0, 1.4fr) minmax(0, 1.2fr) minmax(0, 1fr) 64px 44px; row-gap: 6px; }
  .oi-row > :nth-child(1) { grid-area: 1 / 1; }
  .oi-row > :nth-child(2) { grid-area: 1 / 2; }
  .oi-row > :nth-child(3) { grid-area: 1 / 3; }
  .oi-row > :nth-child(4) { grid-area: 1 / 4 / auto / -1; }
  .oi-row > :nth-child(5) { grid-area: 2 / 2; }
  .oi-row > :nth-child(6) { grid-area: 2 / 3; }
  .oi-row > :nth-child(7) { grid-area: 2 / 4; }
  .oi-row > :nth-child(8) { grid-area: 2 / 5; }
  .oi-row > :nth-child(9) { grid-area: 2 / 6; }
  .oi-head { display: grid; }
  .oi-head > :nth-child(6) { text-align: right; }
  .oi-head > :nth-child(8) { text-align: center; }
}

/* ==================================================================
 * 五、寬度 900px 以下（平板直向、手機）：頂列兩排 — 上：店名、登入的人、測試標示；下：主選單
 * ================================================================== */
@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; height: auto; column-gap: 10px; row-gap: 0; padding-top: env(safe-area-inset-top, 0px); }
  body.beta .topbar { padding-top: 0; } /* BETA 那一條已經留了瀏海的空間 */
  .brand { order: 1; display: flex; align-items: center; min-height: 50px; }
  .topbar-right { order: 2; min-height: 50px; }
  .tabs { order: 3; flex: 0 0 100%; height: 46px; border-top: 1px solid rgba(255, 255, 255, .16); }
  .tabs a { flex: 1 1 auto; justify-content: center; }
  .toolbar-actions { flex-wrap: wrap; }
  .row-actions { flex-wrap: wrap; align-items: center; }
  .job-actions { justify-content: flex-start; }
  .seg-box, .item-row-hint { margin-left: 0; }
  .staff-bar .cap-switch { flex-wrap: wrap; white-space: normal; }
  /* 即時排位：每位師傅的 ↑ ↓ 拉到隊尾 報到 下班 固定換到下一行排成一排（不會只有一顆掉下去） */
  .q-head .spacer { flex: 1 0 100%; height: 0; }
}

/* 平板直向 701–900px：預約表單的每個療程排成兩列（上：療程、類型、時間；下：師傅） */
@media (min-width: 701px) and (max-width: 900px) {
  .form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .item-row-main { grid-template-columns: 24px minmax(0, 1.3fr) minmax(0, 1fr) 132px 64px 44px; }
  .item-row-main > .item-no { grid-area: 1 / 1; }
  .item-row-main > .sel-service { grid-area: 1 / 2; }
  .item-row-main > .sel-kind { grid-area: 1 / 3; }
  .item-row-main > .inp-time { grid-area: 1 / 4; }
  .item-row-main > .item-end { grid-area: 1 / 5; }
  .item-row-main > .icon-btn, .item-row-main > span:empty:not(.item-end) { grid-area: 1 / 6; }
  .item-row-main > .who { grid-area: 2 / 2 / auto / -1; }
  .svc-head { grid-template-columns: 1.2fr 1.4fr 1fr; }
}

/* ==================================================================
 * 六、手機（700px 以下）
 * ================================================================== */
@media (max-width: 700px) {
  /* ---------- 頂列與底部分頁列 ---------- */
  body { --bottom-nav-h: 56px; }
  body.standalone, body.kb-open { --bottom-nav-h: initial; } /* 沒有分頁列的時候不設定 */
  .topbar {
    flex-wrap: nowrap; column-gap: 8px; min-height: 50px;
    padding-left: max(10px, env(safe-area-inset-left, 0px)); padding-right: max(10px, env(safe-area-inset-right, 0px));
  }
  .brand { display: block; flex: 0 1 auto; min-width: 0; font-size: 1rem; line-height: 50px; overflow: hidden; text-overflow: ellipsis; }
  .topbar-right { gap: 6px; }
  .who-btn { padding: 4px 10px; max-width: 46vw; }
  .who-btn .who-role { display: none; }
  .who-btn strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .test-badge { font-size: .72rem; padding: 2px 7px; }
  .sync, .sync.down { font-size: 0; gap: 0; }

  /* 主選單固定在畫面底部；目前這一頁：上緣金色、底色變亮、字加粗 */
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; order: 0; flex: none; height: auto; gap: 0; overflow: visible;
    padding: 0 max(2px, env(safe-area-inset-right, 0px)) env(safe-area-inset-bottom, 0px) max(2px, env(safe-area-inset-left, 0px));
    background: var(--brand); border-top: 1px solid rgba(255, 255, 255, .2); box-shadow: 0 -2px 10px rgba(0, 0, 0, .2);
  }
  .tabs a {
    flex: 1 1 0; min-width: 0; height: 56px; padding: 0 2px; justify-content: center; text-align: center;
    font-size: .82rem; white-space: nowrap; border-top: 3px solid transparent; border-bottom: 0;
  }
  .tabs a.active { border-top-color: #f1c376; border-bottom-color: transparent; background: rgba(255, 255, 255, .14); }
  body.kb-open .tabs { display: none; } /* 打字時不佔位置 */

  main {
    padding: 12px max(12px, env(safe-area-inset-right, 0px)) calc(var(--bottom-nav-h, 0px) + env(safe-area-inset-bottom, 0px) + 28px) max(12px, env(safe-area-inset-left, 0px));
  }
  body.has-update main { padding-bottom: calc(var(--bottom-nav-h, 0px) + env(safe-area-inset-bottom, 0px) + 120px); }

  /* 程式更新提示：放在分頁列上面；對話框開著時，對話框底部讓出位置 */
  #update-bar {
    left: 8px; right: 8px; bottom: calc(var(--bottom-nav-h, 0px) + env(safe-area-inset-bottom, 0px) + 8px);
    width: auto; max-width: none; gap: 10px; padding: 8px 10px 8px 12px; font-size: .86rem; line-height: 1.35;
  }
  body.has-update .overlay { padding-bottom: calc(var(--bottom-nav-h, 0px) + env(safe-area-inset-bottom, 0px) + 100px); }
  body.kb-open.has-update .overlay { padding-bottom: 0; }
  /* 提示訊息：頂列下面、左右留邊，不會超出畫面 */
  #toast-root { left: 10px; right: 10px; top: calc(env(safe-area-inset-top, 0px) + 58px); transform: none; align-items: stretch; }
  .toast { max-width: none; }

  /* ---------- 共用 ---------- */
  .view > * + * { margin-top: 12px; }
  .card { padding: 12px; }
  .card-title { line-height: 1.4; }
  .toolbar { gap: 10px; }
  .date-nav { width: 100%; gap: 6px; }
  .date-nav .date-input { flex: 1 1 150px; min-width: 0; }
  .date-label { margin-left: 0; font-size: 1.05rem; }
  .toolbar-actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .toolbar-actions .btn.big { padding: 8px 10px; font-size: 1rem; }
  .legend { gap: 6px 14px; font-size: .86rem; }
  .legend-hint { flex-basis: 100%; font-size: .82rem; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stat { padding: 8px 10px; min-width: 0; }
  .stat.main { grid-column: 1 / -1; }
  .stat-value { font-size: 1.15rem; overflow-wrap: anywhere; }
  .stat.main .stat-value { font-size: 1.5rem; }
  .acc-owner-only { grid-column: 1 / -1; }
  .form-grid { gap: 10px; }
  .section-head { flex-wrap: wrap; gap: 4px 12px; }
  .detail { grid-template-columns: 76px minmax(0, 1fr); }
  .detail.inline { grid-template-columns: auto minmax(0, 1fr); }
  .detail dd { min-width: 0; overflow-wrap: anywhere; }
  .cust-search input, #cust-q { flex: 1 1 180px; min-width: 0; }
  .acc-range-form { gap: 8px 12px; }
  .desk-cash-split { grid-template-columns: 1fr; gap: 10px; }
  .desk-unpaid li, .desk-history li { padding: 2px 0; }
  .inline-form { grid-template-columns: 1fr; }
  .notice, .warn-box { overflow-wrap: anywhere; }

  /* ---------- 今日預約 ---------- */
  .staff-bar { gap: 8px 10px; padding: 8px 10px; }
  .staff-bar .spacer { display: none; }
  .staff-bar .cap-switch { flex-basis: 100%; }
  /* 時段表在自己的區塊裡上下左右捲 */
  .sched-scroll { max-height: 64dvh; min-height: 300px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }

  /* ---------- 即時排位 ---------- */
  .view-board .toolbar-actions { grid-template-columns: auto 1fr 1fr; }
  #board-popout { display: none; } /* 手機上沒有「另開視窗」 */
  .next-up { margin-left: 0; border-radius: 12px; }
  .job-row { padding: 10px; gap: 8px; }
  .q-card { padding: 10px; }
  .q-head { gap: 6px 8px; }
  .q-head .spacer { flex: 1 0 100%; height: 0; } /* ↑ ↓ 拉到隊尾 報到 下班：換到下一行排好 */
  .assign-select { flex: 1 1 130px; max-width: 100%; }
  .q-job { align-items: flex-start; }
  .seg { padding: 4px 8px; }

  /* ---------- 設定 ---------- */
  .svc-head { grid-template-columns: minmax(0, 1fr) auto; }
  .svc-head > input, .svc-head > select { grid-column: 1 / -1; }
  .cat-block .svc-card { margin: 0 8px 8px; }
  /* 時長與價格：一列排不下就換行 */
  .table.options, .table.options tbody { display: block; width: 100%; margin-left: 0; }
  .table.options tr { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; padding: 6px 0; border-top: 1px dashed var(--line); }
  .table.options td { display: block; padding: 0; }
  .table.options td:empty { display: none; }
  .table.options tr.add-row { background: #f6f3ec; padding: 6px 8px; border-radius: 6px; }

  /* ---------- 表格：沒有 data-label 的在自己的區塊裡左右捲（右邊有陰影表示還有內容） ---------- */
  .table-wrap {
    overscroll-behavior-x: contain;
    background:
      linear-gradient(to right, var(--panel) 40%, rgba(255, 255, 255, 0)) left center / 28px 100% no-repeat local,
      linear-gradient(to left, var(--panel) 40%, rgba(255, 255, 255, 0)) right center / 28px 100% no-repeat local,
      radial-gradient(farthest-side at 0 50%, rgba(31, 43, 41, .22), rgba(31, 43, 41, 0)) left center / 12px 100% no-repeat scroll,
      radial-gradient(farthest-side at 100% 50%, rgba(31, 43, 41, .22), rgba(31, 43, 41, 0)) right center / 12px 100% no-repeat scroll;
  }
  .notice .table-wrap { background: none; }
  .table-wrap > .table { width: max-content; min-width: 100%; max-width: 230%; }
  .table th, .table td { padding-left: 8px; padding-right: 8px; }
  .table .actions { white-space: normal; }

  /* ---------- 表格：儲存格有 data-label 的，一列一張卡片 ---------- */
  .table:has(td[data-label]) { display: block; width: 100%; min-width: 0; max-width: 100%; }
  .table:has(td[data-label]) > thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .table:has(td[data-label]) > tbody, .table:has(td[data-label]) > tfoot { display: block; }
  .table:has(td[data-label]) > * > tr {
    display: block; margin: 0 0 10px; padding: 8px 12px; background: #fff;
    border: 1px solid var(--line); border-radius: 8px;
  }
  .table:has(td[data-label]) > * > tr:last-child { margin-bottom: 0; }
  .table:has(td[data-label]) > tfoot > tr { margin-top: 10px; }
  .table:has(td[data-label]) > * > tr > td, .table:has(td[data-label]) > * > tr > th {
    display: block; padding: 4px 0; border: 0; background: none; text-align: left; white-space: normal; overflow-wrap: anywhere;
  }
  .table:has(td[data-label]) > * > tr > td:empty { display: none; }
  /* 欄位名稱在左、內容在右；金額靠右對齊 */
  .table:has(td[data-label]) > * > tr > td[data-label] { position: relative; padding-left: 5.4rem; min-height: 1.9rem; }
  .table:has(td[data-label]) > * > tr > td[data-label]::before {
    content: attr(data-label); position: absolute; left: 0; top: 5px; width: 5rem;
    color: var(--muted); font-size: .84rem; font-weight: 600; line-height: 1.45; text-align: left; white-space: normal; text-decoration: none;
  }
  /* 卡片裡的輸入欄：文字欄和選單佔滿右半邊；金額、分鐘、百分比維持原本的窄欄 */
  .table:has(td[data-label]) td[data-label] > input:not(.narrow):not(.money):not(.pct):not([type="checkbox"]),
  .table:has(td[data-label]) td[data-label] > select:not(.sel-gender) { width: 100%; }
  .table:has(td[data-label]) > * > tr > td.num { text-align: right; }
  .table:has(td[data-label]) > * > tr > td.actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; padding-top: 8px; text-align: left; }
  .table:has(td[data-label]) > * > tr > td.actions .btn { flex: 1 1 auto; margin-left: 0; }
  .table:has(td[data-label]) > * > tr.total-row { background: #faf8f4; border-top-width: 1px; }
  .table:has(td[data-label]) > * > tr.add-row { background: #f6f3ec; }
  .table:has(td[data-label]) > * > tr.row-warn { background: #fdf3f1; }
  /* 卡片的第一行（時間＋客人、單號、師傅）當標題 */
  .table:has(td[data-label]) > tbody > tr > td:first-child:not([data-label]),
  .table:has(td[data-label]) > tbody > tr > td:first-child:not([data-label]) + td:not([data-label]) {
    display: inline-block; padding-right: .6em; font-weight: 700; font-size: 1.03rem; vertical-align: middle;
  }
  .table:has(td[data-label]) input.money, .table:has(td[data-label]) input.narrow, .table:has(td[data-label]) input.pct { max-width: 100%; }

  /* ---------- 對話框：滿版，高度貼齊看得到的範圍 ---------- */
  .overlay { padding: 0; align-items: stretch; }
  .modal, .modal.lg, .modal.xl { max-width: none; width: 100%; height: 100%; border-radius: 0; box-shadow: none; }
  /* 小對話框（確認、登入）：置中的小卡片，不用整個畫面 */
  .modal.sm { align-self: center; width: calc(100% - 24px); max-width: 480px; height: auto; max-height: calc(100% - 20px); margin: 0 auto; border-radius: 12px; box-shadow: 0 12px 40px rgba(0, 0, 0, .3); }
  .modal-head { padding: 4px 4px 4px 14px; padding-top: calc(4px + env(safe-area-inset-top, 0px)); }
  .modal.sm .modal-head { padding-top: 4px; }
  .modal-title { min-width: 0; font-size: 1.05rem; overflow-wrap: anywhere; }
  .modal-body { padding: 12px 14px 20px; }
  .modal-footer { gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px)); border-radius: 0; }
  .modal.sm .modal-footer { padding-bottom: 10px; border-radius: 0 0 12px 12px; }
  body.kb-open .modal-footer { padding-bottom: 8px; padding-top: 8px; }
  .modal-footer .btn { flex: 1 1 auto; }
  .modal-footer .spacer { display: none; }
  body.kb-open .overlay { padding-top: 0; padding-bottom: 0; }
  body:has(#modal-root > .overlay) { overflow: hidden; }
  .receipt-stage { max-height: none; padding: 10px 6px; justify-content: flex-start; }
  .receipt-frame { margin: 0 auto; } /* 放得下就置中；放不下靠左，可以左右捲 */
  .ho-when { grid-template-columns: 1fr; }
  /* 班表：師傅那一欄窄一點（可以換行），七天的格子左右捲 */
  .roster-table th.roster-name { white-space: normal; min-width: 5.6rem; max-width: 7rem; padding-left: 4px; }
  .roster-table th.roster-name .small { display: block; }
  .roster-nav .hint { flex-basis: 100%; }

  /* ---------- 預約表單：每個療程一張卡片，一欄到底 ---------- */
  .item-row { padding: 10px; }
  .item-row-main { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px 10px; }
  .item-row-main > .item-no { grid-area: 1 / 1; text-align: left; }
  .item-row-main > .item-no::before { content: "療程 "; }
  .item-row-main > .icon-btn, .item-row-main > span:empty:not(.item-end) { grid-area: 1 / 2; justify-self: end; }
  .item-row-main > .sel-service { grid-area: 2 / 1 / auto / -1; }
  .item-row-main > .sel-kind { grid-area: 3 / 1 / auto / -1; }
  .item-row-main > .who { grid-area: 4 / 1 / auto / -1; flex-direction: column; gap: 4px; }
  .item-row-main > .inp-time { grid-area: 5 / 1; }
  .item-row-main > .item-end { grid-area: 5 / 2; }
  .item-row-main .who select { flex: none; }
  /* 兩個師傅選單疊在一起時要分得出來：上面是客人點名的，下面是實際安排的 */
  .item-row-main .who::before, .item-row-main .who::after { font-size: .84rem; font-weight: 600; color: var(--muted); }
  .item-row-main .who:has(.sel-requested)::before { content: "客人點名"; order: 0; }
  .item-row-main .who .sel-requested { order: 1; }
  .item-row-main .who::after { content: "安排的師傅"; order: 2; }
  .item-row-main .who .sel-therapist, .item-row-main .who .gender-fixed { order: 3; }
  .gender-fixed { white-space: normal; min-height: 44px; }
  .dur-picker { gap: 6px 8px; }

  /* ---------- 開單：每一項一張卡片，一欄到底 ---------- */
  .order-meta { gap: 6px 12px; }
  .oi-block { margin-bottom: 10px; padding: 10px; border: 1px solid var(--line-soft); border-radius: 8px; background: #fcfbf8; }
  .oi-row:not(.oi-head) { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px 10px; padding: 0; }
  .oi-row > .item-no { grid-area: 1 / 1; text-align: left; }
  .oi-row > .item-no::before { content: "第 "; }
  .oi-row > .item-no::after { content: " 項"; }
  .oi-row > .icon-btn, .oi-row > span:empty { grid-area: 1 / 2; justify-self: end; }
  .oi-row > .sel-service { grid-area: 2 / 1 / auto / -1; }
  /* 欄位名稱（電腦版在表頭那一列，手機上每一項自己帶） */
  .oi-row:not(.oi-head)::before, .oi-row:not(.oi-head)::after { font-size: .84rem; font-weight: 600; color: var(--muted); margin-bottom: -2px; }
  .oi-row:not(.oi-head)::before { content: "實際服務的師傅"; grid-area: 3 / 1 / auto / -1; }
  .oi-row > .sel-therapist { grid-area: 4 / 1 / auto / -1; }
  .oi-row:not(.oi-head)::after { content: "客人點名（沒有點名就不用選）"; grid-area: 5 / 1 / auto / -1; }
  .oi-row > .sel-requested { grid-area: 6 / 1 / auto / -1; }
  .oi-row > input[type="time"] { grid-area: 7 / 1; }
  .oi-row > .check-cell { grid-area: 7 / 2; justify-content: flex-start; gap: 8px; }
  .oi-row > .check-cell::after { content: "刷保險"; }
  .oi-row > .list-price { grid-area: 8 / 1; text-align: left; white-space: normal; }
  .oi-row > .list-price::before { content: "定價 "; }
  .oi-row > .list-price::after { content: "本次價格（折扣前）→"; display: block; font-size: .84rem; font-weight: 600; color: var(--ink); }
  .oi-row > .inp-price { grid-area: 8 / 2; }
  .total-line { flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; }
  .total-line strong { min-width: 0; font-size: 1.45rem; }
  /* 折扣那一行：方式和數字換到下一行，佔滿寬度 */
  .order-totals .total-line > span + span { order: 3; flex: 1 0 100%; min-width: 0; display: flex; align-items: center; gap: 8px; }
  .order-totals .total-line > span + span select { flex: 1 1 auto; width: auto; min-width: 0; }
  .order-totals .total-line > span + span input.money { flex: 0 0 96px; }
  /* 收款：每種付款方式一行（名稱、金額、填入餘額），說明欄放下一行 */
  .pay-panel { padding: 10px; }
  .pay-line { grid-template-columns: minmax(0, 1fr) 104px auto; gap: 6px 8px; }
  .pay-line > strong { grid-column: 1 / -1; overflow-wrap: anywhere; } /* 應收的金額（含折扣說明）自己一行 */
  .pay-line > .pay-extra { grid-column: 1 / -1; flex-wrap: wrap; }
  .pay-line > span:empty { display: none; }
  .pay-extra input[type="text"]:not(.money) { max-width: none; flex: 1 1 160px; }
  .pay-extra input.money { width: 104px; }
  .collector { padding: 2px 10px; }
}

/* ==================================================================
 * 七、橫放的手機（高度 500px 以下、寬度超過 700px）：頂列回到一排，對話框滿版
 * ================================================================== */
@media (max-height: 500px) and (min-width: 701px) and (max-width: 1199px) {
  .topbar { flex-wrap: nowrap; }
  .brand { display: none; }
  .tabs { order: 1; flex: 1 1 auto; height: 48px; border-top: 0; }
  .tabs a { flex: none; }
  .topbar-right { order: 2; min-height: 48px; }
  .sched-scroll { max-height: 82dvh; min-height: 240px; }
  .overlay { padding: 0; align-items: stretch; }
  .modal, .modal.sm, .modal.lg, .modal.xl { max-width: none; width: 100%; height: 100%; border-radius: 0; }
  .modal-head { padding: 0 max(4px, env(safe-area-inset-right, 0px)) 0 max(14px, env(safe-area-inset-left, 0px)); }
  .modal-body { padding: 10px max(14px, env(safe-area-inset-right, 0px)) 14px max(14px, env(safe-area-inset-left, 0px)); }
  .modal-footer { padding: 6px max(12px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px)); border-radius: 0; }
  body.kb-open .overlay { padding: 0; }
}
