:root {
  --bg: #f6f4f1;
  --card: #ffffff;
  --text: #1f1b16;
  --muted: #6b6259;
  --line: #e4ded6;
  --brand: #c2410c;
  --brand-ink: #ffffff;
  --ok-bg: #e7f5ea; --ok-ink: #17602d;
  --warn-bg: #fff4d6; --warn-ink: #7a5300;
  --err-bg: #fde8e6; --err-ink: #9b1c12;
  --info-bg: #e8f0fb; --info-ink: #1d4a8a;
  --whoami-bg: #fff1e6; --whoami-ink: #7c2d12;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171513; --card: #221f1c; --text: #f1ece6; --muted: #a79d92; --line: #3a352f;
    --brand: #f07c3c; --brand-ink: #1a0d05;
    --ok-bg: #173622; --ok-ink: #9fe0b0;
    --warn-bg: #3b2f10; --warn-ink: #f2d27a;
    --err-bg: #3d1a16; --err-ink: #ffb4a8;
    --info-bg: #182a44; --info-ink: #a9c8f5;
    --whoami-bg: #3a2416; --whoami-ink: #fbd3b5;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif;
}
a { color: var(--brand); }
h1 { font-size: 1.35rem; margin: .2rem 0 .6rem; }
h2 { font-size: 1.1rem; margin: 1.4rem 0 .5rem; }
h3 { font-size: 1rem; margin: 0; }
p { margin: .4rem 0; }
small, .muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

.sticky-head { position: sticky; top: 0; z-index: 10; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: .3rem .8rem; flex-wrap: wrap;
  padding: .6rem 16px; background: var(--brand); color: var(--brand-ink);
}
.topbar a { color: var(--brand-ink); text-decoration: none; }
.brand { font-weight: 700; white-space: nowrap; }
.topbar nav { display: flex; gap: .9rem; font-size: .95rem; overflow-x: auto; }
.topbar nav a { white-space: nowrap; }

.whoami {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem; flex-wrap: wrap;
  padding: .35rem 16px; background: var(--whoami-bg); color: var(--whoami-ink); font-size: .92rem;
  border-bottom: 1px solid var(--line);
}
.whoami form { display: inline; }
.whoami button.link { color: var(--whoami-ink); font-size: .85rem; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin: .4rem 0 .6rem; }
.segmented a { display: flex; flex-direction: column; align-items: center; padding: .55rem .4rem; text-decoration: none; color: var(--text); background: var(--card); font-weight: 600; }
.segmented a small { font-weight: 400; color: var(--muted); font-size: .8rem; }
.segmented a + a { border-left: 1px solid var(--line); }
.segmented a.on { background: var(--brand); color: var(--brand-ink); }
.segmented a.on small { color: var(--brand-ink); opacity: .85; }
.segmented.seg4 { grid-template-columns: repeat(4, 1fr); }
.segmented.seg4 a { flex-direction: row; justify-content: center; font-size: .9rem; padding: .5rem .2rem; }

/* 統計：一個大數字 + 小方塊 */
.hero-label { color: var(--muted); font-size: .9rem; }
.hero-figure { font-size: 2.6rem; font-weight: 700; line-height: 1.15; margin: .1rem 0 .5rem; }
.stat-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.stat-tiles div { background: var(--bg); border-radius: 10px; padding: .45rem .6rem; }
.stat-tiles small { color: var(--muted); font-size: .8rem; }
.stat-tiles b { display: block; font-size: 1.15rem; }
h4.sub { font-size: .92rem; margin: 1rem 0 .35rem; color: var(--muted); }

/* 每月花費長條圖：單一數列、細長條、4px 圓角端點、從同一條基線長出來 */
.month-chart { display: flex; align-items: flex-end; gap: 2px; height: 170px; margin-top: .6rem;
               border-bottom: 1px solid var(--line); padding-top: 1.2rem; }
.mcol { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end;
        align-items: center; position: relative; outline: none; }
.mbar { width: 70%; max-width: 24px; min-height: 0; background: var(--brand); border-radius: 4px 4px 0 0; }
.mval { font-size: .68rem; color: var(--text); white-space: nowrap; margin-bottom: 2px; min-height: 1em; }
.mlabel { position: absolute; bottom: -1.35rem; font-size: .7rem; color: var(--muted); white-space: nowrap; }
.month-chart + details { margin-top: 1.7rem; }
.mcol:hover .mbar, .mcol:focus .mbar { filter: brightness(1.15); }
.mcol:hover::after, .mcol:focus::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--card); font-size: .78rem; padding: .25rem .5rem; border-radius: 6px;
  white-space: nowrap; z-index: 3; pointer-events: none;
}
.mcol:first-child:hover::after, .mcol:first-child:focus::after { left: 0; transform: none; }
.mcol:last-child:hover::after, .mcol:last-child:focus::after { left: auto; right: 0; transform: none; }

/* 橫向長條（排行、比例）：數字在長條尾端 */
.hbars { display: flex; flex-direction: column; gap: .35rem; }
.hrow { display: grid; grid-template-columns: minmax(0, 8.5rem) 1fr auto; gap: .5rem; align-items: center; font-size: .9rem; }
.hname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hname small { color: var(--muted); margin-left: .3rem; font-size: .75rem; }
.htrack { height: 12px; background: var(--bg); border-radius: 0 4px 4px 0; overflow: hidden; }
.hfill { display: block; height: 100%; background: var(--brand); border-radius: 0 4px 4px 0; }
.hval { color: var(--text); font-size: .85rem; min-width: 3.2em; text-align: right; }

.photo-match { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .6rem; }
.photo-pair { display: flex; align-items: center; gap: .6rem; width: 100%; }
.photo-pair figure { margin: 0; text-align: center; }
.photo-pair img, .no-photo { width: 110px; height: 110px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); }
.no-photo { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: .8rem; }
.photo-pair figcaption { font-size: .78rem; color: var(--muted); max-width: 120px; }
.card-foot { margin: -6px 0 10px; padding: 0 14px; font-size: .9rem; text-align: right; }

/* 訂購一覽表 */
.board-person { display: grid; grid-template-columns: 1fr auto; gap: .2rem .6rem; padding: .5rem 0; border-top: 1px dashed var(--line); }
.board-person:first-child { border-top: 0; }
.board-person.me { background: var(--whoami-bg); margin: 0 -14px; padding: .5rem 14px; }
.board-person .items { grid-column: 1 / -1; font-size: .9rem; color: var(--text); }
.board-person .items span + span::before { content: "・"; color: var(--muted); }

.whois { min-height: 1.4em; margin: .3rem 0 0; font-weight: 600; color: var(--ok-ink); }
.whois.miss { color: var(--err-ink); font-weight: 400; }

main { max-width: 760px; margin: 0 auto; padding: 14px 16px 40px; }
footer { max-width: 760px; margin: 0 auto; padding: 0 16px 30px; color: var(--muted); font-size: .9rem; }
footer form { display: inline; }

.flash { max-width: 760px; margin: 12px auto 0; padding: .7rem 1rem; border-radius: var(--radius); }
.flash-ok { background: var(--ok-bg); color: var(--ok-ink); }
.flash-warn { background: var(--warn-bg); color: var(--warn-ink); }
.flash-error { background: var(--err-bg); color: var(--err-ink); }
@media (max-width: 792px) { .flash { margin: 12px 16px 0; } }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin: 10px 0;
}
a.card { display: block; color: inherit; text-decoration: none; }
a.card:active { transform: scale(.995); }
.row { display: flex; align-items: center; justify-content: space-between; gap: .6rem; flex-wrap: wrap; }
.stack > * + * { margin-top: .5rem; }

.badge { display: inline-block; padding: .05rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.b-open { background: var(--ok-bg); color: var(--ok-ink); }
.b-cutoff { background: var(--warn-bg); color: var(--warn-ink); }
.b-delivered { background: var(--info-bg); color: var(--info-ink); }
.b-cancelled, .b-unpaid, .b-changed { background: var(--err-bg); color: var(--err-ink); }
.b-reported { background: var(--warn-bg); color: var(--warn-ink); }
.b-confirmed { background: var(--ok-bg); color: var(--ok-ink); }
.b-none { background: var(--line); color: var(--muted); }

.btn, button {
  font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: .55rem 1rem; border-radius: 10px; min-height: 44px; text-decoration: none; display: inline-flex;
  align-items: center; justify-content: center; gap: .3rem;
}
.btn-primary, button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
.btn-danger, button.danger { color: var(--err-ink); border-color: var(--err-ink); background: transparent; }
button.small, .btn.small { min-height: 34px; padding: .25rem .7rem; font-size: .9rem; }
button.link { border: 0; background: none; color: var(--brand); padding: 0; min-height: 0; text-decoration: underline; }
button:disabled { opacity: .55; cursor: default; }
.btn-block { width: 100%; }

label { display: block; font-weight: 600; margin: .7rem 0 .25rem; }
label.inline { display: inline-flex; align-items: center; gap: .35rem; font-weight: 400; margin: .2rem .9rem .2rem 0; }
input, select, textarea {
  font: inherit; width: 100%; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--text); min-height: 44px;
}
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; accent-color: var(--brand); transform: scale(1.2); }
textarea { min-height: 90px; }
.hint { font-size: .85rem; color: var(--muted); margin: .25rem 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
@media (max-width: 480px) { .grid2 { grid-template-columns: 1fr; } }

/* 菜單 */
details.item { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin: 8px 0; }
details.item > summary {
  list-style: none; cursor: pointer; padding: 14px; display: flex; justify-content: space-between; gap: .5rem; font-weight: 600;
}
details.item > summary::-webkit-details-marker { display: none; }
details.item[open] > summary { border-bottom: 1px solid var(--line); }
details.item form { padding: 4px 14px 14px; }
.opt-group { margin-top: .6rem; }
.opt-group .name { font-weight: 600; font-size: .95rem; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .3rem; }
.chips label {
  margin: 0; font-weight: 400; border: 1px solid var(--line); border-radius: 999px; padding: .35rem .8rem;
  display: inline-flex; gap: .3rem; align-items: center; cursor: pointer; min-height: 38px;
}
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips label:has(input:checked) { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.chips label.locked { opacity: .38; text-decoration: line-through; cursor: not-allowed; background: var(--bg); }
.temp-note { margin: .5rem 0 0; padding: .35rem .6rem; border-radius: 8px; background: var(--info-bg); color: var(--info-ink); font-size: .9rem; }
.temp-note.hot { background: var(--err-bg); color: var(--err-ink); }
.tag { display: inline-block; margin-left: .3rem; padding: 0 .4rem; border-radius: 6px; font-size: .72rem; font-weight: 600;
       line-height: 1.5; vertical-align: 2px; white-space: nowrap; }
.tag-new { background: #ffe7d6; color: #b4400b; }
.tag-rec { background: #fff3c4; color: #7a5a00; }
.tag-cold { background: #dcecff; color: #1d4f91; }
.tag-hot { background: #fde2e0; color: #9b1c12; }
.tag-nocaf { background: #e4f4e6; color: #22662f; }
.tag-season { background: #ece6fb; color: #5b3aa0; }
@media (prefers-color-scheme: dark) {
  .tag-new { background: #4a2512; color: #ffbe94; } .tag-rec { background: #3f3510; color: #f2d97a; }
  .tag-cold { background: #16304f; color: #a9ccf7; } .tag-hot { background: #461a17; color: #ffb4a8; }
  .tag-nocaf { background: #173a20; color: #a6e0b1; } .tag-season { background: #2f2450; color: #cbb8f5; }
}
.qty { display: flex; align-items: center; gap: .4rem; }
.qty input { width: 4.2rem; text-align: center; }
.qty button { width: 44px; padding: 0; }

.item-head { display: flex; align-items: center; gap: .7rem; min-width: 0; }
.item-head .desc { display: block; font-weight: 400; color: var(--muted); font-size: .85rem; line-height: 1.35; margin-top: .1rem; }
img.thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; flex: none; background: var(--line); }
img.item-photo { display: block; width: 100%; max-height: 260px; object-fit: cover; }
.thumbs { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .5rem; }
.thumbs img { height: 120px; max-width: 100%; border-radius: 8px; border: 1px solid var(--line); }
.cat-nav { display: flex; gap: .4rem; overflow-x: auto; padding: .2rem 0 .5rem; }
.cat-nav a { flex: none; padding: .3rem .8rem; border: 1px solid var(--line); border-radius: 999px; background: var(--card); text-decoration: none; color: var(--text); font-size: .9rem; }
h3.cat { margin: 1.1rem 0 .3rem; color: var(--muted); scroll-margin-top: 140px; }
h2.day { border-left: 4px solid var(--brand); padding-left: .5rem; }
.ai-tag { font-size: .72rem; font-weight: 600; padding: 0 .4rem; border-radius: 6px; background: var(--info-bg); color: var(--info-ink); }
.review-item.off { opacity: .55; }
.item-row { display: flex; gap: .55rem; align-items: flex-start; }
.item-row > input[type=checkbox] { margin-top: 1.35rem; flex: none; }
.item-row > details { flex: 1; min-width: 0; }
.danger-zone { border-color: var(--err-ink); }
.audit-entry { padding: 10px 14px; margin: 6px 0; }
.audit-entry p { margin: .2rem 0; }
.device-line { display: flex; gap: .3rem .8rem; flex-wrap: wrap; font-size: .85rem; color: var(--muted); }
.export-bar { display: flex; gap: .45rem; flex-wrap: wrap; align-items: center; margin: 4px 0 10px; }
.thumb-box { display: flex; flex-direction: column; gap: .3rem; align-items: flex-start; }
.tag-picks { display: flex; flex-wrap: wrap; }
.bulk-bar { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin: 6px 0; }
.photo-edit { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; padding: 0 14px 14px; }
.photo-edit input[type=file] { min-height: 0; padding: .3rem; font-size: .85rem; }

/* 表格（管理頁） */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
td.r, th.r { text-align: right; }
tr.inactive td { opacity: .5; }

.line { display: flex; justify-content: space-between; gap: .6rem; padding: .45rem 0; border-top: 1px dashed var(--line); }
.line:first-child { border-top: 0; }
.line.cancelled .what { text-decoration: line-through; color: var(--muted); }
.what small { display: block; }

.copybox { white-space: pre-wrap; background: var(--bg); border: 1px dashed var(--line); border-radius: 10px; padding: .7rem; font-size: .92rem; }
.banner { background: var(--warn-bg); color: var(--warn-ink); padding: .6rem .9rem; border-radius: var(--radius); margin: 10px 0; }
.secret { font: 700 1.2rem/1.2 ui-monospace, Consolas, monospace; letter-spacing: .08em; }
.totals { display: flex; gap: 1.2rem; flex-wrap: wrap; }
.totals div b { display: block; font-size: 1.25rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.actions form { display: inline; }

@media print {
  .topbar, footer, .no-print, .flash { display: none !important; }
  body { background: #fff; color: #000; }
  .card { border: 0; }
}

/* 低調開團：選「🔒 低調開團」才展開勾選範圍 */
.audience { display: none; margin-top: .6rem; padding: .2rem .8rem .6rem; border-left: 3px solid var(--brand); background: var(--bg); border-radius: 8px; }
form:has(input[name=visibility][value=restricted]:checked) .audience { display: block; }
.audience-head { margin: .8rem 0 0; font-weight: 600; }
.people-list { max-height: 260px; overflow-y: auto; margin-top: .4rem; border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
.people-list:not(:has(label:not([hidden]))) { display: none; }
.people-list label { display: flex; gap: .5rem; align-items: center; margin: 0; padding: .45rem .7rem; font-weight: 400; border-bottom: 1px solid var(--line); cursor: pointer; }
.people-list label[hidden] { display: none; }
.people-list input { width: auto; margin: 0; }
.people-list small { margin-left: auto; text-align: right; }
.lock { display: inline-block; padding: 0 .45rem; border-radius: 6px; font-size: .78rem; font-weight: 600; background: var(--warn-bg); color: var(--warn-ink); white-space: nowrap; }
.audience-box { margin: .6rem 0; padding: .5rem .8rem; border-radius: 8px; background: var(--warn-bg); color: var(--warn-ink); font-size: .92rem; }

/* 收款 QR Code：白底加框，掃描時比較不受深色模式影響 */
.qr-preview, .pay-qr img { display: block; max-width: 220px; width: 100%; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; padding: 8px; }
.pay-qr { margin-top: .6rem; }
