/* 崧豪布品管理平台樣式。色彩、尺寸一律用 tokens.css 的變數。
   同一套畫面給平板與手機：≤ 900px 單欄，≤ 600px 手機（表格改卡片、觸控元件至少 48px）。 */

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--c-bg); color: var(--c-ink); font: var(--fs-body)/1.5 var(--font-ui); overflow-x: hidden; }
a { color: var(--c-primary-ink); }
h1, h2, h3 { margin: 0; line-height: 1.3; }
img { max-width: 100%; }

/* ---------- 共用元件 ---------- */
.card { background: var(--c-surface); border: 1px solid var(--c-line); border-radius: var(--r-card); box-shadow: var(--shadow-card); }
.pad { padding: 16px 20px; }
.muted { color: var(--c-ink-2); }
.small { font-size: var(--fs-small); }
.num { font-family: var(--font-num); font-weight: 700; font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.section-h { font-size: 18px; font-weight: 700; margin: 20px 0 10px; }

.pill { display: inline-flex; align-items: center; gap: 6px; border-radius: var(--r-pill); padding: 3px 12px; font-size: 14px; font-weight: 700; white-space: nowrap; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.p-typing { background: var(--s-typing-bg); color: var(--s-typing); }
.p-ready { background: var(--s-ready-bg); color: var(--s-ready); }
.p-printed { background: var(--s-printed-bg); color: var(--s-printed); }
.p-pending { background: var(--s-pending-bg); color: var(--s-pending); }
.p-error { background: var(--s-error-bg); color: var(--s-error); }
.p-auto { background: var(--s-auto-bg); color: var(--s-auto); }

.btn { min-height: var(--touch); border-radius: var(--r-btn); border: 0; background: var(--c-primary); color: #fff; font: 700 18px var(--font-ui); padding: 0 22px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; text-decoration: none; }
.btn:active { background: var(--c-primary-ink); }
.btn.ghost { background: var(--c-surface); color: var(--c-primary-ink); border: 2px solid var(--c-primary); }
.btn.warn { background: var(--s-pending); }
.btn.danger { background: var(--s-error); }
.btn.block { width: 100%; }
.btn.sm { min-height: 48px; font-size: 15px; padding: 0 14px; }
.btn:disabled { background: #C9BFB1; color: #4A4037; cursor: not-allowed; }
.linkish { background: none; border: 0; color: var(--c-primary-ink); text-decoration: underline; font: inherit; cursor: pointer; padding: 4px; min-height: 48px; }

.stepper { display: flex; align-items: center; gap: var(--gap-touch); }
.stepper .k { width: var(--touch); height: var(--touch); border-radius: var(--r-btn); background: var(--c-surface-2); border: 1px solid var(--c-line-strong); font-size: 28px; color: var(--c-ink); cursor: pointer; flex: none; }
.stepper .v { width: 96px; height: var(--touch); border-radius: var(--r-btn); border: 2px solid var(--c-line-strong); background: #fff; text-align: center; font-size: var(--num-tablet); color: var(--c-ink); }
.stepper .v:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px rgba(63,107,90,.25); }
.stepper.sm .k { width: 48px; height: 48px; font-size: 24px; }
.stepper.sm .v { width: 72px; height: 48px; font-size: var(--num-phone); }

.note { border-radius: 12px; padding: 12px 16px; font-size: 15px; }
.note.info { background: var(--s-ready-bg); color: var(--s-ready); }
.note.warn { background: var(--s-pending-bg); color: var(--s-pending); }
.note.err { background: var(--s-error-bg); color: var(--s-error); }

.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 12px; border: 1px solid var(--c-line); background: var(--c-surface); }
table.t { width: 100%; border-collapse: collapse; font-size: 15px; }
table.t th { text-align: left; font-weight: 700; color: var(--c-ink-2); font-size: 14px; padding: 10px 12px; border-bottom: 2px solid var(--c-line); background: var(--c-surface-2); white-space: nowrap; }
table.t td { padding: 10px 12px; border-bottom: 1px solid var(--c-line); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t .r { text-align: right; }

.field { display: flex; flex-direction: column; gap: 6px; font-weight: 500; }
.field input, .field select, .field textarea { font: 16px var(--font-ui); min-height: 52px; padding: 0 14px; border: 1.5px solid var(--c-line-strong); border-radius: var(--r-btn); background: #fff; color: var(--c-ink); }

/* ---------- 標題列 ---------- */
.appbar { min-height: 64px; background: var(--c-primary); color: var(--c-on-primary); display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 20px; font-weight: 700; font-size: 20px; position: sticky; top: 0; z-index: 10; }
.appbar .ttl { display: flex; align-items: center; gap: 8px; min-width: 0; }
.appbar .back { color: #fff; text-decoration: none; font-size: 34px; line-height: 1; min-width: 48px; min-height: 48px; display: inline-flex; align-items: center; justify-content: center; padding-bottom: 4px; }
.appbar .who { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 500; flex: none; }
.appbar .who-name { font-weight: 700; }
.appbar .sw { color: #fff; background: none; font: inherit; border: 1.5px solid rgba(255,255,255,.7); border-radius: var(--r-btn); padding: 6px 12px; min-height: 48px; display: inline-flex; align-items: center; cursor: pointer; }

/* ---------- 管理選單（只有管理者看得到） ---------- */
.adminnav { display: flex; gap: 6px; overflow-x: auto; padding: 6px 20px; background: var(--c-surface); border-bottom: 1px solid var(--c-line); }
.adminnav a { min-height: 48px; display: inline-flex; align-items: center; padding: 0 16px; border-radius: var(--r-btn); color: var(--c-ink-2); text-decoration: none; white-space: nowrap; font-weight: 500; }
.adminnav a.on { background: var(--s-ready-bg); color: var(--c-primary-ink); font-weight: 700; }
@media (max-width: 600px) { .adminnav { padding: 6px 10px; } }

/* ---------- 版面 ---------- */
body.lay-tablet .main { padding: 20px 24px 40px; max-width: 1400px; margin: 0 auto; }

/* ---------- 對話框、提示 ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(36,33,29,.45); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { width: min(520px, 100%); max-height: 90vh; overflow-y: auto; padding: 22px 24px; }
.modal h3 { font-size: 20px; margin-bottom: 12px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 40px); opacity: 0; transition: .25s; z-index: 60; padding: 12px 20px; border-radius: 12px; font-weight: 700; box-shadow: var(--shadow-card); max-width: calc(100vw - 32px); pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.info { background: var(--s-ready); color: #fff; }
.toast.warn { background: var(--s-pending); color: #fff; }

/* ---------- 斷點 ---------- */
@media (max-width: 600px) {
  .appbar { font-size: 18px; padding: 8px 14px; }
  body.lay-tablet .main { padding: 14px 14px 40px; }
  .hide-sm { display: none; }
  .toast { bottom: 88px; }
  .btn { font-size: 17px; }
}
[hidden] { display: none !important; }

/* ===== 手機寬度：表格改成卡片（一列一張卡，欄名在左、值在右），不必左右滑 ===== */
@media (max-width: 600px) {
  .tbl-wrap:has(> table.t:not(.grid-keep)) { overflow: visible; border: 0; background: none; border-radius: 0; }
  table.t:not(.grid-keep) thead { display: none; }
  table.t:not(.grid-keep), table.t:not(.grid-keep) tbody, table.t:not(.grid-keep) tr { display: block; width: 100%; }
  table.t:not(.grid-keep) tr { background: var(--c-surface); border: 1px solid var(--c-line); border-radius: 12px; padding: 10px 14px; margin-bottom: 10px; }
  table.t:not(.grid-keep) td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 5px 0; border: 0; text-align: right; min-width: 0; }
  table.t:not(.grid-keep) td::before { content: attr(data-label); flex: 0 0 auto; max-width: 45%; text-align: left; color: var(--c-ink-2); font-size: 14px; font-weight: 400; }
  table.t:not(.grid-keep) td[data-label=""]::before { display: none; }
  table.t:not(.grid-keep) td[data-label=""] { justify-content: flex-end; }
  table.t:not(.grid-keep) td:first-child { justify-content: flex-start; text-align: left; font-weight: 700; font-size: 17px; padding-top: 0; }
  table.t:not(.grid-keep) td:first-child::before { display: none; }
  table.t:not(.grid-keep) td:empty { display: none; }
  table.t:not(.grid-keep) td > * { min-width: 0; }
  table.t:not(.grid-keep) td > .cv { display: block; }
}
table.t td > .cv { display: contents; }
