/* 富寓室內裝潢公司報價單 ── 樣式 */

:root {
  --primary: #1e3a5f;        /* 深藍 ── 公司主色 */
  --primary-light: #2a4d7c;
  --accent: #c89b3c;          /* 金 ── 強調色 */
  --bg: #f5f5f0;
  --paper: #ffffff;
  --text: #2c2c2c;
  --text-muted: #6b6b6b;
  --border: #d4d4d4;
  --table-header: #e8eef5;
  --table-row-alt: #fafbfc;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Helvetica Neue', 'PingFang TC', 'Microsoft JhengHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 14px;
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

/* === Toolbar === */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--paper);
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.toolbar-hint {
  width: 100%;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  font-size: 12px;
  line-height: 1.5;
  color: #888;
}

.toolbar-hint strong {
  color: #b45309;
}

.cloud-who {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #555;
}

/* 帳號 chip（已登入） */
.cloud-who-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  max-width: 220px;
}
.cloud-who-btn > span:nth-child(2) {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ===== 家群品牌登入頁 ===== */
.login-overlay, .account-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(20, 28, 40, 0.55);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
/* 強制登入閘門：整頁實心品牌背景，蓋住底下所有內容 */
.login-gate {
  z-index: 2000;
  background: linear-gradient(150deg, #20344d 0%, #2e4a6b 55%, #3a5c86 100%);
  backdrop-filter: none;
}
.login-h {
  font-size: 15px; font-weight: 700; color: #2e4a6b;
  margin: 2px 0 14px; letter-spacing: 1px;
}
.caret { color: #aab; }

/* 啟動載入畫面 */
.boot-splash {
  position: fixed; inset: 0; z-index: 2100;
  background: linear-gradient(150deg, #20344d, #2e4a6b);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; color: #fff;
}
.boot-splash .login-logo { width: 64px; height: 64px; font-size: 32px; border-radius: 16px; }
.boot-name { font-size: 18px; font-weight: 700; letter-spacing: 2px; }
.boot-dots { font-size: 13px; color: #b9c6d6; }
.login-card {
  position: relative;
  width: 100%; max-width: 380px;
  background: #fff; border-radius: 16px;
  padding: 34px 30px 24px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.35);
  text-align: center;
}
.login-close {
  position: absolute; top: 12px; right: 14px;
  border: none; background: none; color: #aaa;
  font-size: 18px; cursor: pointer; line-height: 1;
}
.login-close:hover { color: #555; }
.login-brand {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  margin-bottom: 6px;
}
.login-logo {
  width: 52px; height: 52px; border-radius: 13px;
  background: linear-gradient(135deg, #2e4a6b, #4a6fa0);
  color: #fff; font-size: 26px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 16px rgba(46,74,107,0.4);
}
.login-wordmark { text-align: left; }
.lw-cn { font-size: 21px; font-weight: 800; color: #1f2d3d; letter-spacing: 1px; display: flex; align-items: baseline; gap: 7px; }
.lw-sys { font-size: 13px; font-weight: 600; color: #6b7a8d; letter-spacing: 0; }
.lw-en { font-size: 11px; letter-spacing: 4px; color: #9aa7b4; font-weight: 600; }
.login-tagline { font-size: 12px; color: #8a96a3; margin: 4px 0 22px; }

.login-form { display: flex; flex-direction: column; gap: 12px; text-align: left; }
.login-field { display: flex; flex-direction: column; gap: 5px; }
.login-field > span { font-size: 12px; color: #6b7a8d; font-weight: 600; }
.login-field input {
  border: 1px solid #d7dde5; border-radius: 9px;
  padding: 11px 13px; font-size: 14px; color: #1f2d3d;
  font-family: inherit; transition: border-color .15s, box-shadow .15s;
}
.login-field input:focus {
  outline: none; border-color: #2e4a6b;
  box-shadow: 0 0 0 3px rgba(46,74,107,0.12);
}
.login-err {
  background: #fdecec; color: #c0392b; border: 1px solid #f5c6c6;
  border-radius: 8px; padding: 8px 11px; font-size: 12.5px;
}
.login-btn {
  margin-top: 4px; border: none; cursor: pointer;
  background: linear-gradient(135deg, #2e4a6b, #3f6092);
  color: #fff; font-weight: 700; font-size: 15px;
  padding: 12px; border-radius: 10px;
  transition: filter .15s;
}
.login-btn:hover { filter: brightness(1.08); }
.login-btn:disabled { opacity: .6; cursor: default; }
.login-link {
  border: none; background: none; cursor: pointer;
  color: #4a6fa0; font-size: 12.5px; padding: 4px; text-decoration: underline;
}
.login-link:disabled { opacity: .5; cursor: default; }
.login-foot {
  margin-top: 20px; padding-top: 14px; border-top: 1px solid #eef1f4;
  font-size: 11.5px; color: #9aa7b4;
}
.login-foot strong { color: #6b7a8d; }

/* ===== 帳號管理面板 ===== */
.account-card {
  width: 100%; max-width: 380px;
  background: #fff; border-radius: 16px; overflow: hidden;
  box-shadow: 0 24px 60px rgba(0,0,0,0.35);
}
.account-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; border-bottom: 1px solid #eef1f4;
  font-size: 15px;
}
.account-id {
  display: flex; align-items: center; gap: 14px;
  padding: 20px 18px; background: #f6f8fb;
}
.account-avatar {
  width: 48px; height: 48px; border-radius: 12px;
  background: linear-gradient(135deg, #2e4a6b, #4a6fa0);
  display: flex; align-items: center; justify-content: center; font-size: 24px;
}
.account-email { font-weight: 700; color: #1f2d3d; word-break: break-all; }
.account-role { font-size: 12.5px; color: #4a6fa0; margin-top: 2px; font-weight: 600; }
.account-rows { padding: 6px 18px; }
.account-row {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-bottom: 1px dotted #e6eaef; font-size: 13px;
}
.account-row:last-child { border-bottom: none; }
.account-row > span:first-child { color: #8a96a3; }
.account-row > span:last-child { color: #1f2d3d; font-weight: 600; text-align: right; }
.account-actions { display: flex; gap: 10px; padding: 14px 18px; }
.account-actions .btn { flex: 1; justify-content: center; }
.account-foot {
  padding: 12px 18px; background: #f6f8fb; border-top: 1px solid #eef1f4;
  font-size: 11.5px; color: #9aa7b4; text-align: center;
}
.account-foot strong { color: #6b7a8d; }

.toolbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: var(--paper);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  transition: all .15s;
}
.btn .ic {
  width: 17px; height: 17px;
  flex: 0 0 auto;
  display: block;
}
.btn:hover { background: #f0f0ed; }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-light); }
.btn-accent { background: var(--accent); color: white; border-color: var(--accent); }
.btn-danger { color: #c44; }

/* ===== 輸出檔案下拉選單 ===== */
.btn-menu { position: relative; display: inline-flex; }
.btn-menu > .btn.is-open { background: #f0f0ed; }
.btn-menu .caret { margin-left: 2px; font-size: 11px; }
.btn-menu-list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 50;
  min-width: 180px;
  padding: 6px;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.14);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.btn-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  border: none;
  background: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  text-align: left;
  transition: background .12s;
}
.btn-menu-item:hover { background: #f0f0ed; }
.btn-menu-item .ic { width: 17px; height: 17px; flex: 0 0 auto; }
.btn-menu-sep { height: 1px; margin: 4px 6px; background: var(--border); }

/* ===== 清空區（全頁最下面） ===== */
.clear-zone {
  margin: 12px auto 4px;
  padding: 0 4px;
  text-align: center;
}
.clear-zone .btn-danger {
  border-color: #eecccc;
  background: #fff;
}
.clear-zone .btn-danger:hover { background: #fdf2f2; }

/* === Paper (報價單版面) === */
.paper {
  background: var(--paper);
  padding: 32px 40px;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  min-height: 1000px;
}

.header {
  display: grid;
  grid-template-columns: 100px 1fr 100px;
  align-items: center;
  border-bottom: 2px solid var(--primary);
  padding-bottom: 16px;
  margin-bottom: 24px;
  gap: 16px;
}
.header .logo {
  width: 100px;
  height: auto;
  object-fit: contain;
}
.header-text { text-align: center; }
.header-spacer { /* keep grid symmetry */ }
.header h1 {
  margin: 0;
  font-size: 24px;
  color: var(--primary);
  letter-spacing: 4px;
}
.header .company-en {
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--accent);
  letter-spacing: 2px;
  text-transform: uppercase;
}
.header .company-tagline {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 1px;
}
.header h2 {
  margin: 6px 0 0;
  font-size: 18px;
  color: var(--text-muted);
  letter-spacing: 8px;
  font-weight: normal;
}

/* === 檢視控制（分組方式 / 樓層篩選） === */
.view-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 16px 0 4px;
  padding: 8px 12px;
  background: #f0f4f9;
  border-radius: 6px;
  font-size: 13px;
}
.view-controls .vc-label { font-weight: 600; color: var(--text-muted); }
.view-controls select {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  background: white;
}
.view-controls .vc-hint { color: var(--accent); font-size: 12px; }

/* === Info Grid (工程/客戶資料) === */
.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 24px;
  margin-bottom: 24px;
}
.info-row {
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px dotted var(--border);
  padding: 6px 0;
}
.info-row label {
  font-weight: 600;
  color: var(--text-muted);
  min-width: 80px;
  flex-shrink: 0;
}
.info-row input, .info-row textarea {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 14px;
  padding: 2px 4px;
  color: var(--text);
  font-family: inherit;
}
.info-row input:focus, .info-row textarea:focus {
  outline: 1px dashed var(--primary);
  background: #fffae0;
}

/* === Item Table === */
.section-title {
  margin: 24px 0 8px;
  padding: 8px 12px;
  background: var(--table-header);
  border-left: 4px solid var(--primary);
  font-weight: 600;
  font-size: 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.section-title .subtotal {
  font-size: 14px;
  color: var(--primary);
  font-weight: 600;
}

table.items {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 8px;
  font-size: 13px;
  table-layout: fixed;
}
table.items th, table.items td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  vertical-align: middle;
}
table.items th {
  background: var(--table-header);
  font-weight: 600;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}
table.items td input,
table.items td select,
table.items td textarea {
  width: 100%;
  border: none;
  background: transparent;
  font-size: 13px;
  font-family: inherit;
  padding: 2px;
}
table.items td input:focus, table.items td select:focus, table.items td textarea:focus {
  outline: 1px dashed var(--primary);
  background: #fffae0;
}
table.items td input[type=number] { text-align: right; }
/* 項目與備註用 textarea：文字完整換行、依內容自動長高 */
table.items td textarea {
  resize: vertical;
  field-sizing: content;
  min-height: 1.7em;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: hidden;
}
table.items tr:nth-child(even) td { background: var(--table-row-alt); }
table.items td { vertical-align: top; }
table.items .col-floor { width: 58px; }
table.items .col-name { width: 150px; }
table.items .col-unit { width: 52px; }
table.items .col-qty { width: 56px; }
table.items .col-price { width: 78px; }
table.items .col-idx-cell { text-align: center; color: var(--text-muted); font-size: 13px; vertical-align: middle; }
table.items .col-subtotal { width: 92px; text-align: right; font-weight: 600; }
table.items .col-action { width: 132px; text-align: center; }
table.items td.col-action { padding: 4px 6px; }
.act-group { display: flex; gap: 4px; justify-content: center; }
.act-btn {
  width: 26px; height: 28px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; line-height: 1;
  border: 1px solid var(--border); background: var(--paper);
  border-radius: 6px; cursor: pointer; color: var(--text);
  flex: 0 0 auto; transition: background .15s;
}
.act-btn:hover { background: #eef2f7; }
.act-del { color: #c0392b; border-color: #ecc6c6; }
.act-del:hover { background: #fdecec; }

/* 可調寬欄位標題 + 拖曳把手 */
table.items th { position: relative; }
table.items th.col-resizable { overflow: hidden; text-overflow: ellipsis; }
.col-resizer {
  position: absolute;
  top: 0;
  right: 0;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  user-select: none;
}
.col-resizer:hover { background: var(--primary); opacity: 0.45; }
/* 顯示欄位勾選 */
.col-toggle { margin-right: 12px; white-space: nowrap; font-size: 13px; cursor: pointer; }
.col-toggle input { vertical-align: middle; }
table.items .total-cell {
  text-align: right;
  padding-right: 8px;
  font-variant-numeric: tabular-nums;
}
.price-preview {
  width: 100%;
  min-height: 1.7em;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.add-row {
  display: flex;
  gap: 6px;
  margin: 8px 0 16px;
  padding: 8px;
  background: #f7f9fc;
  border-radius: 4px;
  align-items: center;
  flex-wrap: wrap;
}
.add-row select, .add-row input {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
}
.add-row select { min-width: 200px; }
.add-row .btn { padding: 6px 12px; }

/* === Summary === */
.summary {
  margin: 24px 0;
  padding: 16px 20px;
  background: linear-gradient(to right, #fffaec, #fff5d4);
  border-radius: 8px;
  border: 1px solid var(--accent);
}
.summary-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 14px;
}
.summary-row.total {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  border-top: 1px solid var(--accent);
  margin-top: 8px;
  padding-top: 8px;
}
.markup-panel {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px dashed rgba(200, 155, 60, .55);
}
.markup-panel select,
.markup-panel input[type=number] {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  background: white;
}
.markup-panel input[type=number] {
  width: 96px;
  text-align: right;
}
.markup-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  color: var(--primary);
}
.markup-total {
  margin-left: auto;
  font-weight: 700;
  color: var(--primary);
}

.payment-schedule {
  margin-top: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}
.payment-cell {
  padding: 10px;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 6px;
  text-align: center;
}
.payment-cell .label { font-size: 12px; color: var(--text-muted); }
.payment-cell .amount { font-size: 16px; font-weight: 700; color: var(--primary); margin-top: 4px; }

/* === Footer === */
.footer {
  margin-top: 32px;
}
.terms {
  background: #fafafa;
  padding: 16px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.7;
}
.terms ol { margin: 0; padding-left: 20px; }
.terms li { margin-bottom: 4px; }

.warranty { margin-top: 12px; }
.warranty > strong { display: block; margin-bottom: 6px; }
.warranty-cols { display: flex; gap: 12px; border: 1px solid #d6dde6; border-radius: 4px; overflow: hidden; background: #fff; }
.warranty-col { flex: 1; padding: 8px 12px; }
.warranty-col + .warranty-col { border-left: 1px solid #eee; }
.warranty-head { font-size: 12px; font-weight: 700; margin-bottom: 4px; }
.warranty-head.warranty-inc { color: #2e7d4a; }
.warranty-head.warranty-exc { color: #b23a3a; }
.warranty-col ul { margin: 0; padding-left: 16px; }
.warranty-col li { margin-bottom: 2px; }

.signature-area {
  margin-top: 24px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
.sig-block {
  border: 1px solid var(--border);
  padding: 16px;
  border-radius: 6px;
  min-height: 140px;
}
.sig-block h4 {
  margin: 0 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  color: var(--primary);
  font-size: 14px;
}
.sig-info { font-size: 12px; line-height: 1.8; }
.sig-info .row { display: flex; gap: 4px; }
.sig-info .key { color: var(--text-muted); min-width: 60px; }

.bank-selector {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}
.bank-selector select {
  padding: 2px 6px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: white;
}

/* === Lock 預覽模式 / 匯出（PDF·PNG）時切到乾淨檢視 === */
body.locked .no-print,
body.exporting .no-print { display: none !important; }
/* 但鎖定預覽時要保留「返回編輯」浮動鈕，否則無法解鎖 */
body.locked .unlock-fab { display: inline-flex !important; }
body.exporting .unlock-fab { display: none !important; }
body.locked ::placeholder,
body.exporting ::placeholder { color: transparent !important; }
body.locked .info-row input,
body.locked .info-row textarea,
body.locked table.items td input,
body.locked table.items td select,
body.locked table.items td textarea,
body.exporting .info-row input,
body.exporting .info-row textarea,
body.exporting table.items td input,
body.exporting table.items td select,
body.exporting table.items td textarea {
  outline: none;
  background: transparent !important;
  -webkit-appearance: none;
  appearance: none;
  pointer-events: none;
}
body.locked input[type=checkbox],
body.exporting input[type=checkbox] { pointer-events: none; }
body.locked .app { padding-top: 8px; }
body.exporting .col-resizer { display: none !important; }

.unlock-fab {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  padding: 10px 16px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 24px;
  font-size: 13px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  cursor: pointer;
}
.unlock-fab:hover { background: var(--primary-light); }

/* === 手機 RWD === */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

@media (max-width: 768px) {
  body { font-size: 13px; }
  .app { padding: 10px; }
  .paper { padding: 16px 14px; border-radius: 6px; min-height: auto; }

  /* Toolbar：標題置頂，按鈕橫向捲動 */
  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px 12px;
  }
  .toolbar-actions {
    flex-wrap: wrap;
    gap: 6px;
  }
  .toolbar-actions .btn {
    flex: 1 1 calc(50% - 3px);
    padding: 8px 6px;
    font-size: 12px;
    text-align: center;
  }
  .toolbar-actions .btn-menu { flex: 1 1 calc(50% - 3px); }
  .toolbar-actions .btn-menu > .btn { width: 100%; }
  .btn-menu-list { min-width: 200px; }
  .clear-zone .btn-danger { width: 100%; padding: 12px; }

  /* Header：縮小 logo 與字級 */
  .header {
    grid-template-columns: 56px 1fr 0;
    gap: 10px;
    padding-bottom: 10px;
    margin-bottom: 16px;
  }
  .header .logo { width: 56px; }
  .header-spacer { display: none; }
  .header h1 { font-size: 18px; letter-spacing: 2px; }
  .header h2 { font-size: 14px; letter-spacing: 4px; margin-top: 4px; }

  /* 工程/客戶資料：改單欄 */
  .info-grid {
    grid-template-columns: 1fr;
    gap: 6px;
    margin-bottom: 16px;
  }
  .info-row { padding: 4px 0; }
  .info-row label { min-width: 72px; font-size: 13px; }
  .info-row input { font-size: 13px; }

  /* 新增項目區：下拉全寬堆疊 */
  .add-row {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .add-row > * { width: 100%; }
  .add-row select,
  .add-row input { min-width: 0; }
  .add-row .btn { width: 100%; }

  /* 區段標題 */
  .section-title {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    font-size: 14px;
    padding: 8px 10px;
    margin: 16px 0 8px;
  }
  .section-title .subtotal { font-size: 13px; }

  /* 項目表：橫向捲動避免被擠爆 */
  .table-scroll {
    margin: 0 -14px 12px;          /* 撐滿 paper 邊到邊，捲動更直覺 */
    padding: 0 14px;
  }
  table.items {
    min-width: 720px;              /* 維持原本欄位寬比，超出就捲動 */
    font-size: 12px;
  }
  table.items th, table.items td { padding: 4px 6px; }

  /* 手機：填寫欄位加高加大好按（單價、數量、項目等） */
  table.items td input,
  table.items td select,
  table.items td textarea {
    font-size: 16px;      /* 字大好讀，iOS 聚焦時不自動放大頁面 */
    padding: 10px 8px;
    min-height: 44px;     /* 加大點擊區，手指好按 */
    line-height: 1.3;
  }
  table.items td input[type=number] { font-size: 16px; }
  /* 單價/數量欄位稍加寬，容納放大的數字 */
  table.items .col-price { width: 96px; }
  table.items .col-qty { width: 72px; }
  table.items { min-width: 760px; }

  /* 合計區 */
  .summary { padding: 12px 14px; }
  .summary-row { font-size: 13px; }
  .summary-row.total { font-size: 16px; }
  .payment-schedule {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  /* 簽章 */
  .signature-area {
    grid-template-columns: 1fr;
    gap: 14px;
  }
  .sig-block { min-height: auto; padding: 12px; }
  .sig-block h4 { font-size: 13px; }
  .sig-block h4 span[style*="float:right"] {
    float: none !important;
    display: block;
    margin-top: 4px;
  }
  .sig-info .key { min-width: 70px; }
  .bank-selector { display: block; margin-top: 4px; }
  .bank-selector select { width: 100%; margin-top: 2px; }

  /* 解鎖鈕貼右下 */
  .unlock-fab {
    top: auto;
    bottom: 16px;
    right: 16px;
    padding: 12px 18px;
  }
}

@media (max-width: 380px) {
  .paper { padding: 14px 10px; }
  .table-scroll { margin: 0 -10px 12px; padding: 0 10px; }
  .header h1 { font-size: 16px; letter-spacing: 1px; }
  .header h2 { font-size: 13px; letter-spacing: 3px; }
  .toolbar-actions .btn { font-size: 11px; }
}

/* === Print === */
@page {
  size: A4 portrait;
  margin: 12mm 14mm;
}

/* 共用列印樣式 ── 同時觸發於 @media print 與 body.printing（PDF 產生時）*/
@media print {
  body { background: white; font-size: 11px; }
  .app { max-width: 100%; padding: 0; margin: 0; }
  .toolbar, .no-print { display: none !important; }
  .paper {
    box-shadow: none;
    padding: 12mm 14mm;
    min-height: auto;
    border-radius: 0;
  }
  .header { grid-template-columns: 70px 1fr 70px; padding-bottom: 8px; margin-bottom: 12px; }
  .header .logo { width: 70px; }
  .header h1 { font-size: 18px; }
  .header h2 { font-size: 14px; }
  .add-row { display: none; }
  table.items th, table.items td {
    padding: 3px 6px;
    font-size: 10.5px;
  }
  .section-title { font-size: 12px; padding: 4px 8px; margin: 12px 0 4px; }
  .summary { padding: 8px 12px; margin: 12px 0; background: #fff8e0; }
  .payment-cell { padding: 6px; }
  .terms { font-size: 9.5px; padding: 8px; }
  .warranty { font-size: 9.5px; }
  .warranty-col { padding: 6px 8px; }
  .info-grid { gap: 4px 16px; margin-bottom: 12px; }
  .info-row { padding: 2px 0; }
  .signature-area { margin-top: 16px; gap: 16px; }
  .sig-block { padding: 10px; min-height: 100px; }
  input, select {
    -webkit-appearance: none;
    appearance: none;
    background: transparent !important;
  }
  .info-row input, .info-row textarea,
  table.items td input, table.items td select {
    border: none;
    outline: none;
  }
  table.items, tr { page-break-inside: avoid; }
  .section-title, .summary, .signature-area { page-break-inside: avoid; }
  ::placeholder { color: transparent; }
}

/* PDF 產生模式 ── 同樣的樣式，但用 class 觸發 */
body.printing { background: white; font-size: 11px; }
body.printing .app { max-width: 210mm; padding: 0; margin: 0; }
body.printing .toolbar,
body.printing .no-print { display: none !important; }
body.printing .paper {
  box-shadow: none;
  padding: 12mm 14mm;
  min-height: auto;
  border-radius: 0;
  width: 210mm;
}
body.printing .header { grid-template-columns: 70px 1fr 70px; padding-bottom: 8px; margin-bottom: 12px; }
body.printing .header .logo { width: 70px; }
body.printing .header h1 { font-size: 18px; }
body.printing .header h2 { font-size: 14px; }
body.printing .add-row { display: none; }
body.printing table.items th,
body.printing table.items td {
  padding: 3px 6px;
  font-size: 10.5px;
}
body.printing .section-title { font-size: 12px; padding: 4px 8px; margin: 12px 0 4px; }
body.printing .summary { padding: 8px 12px; margin: 12px 0; background: #fff8e0; }
body.printing .payment-cell { padding: 6px; }
body.printing .terms { font-size: 9.5px; padding: 8px; }
body.printing .warranty { font-size: 9.5px; }
body.printing .warranty-col { padding: 6px 8px; }
body.printing .info-grid { gap: 4px 16px; margin-bottom: 12px; }
body.printing .info-row { padding: 2px 0; }
body.printing .signature-area { margin-top: 16px; gap: 16px; }
body.printing .sig-block { padding: 10px; min-height: 100px; }
body.printing input,
body.printing select {
  -webkit-appearance: none;
  appearance: none;
  background: transparent !important;
}
body.printing .info-row input,
body.printing .info-row textarea,
body.printing table.items td input,
body.printing table.items td select {
  border: none;
  outline: none;
}
body.printing ::placeholder { color: transparent; }

/* ===== 雲端報價單清單 ===== */
[x-cloak] { display: none !important; }
.cloud-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0, 0, 0, .45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow: auto;
}
.cloud-panel {
  background: #fff; border-radius: 10px;
  width: 100%; max-width: 560px; padding: 18px 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
}
.cloud-panel-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px;
}
.cloud-list { width: 100%; border-collapse: collapse; }
.cloud-list td { padding: 10px 6px; border-bottom: 1px solid #eee; vertical-align: middle; }
.cloud-list tr.is-current { background: #fff8e1; }
.cloud-list .btn { margin-left: 4px; }
.cloud-search {
  width: 100%; box-sizing: border-box;
  padding: 8px 10px; margin: 4px 0 8px;
  border: 1px solid #ddd; border-radius: 6px; font-size: 14px;
}

/* ===== 報價設定編輯面板（請款分期／加項／違約金／條款）====== */
.qsettings { border:1px dashed #cbd5e1; border-radius:6px; padding:8px 10px; margin:8px 0; background:#f8fafc; }
.qsettings .qs-head { font-size:12px; font-weight:700; color:#2e4a6b; margin-bottom:6px; }
.qsettings .qs-row { display:flex; gap:6px; align-items:center; margin:4px 0; flex-wrap:wrap; }
.qsettings input[type=text], .qsettings input[type=number], .qsettings input[type=date] { border:1px solid #cbd5e1; border-radius:4px; padding:4px 6px; font-size:12px; }
.qsettings button { border:1px solid #cbd5e1; background:#fff; border-radius:4px; padding:3px 8px; font-size:12px; cursor:pointer; }
.qsettings .qs-add { color:#2e4a6b; border-color:#2e4a6b; font-weight:600; margin-top:4px; }
.qsettings .qs-del { color:#c0392b; border-color:#e2b3ad; }
.qsettings .qs-hint { font-size:11px; color:#8a94a3; }

/* ===== 平台訂閱管理中控台 ===== */
.admin-overlay { position:fixed; inset:0; background:#f4f6f9; z-index:2000; overflow:auto; }
.admin-panel { max-width:1100px; margin:0 auto; padding:20px 24px 60px; }
.admin-head { display:flex; align-items:center; gap:12px; padding:8px 0 14px; border-bottom:2px solid #2e4a6b; position:sticky; top:0; background:#f4f6f9; z-index:2; }
.admin-head strong { font-size:18px; color:#2e4a6b; }
.admin-count { font-size:13px; color:#888; }
.admin-msg { margin:12px 0; padding:10px 12px; background:#eef6ff; border:1px solid #cfe2f7; border-radius:6px; font-size:14px; color:#25507d; }
.admin-card { margin:14px 0; padding:14px 16px; background:#fff; border:1px solid #e2e8f0; border-radius:8px; }
.admin-card-title { font-weight:700; color:#2e4a6b; margin-bottom:10px; }
.admin-newco { display:flex; gap:8px; flex-wrap:wrap; }
.admin-newco input { flex:1; min-width:150px; padding:8px 10px; border:1px solid #cbd5e1; border-radius:6px; font-size:14px; }
.admin-hint { margin-top:8px; font-size:12px; color:#8a94a3; }
.admin-search { width:100%; margin:12px 0; padding:9px 12px; border:1px solid #cbd5e1; border-radius:6px; font-size:14px; box-sizing:border-box; }
.admin-loading { color:#c80; font-size:13px; margin:8px 0; }
.admin-table { width:100%; border-collapse:collapse; background:#fff; border:1px solid #e2e8f0; border-radius:8px; overflow:hidden; font-size:13px; }
.admin-table thead th { background:#2e4a6b; color:#fff; padding:9px 10px; text-align:left; font-weight:600; }
.admin-table td { padding:9px 10px; border-top:1px solid #eef0f3; vertical-align:middle; }
.admin-table tbody:hover td { background:#f8fafc; }
.admin-table .mono { font-family:ui-monospace,monospace; font-size:12px; color:#555; }
.admin-table .row-off td { opacity:.5; }
.sub-badge { display:inline-block; padding:2px 9px; border-radius:20px; font-size:12px; font-weight:600; }
.sub-active { background:#e3f6e8; color:#1f8a3b; } .sub-trialing { background:#e7f0ff; color:#2b6cb0; }
.sub-past_due { background:#fff2d9; color:#b7791f; } .sub-canceled { background:#f1f1f1; color:#999; } .sub-none { background:#f1f1f1; color:#999; }
.btn-sm { padding:4px 10px; font-size:12px; }
.btn-danger { color:#c0392b; border-color:#e2b3ad; }
.admin-edit-cell { background:#f8fafc; padding:14px 16px !important; }
.admin-edit-grid { display:grid; grid-template-columns:repeat(3,1fr); gap:8px 12px; }
.admin-edit-grid label { display:flex; flex-direction:column; font-size:12px; color:#556; gap:3px; }
.admin-edit-grid label.col2 { grid-column:span 2; }
.admin-edit-grid input { padding:6px 8px; border:1px solid #cbd5e1; border-radius:5px; font-size:13px; }
.admin-bank-title { margin:12px 0 6px; font-weight:600; color:#2e4a6b; font-size:13px; }
.admin-sub-row { display:flex; align-items:center; gap:8px; flex-wrap:wrap; margin:14px 0 6px; padding-top:12px; border-top:1px dashed #cbd5e1; font-size:13px; }
.admin-sub-row select, .admin-sub-row input { padding:6px 8px; border:1px solid #cbd5e1; border-radius:5px; font-size:13px; }
.admin-edit-actions { display:flex; gap:8px; margin-top:12px; }
@media (max-width:700px){ .admin-edit-grid{ grid-template-columns:1fr; } .admin-edit-grid label.col2{ grid-column:span 1; } }
