/* ============================================================
   格侖服務報告 e 化 — 樣式
   兩個視圖共用同一份資料：
     .view#viewFill  填寫模式（手機優先，大字、直排）
     .view#viewPage  整頁模式（A4 1:1 複刻，PDF 由此輸出）
   ============================================================ */

:root {
  color-scheme: light;

  --brand:        #2fa36b;   /* JIATEK 綠 */
  --brand-dark:   #238053;
  --brand-blue:   #1a63b8;   /* JIATEK 藍 */
  --ink:          #16202a;
  --ink-2:        #47576a;
  --ink-3:        #7d8b9b;
  --line:         #d9e0e7;
  --bg:           #eef1f4;
  --surface:      #ffffff;
  --focus:        #2fa36b;
  --danger:       #c0392b;

  --radius:       12px;
  --appbar-h:     56px;
  --actionbar-h:  64px;

  /* A4 幾何：與原範本量測值對齊 */
  --pw:      210mm;
  --ph:      297mm;
  --pad-x:   10mm;
  --bw:      0.25mm;   /* 表格線寬 */
  --row-h:   6.4mm;    /* 資訊列／處理項目列 */
  --part-h:  6.1mm;    /* 更換零件列 */
  --fs:      3.05mm;   /* 表單內文字級 */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, "Microsoft JhengHei",
               "PingFang TC", "Noto Sans TC", "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ── 上方工具列 ───────────────────────────────────────────── */

.appbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--appbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  padding-top: env(safe-area-inset-top);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 3px rgba(22, 32, 42, .06);
}

.appbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
}
.appbar-brand img { height: 24px; width: auto; display: block; }

.seg {
  display: flex;
  margin-left: auto;
  background: #e7ebef;
  border-radius: 999px;
  padding: 3px;
}
.seg-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.seg-btn.is-on {
  background: var(--surface);
  color: var(--brand-dark);
  box-shadow: 0 1px 3px rgba(22, 32, 42, .18);
}

.appbar-tools { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }

.save-hint {
  font-size: 12px;
  color: var(--ink-3);
  white-space: nowrap;
}

@media (max-width: 420px) {
  .appbar { gap: 8px; padding: 0 10px; }
  .appbar-brand .brand-text { display: none; }
  .seg-btn { padding: 7px 11px; }
}

.ghost-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  font: inherit;
  font-size: 14px;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.ghost-btn:hover { border-color: var(--ink-3); }

.main { flex: 1 1 auto; min-height: 0; }

.view { display: none; }
.view.is-on { display: block; }

/* ── 填寫模式 ─────────────────────────────────────────────── */

#viewFill {
  max-width: 720px;
  margin: 0 auto;
  padding: 14px 12px calc(var(--actionbar-h) + 24px);
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 16px 4px;
  margin-bottom: 14px;
}

.card-h {
  margin: 0 0 14px;
  font-size: 16px;
  font-weight: 700;
  color: var(--brand-dark);
  letter-spacing: .01em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-h::before {
  content: "";
  width: 4px;
  height: 16px;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--brand), var(--brand-blue));
}

.field { margin-bottom: 16px; }

.field > label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 6px;
}

/* 涵蓋 .field 與動態產生的 .item-card 兩種容器 —— 兩者都在 .card 裡 */
.card input[type="text"],
.card input[type="tel"],
.card input[type="date"],
.card input[type="datetime-local"],
.card input[type="number"],
.card textarea {
  width: 100%;
  font: inherit;
  font-size: 18px;
  line-height: 1.45;
  color: var(--ink);
  background: #fbfcfd;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 12px;
  min-height: 48px;
  resize: none;
  overflow: hidden;
}
.card textarea { line-height: 1.5; }

.card input:focus,
.card textarea:focus {
  outline: none;
  border-color: var(--focus);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(47, 163, 107, .16);
}

.inline { display: flex; gap: 8px; align-items: stretch; }
.inline input { flex: 1 1 auto; }

.mini-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--brand-dark);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 0 14px;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
}
.mini-btn:hover { border-color: var(--brand); }

/* 選項 chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  appearance: none;
  font: inherit;
  font-size: 16px;
  padding: 11px 16px;
  min-height: 46px;
  border: 1px solid var(--line);
  background: #fbfcfd;
  color: var(--ink-2);
  border-radius: 10px;
  cursor: pointer;
}
.chip:hover { border-color: var(--ink-3); }
.chip.is-on {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  font-weight: 600;
}
.chip-extra { margin-top: 10px; }

/* 動態列表 */
.stack { display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }

.item-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: #fbfcfd;
}
.item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.item-no { font-size: 14px; font-weight: 700; color: var(--brand-dark); }
.item-sub { font-size: 13px; font-weight: 600; color: var(--ink-2); margin: 10px 0 5px; }
.item-card textarea,
.item-card input {
  background: var(--surface);
}

.del-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-3);
  font: inherit;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.del-btn:hover { color: var(--danger); border-color: var(--danger); }
/* 只剩一張卡時不給刪 —— 表單至少要有一列 */
#fillItems .item-card:only-child .del-btn,
#fillParts .item-card:only-child .del-btn { display: none; }

.part-grid { display: grid; grid-template-columns: 1fr 1fr 88px; gap: 8px; }
.part-grid > div > span {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 5px;
}
@media (max-width: 480px) {
  .part-grid { grid-template-columns: 1fr; }
}

.row-btns { margin-bottom: 16px; }
.add-btn {
  appearance: none;
  width: 100%;
  border: 1px dashed var(--brand);
  background: rgba(47, 163, 107, .06);
  color: var(--brand-dark);
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  padding: 13px;
  border-radius: 10px;
  cursor: pointer;
}
.add-btn:hover { background: rgba(47, 163, 107, .12); }

/* 簽名按鈕 */
.sign-pad-btn {
  appearance: none;
  width: 100%;
  height: 120px;
  border: 1px dashed var(--ink-3);
  border-radius: 10px;
  background: #fbfcfd;
  color: var(--ink-3);
  font: inherit;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
}
.sign-pad-btn:hover { border-color: var(--brand); color: var(--brand-dark); }
.sign-pad-btn.has-sign { border-style: solid; border-color: var(--line); background: var(--surface); }
.sign-pad-btn .sign-img { max-height: 100%; max-width: 100%; object-fit: contain; }

.fill-note {
  font-size: 13px;
  line-height: 1.7;
  color: var(--ink-3);
  margin: 4px 4px 0;
}

/* ── 整頁模式 ─────────────────────────────────────────────── */

#viewPage { padding-bottom: calc(var(--actionbar-h) + 20px); }

.page-toolbar {
  position: sticky;
  top: calc(var(--appbar-h) + env(safe-area-inset-top));
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: rgba(238, 241, 244, .94);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}

.zoom { display: flex; background: #e0e5ea; border-radius: 8px; padding: 2px; }
.zoom-btn {
  appearance: none;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  padding: 6px 11px;
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
}
.zoom-btn.is-on { background: var(--surface); color: var(--brand-dark); }

.page-tip { font-size: 12px; color: var(--ink-3); }
@media (max-width: 560px) { .page-tip { display: none; } }

.page-viewport {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 16px 12px 0;
  -webkit-overflow-scrolling: touch;
}

.page {
  width: var(--pw);
  min-height: var(--ph);
  padding: 10mm var(--pad-x) 8mm;
  background: #fff;
  color: #000;
  transform-origin: top left;
  box-shadow: 0 2px 14px rgba(22, 32, 42, .16);
  display: flex;
  flex-direction: column;
  font-size: var(--fs);
  line-height: 1.32;
}

/* 頁首 */
.p-head {
  height: 14mm;
  margin-bottom: 3mm;
  display: flex;
  align-items: center;
  position: relative;
  flex: 0 0 auto;
}
.p-logo { height: 14mm; width: auto; display: block; }
.p-title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 58mm;
  height: 10.7mm;
  border: 0.3mm solid #000;
  border-radius: 3mm;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 5.4mm;
  letter-spacing: .04em;
}

/* 表格骨架 */
.grid {
  border-top: var(--bw) solid #000;
  border-left: var(--bw) solid #000;
}
.r { display: flex; }
.c {
  border-right: var(--bw) solid #000;
  border-bottom: var(--bw) solid #000;
  padding: 0.9mm 1.4mm;
  min-height: var(--row-h);
  display: flex;
  align-items: center;
  gap: 1.2mm;
  min-width: 0;
  overflow: hidden;
}
.lb { font-style: normal; white-space: nowrap; flex: 0 0 auto; }
.ta-c { justify-content: center; }

/* 可編輯欄位 */
.f {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 4mm;
  outline: none;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  cursor: text;
}
.f:focus { background: rgba(47, 163, 107, .10); }
.f.is-empty::before {
  content: attr(data-ph);
  color: #c3ccd4;
}
.exporting .f:focus { background: transparent; }
.exporting .f.is-empty::before { content: ""; }

.f-other { flex: 0 1 22mm; border-bottom: var(--bw) dotted #999; }
.exporting .f-other { border-bottom-color: transparent; }

/* 勾選框 */
.ck {
  display: inline-flex;
  align-items: center;
  gap: 0.8mm;
  margin-right: 1.6mm;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  flex: 0 0 auto;
}
.ck .bx {
  width: 2.9mm;
  height: 2.9mm;
  border: 0.25mm solid #000;
  display: inline-block;
  position: relative;
  flex: 0 0 auto;
}
.ck.is-on .bx::after {
  content: "";
  position: absolute;
  left: 0.85mm;
  top: 0.15mm;
  width: 0.9mm;
  height: 1.9mm;
  border: solid #000;
  border-width: 0 0.4mm 0.4mm 0;
  transform: rotate(42deg);
}

/* 本文區 */
.body-grid { margin-top: 2.5mm; display: flex; flex-direction: column; }
.r-case .c { flex: 1 1 100%; min-height: 12.7mm; align-items: flex-start; }
.f-case { min-height: 10mm; }
.r-sub .c { min-height: var(--row-h); }
.rows { display: flex; flex-direction: column; }

.r-item .c { align-items: flex-start; }
.item-idx { flex: 0 0 5mm; }
.filler .c { min-height: var(--row-h); cursor: cell; }
.filler:hover .c { background: rgba(47, 163, 107, .07); }
.exporting .filler:hover .c { background: transparent; }

/* 頁尾區塊 */
.foot-grid { display: flex; align-items: stretch; margin-top: 1mm; flex: 0 0 auto; }
.foot-left  { flex: 0 0 50%; min-width: 0; }
.foot-right { flex: 1 1 auto; min-width: 0; }
.foot-left  > .grid,
.foot-right > .grid { height: 100%; display: flex; flex-direction: column; }
.foot-left  > .grid { border-right: 0; }
.foot-right > .grid { border-left: 0; }
.foot-left  .rows   { flex: 1 1 auto; }
.foot-right .r-sign { flex: 1 1 auto; }

.r-part .c { min-height: var(--part-h); }
.r-memo .c { flex: 1 1 100%; min-height: 18.6mm; align-items: flex-start; }
.f-memo { min-height: 15mm; }

.r-sign .c { min-height: 36.4mm; align-items: stretch; }
.sign-cell {
  flex-direction: column;
  gap: 0;
  cursor: pointer;
  position: relative;
}
.sign-cell:hover { background: rgba(47, 163, 107, .06); }
.exporting .sign-cell:hover { background: transparent; }
.sign-slot {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 0.5mm 0;
}
.sign-slot .sign-img { max-height: 100%; max-width: 100%; object-fit: contain; }
.sign-date {
  display: flex;
  align-items: center;
  gap: 1.2mm;
  flex: 0 0 auto;
  min-height: 4.6mm;
}

.p-foot {
  margin-top: auto;
  padding-top: 3mm;
  text-align: center;
  font-size: 3.2mm;
}

/* 頁尾公司名＝官網連結。維持紙本外觀（同色同字級），只加一條淡底線讓人看得出可點；
   列印時（見 @media print）拿掉底線，印出來的紙本才跟原範本一致。 */
.p-foot-link {
  color: inherit;
  text-decoration: none;
  border-bottom: 0.2mm solid rgba(0, 0, 0, .38);
}
.p-foot-link:hover,
.p-foot-link:focus-visible { color: var(--brand-dark); border-bottom-color: currentColor; }

/* ── 下方動作列 ───────────────────────────────────────────── */

.actionbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  height: calc(var(--actionbar-h) + env(safe-area-inset-bottom));
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  display: flex;
  gap: 10px;
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
}

.btn {
  appearance: none;
  flex: 1 1 0;
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 10px;
  padding: 12px;
  cursor: pointer;
  min-height: 44px;
}
.btn:hover { border-color: var(--ink-3); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn-primary {
  background: linear-gradient(180deg, var(--brand), var(--brand-dark));
  border-color: var(--brand-dark);
  color: #fff;
}
.btn-primary:hover { filter: brightness(1.05); }

/* ── 簽名板 ───────────────────────────────────────────────── */

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(16, 24, 32, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}
.modal[hidden] { display: none; }

.modal-box {
  background: var(--surface);
  border-radius: 14px;
  width: min(760px, 100%);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { margin: 0; font-size: 17px; }

.sign-wrap {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfcfd;
  height: min(46vh, 320px);
  overflow: hidden;
}
#signCanvas { display: block; width: 100%; height: 100%; touch-action: none; }
.sign-guide {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  color: #c3ccd4;
  font-size: 17px;
}
.sign-wrap.has-ink .sign-guide { display: none; }

.modal-foot { display: flex; gap: 10px; }

/* ── 提示 ─────────────────────────────────────────────────── */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--actionbar-h) + 18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 70;
  background: rgba(22, 32, 42, .94);
  color: #fff;
  font-size: 14px;
  padding: 10px 16px;
  border-radius: 999px;
  max-width: 90vw;
  text-align: center;
}
.toast[hidden] { display: none; }

/* ── 列印（整頁模式可直接列印）───────────────────────────── */

@media print {
  @page { size: A4 portrait; margin: 0; }
  html, body { background: #fff; height: auto; }
  .app { min-height: 0; display: block; }   /* 100dvh 會把版面撐成整頁高，列印時多出一頁 */
  .appbar, .actionbar, .page-toolbar, .modal, .toast, #viewFill { display: none !important; }
  #viewPage { display: block !important; padding: 0; }
  /* applyZoom() 會寫行內 height（頁高＋邊距），行內樣式蓋過樣式表，列印時會溢頁 */
  .page-viewport { overflow: visible; padding: 0; height: auto !important; }
  /* 瀏覽器列印時，min-height 剛好 297mm 會因為次像素進位溢到第二頁。
     空白列已把內容補到 296.5mm 以內，這裡把下限調低一點就會剛好一頁。 */
  .page { transform: none !important; box-shadow: none; margin: 0; min-height: 296mm; }
  .p-foot-link { border-bottom: 0; }   /* 印出來要跟紙本一致，不留連結痕跡 */
  .f.is-empty::before { content: ""; }
  .f-other { border-bottom-color: transparent; }
}


/* ============================================================
   v2 外殼 — 四個分頁、清單、挑選器
   沿用上面 v1 的設計語彙與色票，報告編輯器內部樣式完全不動。
   ============================================================ */

/* ── 登入閘 ───────────────────────────────────────────────── */
.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(160deg, #f4f7f9, #e3eaef);
  overflow-y: auto;
}
.gate[hidden] { display: none; }
.gate-box {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: 16px;
  padding: 28px 24px 24px;
  box-shadow: 0 12px 40px rgba(22, 32, 42, .14);
}
.gate-logo { height: 34px; width: auto; display: block; margin: 0 auto 18px; }
.gate-title { margin: 0 0 6px; font-size: 20px; text-align: center; }
.gate-desc { margin: 0 0 18px; font-size: 13px; color: var(--ink-2); text-align: center; line-height: 1.6; }
.gate-fields { display: flex; flex-direction: column; gap: 12px; }
.gate-fields label { font-size: 13px; font-weight: 600; color: var(--ink-2); display: block; margin-bottom: 5px; }
.gate-fields input {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  font-size: 16px;                 /* 16px 以下 iOS 聚焦時會放大整頁 */
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
}
.gate-fields input:focus { outline: 2px solid var(--focus); outline-offset: -1px; }
.gate-err {
  margin: 14px 0 0;
  padding: 10px 12px;
  background: #fdecea;
  color: var(--danger);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.6;
}
.gate-submit { width: 100%; margin-top: 18px; min-height: 48px; font-size: 16px; }

/* ── 使用者選單 ───────────────────────────────────────────── */
.who-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  max-width: 170px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.who-btn:hover { border-color: var(--brand); color: var(--brand-dark); }
.menu {
  position: absolute;
  right: 12px;
  top: calc(var(--appbar-h) - 4px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(22, 32, 42, .16);
  padding: 6px;
  z-index: 60;
  min-width: 148px;
}
.menu[hidden] { display: none; }
.menu button {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 9px 12px;
  border-radius: 7px;
  font-size: 14px;
  color: var(--ink);
  cursor: pointer;
}
.menu button:hover { background: var(--bg); color: var(--brand-dark); }

/* ── 未掛登入保護／連線失敗的警告 ─────────────────────────── */
.auth-warn {
  background: var(--danger);
  color: #fff;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}

/* ── 分頁列 ───────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1 1 auto;
  justify-content: center;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  font-size: 15px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { color: var(--brand-dark); }
.tab.is-on { background: var(--brand); color: #fff; }

.who { font-size: 12px; color: var(--ink-3); max-width: 160px; overflow: hidden;
       text-overflow: ellipsis; white-space: nowrap; }

/* ── 分頁畫面 ─────────────────────────────────────────────── */
.screen { display: none; padding: 14px 12px 28px; max-width: 1100px; margin: 0 auto; }
.screen.is-on { display: block; }

/* 編輯器蓋在最上層：它自己有工具列，不需要外層 appbar */
.screen.editor.is-on {
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--bg);
  padding: 0;
  max-width: none;
}
.editor-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding-bottom: var(--actionbar-h); }

.editor-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 2;
}
.editor-title { font-weight: 700; font-size: 15px; white-space: nowrap;
                overflow: hidden; text-overflow: ellipsis; }
.editor-bar .seg { margin-left: auto; }

/* ── 工具列與搜尋 ─────────────────────────────────────────── */
.toolbar { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.search {
  flex: 1 1 240px;
  min-height: 44px;
  padding: 0 14px;
  font-size: 16px;              /* 16px 以下 iOS 會自動放大頁面 */
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}
.search:focus { outline: 2px solid var(--focus); outline-offset: -1px; }

/* ── 清單 ─────────────────────────────────────────────────── */
.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.row:hover { border-color: var(--brand); }
.row.is-on { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(47,163,107,.18); }
.row-main { flex: 1 1 auto; min-width: 0; }
.row-title { font-weight: 700; font-size: 15px; }
.row-sub { font-size: 13px; color: var(--ink-2); margin-top: 3px;
           display: flex; flex-wrap: wrap; gap: 4px 12px; }
.row-actions { display: flex; gap: 6px; flex: 0 0 auto; }
.list-compact .row { padding: 9px 12px; }

.pill { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px;
        background: var(--bg); color: var(--ink-2); }
.pill.draft { background: #fdf0d5; color: #8a6100; }
.pill.final { background: #e2f4ea; color: var(--brand-dark); }

.empty { color: var(--ink-3); font-size: 14px; padding: 22px 4px; text-align: center; }

/* ── 客戶頁的兩欄 ─────────────────────────────────────────── */
.split { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
@media (min-width: 900px) { .split { grid-template-columns: minmax(0, 380px) minmax(0, 1fr); } }
.detail { background: var(--surface); border: 1px solid var(--line);
          border-radius: var(--radius); padding: 14px 16px; }
.detail h3 { margin: 16px 0 8px; font-size: 14px; color: var(--ink-2);
             text-transform: uppercase; letter-spacing: .04em; }
.detail h3:first-child { margin-top: 0; }
.detail-head { display: flex; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.detail-name { font-size: 19px; font-weight: 700; flex: 1 1 auto; }

/* ── 新建報告的三個選項 ───────────────────────────────────── */
.choice-grid { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 760px) { .choice-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.choice {
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 132px;
}
.choice:hover { border-color: var(--brand); }
.choice-title { font-size: 17px; font-weight: 700; color: var(--brand-dark); }
.choice-desc { font-size: 13px; color: var(--ink-2); line-height: 1.6; }

.hint-block { margin-top: 16px; font-size: 13px; color: var(--ink-3); line-height: 1.7; }

/* ── 挑選器與表單彈窗 ─────────────────────────────────────── */
.modal-wide .modal-box, .modal-box.modal-wide { max-width: 640px; }
.modal-body { padding: 14px 16px; overflow-y: auto; }
.modal-body .search { width: 100%; margin-bottom: 10px; }
.modal-body .list { max-height: 52vh; overflow-y: auto; }

.form-grid { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 560px) { .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.form-grid .f-wide { grid-column: 1 / -1; }
.form-grid label { display: block; font-size: 13px; font-weight: 600;
                   color: var(--ink-2); margin-bottom: 5px; }
.form-grid input, .form-grid textarea, .form-grid select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  font-size: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
}
.form-grid textarea { min-height: 84px; resize: vertical; }
.form-grid input:focus, .form-grid textarea:focus, .form-grid select:focus { outline: 2px solid var(--focus); outline-offset: -1px; }

.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.spacer { flex: 1 1 auto; }

.lbl-short { display: none; }

/* 編輯器工具列在手機上放不下一排：儲存鈕會被推到畫面外、標題被壓成 0 寬。
   ⚠️ 頁面層級的 scrollWidth 完全看不出這件事（沒把頁面撐寬），只有逐一量
   每個子元件的 right、再用 elementFromPoint 做 hit-test 才抓得到。
   收成兩排；標題用 flex-basis:0 才會「縮到剩多少就用多少」而不是要求內容寬度
   —— 用 auto 會把儲存鈕擠到下一行，變成四排、吃掉四分之一螢幕。 */
@media (max-width: 620px) {
  .editor-bar { flex-wrap: wrap; row-gap: 8px; }
  .lbl-long { display: none; }
  .lbl-short { display: inline; }

  /* 第一排：返回 ｜ 標題 ｜ 未存 ｜ 儲存 */
  #edBack { order: 1; flex: 0 0 auto; }
  .editor-title {
    order: 2;
    flex: 1 1 0;            /* 0 而非 auto：讓它讓位給右邊的鈕 */
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #saveHint { order: 3; flex: 0 0 auto; }
  #edSave { order: 4; flex: 0 0 auto; }

  .editor-bar::after { content: ""; flex-basis: 100%; height: 0; order: 5; }  /* 強制換行 */

  /* 第二排：客戶 ｜ ＋下一趟 ｜（推到右）模式切換 */
  #edPickCustomer { order: 6; }
  #edNextVisit { order: 7; }
  .editor-bar .seg { order: 8; margin-left: auto; }
}

@media (max-width: 560px) {
  .appbar-brand .brand-text, .who { display: none; }
  .tabs { justify-content: flex-start; }
  .tab { padding: 8px 11px; font-size: 14px; }
}

/* ── 列印：外殼一律不印，只留 A4 那一頁 ───────────────────── */
@media print {
  .tabs, .editor-bar, .auth-warn, .toolbar, .pickModal, #pickModal, #formModal { display: none !important; }
  /* 編輯器在螢幕上是 fixed 覆蓋層；列印時要退回一般流，否則只印得到一個視窗高度 */
  .screen.editor.is-on { position: static; inset: auto; display: block; z-index: auto; }
  .editor-body { overflow: visible; padding-bottom: 0; }
  .screen { display: none !important; padding: 0; max-width: none; }
  .screen.editor.is-on { display: block !important; }
}
