/* 集古村收據工作台 — 淺色企業風（純白 + 深藍頂欄） */
:root {
  color-scheme: light;
  --navy: #0f2a47;
  --bg: #ffffff;
  --card: #ffffff;
  --panel-head: #f8fafc;
  --line: #e3e8ef;
  --line-soft: #eef2f7;
  --line-strong: #cbd5e1;
  --fg: #0f172a;
  --dim: #5b6b7f;
  --accent: #1d4ed8;
  --accent-soft: #eff4ff;
  --ok: #166534;
  --ok-soft: #dcfce7;
  --warn: #92400e;
  --warn-soft: #fef3c7;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 42, 71, .06);
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.6 "PingFang HK", "Microsoft JhengHei", "Noto Sans TC", -apple-system, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, p, ul, table { margin: 0; }
ul { padding: 0; list-style: none; }
button { font: inherit; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--dim); font-size: 12px; }

/* ---------- shell ---------- */
.wrap { width: min(1200px, 100%); margin: 0 auto; padding: 0 var(--s5); }

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--navy);
  border-bottom: 1px solid #0a1f36;
}
.topbar__inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s3); height: 58px;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; }
.brand__mark {
  width: 18px; height: 18px; border-radius: 5px;
  background: linear-gradient(135deg, #3b82f6, #93c5fd);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25);
}
.brand__name { font-size: 14.5px; font-weight: 600; letter-spacing: .01em; }
.topbar__meta { display: flex; align-items: center; gap: var(--s3); }
.chip {
  font-size: 12px; color: #c7d7ea; border: 1px solid rgba(199, 215, 234, .35);
  padding: 2px 8px; border-radius: 999px; white-space: nowrap;
}

.main { padding-top: var(--s5); padding-bottom: 64px; }
.page-head { margin-bottom: var(--s4); }
.page-title { font-size: 19px; font-weight: 650; letter-spacing: -.01em; text-align: left; }
.page-sub { color: var(--dim); font-size: 13px; margin-top: 2px; }

/* ---------- kpi ---------- */
.kpi {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--s3); margin-bottom: var(--s5);
}
.kpi li {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px var(--s4) 14px;
}
.kpi span { display: block; color: var(--dim); font-size: 12px; margin-bottom: 4px; }
.kpi strong {
  font-size: 23px; font-weight: 650; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; line-height: 1.25;
}
.kpi .is-warn strong { color: var(--warn); }

/* ---------- layout ---------- */
.grid {
  display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: var(--s4); align-items: start;
}
.col { display: grid; gap: var(--s4); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card__head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s2);
  padding: 11px var(--s4);
  background: var(--panel-head);
  border-bottom: 1px solid var(--line);
}
.card__head h2 { font-size: 13px; font-weight: 650; color: #24364b; letter-spacing: .01em; }
.card__body { padding: var(--s3) var(--s4) var(--s4); }
.card__body.flush { padding: 0; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table thead th {
  text-align: left; font-weight: 600; font-size: 12px; color: var(--dim);
  padding: 8px var(--s3); border-bottom: 1px solid var(--line);
  background: #fbfcfe; white-space: nowrap;
}
.table tbody td { padding: 9px var(--s3); border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; white-space: nowrap; }
.table td.empty { text-align: center; color: var(--dim); padding: 22px var(--s3); }
.table td.actions { text-align: right; white-space: nowrap; }
.table .need { white-space: normal; }
.table td[data-label="單據日期"], .table td[data-label="同事發出群組日期"],
.table td[data-label="類別"], .table td[data-label="提交人"] { white-space: nowrap; }
.table td[data-label="同事補充描述"],
.table td[data-label="自動擷取的資訊"] {
  max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--dim);
}
.table .need__detail { display: block; margin-top: 2px; font-size: 12px; color: var(--dim); }
.table--fixed { table-layout: fixed; }
.table--pending th:nth-child(1) { width: 22%; }
.table--pending th:nth-child(2) { width: 20%; }
.table--pending th:nth-child(3) { width: 15%; }
.table--pending th:nth-child(4) { width: 19%; }
.table--pending th:nth-child(5) { width: 24%; }
.table--claims th:nth-child(1) { width: 56%; }
.table--claims th:nth-child(2) { width: 12%; }
.table--claims th:nth-child(3) { width: 16%; }
.table--claims th:nth-child(4) { width: 16%; }

/* ---------- form controls ---------- */
input, select {
  font: inherit; font-size: 13.5px;
  padding: 7px 10px; border-radius: 7px;
  border: 1px solid var(--line-strong); background: #fff; color: var(--fg);
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder { color: #94a3b8; }
input:focus, select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input.cell { width: 100%; min-width: 0; padding: 5px 8px; font-size: 13px; }
input.cell[type="date"] { font-size: 12.5px; padding: 4px 6px; }
input.cell.num { text-align: right; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 14px; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--line-strong); background: #fff; color: var(--fg);
  font-size: 13.5px; font-weight: 500;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: #f5f7fa; border-color: #94a3b8; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: #1a43bd; border-color: #1a43bd; }
.btn--ghost { background: transparent; border-color: rgba(255, 255, 255, .28); color: #e8eff8; }
.btn--ghost:hover { background: rgba(255, 255, 255, .1); border-color: rgba(255, 255, 255, .5); }
.btn--sm { padding: 4px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus-visible, select:focus-visible { outline: none; }

.inline-form { display: flex; flex-wrap: wrap; gap: var(--s2); margin-bottom: var(--s3); }
.inline-form input[type="text"] { flex: 1 1 160px; min-width: 120px; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; border: 1px solid transparent;
  white-space: nowrap;
}
.badge--warn { background: var(--warn-soft); color: var(--warn); border-color: #fcd34d; }
.badge--ok { background: var(--ok-soft); color: var(--ok); border-color: #86efac; }
.badge--info { background: var(--accent-soft); color: var(--accent); border-color: #bfdbfe; }

/* ---------- tasks ---------- */
.tasks { display: grid; gap: var(--s2); }
.task {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: var(--s2);
  padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px;
}
.task__title { font-weight: 550; font-size: 13.5px; }
.task__meta { color: var(--dim); font-size: 12px; }
.task.is-done .task__title { text-decoration: line-through; color: var(--dim); font-weight: 400; }
.prio { display: inline-flex; align-items: center; gap: 5px; }
.prio::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #94a3b8; }
.prio--1::before { background: #dc2626; }
.prio--2::before { background: #d97706; }
.prio--3::before { background: #64748b; }

/* ---------- month bar + stepper ---------- */
.month-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2);
  padding: var(--s3) var(--s4); margin-bottom: var(--s3);
  background: var(--panel-head); border: 1px solid var(--line); border-radius: var(--radius);
}
.month-bar label { color: var(--dim); font-size: 12.5px; }
.month-bar select { min-width: 130px; }
.month-bar .badge { margin-left: auto; }

.stepper {
  display: flex; flex-wrap: wrap; gap: var(--s2);
  list-style: none; padding: 0; margin: 0 0 var(--s5);
  counter-reset: step;
}
.stepper li {
  flex: 1 1 120px; position: relative;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; font-size: 12.5px; color: var(--dim);
  background: #fff; border: 1px solid var(--line); border-radius: 999px;
  counter-increment: step;
}
.stepper li::before {
  content: counter(step);
  display: grid; place-items: center;
  width: 18px; height: 18px; border-radius: 50%;
  background: #eef2f7; color: var(--dim); font-size: 11px; font-weight: 700;
}
.stepper li.is-done { color: var(--ok); border-color: #bbf7d0; background: var(--ok-soft); }
.stepper li.is-done::before { background: var(--ok); color: #fff; content: "✓"; }
.stepper li.is-current { color: var(--accent); border-color: #bfdbfe; background: var(--accent-soft); }
.stepper li.is-current::before { background: var(--accent); color: #fff; }

/* ---------- cycle panel ---------- */
.cycle { display: grid; gap: var(--s3); }
.cycle__empty { color: var(--dim); font-size: 13px; }
.cycle__meta {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--s2); margin: 0;
}
.cycle__meta div { background: #fbfcfe; border: 1px solid var(--line-soft); border-radius: 8px; padding: 8px 10px; }
.cycle__meta dt { color: var(--dim); font-size: 11.5px; margin-bottom: 2px; }
.cycle__meta dd { margin: 0; font-size: 13px; font-weight: 550; word-break: break-all; }
.cycle__actions { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }
.cycle__actions .cell { max-width: 160px; }
.cycle__actions a.btn { text-decoration: none; }

/* ---------- toast ---------- */
.toast { min-height: 22px; margin-top: var(--s4); font-size: 13px; color: var(--dim); }
.toast.error { color: #b91c1c; }
.toast.ok { color: var(--ok); }

/* ---------- login ---------- */
#login { min-height: 100dvh; display: grid; place-items: center; padding: var(--s4); background: #f7f9fc; }
.login-card {
  width: min(370px, 100%); background: var(--card);
  border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 4px 16px rgba(15, 42, 71, .08);
  padding: var(--s6) var(--s5);
}
.login-card h1 { font-size: 17px; font-weight: 650; }
.login-card .hint { color: var(--dim); font-size: 12.5px; margin: 4px 0 20px; }
.login-card form { display: grid; gap: 10px; }
.login-card label { font-size: 12.5px; color: var(--dim); }
.login-card input { width: 100%; }
.error { color: #b91c1c; font-size: 12.5px; min-height: 18px; margin-top: 10px; }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 720px) {
  .wrap { padding: 0 var(--s4); }
  .main { padding-top: var(--s4); padding-bottom: 48px; }
  .kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s2); }
  .kpi strong { font-size: 20px; }
  .topbar__inner { height: 52px; }
  .brand__name { font-size: 13.5px; }
  .chip { display: none; }
  .page-title { font-size: 17px; }
  .card__head, .card__body { padding-left: var(--s3); padding-right: var(--s3); }
  .table thead th, .table tbody td { padding-left: 10px; padding-right: 10px; }

  /* 表格在手機改為緊湊卡片：一行睇得出日期、商戶、金額、狀態 */
  .table--cards { table-layout: auto; display: block; }
  .table--cards thead { display: none; }
  .table--cards tbody { display: block; }
  .table--cards tbody tr {
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr) auto;
    grid-template-areas:
      "pick merch  amount"
      "pick send   status"
      "pick date   photo"
      "pick msg    photo"
      "pick ocr    ocr"
      "pick detail who";
    gap: 2px 10px; padding: 10px 12px;
    border-bottom: 1px solid var(--line-soft);
    align-items: center;
  }
  .table--cards tbody tr:last-child { border-bottom: 0; }
  .table--cards tbody td {
    display: block; min-width: 0;
    padding: 0; border: 0; white-space: normal; text-align: left !important;
  }
  .table--cards tbody td::before { content: none; }
  .table--cards tbody td[data-label="揀"] {
    grid-area: pick; display: grid; place-items: start center; padding-top: 2px;
    align-self: start;
  }
  .table--cards tbody td[data-label="日期"],
  .table--cards tbody td[data-label="單據日期"] {
    grid-area: date; color: var(--dim); font-size: 12px;
  }
  .table--cards tbody td[data-label="同事發出群組日期"] {
    grid-area: send; color: var(--dim); font-size: 12px;
  }
  /* 手機冇表頭，兩個日期要自己帶名，否則睇唔出邊個係邊個 */
  .table--cards tbody td[data-label="單據日期"]::before { content: "單據日期 "; font-size: 11px; }
  .table--cards tbody td[data-label="同事發出群組日期"]::before { content: "同事發出群組日期 "; font-size: 11px; }
  .table--cards tbody td[data-label="同事補充描述"] {
    grid-area: msg; color: var(--fg); font-size: 12px; opacity: .9;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .table--cards tbody td[data-label="同事補充描述"]::before { content: "補充描述 "; font-size: 11px; }
  .table--cards tbody td[data-label="自動擷取的資訊"] {
    grid-area: ocr; color: var(--dim); font-size: 12px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .table--cards tbody td[data-label="自動擷取的資訊"]::before {
    content: "自動擷取的資訊 "; font-size: 11px;
  }
  .table--cards tbody td[data-label="同事補充描述"].is-blank::before,
  .table--cards tbody td[data-label="自動擷取的資訊"].is-blank::before { content: none; }
  .table--cards tbody td[data-label="同事補充描述"].is-blank,
  .table--cards tbody td[data-label="自動擷取的資訊"].is-blank { opacity: .45; }

  .table--cards tbody td[data-label="商戶"] {
    grid-area: merch; font-size: 14px; font-weight: 600; line-height: 1.3;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .table--cards tbody td[data-label="商戶"] .muted {
    font-size: 11.5px; font-weight: 400; color: var(--dim);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .table--cards tbody td[data-label="類別"] { grid-area: detail; color: var(--dim); font-size: 12px; }
  .table--cards tbody td[data-label="金額"] {
    grid-area: amount; text-align: right !important;
    font-size: 14.5px; font-weight: 650; font-variant-numeric: tabular-nums;
    white-space: nowrap;
  }
  .table--cards tbody td[data-label="提交人"] {
    grid-area: who; color: var(--dim); font-size: 11.5px; text-align: right !important;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .table--cards tbody td[data-label="提交人"] .muted { display: inline; font-size: 11px; }
  .table--cards tbody td[data-label="提交人"] .muted::before { content: " · "; }
  .table--cards tbody td[data-label="欠"] { grid-area: detail; font-size: 11.5px; color: var(--dim); }
  .table--cards tbody td[data-label="欠"] .badge { display: none; }
  .table--cards tbody td[data-label="狀態"] {
    grid-area: status; text-align: right !important; white-space: nowrap;
  }
  .table--cards tbody td[data-label="狀態"] .badge { font-size: 11px; padding: 2px 7px; }
  .table--cards tbody td[data-label="狀態"] .muted { font-size: 10.5px; }
  .table--cards tbody td[data-label="相片"] { grid-area: photo; text-align: right !important; align-self: start; }
  .table--cards tbody td[data-label="相片"] .thumb img { width: 46px; height: 46px; }
  .table--cards tbody td.actions { grid-column: 1 / -1; margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; }
  .table--cards tbody td.empty { display: block; text-align: center !important; padding: 8px 0; }
  .table--cards tbody td.empty::before { content: none; }
}

  /* 一般表格：保留「欄位名 + 值」兩欄 */
  .table--labels, .table--labels tbody { display: block; }
  .table--labels thead { display: none; }
  .table--labels tbody tr {
    display: grid; gap: 6px; padding: 12px;
    border-bottom: 1px solid var(--line-soft);
  }
  .table--labels tbody tr:last-child { border-bottom: 0; }
  .table--labels tbody td {
    display: grid; grid-template-columns: 92px minmax(0, 1fr);
    gap: 10px; align-items: baseline;
    padding: 0; border: 0; text-align: left !important; white-space: normal;
  }
  .table--labels tbody td::before {
    content: attr(data-label); color: var(--dim); font-size: 12px;
  }
  .table--labels tbody td.num { text-align: left !important; }
  .table--labels tbody td.empty {
    display: block; text-align: center !important; padding: 8px 0;
  }
  .table--labels tbody td.empty::before { content: none; }
}
/* ---------- 單據詳情 sheet ---------- */
.row { cursor: pointer; }
.row:hover { background: #f8fafc; }

.sheet {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(15, 23, 42, .42);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet__card {
  background: #fff; width: min(600px, 100%); max-height: 88dvh; overflow-y: auto;
  border-radius: 16px 16px 0 0; padding: 16px 16px 24px;
  will-change: transform, opacity; overscroll-behavior: contain;
  box-shadow: 0 -12px 40px rgba(15, 23, 42, .22);
}
.sheet__head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding-bottom: 10px; border-bottom: 1px solid var(--line-soft); margin-bottom: 12px;
}
.sheet__head strong { font-size: 16px; }
body.no-scroll { overflow: hidden; }
.sheet__tools { display: flex; gap: 6px; }
.edit-form { display: grid; gap: 10px; }
.ef { display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 10px; align-items: center; }
.ef > span { color: var(--dim); font-size: 12.5px; }
.ef input, .ef select { width: 100%; }
.edit-form__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.sheet__photo { display: block; margin-bottom: 14px; }
.sheet__photo img {
  width: 100%; max-height: 260px; object-fit: contain;
  border-radius: 10px; background: #f1f5f9;
}
.dl-list { display: grid; gap: 8px; }
.dl { display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 10px; align-items: start; }
.dl dt { color: var(--dim); font-size: 12.5px; }
.dl dd { margin: 0; font-size: 13.5px; word-break: break-word; }
.sheet h4 { margin: 16px 0 6px; font-size: 13px; color: var(--dim); font-weight: 600; }
.items { margin: 0; padding-left: 18px; font-size: 13px; display: grid; gap: 3px; }
.extras {
  margin: 0; padding: 10px; border-radius: 8px; background: #f8fafc;
  font-size: 12px; white-space: pre-wrap; word-break: break-word;
}
@media (min-width: 720px) {
  .sheet { align-items: center; }
  .sheet__card { border-radius: 16px; }
}

/* ---------- receipt photos ---------- */
.thumb {
  display: inline-block; width: 46px; height: 46px;
  border: 1px solid var(--line); border-radius: 6px; overflow: hidden;
  background: #f5f7fa;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.upload {
  display: inline-block; cursor: pointer; white-space: nowrap;
  font-size: 12px; color: var(--accent);
  border: 1px dashed var(--line-strong); border-radius: 6px; padding: 3px 8px;
}
.upload:hover { background: var(--accent-soft); }

/* ---------- sidebar shell ---------- */
#dashboard {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 100dvh;
  background: var(--bg);
}

.side {
  display: flex; flex-direction: column; gap: var(--s4);
  padding: var(--s4) var(--s3);
  background: var(--navy);
  position: sticky; top: 0; height: 100dvh;
}
.side__brand { display: flex; align-items: center; gap: 9px; padding: 0 var(--s2); }
.side__brand .brand__name { font-size: 14px; font-weight: 650; color: #fff; }
.side__nav { display: grid; gap: 3px; }
.side__item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 12px; border-radius: 8px; text-decoration: none;
  color: #b9cbe0; font-size: 13.5px; font-weight: 500;
}
.side__item:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.side__item.is-active { background: rgba(255, 255, 255, .14); color: #fff; font-weight: 650; }
.side__count {
  min-width: 20px; text-align: center; padding: 0 6px;
  font-size: 11.5px; font-weight: 700; border-radius: 999px;
  background: #fcd34d; color: #78350f;
}
.side__foot {
  margin-top: auto; display: flex; align-items: center; justify-content: space-between;
  gap: var(--s2); padding-top: var(--s3);
  border-top: 1px solid rgba(255, 255, 255, .12);
}
.side__foot .chip { border-color: rgba(255, 255, 255, .25); color: #b9cbe0; }

.main { min-width: 0; padding: var(--s4) var(--s5) 64px; }

.topbar {
  position: static; background: transparent; border: 0;
  padding: 0 0 var(--s4);
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: var(--s3);
}
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }
.toolbar label { color: var(--dim); font-size: 12.5px; }
.toolbar select { min-width: 130px; }

.view { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s4); }
.quick { display: flex; flex-wrap: wrap; gap: var(--s2); }
.quick a.btn { text-decoration: none; }

@media (max-width: 900px) {
  #dashboard { grid-template-columns: minmax(0, 1fr); }
  .topbar {
    display: grid; grid-template-columns: auto minmax(0, 1fr);
    align-items: center; gap: 6px 10px; padding-bottom: var(--s3);
  }
  .topbar > div { min-width: 0; }
  .topbar .page-title { font-size: 18px; text-align: left; line-height: 1.25; }
  .topbar .page-sub { font-size: 12px; text-align: left; }
  .topbar .toolbar {
    grid-column: 1 / -1; justify-content: flex-start;
    gap: 6px 8px; padding-top: 6px; border-top: 1px solid var(--line-soft);
  }
  .toolbar label { white-space: nowrap; font-size: 12px; }
  .toolbar select { min-width: 0; width: auto; padding: 7px 10px; font-size: 13px; }
  .toolbar .btn { white-space: nowrap; padding: 8px 12px; font-size: 12.5px; }
  .account-bar { width: 100%; justify-content: space-between; }
  .account-bar select { flex: 1 1 auto; }
  .stepper { gap: 8px; margin-bottom: var(--s4); }
  .stepper li { flex: 1 1 46%; font-size: 12px; padding: 8px 10px; }
  .side { display: none; }
  .side__brand { flex: 0 0 auto; }
  .side__nav { display: grid; gap: 3px; }
  .side__item { white-space: nowrap; padding: 10px 12px; font-size: 14px; }
  .side__foot { margin-top: auto; border-top: 1px solid rgba(255,255,255,.12); padding-top: var(--s3); }
  .side__foot .chip { display: none; }
  .main { padding: var(--s4) var(--s4) 48px; }
  .topbar { flex-direction: row; flex-wrap: wrap; align-items: center; }

  #nav-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; border-radius: 9px; border: 1px solid var(--line);
    background: var(--card); font-size: 18px; line-height: 1;
  }
  .nav-scrim {
    position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
    z-index: 70;
  }
}

.nav-toggle { display: none; }
body.nav-open { overflow: hidden; }

.sheet__hint {
  margin: 10px 0 0; text-align: center;
  color: var(--dim); font-size: 11.5px;
}

.kpi-note { margin: -10px 0 var(--s4); color: var(--dim); font-size: 12px; line-height: 1.5; }
.tag {
  display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 999px;
  background: #eef2ff; color: #3730a3; font-size: 11px; font-weight: 600;
  vertical-align: middle;
}

.account-bar { display: inline-flex; align-items: center; gap: 6px; }
.account-bar label { color: var(--dim); font-size: 12.5px; }

.history-wrap { margin-top: 16px; }
.history { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 5px; font-size: 12.5px; }
.history li { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- 管理頁 / 批次 / 版本記錄 ---------- */
.side__group {
  margin: var(--s3) 0 2px; padding: 0 12px;
  font-size: 11px; letter-spacing: .08em; color: #7f93aa; text-transform: uppercase;
}
.version { font-variant-numeric: tabular-nums; font-weight: 650; }
.changes { margin: 4px 0 0; padding-left: 16px; font-size: 12.5px; color: var(--dim); }
.changes li { margin: 2px 0; }
.secret {
  margin: 8px 0 0; padding: 12px; border-radius: 8px; background: #f1f5f9;
  font-size: 12.5px; word-break: break-all;
}
.filter-chip {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 var(--s3); padding: 6px 10px; width: fit-content;
  border-radius: 999px; background: #eef2ff; color: #3730a3; font-size: 12.5px;
}
.card__head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); }

.period-tools { display: inline-flex; align-items: center; gap: var(--s2); }

/* 手機：一般表格改為「label 在上、值在下」，避免窄欄擠字 */
@media (max-width: 480px) {
  .table--labels tbody td { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .table--labels tbody td::before { font-size: 11px; letter-spacing: .02em; }
  .table--labels .changes { padding-left: 14px; font-size: 12px; }
  .table--labels tbody td.actions { margin-top: 4px; }
}

@media (max-width: 720px) {
  .kpi { gap: 10px; }
  .kpi li { padding: 10px 12px 12px; }
  .kpi span { font-size: 11.5px; }
  .kpi strong { font-size: 19px; }
  .kpi-note { font-size: 11.5px; margin-top: -6px; }
}

.cycle-list { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 6px; font-size: 13px; }
.cycle-list li { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; }

/* 檔名等長字串：容許斷行，唔好爆格 */
.cycle-list li, .dl dd, .card__body p { overflow-wrap: anywhere; }

.choice-list { display: grid; gap: 8px; margin-top: 10px; }
.choice {
  display: grid; gap: 2px; text-align: left; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: #fff;
}
.choice strong { font-size: 14px; }
.choice span { font-size: 12px; }
.choice:disabled { opacity: .55; }

.choice { display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 2px; text-align: left; }
.choice strong { font-weight: 650; }
.choice span { color: var(--dim); }

/* 主選項要保持藍底白字，唔可以被 .choice 的白底蓋過 */
.choice.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.choice.btn--primary strong, .choice.btn--primary span { color: #fff; }
.choice.btn--primary span { opacity: .85; }

/* ---------- App 式首頁 ---------- */
.home-hero {
  display: grid; gap: 6px; padding: 22px; border-radius: 20px;
  background: #fff; border: 1px solid var(--line); margin-bottom: 16px;
}
.home-hero__label { margin: 0; color: var(--dim); font-size: 14px; }
.home-hero__amount { font-size: 40px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.home-hero__meta { display: flex; gap: 6px; color: var(--dim); font-size: 13px; align-items: center; }
.home-hero__meta .dot { opacity: .5; }

.home-actions { display: grid; gap: 12px; margin-bottom: 16px; }
.home-action {
  display: flex; align-items: center; gap: 16px; min-height: 96px; padding: 18px 20px;
  border-radius: 20px; background: #fff; border: 1px solid var(--line);
  text-decoration: none; color: inherit; box-shadow: 0 2px 6px rgba(15, 23, 42, .04);
}
.home-action:active { transform: scale(.99); }
.home-action__icon {
  display: grid; place-items: center; width: 52px; height: 52px; flex: 0 0 auto;
  border-radius: 16px; background: var(--accent-soft); color: var(--accent);
}
.home-action__text { display: grid; gap: 2px; flex: 1 1 auto; }
.home-action__text strong { font-size: 22px; font-weight: 650; }
.home-action__text small { color: var(--dim); font-size: 13px; }
.home-action__chev { color: var(--dim); font-size: 22px; }

.mini-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 0; }
.mini-stats dt { color: var(--dim); font-size: 12px; }
.mini-stats dd { margin: 2px 0 0; font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; }

.more-row {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; min-height: 56px; padding: 0 18px; font-size: 16px;
  background: none; border: 0; border-bottom: 1px solid var(--line-soft);
  color: inherit; text-decoration: none; text-align: left;
}
.more-row:last-child { border-bottom: 0; }

/* ---------- 同事電話簿 ---------- */
.card__note { margin: 0; padding: 12px 18px 0; font-size: 12.5px; }
.sender-list { list-style: none; margin: 0; padding: 0; }
.sender-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center; gap: 10px; min-height: 52px; padding: 8px 18px;
  border-bottom: 1px solid var(--line-soft);
}
.sender-row:last-child { border-bottom: 0; }
.sender-row__name { font-size: 15px; font-weight: 600; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.sender-row__phone { font-size: 13px; color: var(--dim);
  font-variant-numeric: tabular-nums; white-space: nowrap; }

.tabbar { display: none; }
@media (max-width: 900px) {
  .tabbar {
    display: grid; grid-template-columns: repeat(4, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 65;
    background: #fff; border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .tabbar__item {
    display: grid; justify-items: center; gap: 3px;
    font-size: 11px; color: var(--dim); text-decoration: none; padding: 4px 0;
  }
  .tabbar__item.is-active { color: var(--accent); font-weight: 650; }
  .main { padding-bottom: 96px; }
}

.nav-toggle, .nav-scrim { display: none !important; }

/* 帳號切換：放右上角 */
.topbar { position: relative; }
.account-bar {
  display: inline-flex; align-items: center; gap: 6px;
  margin-left: auto; align-self: flex-start;
}
.account-bar label { color: var(--dim); font-size: 12.5px; white-space: nowrap; }
.account-bar select { min-width: 0; max-width: 150px; padding: 6px 10px; font-size: 13px; }

@media (max-width: 900px) {
  .topbar { grid-template-columns: minmax(0, 1fr) auto; }
  .account-bar { grid-column: 2; grid-row: 1; justify-self: end; }
  .account-bar label { display: none; }
  .account-bar select { max-width: 120px; }
}

/* 月結頁 */
.cycle-hero { display: grid; gap: 6px; padding: 6px 0 16px; }
.cycle-hero__label { color: var(--dim); font-size: 14px; }
.cycle-hero__amount { font-size: 40px; font-weight: 700; letter-spacing: -.02em; }
.cycle-hero__meta {
  color: var(--dim); font-size: 13px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.cycle-hero--empty { padding: 8px 0 4px; }
.cycle__actions { display: grid; gap: 10px; margin-top: 6px; }
.cycle__file { margin: 10px 0 0; font-size: 12px; overflow-wrap: anywhere; }

/* 版本記錄：點開才睇詳情 */
.log-list { display: grid; gap: 10px; }
.log-item {
  background: #fff; border: 1px solid var(--line); border-radius: 16px; overflow: hidden;
}
.log-head {
  display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto;
  align-items: center; gap: 10px; width: 100%;
  min-height: 60px; padding: 14px 16px;
  background: none; border: 0; font-size: 15px; text-align: left; color: inherit;
}
.log-date { color: var(--dim); font-size: 12.5px; }
.log-title { font-weight: 600; }
.log-chev { color: var(--dim); transition: transform .18s ease; }
.log-item.is-open .log-chev { transform: rotate(90deg); }
.log-body { padding: 0 16px 16px; border-top: 1px solid var(--line-soft); }
.log-body .changes { margin: 12px 0 8px; }
.log-files { margin: 0; font-size: 12px; }

.log-title { text-align: left; justify-self: start; overflow-wrap: anywhere; }
.log-head { grid-template-columns: auto auto minmax(0, 1fr) auto; }

/* 月結：動作組（主掣 flex 1，上限 560px；副掣固定 88px） */
.cycle-cta { display: flex; gap: 10px; align-items: stretch; max-width: 560px; }
.cycle-cta__main { flex: 1 1 auto; min-height: 52px; font-size: 15px; }
.cycle-cta__sub { flex: 0 0 auto; min-width: 88px; min-height: 52px; }

.cycle-foot__file { color: var(--dim); font-size: 12px; margin: 12px 0 0; overflow-wrap: anywhere; }

.claim-list { display: grid; }
.claim-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--line-soft);
}
.claim-row:last-child { border-bottom: 0; }
.claim-row__main { display: grid; gap: 2px; }
.claim-row__main strong { font-size: 17px; }
.claim-row__main .muted { font-size: 12px; overflow-wrap: anywhere; }
.claim-row__aside { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

.choice.btn--primary:disabled,
.choice.btn--primary:disabled strong,
.choice.btn--primary:disabled span { background: #e2e8f0; color: #64748b; }

.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px;
  border-radius: 12px; border: 1px solid var(--line); color: var(--accent);
  background: #fff; text-decoration: none;
}
.icon-btn--off { color: #cbd5e1; border-style: dashed; }

/* 向左掃：取消 / 刪除 */
tr.row--void, .claim-row.row--void { opacity: .45; }
tr.row--void td, .claim-row.row--void strong { text-decoration: line-through; }
.row-actions td { background: #fff7f7; }
.row-actions .btn, .claim-row__more .btn { margin-right: 8px; }
.claim-row { flex-wrap: wrap; }
.claim-row__more { width: 100%; padding-top: 10px; }
.btn--danger { color: #b91c1c; border-color: #fecaca; background: #fff; }

/* 月結頁：手機單欄，主掣在上、兩個掣都係整行寬 */
@media (max-width: 720px) {
  .cycle-cta { display: grid; grid-template-columns: 1fr; gap: 8px; max-width: none; }
  .cycle-cta__main { order: -1; min-height: 56px; }
  .cycle-cta__sub { min-height: 48px; }
  .cycle-hero__amount { font-size: 34px; }
}

/* ---------- 月曆揀月份 ---------- */
.period-btn {
  display: inline-flex; align-items: center; gap: 8px; min-height: 40px;
  padding: 6px 12px; border-radius: 10px; border: 1px solid var(--line-strong);
  background: #fff; color: var(--fg); font-size: 14px; font-weight: 600; cursor: pointer;
}
.period-btn:hover { background: #f5f7fa; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- 收據搜尋 ---------- */
.search-bar {
  display: flex; align-items: center; gap: 8px; min-width: 0;
  margin: 0 0 var(--s2); padding: 0 2px;
}
.search-bar select,
.search-bar input {
  height: 44px; border-radius: 10px; border: 1px solid var(--line-strong);
  background: #fff; color: inherit; font-size: 14px; padding: 0 10px;
}
.search-bar select { flex: 0 1 auto; min-width: 0; max-width: 46%; }
.search-bar input { flex: 1 1 0; width: 100%; min-width: 0; font-size: 15px; }
.search-bar .btn { flex: 0 0 auto; height: 44px; }
.search-count { margin: 0 0 var(--s2); padding: 0 2px; font-size: 12.5px; min-height: 0; }

/* ---------- 收據勾選 ---------- */
.pick { width: 44px; text-align: center; }
.pick input { width: 20px; height: 20px; accent-color: var(--accent); }
.pick-bar {
  position: sticky; bottom: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-top: 12px; padding: 12px 16px; border-radius: 14px;
  background: #fff; border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(15, 23, 42, .12);
}
.pick-bar__sum { font-size: 13.5px; color: var(--fg); min-width: 0; }
.pick-bar__actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
#pick-delete { min-height: 44px; }
.pick-bar__sum .muted { margin-left: 6px; }
.repeat-list { margin: 8px 0 12px; padding-left: 18px; font-size: 13px; display: grid; gap: 4px; }
@media (max-width: 720px) { .pick-bar { bottom: 72px; } }

/* ---------- 首頁：切換、方格三掣、波浪、系統連接 ---------- */
.home-hero { position: relative; overflow: hidden; padding-bottom: 54px; }
.home-hero__top { display: flex; align-items: center; gap: 12px; }
.home-hero__switch { display: inline-flex; gap: 4px; margin-left: auto; }
.seg {
  min-height: 32px; padding: 4px 12px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--dim); font-size: 12.5px;
}
.seg.is-active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
/* 首頁支出卡：波浪背景（影片優先，Canvas 做後備） */
.home-hero__video, .home-hero__canvas {
  position: absolute; left: 0; bottom: 0; width: 100%; height: 62px;
  pointer-events: none; display: block;
}
.home-hero__video {
  object-fit: fill;            /* fill = 整條浪都顯示，唔會 cover 裁走上方 */
  mix-blend-mode: multiply;
  opacity: 1;
}
/* 文字／金額要浮在波浪之上 */
.home-hero > :not(.home-hero__video):not(.home-hero__canvas) { position: relative; z-index: 1; }
@media (prefers-reduced-motion: reduce) {
  .home-hero__wave { animation: none; }
}

.home-actions { grid-template-columns: repeat(3, minmax(0, 132px)); gap: 12px; }
.home-action--tile {
  display: grid; justify-items: center; align-content: center; gap: 8px;
  min-height: 0; aspect-ratio: 1 / 1; padding: 12px 8px; border-radius: 16px;
  box-shadow: none; text-align: center;
}
.home-action--tile .home-action__icon { width: 44px; height: 44px; border-radius: 14px; }
.home-action--tile strong { font-size: 13.5px; }
.home-action--tile .home-action__chev,
.home-action--tile small { display: none; }

.mini-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.status-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.status-list li { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.status-list .muted { margin-left: auto; font-size: 12px; }
.dot--ok { background: #16a34a; }
.dot--bad { background: #dc2626; }
.dot--wait { background: #cbd5e1; }

/* ---------- 側欄頭像 ---------- */
.brand__avatar {
  display: grid; place-items: center; width: 34px; height: 34px; padding: 0;
  border-radius: 50%; overflow: hidden; cursor: pointer; flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, .35); background: rgba(255, 255, 255, .14);
  color: #fff; font-size: 14px; font-weight: 700;
}
.brand__avatar img { width: 100%; height: 100%; object-fit: cover; }
.account-avatar { display: inline-flex; margin: 0 0 12px; cursor: pointer; }

/* ---------- 月結：一格格工具按鈕 ---------- */
.cycle-tools { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.cycle-tools .btn { flex: 0 0 auto; min-height: 44px; }

/* ---------- 異動紀錄：摺疊 + 逐欄比較 ---------- */
.history-wrap { margin-top: 16px; border-top: 1px solid var(--line-soft); padding-top: 10px; }
.history-wrap > summary {
  cursor: pointer; font-weight: 600; font-size: 13.5px; padding: 4px 0; list-style: none;
}
.history-wrap > summary::-webkit-details-marker { display: none; }
.history-wrap > summary::before { content: "›"; display: inline-block; margin-right: 6px; transition: transform .15s; }
.history-wrap[open] > summary::before { transform: rotate(90deg); }
.hist { display: grid; gap: 6px; padding: 8px 0; border-top: 1px solid var(--line-soft); }
.hist__head { display: flex; gap: 8px; align-items: baseline; font-size: 12.5px; flex-wrap: wrap; }
.hist__diff { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.hist__diff li { display: flex; flex-wrap: wrap; gap: 6px; font-size: 12.5px; }
.hist__key { color: var(--dim); min-width: 56px; }
.hist__diff .from { color: #b91c1c; text-decoration: line-through; }
.hist__diff .arrow { color: var(--dim); }
.hist__diff .to { color: #15803d; font-weight: 600; }

/* 手機：三格平均分，方形磚 */
@media (max-width: 720px) {
  .home-actions { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .home-action--tile { padding: 10px 6px; }
  .home-action--tile .home-action__icon { width: 38px; height: 38px; }
}

@media (max-width: 720px) {
  .pick-bar { flex-wrap: nowrap; padding: 10px 12px; }
  .pick-bar__sum { font-size: 12.5px; line-height: 1.35; }
  #pick-generate { flex: 0 0 auto; white-space: nowrap; min-height: 44px; }
  #pick-delete { min-height: 44px; padding: 0 12px; }
  .pick-bar__actions { gap: 6px; }
}

/* ---------- 相片燈箱 ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 90;          /* 高過 .sheet 的 80 */
  display: flex; align-items: center; justify-content: center;
  background: rgba(2, 6, 23, .86); padding: 24px;
}
.lightbox__img {
  max-width: 94vw; max-height: 82dvh; object-fit: contain;
  border-radius: 10px; box-shadow: 0 20px 60px rgba(0, 0, 0, .45);
  background: #0b1220;
}
.lightbox__bar {
  position: absolute; top: 12px; right: 12px; left: 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  color: #e2e8f0; font-size: 13px;
}
.lightbox__actions { display: flex; gap: 8px; align-items: center; }
.lightbox__btn {
  min-height: 44px; min-width: 44px; padding: 0 14px; cursor: pointer;
  border-radius: 12px; border: 1px solid rgba(255, 255, 255, .28);
  background: rgba(255, 255, 255, .12); color: #fff; font-size: 14px;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
}
.lightbox__btn:hover { background: rgba(255, 255, 255, .22); }
@media (max-width: 720px) {
  .lightbox { padding: 12px; }
  .lightbox__img { max-height: 76dvh; }
}
