:root {
  --blue: #2f6fd6;
  --blue-dark: #1f56b3;
  --bg: #f2f4f7;
  --card: #ffffff;
  --text: #1c1f24;
  --muted: #6b7280;
  --line: #e2e5ea;
  --todo-bg: #fff4c2;
  --todo-line: #f0c400;
  --done: #1a9b55;
  --danger: #d33a2c;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --card: #1c1f25;
    --text: #eef0f3;
    --muted: #9aa1ac;
    --line: #2d313a;
    --todo-bg: #4a3f0c;
    --todo-line: #d9b000;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", sans-serif; }
body { min-height: 100dvh; padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: calc(env(safe-area-inset-top) + 8px) 16px 8px; background: var(--blue); color: #fff; }
.title-btn { display: flex; align-items: center; gap: 8px; background: none; border: 0; color: #fff;
  font-size: 19px; font-weight: 700; padding: 6px 0; min-width: 0; }
.title-btn span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #f7c600; flex: none; }
.top-actions { display: flex; gap: 6px; }
.icon-btn { background: rgba(255,255,255,.18); color: #fff; border: 0; border-radius: 8px; padding: 6px 12px; }

main { padding: 12px 16px; max-width: 640px; margin: 0 auto; }
.board { background: var(--card); border-radius: 14px; padding: 6px 14px 12px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.field { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.field-label { width: 4.5em; flex: none; color: var(--muted); }
.field-value { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 6px 0;
  font-size: 18px; font-weight: 600; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.field-value .v { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.field-value .v.empty { color: var(--muted); font-weight: 400; }
.field-value .chev { color: var(--muted); flex: none; }
.step { display: flex; gap: 4px; flex: none; }
.step button { width: 40px; height: 36px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip { border: 1px solid var(--todo-line); background: var(--todo-bg); border-radius: 999px; padding: 6px 12px; font-size: 15px; }
.chip.unit:not(.active) { border-color: var(--line); background: var(--bg); }
.unit-chips:not(:empty) { margin-top: 10px; }
.unit-chips + .chips { margin-top: 8px; }
.chip.active { background: var(--blue); border-color: var(--blue); color: #fff; }
.chip.done { border-color: var(--line); background: transparent; color: var(--muted); }
.floor-status { margin-top: 8px; font-size: 14px; color: var(--muted); }
.floor-status b { color: var(--text); }

.preview-wrap { margin-top: 12px; }
#boardPreview { width: 100%; border-radius: 12px; display: block; background: #3d5a4a; }

.shoot { position: fixed; left: 0; right: 0; bottom: 0; display: flex; gap: 10px; justify-content: center; align-items: center;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); }
.shoot-btn { flex: 1; max-width: 420px; text-align: center; background: var(--blue); color: #fff; font-size: 20px; font-weight: 700;
  border-radius: 14px; padding: 16px; }
.shoot-btn:active { background: var(--blue-dark); }
.pick-btn { border: 1px solid var(--line); border-radius: 14px; padding: 16px; color: var(--muted); }

dialog { border: 0; padding: 0; color: var(--text); background: var(--card); }
dialog::backdrop { background: rgba(0,0,0,.45); }
.sheet { width: 100%; max-width: 640px; margin: auto auto 0; border-radius: 16px 16px 0 0; max-height: 85dvh;
  display: none; flex-direction: column; padding-bottom: env(safe-area-inset-bottom); }
.sheet[open] { display: flex; }
.sheet.tall { height: 85dvh; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); margin: 0; }
.sheet-foot { padding: 12px 16px; border-top: 1px solid var(--line); }
.text-btn { background: none; border: 0; color: var(--blue); font-weight: 600; padding: 4px; }
.manual { display: flex; gap: 8px; padding: 10px 16px; }
.manual input { flex: 1; min-width: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-size: 17px; }
.pick-list { overflow-y: auto; padding: 0 0 16px; }
.pick-sec { padding: 12px 16px 4px; font-size: 13px; color: var(--muted); }
.opt { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 8px; text-align: left;
  padding: 13px 16px; border: 0; border-bottom: 1px solid var(--line); background: none; font-size: 17px; }
.opt.todo { background: var(--todo-bg); box-shadow: inset 4px 0 0 var(--todo-line); font-weight: 600; }
.opt.done { color: var(--muted); }
.opt.current { outline: 2px solid var(--blue); outline-offset: -2px; }
.opt .badge { font-size: 13px; padding: 2px 8px; border-radius: 999px; background: var(--todo-line); color: #222; flex: none; font-weight: 600; }
.opt .badge.ok { background: var(--done); color: #fff; }
.opt .del { color: var(--muted); font-size: 13px; padding: 4px 8px; flex: none; }

.full { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; background: #000; color: #fff; }
.full[open] { display: flex; flex-direction: column; }
.result-body { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: env(safe-area-inset-top) 8px 0; }
.result-body img { max-width: 100%; max-height: calc(100% - 40px); object-fit: contain; }
.result-body .muted { color: #aaa; font-size: 13px; text-align: center; padding: 6px 12px; }
.result-actions { display: flex; gap: 10px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
.result-actions button { flex: 1; padding: 15px; border-radius: 12px; font-size: 18px; }

.primary { background: var(--blue); color: #fff; border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 600; }
.primary.small { padding: 8px 14px; }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; display: inline-block; }
.full .ghost { color: #fff; border-color: #555; }
.danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); border-radius: 10px; padding: 10px 14px; width: 100%; }
.file-btn { cursor: pointer; text-align: center; }

.settings-body { overflow-y: auto; padding: 4px 16px 24px; display: flex; flex-direction: column; gap: 10px; }
.settings-body h3 { margin: 14px 0 0; font-size: 15px; color: var(--muted); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row select { padding: 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); min-width: 0; flex: 1; }
.fe { display: flex; align-items: center; gap: 6px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.fe input[type=text] { flex: 1; min-width: 0; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.fe button { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; width: 36px; height: 36px; flex: none; }
.fe .kind { font-size: 12px; color: var(--muted); width: 3.2em; flex: none; }
.muted { color: var(--muted); font-size: 14px; margin: 0; }

.progress-list { overflow-y: auto; padding: 0 16px 16px; }
.pg-b { margin: 14px 0 4px; font-weight: 700; }
.pg-f { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.pg-f .fl { width: 3.2em; flex: none; font-weight: 600; }
.pg-f .its { display: flex; flex-wrap: wrap; gap: 6px; }
.pg-f .its button { font-size: 14px; }

.toast { position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: rgba(20,20,20,.92); color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none;
  transition: .25s; max-width: calc(100vw - 32px); z-index: 50; text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.busy { position: fixed; inset: 0; background: rgba(0,0,0,.5); color: #fff; display: grid; place-items: center; z-index: 60; font-size: 18px; }

/* 類別四鍵 */
.seg { flex: 1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.seg button { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 8px 2px; font-size: 14px; white-space: nowrap; }
.seg button.on { color: #fff; font-weight: 700; border-color: transparent; }
.seg .cat-0.on { background: #2f6fd6; }
.seg .cat-1.on { background: #d33a2c; }
.seg .cat-2.on { background: #1a9b55; }
.seg .cat-3.on { background: #e08a00; }

/* 戶別開關 */
.board-tools:not(:empty) { display: flex; justify-content: flex-end; padding-top: 10px; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 15px; color: var(--muted); cursor: pointer; }
.switch input { display: none; }
.switch .track { width: 42px; height: 24px; border-radius: 12px; background: var(--line); position: relative; transition: .2s; }
.switch .track::after { content: ''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch input:checked + .track { background: var(--blue); }
.switch input:checked + .track::after { left: 20px; }

/* 待機 */
.standby { position: fixed; inset: 0; z-index: 100; background: #000; color: #444; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.standby[hidden] { display: none; }
.standby-clock { font-size: 18px; color: #555; text-align: center; padding: 0 24px; }
.standby-hint { font-size: 14px; color: #333; }
html.standby-on, html.standby-on body { background: #000; }

/* 進度分頁 */
.tabs { display: flex; gap: 6px; padding: 10px 16px 0; }
.tabs button { flex: 1; padding: 8px; border: 1px solid var(--line); background: var(--bg); border-radius: 8px; }
.tabs button.on { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 600; }
.progress-list[hidden] { display: none; }

/* 請款表 */
.bill-legend { font-size: 13px; color: var(--muted); padding: 12px 0 0; line-height: 2; }
.bill-legend b { color: var(--text); }
.lg { display: inline-block; width: 18px; height: 14px; vertical-align: -2px; margin: 0 4px 0 10px; border: 1px solid var(--line);
  font-size: 11px; line-height: 13px; text-align: center; }
.bill-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: 8px; }
table.bill { border-collapse: collapse; font-size: 12px; }
.bill th, .bill td { border: 1px solid var(--line); min-width: 34px; height: 34px; padding: 0 2px; text-align: center; white-space: nowrap; }
.bill thead th { background: var(--bg); font-weight: 600; position: sticky; top: 0; }
.bill th.it { position: sticky; left: 0; z-index: 1; background: var(--card); text-align: left; padding: 2px 8px; min-width: 120px; font-weight: 600; }
.bill thead th.it { z-index: 2; background: var(--bg); }
.bill th.it small { display: block; font-weight: 400; color: var(--blue); font-size: 11px; }
.bill td small { display: block; font-size: 10px; line-height: 1; }
.none { background: transparent; }
.paid { background: #111; color: #fff; }
.unpaid { background: #bcbcbc; }
.cur, td.current { background: #ffd60a; color: #222; font-weight: 700; cursor: pointer; }
td.current.full { background: #8fd18f; }
@media (prefers-color-scheme: dark) { .paid { background: #000; border-color: #555; } .unpaid { background: #6b6b6b; } }

.txt { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-size: 15px; }
.floor-status .up { color: var(--blue); }

.album-btn { border: 0; border-radius: 14px; padding: 16px 14px; background: #1a9b55; color: #fff; font-weight: 700; white-space: nowrap; }
.album-btn[hidden] { display: none; }
