:root {
  --brand: #ffcd14;
  --brand-dark: #e0b000;
  --ink: #1a1a1a;
  --ink2: #555;
  --mute: #8a8a8a;
  --line: #e6e6e6;
  --bg: #f6f6f4;
  --card: #fff;
  --red: #d6332a;
  --red-bg: #fdecea;
  --green: #1f8a4c;
  --green-bg: #e7f6ed;
  --blue: #2563c9;
  --blue-bg: #e9f0fc;
  --orange: #c26a00;
  --orange-bg: #fff3df;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 2px 10px rgba(0, 0, 0, 0.04);
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang TC', 'Noto Sans TC', 'Microsoft JhengHei', sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
body { margin: 0; font-size: 15px; line-height: 1.5; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 14px; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 0 0 8px; }
.mute { color: var(--mute); }
.small { font-size: 13px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.red { color: var(--red); }
.green { color: var(--green); }
.orange { color: var(--orange); }
.nowrap { white-space: nowrap; }
.wrap { white-space: pre-wrap; word-break: break-word; }

/* 版面 */
.testbar { background: var(--brand); color: var(--ink); text-align: center; font-size: 13px; font-weight: 700; padding: 4px 8px; letter-spacing: 1px; }
.topbar { position: sticky; top: 0; z-index: 20; background: var(--ink); color: #fff; display: flex; align-items: center; gap: 10px; padding: 0 16px; height: 52px; }
.topbar .logo { font-weight: 800; font-size: 17px; display: flex; align-items: center; gap: 8px; color: #fff; }
.topbar .logo b { background: var(--brand); color: var(--ink); border-radius: 6px; padding: 1px 7px; }
.topbar .sp { flex: 1; }
.topbar .who { font-size: 13px; color: #ccc; }
.topbar .who a { color: #fff; margin-left: 10px; }
.layout { display: flex; min-height: calc(100vh - 80px); }
.side { width: 210px; flex-shrink: 0; background: #fff; border-right: 1px solid var(--line); padding: 10px 8px 40px; position: sticky; top: 52px; height: calc(100vh - 52px); overflow-y: auto; }
.side .grp { font-size: 12px; color: var(--mute); padding: 12px 10px 4px; font-weight: 700; }
.side a { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; color: var(--ink); font-size: 15px; }
.side a:hover { background: #f3f3f0; text-decoration: none; }
.side a.on { background: var(--brand); font-weight: 700; }
.side a .cnt { margin-left: auto; background: var(--red); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 6px; }
.main { flex: 1; min-width: 0; padding: 20px 24px 100px; max-width: 1200px; }
.tabbar { display: none; }

@media (max-width: 860px) {
  .side { display: none; }
  .main { padding: 14px 12px 96px; }
  .topbar { padding: 0 12px; }
  .tabbar { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: #fff; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .tabbar a { flex: 1; text-align: center; padding: 7px 0 6px; color: var(--ink2); font-size: 11px; }
  .tabbar a .i { display: block; font-size: 21px; line-height: 1.1; }
  .tabbar a.on { color: var(--ink); font-weight: 700; }
  .tabbar a.on .i { filter: none; }
  h1 { font-size: 20px; }
}
.drawer-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 40; }
.drawer { position: fixed; left: 0; right: 0; bottom: 0; max-height: 80vh; overflow-y: auto; background: #fff; border-radius: 16px 16px 0 0; z-index: 41; padding: 10px 14px calc(20px + env(safe-area-inset-bottom)); }
.drawer .grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.drawer .grid a { background: #f6f6f4; border-radius: 10px; padding: 12px 4px; text-align: center; color: var(--ink); font-size: 13px; }
.drawer .grid a .i { display: block; font-size: 22px; }

/* 元件 */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card.pad0 { padding: 0; overflow: hidden; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.top { align-items: flex-start; }
.sp { flex: 1; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 860px) { .grid3, .grid4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 520px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 9px; padding: 8px 14px; font-size: 15px; cursor: pointer; font-family: inherit; min-height: 38px; white-space: nowrap; }
.btn:hover { background: #f5f5f2; text-decoration: none; }
.btn.pri { background: var(--brand); border-color: var(--brand); font-weight: 700; }
.btn.pri:hover { background: var(--brand-dark); }
.btn.dark { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.danger { color: var(--red); border-color: #f1c4c1; }
.btn.sm { padding: 4px 10px; font-size: 13px; min-height: 30px; }
.btn.lg { padding: 12px 20px; font-size: 17px; min-height: 48px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.link { border: 0; background: none; color: var(--blue); padding: 0 4px; min-height: 0; }

label.f { display: block; font-size: 13px; color: var(--ink2); margin-bottom: 4px; font-weight: 600; }
.field { margin-bottom: 12px; }
.hint { font-size: 12px; color: var(--mute); margin-top: 3px; }
input, select, textarea { font-family: inherit; font-size: 16px; border: 1px solid #d5d5d0; border-radius: 9px; padding: 8px 10px; width: 100%; background: #fff; color: var(--ink); min-height: 40px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); border-color: var(--brand-dark); }
input[type='checkbox'] { width: 20px; height: 20px; min-height: 0; vertical-align: middle; accent-color: var(--ink); }
textarea { min-height: 70px; resize: vertical; }
input.num { text-align: right; }
.chk { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 15px; }

.badge { display: inline-block; font-size: 12px; border-radius: 6px; padding: 1px 7px; background: #eee; color: var(--ink2); white-space: nowrap; font-weight: 600; }
.badge.y { background: #fff4c2; color: #6b5500; }
.badge.g { background: var(--green-bg); color: var(--green); }
.badge.r { background: var(--red-bg); color: var(--red); }
.badge.b { background: var(--blue-bg); color: var(--blue); }
.badge.o { background: var(--orange-bg); color: var(--orange); }
.badge.k { background: var(--ink); color: #fff; }

.tabs { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tabs a, .tabs button { flex-shrink: 0; padding: 7px 14px; border-radius: 20px; background: #fff; border: 1px solid var(--line); color: var(--ink); font-size: 14px; cursor: pointer; font-family: inherit; }
.tabs .on { background: var(--ink); color: #fff; border-color: var(--ink); }

table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; font-weight: 600; color: var(--ink2); background: #fafaf8; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; font-size: 13px; }
table.t td { padding: 8px 10px; border-bottom: 1px solid #f0f0ec; vertical-align: top; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: #fffbea; }
table.t tfoot td { font-weight: 700; background: #fafaf8; }
.tscroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* 手機：列表變卡片 */
.mlist { display: none; }
@media (max-width: 860px) {
  .dlist { display: none; }
  .mlist { display: block; }
}
.mitem { padding: 12px 14px; border-bottom: 1px solid #f0f0ec; display: block; color: var(--ink); }
.mitem:last-child { border-bottom: 0; }
.mitem .l1 { display: flex; justify-content: space-between; gap: 8px; font-weight: 700; }
.mitem .l2 { display: flex; justify-content: space-between; gap: 8px; color: var(--ink2); font-size: 13px; margin-top: 2px; }
a.mitem:hover { text-decoration: none; background: #fffbea; }

.kpi { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; display: block; color: var(--ink); }
a.kpi:hover { text-decoration: none; outline: 2px solid var(--brand); }
.kpi .k { font-size: 13px; color: var(--ink2); }
.kpi .v { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 12px; color: var(--mute); }
.kpi.alert .v { color: var(--red); }

.notice { border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; }
.notice.warn { background: var(--orange-bg); color: #6b3b00; }
.notice.err { background: var(--red-bg); color: #7a1610; }
.notice.ok { background: var(--green-bg); color: #0d4d27; }
.notice.info { background: var(--blue-bg); color: #113a7a; }
.notice ul { margin: 4px 0 0; padding-left: 20px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 90px; z-index: 100; background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 15px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25); max-width: 90vw; }
.toast.err { background: var(--red); }

.modal-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); z-index: 60; display: flex; align-items: flex-start; justify-content: center; padding: 40px 12px; overflow-y: auto; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 640px; padding: 18px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3); }
.modal.wide { max-width: 920px; }
.modal .mh { display: flex; align-items: center; margin-bottom: 12px; }
.modal .mh h2 { margin: 0; flex: 1; }
.modal .mf { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
@media (max-width: 520px) { .modal-bg { padding: 0; align-items: flex-end; } .modal { border-radius: 14px 14px 0 0; max-height: 92vh; overflow-y: auto; } }

/* 搜尋選擇器 */
.picker { position: relative; }
.picker .dd { position: absolute; left: 0; right: 0; top: 100%; z-index: 50; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12); max-height: 320px; overflow-y: auto; margin-top: 4px; }
.picker .dd div { padding: 9px 12px; cursor: pointer; border-bottom: 1px solid #f4f4f0; font-size: 14px; }
.picker .dd div:hover, .picker .dd div.hl { background: #fffbea; }
.picker .dd .c { color: var(--mute); font-size: 12px; margin-right: 6px; font-variant-numeric: tabular-nums; }
.picked { display: flex; align-items: center; gap: 8px; border: 1px solid #d5d5d0; border-radius: 9px; padding: 7px 10px; min-height: 40px; background: #fffdf4; }
.picked .x { margin-left: auto; cursor: pointer; color: var(--mute); }

/* 品項編輯 */
.items { width: 100%; border-collapse: collapse; }
.items th { font-size: 12px; color: var(--ink2); text-align: left; padding: 4px 4px; font-weight: 600; }
.items td { padding: 4px; vertical-align: top; }
.items td input, .items td select { min-height: 38px; }
.item-card { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 8px; background: #fcfcfa; }
.totals { display: flex; justify-content: flex-end; gap: 18px; flex-wrap: wrap; font-size: 15px; margin-top: 8px; }
.totals b { font-size: 18px; }

.dl { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; font-size: 14px; }
.dl dt { color: var(--mute); }
.dl dd { margin: 0; word-break: break-word; }
@media (max-width: 520px) { .dl { grid-template-columns: 90px 1fr; } }

.steps { display: flex; gap: 4px; flex-wrap: wrap; margin: 6px 0 12px; }
.steps span { font-size: 12px; padding: 3px 9px; border-radius: 12px; background: #eee; color: var(--mute); }
.steps span.on { background: var(--ink); color: #fff; }
.steps span.done { background: var(--green-bg); color: var(--green); }

.vcard { border: 2px solid var(--ink); border-radius: 6px; padding: 14px; background: #fff; }
.copybox { background: #f7f7f4; border: 1px dashed #ccc; border-radius: 8px; padding: 10px; font-family: inherit; white-space: pre-wrap; font-size: 14px; }
.empty { text-align: center; color: var(--mute); padding: 30px 10px; }
.loading { color: var(--mute); padding: 30px; text-align: center; }
.sticky-actions { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 14px 0 6px; display: flex; gap: 8px; justify-content: flex-end; z-index: 5; }
@media (max-width: 860px) { .sticky-actions { bottom: 58px; } }

@media print {
  .testbar, .topbar, .side, .tabbar, .noprint, .sticky-actions, .toast { display: none !important; }
  .main { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 0; padding: 0; }
  body { background: #fff; }
  .print-only { display: block !important; }
}
.print-only { display: none; }

/* 品項列（桌機一列、手機換行） */
.irow { display: grid; grid-template-columns: minmax(0, 2.6fr) 80px 90px 100px 100px 90px 34px; gap: 6px; align-items: start; padding: 6px 0; border-bottom: 1px dashed #eee; }
.irow.head { font-size: 12px; color: var(--ink2); font-weight: 600; border-bottom: 1px solid var(--line); padding: 2px 0; }
.irow .amt { padding-top: 9px; text-align: right; font-variant-numeric: tabular-nums; }
.irow .del { padding-top: 6px; text-align: center; cursor: pointer; color: var(--mute); font-size: 18px; }
.irow .sub { grid-column: 1 / -1; font-size: 12px; color: var(--mute); margin-top: -2px; }
.irow.p7 { grid-template-columns: minmax(0, 2.2fr) 80px 80px 90px minmax(0, 1.6fr) 100px 34px; }
@media (max-width: 860px) {
  .irow, .irow.p7 { grid-template-columns: 1fr 1fr 1fr; background: #fcfcfa; border: 1px solid var(--line); border-radius: 10px; padding: 8px; margin-bottom: 8px; }
  .irow > :first-child { grid-column: 1 / -1; }
  .irow.head { display: none; }
  .irow .lbl { display: block; font-size: 11px; color: var(--mute); }
  .irow .del { grid-column: 3; text-align: right; }
}
.irow .lbl { display: none; }
@media (max-width: 860px) { .irow .lbl { display: block; } }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 7px 14px; font-size: 14px; cursor: pointer; font-family: inherit; }
.seg button.on { background: var(--ink); color: #fff; }
.voucher { border: 2px solid var(--ink); border-radius: 4px; background: #fffef8; padding: 16px; }
.voucher table { width: 100%; border-collapse: collapse; font-size: 14px; }
.voucher th, .voucher td { border: 1px solid #ccc; padding: 6px 8px; }
.voucher th { background: #f4f1e3; }
.strike { text-decoration: line-through; color: var(--mute); }
.big-num { font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.qa { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
.qa a { background: var(--ink); color: #fff; border-radius: 12px; padding: 14px 8px; text-align: center; font-weight: 700; font-size: 15px; }
.qa a:hover { text-decoration: none; opacity: 0.9; }
.qa a .i { display: block; font-size: 22px; margin-bottom: 2px; }
@media (max-width: 520px) { .qa { grid-template-columns: repeat(2, 1fr); } }
.sec-title { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; }
.sec-title h2 { margin: 0; }
.sec-title .sp { flex: 1; }
.span2 { grid-column: span 2; }
@media (max-width: 520px) { .span2 { grid-column: auto; } }
.picked b { font-size: 14px; font-weight: 600; line-height: 1.35; }
