:root {
  --bg: #f6f2ec;
  --card: #ffffff;
  --ink: #2b2520;
  --muted: #857a70;
  --line: #e6ded3;
  --brand: #3d342c;
  --accent: #b5754c;
  --accent-soft: #f3e6dc;
  --danger: #c0473a;
  --ok: #4f7a52;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
  padding-bottom: calc(72px + var(--safe-b));
}
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; }

/* 頂部列 */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + var(--safe-t)) 12px 10px;
  background: var(--brand); color: #fff;
}
.topbar h1 { flex: 1; margin: 0; font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { background: none; border: 0; color: inherit; font-size: 30px; line-height: 1; padding: 0 8px 4px 0; cursor: pointer; }
#topActions { display: flex; gap: 6px; }
.top-btn { background: rgba(255,255,255,.14); border: 0; color: #fff; border-radius: 999px; padding: 6px 12px; font-size: 14px; cursor: pointer; }

/* 底部分頁 */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; background: #fff; border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  padding: 8px 0 6px; font-size: 12px; color: var(--muted); text-decoration: none;
}
.tabbar a span { font-size: 22px; line-height: 1.2; filter: grayscale(1); opacity: .6; }
.tabbar a.active { color: var(--accent); font-weight: 600; }
.tabbar a.active span { filter: none; opacity: 1; }

main { padding: 14px 14px 24px; max-width: 760px; margin: 0 auto; }

/* 通用元件 */
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(60,40,20,.06); }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 13px; }
.section-title { font-size: 14px; color: var(--muted); margin: 18px 4px 8px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty .big { font-size: 44px; margin-bottom: 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 600; cursor: pointer;
  background: var(--accent); color: #fff; text-decoration: none;
}
.btn.block { width: 100%; }
.btn.ghost { background: var(--accent-soft); color: var(--accent); }
.btn.line { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: #fbe9e7; color: var(--danger); }
.btn.sm { padding: 7px 12px; font-size: 14px; border-radius: 10px; }
.btn-row { display: flex; gap: 8px; }
.btn-row > * { flex: 1; }

.fab {
  position: fixed; right: 18px; bottom: calc(84px + var(--safe-b)); z-index: 15;
  width: 58px; height: 58px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; font-size: 30px; line-height: 1;
  box-shadow: 0 6px 16px rgba(181,117,76,.4); cursor: pointer;
}

label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=tel], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
  font-size: 16px; /* 避免 iOS 自動放大 */
}
textarea { min-height: 72px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 12px; font-size: 14px; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }

.search { position: relative; margin-bottom: 10px; }
.search input { padding-left: 36px; }
.search::before { content: "🔍"; position: absolute; left: 11px; top: 50%; transform: translateY(-50%); font-size: 15px; opacity: .55; }

/* 清單 */
.list-item { display: flex; gap: 12px; align-items: center; background: var(--card); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; text-decoration: none; color: inherit; box-shadow: 0 1px 2px rgba(60,40,20,.06); cursor: pointer; }
.thumb { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; background: var(--accent-soft); flex: none; display: flex; align-items: center; justify-content: center; font-size: 26px; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.li-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.price { font-weight: 700; color: var(--accent); white-space: nowrap; }
.badge { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); margin-right: 4px; }
.badge.gray { background: #eee8e1; color: var(--muted); }
.badge.ok { background: #e4efe4; color: var(--ok); }

/* 帶客品項 */
.room-head { display: flex; justify-content: space-between; align-items: baseline; margin: 16px 4px 8px; font-weight: 700; }
.item-card { background: var(--card); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; box-shadow: 0 1px 2px rgba(60,40,20,.06); }
.item-photos { display: flex; gap: 6px; overflow-x: auto; margin-top: 10px; }
.item-photos img { width: 76px; height: 76px; object-fit: cover; border-radius: 8px; flex: none; }
.stars { color: #e0a33b; letter-spacing: 1px; }

.photo-strip { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.photo-strip .ph { position: relative; width: 84px; height: 84px; }
.photo-strip .ph img { width: 100%; height: 100%; object-fit: cover; border-radius: 10px; }
.photo-strip .ph button { position: absolute; top: -6px; right: -6px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: var(--ink); color: #fff; font-size: 14px; line-height: 24px; padding: 0; cursor: pointer; }
.add-photo { width: 84px; height: 84px; border-radius: 10px; border: 2px dashed var(--line); background: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 12px; color: var(--muted); cursor: pointer; }
.add-photo b { font-size: 24px; line-height: 1.1; }

.suggest { border: 1px solid var(--line); border-radius: 10px; margin: -6px 0 12px; overflow: hidden; background: #fff; }
.suggest .s-item { display: flex; gap: 10px; align-items: center; padding: 8px; border-bottom: 1px solid var(--line); cursor: pointer; }
.suggest .s-item:last-child { border-bottom: 0; }
.suggest .thumb { width: 40px; height: 40px; font-size: 18px; }
.matched { background: #e4efe4; color: var(--ok); border-radius: 10px; padding: 8px 10px; font-size: 14px; margin: -6px 0 12px; }

.rating { display: flex; gap: 4px; margin-bottom: 12px; }
.rating button { background: none; border: 0; font-size: 28px; padding: 0 2px; cursor: pointer; color: #ddd3c7; }
.rating button.on { color: #e0a33b; }

.stepper { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }
.stepper button { width: 44px; height: 44px; border: 0; background: var(--accent-soft); font-size: 20px; cursor: pointer; }
.stepper input { border: 0; text-align: center; border-radius: 0; }

/* 底部抽屜 */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(30,20,10,.4); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-height: 92vh; overflow-y: auto; background: var(--bg);
  border-radius: 18px 18px 0 0; padding: 8px 16px calc(20px + var(--safe-b));
  max-width: 760px; margin: 0 auto;
  animation: up .22s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
.sheet-handle { width: 40px; height: 5px; border-radius: 3px; background: #d6ccc0; margin: 4px auto 10px; }
.sheet h2 { font-size: 18px; margin: 0 0 14px; }

.toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%); z-index: 60; background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px; max-width: 86vw; text-align: center; }

/* PIN 鎖 */
.lock { position: fixed; inset: 0; z-index: 100; background: var(--brand); color: #fff; display: flex; align-items: center; justify-content: center; }
.lock-box { text-align: center; width: 280px; }
.lock-title { font-size: 18px; margin-bottom: 18px; }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin-bottom: 28px; height: 16px; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; }
.pin-dots i.on { background: #fff; }
.pin-dots.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.pin-pad button { height: 64px; border-radius: 50%; border: 0; background: rgba(255,255,255,.12); color: #fff; font-size: 26px; cursor: pointer; }
.pin-pad button.blank { background: none; }

/* 報價單 */
.quote-tools { margin-bottom: 12px; }
.seg { display: flex; background: #eae2d8; border-radius: 10px; padding: 3px; margin-bottom: 10px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 8px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.paper { background: #fff; border-radius: 6px; padding: 22px 18px; box-shadow: 0 2px 10px rgba(60,40,20,.1); font-size: 13px; color: #222; }
.paper.internal { outline: 3px dashed var(--danger); outline-offset: -3px; }
.q-head { display: flex; justify-content: space-between; gap: 12px; border-bottom: 2px solid #222; padding-bottom: 10px; margin-bottom: 12px; }
.q-company { font-size: 17px; font-weight: 700; }
.q-title { font-size: 22px; font-weight: 700; letter-spacing: 4px; text-align: right; }
.q-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 16px; margin-bottom: 14px; }
.q-table { width: 100%; border-collapse: collapse; }
.q-table th { background: #f1ece6; font-weight: 600; text-align: left; padding: 6px 4px; border-bottom: 1px solid #ccc; white-space: nowrap; }
.q-table td { padding: 6px 4px; border-bottom: 1px solid #e5e5e5; vertical-align: top; }
.q-table .num { text-align: right; white-space: nowrap; }
.q-table img { width: 56px; height: 56px; object-fit: cover; border-radius: 4px; }
.q-table .room-row td { background: #faf7f3; font-weight: 700; }
.q-table .cost { color: var(--danger); }
.q-sum { margin-left: auto; margin-top: 12px; width: 240px; max-width: 100%; }
.q-sum div { display: flex; justify-content: space-between; padding: 3px 0; }
.q-sum .total { border-top: 2px solid #222; font-size: 16px; font-weight: 700; margin-top: 4px; padding-top: 6px; }
.q-sum .cost { color: var(--danger); }
.q-notes { margin-top: 18px; white-space: pre-wrap; color: #555; border-top: 1px solid #ddd; padding-top: 10px; }
.internal-tag { color: var(--danger); font-weight: 700; text-align: center; margin-bottom: 8px; }
@media (max-width: 520px) {
  .paper:not(.export) { padding: 16px 10px; font-size: 12px; }
  .paper:not(.export) .q-table img { width: 44px; height: 44px; }
  .paper:not(.export) .q-table .hide-sm { display: none; }
}
/* 匯出 PDF / 圖片用的固定 A4 版面 */
.paper.export { width: 794px; padding: 44px 40px; font-size: 13px; border-radius: 0; box-shadow: none; outline: none; }
.paper.export .q-table img { width: 64px; height: 64px; }

@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; padding: 0; }
  .no-print, .tabbar, .topbar, .fab, .quote-tools { display: none !important; }
  main { padding: 0; max-width: none; }
  .paper { box-shadow: none; padding: 0; border-radius: 0; font-size: 11pt; outline: none; }
  .q-table .hide-sm { display: table-cell !important; }
  .q-table tr { break-inside: avoid; }
}

a { color: var(--accent); }

/* 同步狀態 */
.sync { flex: none; border: 0; border-radius: 999px; padding: 4px 10px; font-size: 12px; background: rgba(255,255,255,.14); color: #fff; cursor: pointer; white-space: nowrap; }
.sync.ok { background: rgba(120,190,120,.25); }
.sync.warn { background: #e0a33b; color: #2b2520; }
.sync.off { opacity: .7; }

/* 報價頁：快速調整品項 */
.q-edit { border-top: 1px solid var(--line); padding: 8px 0; }
.q-edit:first-of-type { border-top: 0; }
.q-edit input { padding: 8px 10px; font-size: 15px; }
.q-edit-nums { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 6px; }
.q-edit-nums.internal { grid-template-columns: 1fr 1fr 1fr; }
.q-edit-nums label span { display: block; font-size: 12px; color: var(--muted); }
.q-edit-nums .cost { color: var(--danger); }

/* 電腦版：畫面加寬，報價頁左右兩欄 */
@media (min-width: 980px) {
  main { max-width: 1240px; padding: 20px 24px 40px; }
  #view > .list-item, #view > .card, #view > .item-card, #view > .room-head, #view > .search, #view > .chips, #view > #vlist, #view > #plist, #view > .section-title, #view > .empty { max-width: 820px; margin-left: auto; margin-right: auto; }
  .quote-layout { display: grid; grid-template-columns: 380px 1fr; gap: 20px; align-items: start; }
  .quote-side { position: sticky; top: 76px; max-height: calc(100vh - 160px); overflow-y: auto; }
  .paper { padding: 36px 40px; font-size: 14px; }
  .fab { right: calc(50% - 410px); }
}
@media print {
  .quote-layout { display: block; }
  .quote-side { display: none !important; }
}
