:root {
  --bg: #f5f3ef; --card: #fff; --ink: #1f1d1a; --muted: #7a746c; --line: #e3ded6;
  --accent: #7a1f2b; --accent-ink: #fff; --ok: #2f7d4f; --warn: #b7791f; --err: #b3261e;
  --A: #2b6cb0; --T: #2f855a; --C: #b7791f; --BOSS: #6b46c1;
  font-family: -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; }
button { font: inherit; cursor: pointer; border-radius: 8px; padding: 8px 14px; border: 1px solid var(--line); background: #fff; color: var(--ink); }
button:disabled { opacity: .6; cursor: wait; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.ghost { background: transparent; }
button.small { padding: 4px 10px; font-size: 13px; }
button.danger { color: var(--err); border-color: #f0c9c6; }
button.danger-bg { background: var(--err); border-color: var(--err); }
input, select, textarea { font: inherit; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; width: 100%; color: var(--ink); }
textarea { resize: vertical; }

.top { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 10px 16px; background: #fff; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--accent); }
.who { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
#btnSound.off { border-color: var(--warn); color: var(--warn); font-weight: 600; }
#btnSound.on { color: var(--ok); }

main { max-width: 1100px; margin: 0 auto; padding: 16px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.tabs { display: flex; gap: 4px; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.tab { border: 0; padding: 6px 14px; }
.tab.active { background: var(--accent); color: #fff; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; flex: 1; }
.filters select, .filters input[type=date] { width: auto; }
.filters input[type=search] { flex: 1; min-width: 160px; }

.group { margin-bottom: 22px; }
.group-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 6px;
  border-bottom: 2px solid var(--ink); padding-bottom: 4px; margin-bottom: 10px; }
.group-head h3 { margin: 0; font-size: 17px; }
.sum { color: var(--muted); font-size: 14px; }
.sum b { color: var(--ink); font-size: 16px; }
.today { background: var(--accent); color: #fff; font-size: 12px; padding: 2px 8px; border-radius: 99px; margin-left: 6px; vertical-align: middle; }
.past { background: #ddd; font-size: 12px; padding: 2px 8px; border-radius: 99px; margin-left: 6px; vertical-align: middle; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.card.delivered { opacity: .85; border-left: 4px solid var(--ok); }
.card-top { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.badge { color: #fff; font-size: 13px; padding: 2px 10px; border-radius: 99px; background: #555; font-weight: 600; }
.unit-A { background: var(--A); } .unit-T { background: var(--T); } .unit-C { background: var(--C); } .unit-BOSS { background: var(--BOSS); } .unit-WH { background: var(--accent); }
.method { font-size: 13px; padding: 2px 8px; border-radius: 6px; border: 1px solid; }
.m-car { color: var(--accent); } .m-home { color: #2b6cb0; }
.time { font-weight: 700; font-variant-numeric: tabular-nums; }
.bottles { font-weight: 700; }
.status { margin-left: auto; font-size: 13px; font-weight: 600; }
.s-done { color: var(--ok); } .s-wait { color: var(--warn); }
.card-body { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 4px 20px; }
.kv { display: flex; gap: 8px; line-height: 1.5; }
.kv > span { color: var(--muted); min-width: 64px; flex-shrink: 0; font-size: 13px; padding-top: 1px; }
.kv.meta { color: var(--muted); font-size: 13px; }
.muted { color: var(--muted); }
.card-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 10px; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: flex-start; justify-content: center; z-index: 20; overflow-y: auto; padding: 24px 12px; }
.dialog { background: #fff; border-radius: 14px; padding: 20px; width: 100%; max-width: 640px; }
.dialog h2 { margin: 0 0 6px; font-size: 19px; }
.sub { color: var(--muted); margin: 0 0 12px; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: end; }
.form.one { grid-template-columns: 1fr; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
.form .wide, .form fieldset, .form .err { grid-column: 1 / -1; }
.form label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--err); }
.form label.check input { width: auto; }
fieldset.radio { border: 1px solid var(--line); border-radius: 8px; display: flex; gap: 20px; padding: 8px 12px; margin: 0; }
fieldset.radio legend { font-size: 14px; color: var(--muted); padding: 0 4px; }
fieldset.radio label { flex-direction: row; align-items: center; gap: 6px; color: var(--ink); font-size: 16px; }
fieldset.radio input { width: auto; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.err { color: var(--err); margin: 0; min-height: 1em; font-size: 14px; }
.thumbs, .photos { display: flex; flex-wrap: wrap; gap: 8px; }
.thumbs img { width: 80px; height: 80px; object-fit: cover; border-radius: 8px; }
.photos img { width: 100%; max-width: 280px; border-radius: 10px; }

.login { max-width: 360px; margin: 12vh auto; background: #fff; padding: 28px; border-radius: 16px; border: 1px solid var(--line); }
.login h1 { margin: 0 0 18px; font-size: 22px; color: var(--accent); text-align: center; }
.login form { display: grid; gap: 14px; }
.login label { display: grid; gap: 4px; color: var(--muted); font-size: 14px; }

#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 50; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: #333; color: #fff; padding: 12px 14px; border-radius: 10px; box-shadow: 0 4px 16px rgba(0,0,0,.2); transition: opacity .4s; }
.toast.ok { background: var(--ok); } .toast.error { background: var(--err); } .toast.new { background: var(--accent); font-weight: 600; }
.toast.hide { opacity: 0; }

@media (max-width: 600px) {
  .form { grid-template-columns: 1fr; }
  main { padding: 12px; }
  .status { margin-left: 0; width: 100%; }
}

/* 名額、排位、一覽 */
.section { margin-bottom: 14px; }
.section-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 8px 0; font-size: 14px; color: var(--muted); }
.section-head b { color: var(--ink); }
.cap { background: #eef5ef; color: var(--ok); padding: 2px 8px; border-radius: 6px; font-weight: 600; }
.cap.full { background: #fbeaea; color: var(--err); }
.sub-head { margin: 10px 0 6px; font-size: 13px; color: var(--warn); font-weight: 700; border-top: 1px dashed var(--line); padding-top: 8px; }
.slot { font-size: 13px; font-weight: 700; padding: 2px 8px; border-radius: 6px; }
.s-main { background: #eef5ef; color: var(--ok); }
.s-backup { background: #fdf3e1; color: var(--warn); }
.mv { padding: 0 6px; font-size: 11px; line-height: 18px; border-radius: 4px; }
.mv:disabled { opacity: .25; cursor: default; }
.mvbox { display: inline-flex; flex-direction: column; gap: 2px; }
.line { display: grid; grid-template-columns: 52px 56px 64px 1.3fr 36px 1.4fr 2.1fr 76px 118px; gap: 8px; align-items: center;
  background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; margin-bottom: 4px; font-size: 14px; cursor: pointer; }
.line:hover { border-color: #c9bfb2; }
.line.head { background: transparent; border: 0; color: var(--muted); font-size: 12px; cursor: default; padding-top: 0; padding-bottom: 0; }
.line.delivered { background: #f3f8f4; }
.line small { display: block; color: var(--muted); font-size: 12px; }
.line .seq { display: flex; flex-direction: column; align-items: center; gap: 1px; }
.line .seq b { font-size: 15px; }
.line .acts { display: flex; gap: 4px; justify-content: flex-end; flex-wrap: wrap; font-size: 12px; }
.avail { margin: -4px 0 0; font-size: 14px; min-height: 1em; }
.avail.ok { color: var(--ok); } .avail.warn { color: var(--warn); font-weight: 600; } .avail.full { color: var(--err); font-weight: 700; }
.capset { display: grid !important; grid-template-columns: 1fr 1fr; gap: 12px; }
.capset label { color: var(--muted); }
.mt { margin: 20px 0 8px; font-size: 16px; }
.ovr-row { display: flex; gap: 12px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.ovr-row span:first-child { min-width: 120px; font-weight: 600; }
.ovr-row button { margin-left: auto; }
.ovr-add { display: flex; gap: 8px; margin-top: 10px; }
.ovr-add input, .ovr-add select { width: auto; }
.dialog .card { border: 0; padding: 0; }

@media (max-width: 900px) {
  .line { grid-template-columns: 40px auto auto 1fr; gap: 2px 8px; }
  .line.head { display: none; }
  .line > span:nth-child(1) { grid-column: 1; grid-row: 1 / 7; align-self: start; }
  .line > span:nth-child(2) { grid-column: 2; grid-row: 1; }
  .line > span:nth-child(3) { grid-column: 3; grid-row: 1; }
  .line > span:nth-child(5) { grid-column: 4; grid-row: 1; }
  .line > span:nth-child(4) { grid-column: 2 / 5; grid-row: 2; }
  .line > span:nth-child(6) { grid-column: 2 / 5; grid-row: 3; }
  .line > span:nth-child(7) { grid-column: 2 / 5; grid-row: 4; }
  .line > span:nth-child(8) { grid-column: 2 / 5; grid-row: 5; }
  .line > span:nth-child(9) { grid-column: 2 / 5; grid-row: 6; justify-content: flex-start; }
  .line .bottles::after { content: " 瓶"; }
  .line > span:nth-child(7) small { display: inline; margin-right: 10px; }
}

/* 調撥單號、物流中心 */
.tno { display: inline-block; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; padding: 1px 6px; border-radius: 4px; background: #f1ede6; color: var(--ink); white-space: nowrap; margin: 1px 0; }
.tno.ready { background: #e3f1e7; color: var(--ok); font-weight: 700; }
.note { color: var(--ink); }
.trk { color: #2b6cb0; text-decoration: none; white-space: nowrap; font-family: ui-monospace, Menlo, Consolas, monospace; }
.trk:hover { text-decoration: underline; }
.whinfo { display: flex; flex-direction: column; gap: 2px; }
.line .prep small { line-height: 1.6; }
.line .prep small b { color: var(--muted); font-weight: 600; margin-right: 2px; }
.line .prep small span { margin-right: 6px; }
fieldset.prepbox { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: grid; gap: 10px; margin: 0; }
fieldset.prepbox legend { font-size: 14px; color: var(--muted); padding: 0 4px; }
.ready-list { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; }
.ready-list .small { width: 100%; font-size: 13px; }
label.chk { flex-direction: row !important; align-items: center; gap: 6px; color: var(--ink) !important; font-family: ui-monospace, Menlo, Consolas, monospace; }
label.chk input { width: auto; }
.line .prep small { display: block !important; }

/* 注意事項、宅配到貨日、調撥說明 */
.caution { color: var(--err); font-weight: 700; display: block; }
.line .caution { font-size: 13px; margin-top: 2px; }
.caution-box { margin: 0 0 12px; padding: 8px 10px; background: #fbeaea; border-radius: 8px; }
.kv.wide-kv { grid-column: 1 / -1; }
.tno i { font-style: normal; color: var(--muted); font-family: inherit; }
.tno.ready i { color: inherit; opacity: .8; }
.line .time small { font-weight: 400; }

/* 一覽表：備貨／物流欄排版 */
.line .prep { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.pp { display: grid; grid-template-columns: 30px 1fr; gap: 6px; align-items: start; }
.pl { color: var(--muted); font-size: 12px; font-weight: 600; padding-top: 2px; }
.pv { display: flex; flex-wrap: wrap; gap: 3px 6px; align-items: center; min-width: 0; }
.pv .tno { margin: 0; }
.pi { white-space: nowrap; }
.pn { flex-basis: 100%; font-size: 12px; color: var(--ink); line-height: 1.45; }

/* 歷史紀錄 */
.hist-title { margin: 0; font-size: 18px; }
.hist-sum { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.hist-sum b { color: var(--ink); }
.hist-units { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 4px; }
.hist-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: 10px; }
table.hist { border-collapse: collapse; width: 100%; font-size: 13px; min-width: 980px; }
table.hist th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; padding: 8px; border-bottom: 2px solid var(--line); position: sticky; top: 0; background: #fff; }
table.hist td { padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.hist tr[data-hid] { cursor: pointer; }
table.hist tr[data-hid]:hover td { background: #faf8f4; }
table.hist small { display: block; color: var(--muted); font-size: 12px; }
table.hist .nw { white-space: nowrap; }
table.hist .num { text-align: right; font-weight: 700; }
table.hist .caution { font-size: 12px; }
#hMonth { width: auto; }

/* 雲端備份 */
.drive-st { font-weight: 700; margin: 4px 0 8px; }
.drive-st.on { color: var(--ok); } .drive-st.off { color: var(--warn); }
.drive-st .muted { font-weight: 400; }
ol.drive-steps { padding-left: 20px; line-height: 1.7; font-size: 14px; }
ol.drive-steps li { margin-bottom: 6px; }
details.drive-steps summary { cursor: pointer; color: var(--muted); margin: 8px 0; }
.drive-url { display: flex; gap: 8px; }
.drive-url input { flex: 1; }
.codebox { width: 100%; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; margin-top: 6px; }
.btnlink { display: inline-block; padding: 8px 14px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); text-decoration: none; font-size: 15px; }
.bk-err { color: var(--err); font-size: 13px; align-self: center; }
.s-over { background: #fbeaea; color: var(--err); }
