:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #f9fafb;
  --border: #e3e6ea;
  --text: #1c2430;
  --muted: #6b7684;
  --accent: #2456d6;
  --accent-soft: #e8eefc;
  --pos: #12804a;
  --neg: #c4321f;
  --warn: #a96500;
  --side: #141b26;
  --side-text: #c8d0dc;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141b; --panel: #171e28; --panel-2: #1c2430; --border: #2a3441; --text: #e4e9f0;
    --muted: #8d99a8; --accent: #6f9bff; --accent-soft: #1d2a45; --pos: #46c486; --neg: #ff7a66;
    --warn: #f0b04a; --side: #0a0e14; --side-text: #aeb8c6; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141b; --panel: #171e28; --panel-2: #1c2430; --border: #2a3441; --text: #e4e9f0;
  --muted: #8d99a8; --accent: #6f9bff; --accent-soft: #1d2a45; --pos: #46c486; --neg: #ff7a66;
  --warn: #f0b04a; --side: #0a0e14; --side-text: #aeb8c6; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 "Segoe UI", "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.neg { color: var(--neg); }
.pos { color: var(--pos); }

/* layout */
.layout { display: grid; grid-template-columns: 180px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-text); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { color: #fff; font-weight: 700; font-size: 18px; letter-spacing: .08em; padding: 4px 10px 18px; }
.brand small { display: block; font-size: 11px; font-weight: 400; letter-spacing: 0; color: var(--side-text); }
.side a { color: var(--side-text); padding: 8px 10px; border-radius: 6px; display: block; }
.side a:hover { background: rgba(255, 255, 255, .06); text-decoration: none; }
.side a.on { background: rgba(255, 255, 255, .12); color: #fff; }
.side .spacer { flex: 1; }
.side .foot { font-size: 12px; }
main { padding: 22px 22px 60px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .grow { flex: 1; }
.crumb { font-size: 12px; color: var(--muted); margin-bottom: 4px; }

/* panels */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.panel.flush { padding: 0; overflow: hidden; }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.panel-head h2 { margin: 0; }
.panel-head .grow { flex: 1; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi .sub { font-size: 12px; color: var(--muted); }

/* tables */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--panel-2); white-space: nowrap; position: sticky; top: 0; z-index: 1; }
tbody tr:hover td { background: var(--panel-2); }
tr.clickable { cursor: pointer; }
tfoot td { font-weight: 600; background: var(--panel-2); }
td.actions { white-space: nowrap; text-align: right; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* forms */
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { width: 100%; min-height: 120px; font-family: Consolas, monospace; font-size: 12px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--panel);
  border-radius: 6px; padding: 6px 12px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--panel-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--neg); }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn.icon { padding: 3px 7px; border-color: transparent; background: transparent; color: var(--muted); }
.btn.icon:hover { color: var(--neg); background: var(--panel-2); }
.btn[disabled] { opacity: .5; cursor: default; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px 16px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--muted); }
.field.wide { grid-column: 1 / -1; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: var(--panel); padding: 5px 10px; cursor: pointer; }
.seg button.on { background: var(--accent); color: #fff; }

/* tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs a { padding: 9px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs a.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* badges */
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); }
.badge.active, .badge.issued { color: var(--pos); border-color: color-mix(in srgb, var(--pos) 35%, transparent); background: color-mix(in srgb, var(--pos) 10%, transparent); }
.badge.draft { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); background: color-mix(in srgb, var(--warn) 10%, transparent); }
.badge.stopped, .badge.inactive { color: var(--muted); }

/* invoice editor */
.grid-edit th, .grid-edit td { padding: 4px 4px; font-size: 13px; }
.grid-edit input, .grid-edit select { width: 100%; padding: 4px 5px; font-size: 13px; }
.grid-edit input.n { text-align: right; font-variant-numeric: tabular-nums; }
.grid-edit .w-op { min-width: 150px; }
.grid-edit .w-cur { width: 84px; }
.grid-edit .w-rate { width: 62px; }
.grid-edit .w-amt { min-width: 100px; }
.grid-edit .w-pct { width: 46px; }
.grid-edit .w-div { width: 38px; }
.grid-edit .w-pl { width: 54px; }
.grid-edit td.calc { color: var(--muted); }
.grid-edit td.calc.strong { color: var(--text); font-weight: 600; }
.totals-bar {
  position: sticky; bottom: 0; z-index: 5; display: flex; gap: 24px; align-items: center; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 16px;
  box-shadow: 0 -4px 16px rgba(16, 24, 40, .08);
}
.totals-bar .t { display: flex; flex-direction: column; }
.totals-bar .t span:first-child { font-size: 12px; color: var(--muted); }
.totals-bar .t span:last-child { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.totals-bar .grow { flex: 1; }
.dirty-dot { color: var(--warn); font-size: 12px; }

/* bars */
.bars { display: grid; grid-template-columns: repeat(12, 1fr); gap: 8px; align-items: end; height: 170px; padding-top: 10px; }
.bar { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; font-size: 11px; color: var(--muted); }
.bar .fill { width: 70%; max-width: 40px; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 1px; }
.bar .v { font-variant-numeric: tabular-nums; color: var(--text); font-size: 11px; }

/* modal & toast */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 14, 20, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--panel); border-radius: 10px; width: min(720px, 100%); box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.modal header { padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 600; }
.modal .body { padding: 18px; }
.modal footer { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.toast { position: fixed; right: 20px; bottom: 20px; background: var(--side); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 60; box-shadow: 0 6px 20px rgba(0, 0, 0, .2); }
.toast.err { background: var(--neg); }

/* printable documents (invoice / statement) */
.doc-actions { display: flex; gap: 8px; justify-content: center; margin-bottom: 14px; }

@media print {
  @page { size: A4; margin: 10mm; }
  body { background: #fff; }
  .side, .no-print, .doc-actions, .tabs, .page-head .toolbar { display: none !important; }
  .layout { display: block; }
  main { padding: 0; }
  .doc { box-shadow: none; width: auto; padding: 0; }
  .panel { border: 0; box-shadow: none; }
}


/* 方案切換 */
.plan-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: -6px 0 14px; }
.plan-bar .seg a { display: flex; flex-direction: column; align-items: center; padding: 5px 14px; color: var(--text); background: var(--panel); line-height: 1.25; }
.plan-bar .seg a + a { border-left: 1px solid var(--border); }
.plan-bar .seg a:hover { text-decoration: none; background: var(--panel-2); }
.plan-bar .seg a.on { background: var(--accent); color: #fff; }
.plan-bar .seg a small { font-size: 11px; opacity: .8; font-variant-numeric: tabular-nums; }
.badge.plan { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, transparent); background: var(--accent-soft); }

/* 側邊欄代理商清單 */
.side { overflow-y: auto; }
.side-agents { margin: 2px 0 8px 8px; padding-left: 8px; border-left: 1px solid rgba(255, 255, 255, .12); display: flex; flex-direction: column; gap: 1px; }
.side-agents input { background: rgba(255, 255, 255, .06); border-color: rgba(255, 255, 255, .12); color: #fff; font-size: 12px; padding: 4px 8px; margin: 2px 0 4px; }
.side-agents input::placeholder { color: rgba(255, 255, 255, .45); }
.side .side-agents a { padding: 4px 8px; font-size: 13px; display: flex; gap: 6px; align-items: baseline; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side .side-agents a .code { font-size: 11px; opacity: .55; min-width: 28px; }
.side .side-agents a.stopped { opacity: .5; }
.side .foot .me { padding: 8px 10px 4px; display: flex; flex-direction: column; color: #fff; }
.side .foot .me span { font-size: 11px; color: var(--side-text); }

/* 返回按鈕 */
.btn.back { padding: 5px 10px; }

/* 登入 */
#auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--side); }
.auth-card { background: var(--panel); border-radius: 12px; padding: 28px; width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; box-shadow: 0 20px 50px rgba(0, 0, 0, .35); }
.auth-card .brand { color: var(--text); padding: 0; }
.auth-card .brand small { color: var(--muted); }
.auth-card h2 { margin: 4px 0 0; }
.auth-card p { margin: 0; font-size: 13px; }
.auth-card .btn { justify-content: center; padding: 9px; }
.auth-err { color: var(--neg); font-size: 13px; min-height: 1em; }

/* LOGO */
.side .brand { display: block; padding: 0 6px 14px; text-align: center; }
.side .brand:hover { background: none; text-decoration: none; }
.side .brand img { width: 100%; max-width: 160px; height: auto; display: block; margin: 0 auto 4px; }
.side .brand small { display: block; color: var(--side-text); font-size: 11px; letter-spacing: .1em; }
.auth-card .brand { text-align: center; }
.auth-card .brand img { width: 220px; max-width: 100%; height: auto; display: block; margin: 0 auto 4px; }


/* ================================================================
   帳單 / 對帳單（列印文件）
   深藍 #14284b 為主色，金色 #c9952b 呼應 LOGO；細線表格、數字靠右
   ================================================================ */
.doc {
  --ink: #111827; --body: #1f2937; --muted: #6b7280; --soft: #4b5563;
  --navy: #14284b; --gold: #c9952b; --line: #e5e9f0; --line-2: #d6dce6; --tint: #f4f6fa;
  background: #fff; color: var(--body); width: 210mm; max-width: 100%; margin: 0 auto; padding: 16mm 14mm 12mm;
  box-shadow: 0 2px 14px rgba(0, 0, 0, .12); font-size: 11.5px; line-height: 1.45;
  font-family: "Segoe UI", "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
}
.doc[lang="zh-Hans"] { font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", "Noto Sans SC", sans-serif; }
.doc, .doc * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.doc table { width: 100%; border-collapse: collapse; }
.doc th, .doc td { border: 0; padding: 5px 8px; background: none; position: static; color: inherit; }
.doc .num { font-variant-numeric: tabular-nums; }
.doc .neg { color: #b42318; }
.doc a { color: inherit; }

/* 抬頭 */
.doc .doc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; }
.doc .doc-logo { height: 60px; width: auto; display: block; }
.doc .doc-head-r { text-align: right; }
.doc .doc-title { font-size: 28px; font-weight: 300; letter-spacing: .32em; margin-right: -.32em; color: var(--navy); line-height: 1; }
.doc[lang="zh-Hans"] .doc-title { font-weight: 600; letter-spacing: .25em; margin-right: -.25em; }
.doc .doc-meta { display: grid; grid-template-columns: auto auto; justify-content: end; gap: 3px 16px; margin: 14px 0 0; }
.doc .doc-meta dt { color: var(--muted); font-size: 9.5px; letter-spacing: .1em; text-transform: uppercase; align-self: center; }
.doc .doc-meta dd { margin: 0; color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.doc .doc-rule { height: 3px; margin: 16px 0 18px; border-radius: 2px; background: linear-gradient(90deg, var(--navy) 0 72%, var(--gold) 72% 100%); }

/* 客戶 / 應付金額 */
.doc .lbl { font-size: 9.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin-bottom: 5px; }
.doc .doc-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 6px; }
.doc .party { padding: 13px 16px; border: 1px solid var(--line); border-radius: 8px; }
.doc .party-name { font-size: 17px; font-weight: 600; color: var(--ink); letter-spacing: .01em; line-height: 1.25; }
.doc .party-sub { margin-top: 6px; }
.doc .pill { display: inline-block; padding: 1px 9px; border-radius: 99px; background: #eef2f9; color: var(--navy); font-size: 10px; font-weight: 600; }
.doc .due-card { padding: 13px 18px; border-radius: 8px; background: var(--navy); color: #fff; text-align: right; }
.doc .due-card .lbl { color: #c3cde0; }
.doc .due-amt { font-size: 25px; font-weight: 600; letter-spacing: .01em; line-height: 1.15; font-variant-numeric: tabular-nums; }
.doc .due-amt .cur { font-size: 12px; font-weight: 600; color: #e8c27a; margin-right: 6px; letter-spacing: .06em; }
.doc .due-sub { font-size: 10px; color: #c3cde0; margin-top: 4px; }

/* 區段標題 */
.doc .sec { display: flex; align-items: center; gap: 10px; margin: 24px 0 10px; font-size: 10.5px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; color: var(--navy); break-after: avoid; }
.doc .sec::after { content: ""; flex: 1; height: 1px; background: var(--line-2); }

/* 表格 */
.doc .tbl thead th { background: var(--tint); color: var(--soft); font-size: 9.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; text-align: right; line-height: 1.25; padding: 6px 8px; border-bottom: 1px solid var(--line-2); white-space: normal; }
.doc .tbl th:first-child, .doc .tbl td:first-child { text-align: left; }
.doc .tbl tbody td { border-bottom: 1px solid #eef1f5; color: var(--ink); text-align: right; }
.doc .tbl tbody td:first-child { color: var(--ink); }
.doc .tbl td.c { text-align: center; }
.doc .tbl td.m { color: var(--muted); }
.doc .tbl td.strong { font-weight: 700; color: var(--navy); }
.doc .tbl .sub-row td { border-top: 1.5px solid var(--navy); background: #fafbfd; color: var(--navy); font-weight: 700; text-align: right; }
.doc .tbl .sub-row td:first-child { text-align: left; }
.doc .tbl .total-row td { border-top: 2px solid var(--navy); background: var(--tint); color: var(--navy); font-weight: 700; text-align: right; }
.doc .tbl .total-row td:first-child { text-align: left; }
.doc .tbl .adj-row td { background: #fff9ec; color: #7a4f00; }
.doc .details td, .doc .details th { font-size: 10px; padding: 4px 5px; }
.doc .details td.op { font-weight: 600; overflow-wrap: anywhere; }
.doc .pct { color: #a16207; font-size: 9px; }
.doc tr { break-inside: avoid; }
.doc thead { display: table-header-group; }
.doc tfoot { display: table-row-group; }

/* 幣別區塊 */
.doc .cur-block { margin-top: 12px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.doc .cur-block + .cur-block { margin-top: 14px; }
.doc .cur-head { display: flex; align-items: center; gap: 12px; padding: 7px 10px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 10.5px; break-after: avoid; }
.doc .cur-tag { background: var(--navy); color: #fff; font-weight: 700; font-size: 11px; padding: 2px 9px; border-radius: 4px; letter-spacing: .05em; }
.doc .cur-head .cur-sum { margin-left: auto; color: var(--navy); font-weight: 700; font-size: 11.5px; font-variant-numeric: tabular-nums; }
.doc .cur-block table { table-layout: fixed; }
.doc .cur-block .tbl.details th:nth-child(1) { width: 17%; }
.doc .cur-block .tbl.details th:nth-child(n+2) { width: 9.2%; }

/* 合計 */
.doc .totals { display: flex; justify-content: flex-end; margin-top: 16px; break-inside: avoid; }
.doc .totals-box { width: 56%; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.doc .totals-box .row { display: flex; justify-content: space-between; gap: 12px; padding: 7px 14px; border-bottom: 1px solid #eef1f5; }
.doc .totals-box .row > span:first-child { color: var(--soft); }
.doc .totals-box .row b { color: var(--ink); font-variant-numeric: tabular-nums; }
.doc .totals-box .row.grand { background: var(--navy); border: 0; font-size: 14px; }
.doc .totals-box .row.grand > span:first-child { color: #e8c27a; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; font-size: 11px; align-self: center; }
.doc .totals-box .row.grand b { color: #fff; }
.doc .aging { width: 56%; margin: 10px 0 0 auto; }
.doc .aging td, .doc .aging th { font-size: 10px; }
.doc .notes { margin-top: 18px; padding: 9px 12px; border-left: 3px solid var(--gold); background: #fbf8f1; color: var(--soft); font-size: 10px; line-height: 1.7; break-inside: avoid; }
.doc .doc-foot { margin-top: 26px; padding-top: 8px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; color: #9ca3af; font-size: 9.5px; letter-spacing: .04em; }

/* 對帳單 */
.doc .stmt td:first-child { font-weight: 600; }
.doc .stmt .prev td { color: var(--soft); font-style: italic; }

/* SUMMARY 欄寬（含計費期間欄） */
.doc .cur-block .tbl:not(.details):not(.stmt) th:nth-child(1) { width: 27%; }
.doc .cur-block .tbl:not(.details):not(.stmt) th:nth-child(2) { width: 16%; }
.doc .cur-block .tbl:not(.details):not(.stmt) th:nth-child(3) { width: 13%; }
.doc .cur-block .tbl:not(.details):not(.stmt) th:nth-child(4) { width: 9%; }
.doc .cur-block .tbl:not(.details):not(.stmt) th:nth-child(5) { width: 12%; }
.doc .cur-block .tbl:not(.details):not(.stmt) th:nth-child(6) { width: 9%; }
.doc .cur-block .tbl:not(.details):not(.stmt) th:nth-child(7) { width: 14%; }
.doc .cur-block .tbl.usd-bill th:nth-child(1) { width: 36%; }
.doc .cur-block .tbl.usd-bill th:nth-child(2) { width: 20%; }
.doc .cur-block .tbl.usd-bill th:nth-child(3) { width: 16%; }
.doc .cur-block .tbl.usd-bill th:nth-child(4) { width: 12%; }
.doc .cur-block .tbl.usd-bill th:nth-child(5) { width: 16%; }
.doc .adj-note { font-size: 9.5px; color: #7a4f00; }

/* 列印 / PDF：拿掉畫面上的卡片外框，用紙張本身 */
@media print {
  .doc { box-shadow: none; width: auto; max-width: none; margin: 0; padding: 0; }
  .page-head, .plan-bar, .crumb { display: none !important; }
}

/* 帳單編輯：營運商下方的計費期間 */
.grid-edit .w-period { display: block; margin-top: 3px; font-size: 11px; padding: 2px 6px; border-color: transparent; background: transparent; color: var(--muted); }
.grid-edit .w-period:hover, .grid-edit .w-period:focus { border-color: var(--border); background: var(--panel); }
.grid-edit .w-period.custom { color: var(--warn); font-weight: 600; background: color-mix(in srgb, var(--warn) 8%, transparent); }
.doc .tbl td.per { text-align: left; white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; }
.doc .per.custom { color: #b45309; font-weight: 600; }
.doc .details .per { font-size: 9px; font-weight: 600; white-space: nowrap; }
.doc .tbl th.per { text-align: left; }
.doc .tbl td.per.custom, .doc .details .per.custom { color: #b45309; font-weight: 700; }

/* 必填欄位 */
.field .req { color: var(--neg); margin-left: 2px; }
input.invalid, select.invalid { border-color: var(--neg); background: color-mix(in srgb, var(--neg) 6%, var(--panel)); outline: 2px solid color-mix(in srgb, var(--neg) 25%, transparent); }
.warn { color: var(--warn); }

/* 每月需填返水 */
.badge.need { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); background: color-mix(in srgb, var(--warn) 10%, transparent); }
.grid-edit input.need { border-color: color-mix(in srgb, var(--warn) 60%, var(--border)); background: color-mix(in srgb, var(--warn) 8%, var(--panel)); }

/* 介面語系切換 */
.ui-lang { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; align-self: center; }
.ui-lang button { border: 0; background: transparent; color: inherit; padding: 4px 10px; font-size: 12px; cursor: pointer; }
.ui-lang button.on { background: var(--accent); color: #fff; }
.side .ui-lang { margin: 6px 10px; border-color: rgba(255, 255, 255, .18); color: var(--side-text); }
.auth-card .ui-lang { margin: 4px auto 0; color: var(--muted); }

/* 鎖帳 */
.badge.lock { color: #6b4e00; border-color: #e3c56b; background: #fff6d6; }
.lock-note { margin: -8px 0 14px; padding: 9px 14px; border-radius: 8px; background: #fff6d6; color: #6b4e00; border: 1px solid #e3c56b; font-size: 13px; }
.lock-panel { border-left: 4px solid #d4a72c; }

/* 鎖帳 */
.badge.lock { color: #6b4e00; border-color: #e3c56b; background: #fff6d6; }
.lock-note { margin: -8px 0 14px; padding: 9px 14px; border-radius: 8px; background: #fff6d6; color: #6b4e00; border: 1px solid #e3c56b; font-size: 13px; }
.lock-panel { border-left: 4px solid #d4a72c; }

/* ================================================================
   帳單編輯表格：欄位分組、輸入格像試算表、結果欄醒目
   ================================================================ */
.grid-edit { --g-in: color-mix(in srgb, #2563eb 5%, transparent); --g-set: color-mix(in srgb, #d97706 6%, transparent);
  --g-res: color-mix(in srgb, var(--accent) 9%, transparent); --g-final: color-mix(in srgb, var(--accent) 16%, transparent);
  --g-extra: color-mix(in srgb, #16a34a 6%, transparent); border-collapse: separate; border-spacing: 0; }
/* 分組標題列 */
.grid-edit tr.grp th { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-align: center; padding: 6px 4px; border-bottom: 2px solid transparent; text-transform: uppercase; }
.grid-edit tr.grp th.g-in { background: var(--g-in); color: #1d4ed8; border-bottom-color: #93b4f5; }
.grid-edit tr.grp th.g-set { background: var(--g-set); color: #b45309; border-bottom-color: #f2c37b; }
.grid-edit tr.grp th.g-calc { color: var(--muted); border-bottom-color: var(--border); }
.grid-edit tr.grp th.g-res { background: var(--g-final); color: var(--accent); border-bottom-color: var(--accent); }
.grid-edit tr.grp th.g-extra { background: var(--g-extra); color: #15803d; border-bottom-color: #86d3a0; }
.grid-edit thead tr:nth-child(2) th { top: 29px; }
/* 欄位底色 */
.grid-edit td.in { background: var(--g-in); }
.grid-edit td.set { background: var(--g-set); }
.grid-edit td.res { background: var(--g-res); color: var(--text); }
.grid-edit td.res.final { background: var(--g-final); font-weight: 700; font-size: 14px; color: var(--accent); border-left: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); }
.grid-edit td.extra { background: var(--g-extra); }
.grid-edit td.calc { color: var(--muted); }
/* 輸入格：平常像試算表格子，滑過 / 輸入時才出現外框 */
.grid-edit td input, .grid-edit td select { border-color: transparent; background: transparent; border-radius: 4px; transition: border-color .12s, background .12s; }
.grid-edit tr:hover td input, .grid-edit tr:hover td select { border-color: var(--border); background: var(--panel); }
.grid-edit td input:focus, .grid-edit td select:focus { border-color: var(--accent); background: var(--panel); outline: 2px solid var(--accent-soft); }
.grid-edit td input.need { border-color: color-mix(in srgb, var(--warn) 55%, transparent); background: color-mix(in srgb, var(--warn) 10%, var(--panel)); }
/* 營運商欄固定在左邊 */
.grid-edit td.opcell, .grid-edit thead tr:nth-child(2) th:nth-child(2) { position: sticky; left: 0; z-index: 2; background: var(--panel); box-shadow: 1px 0 0 var(--border); }
.grid-edit thead tr:nth-child(2) th:nth-child(2) { z-index: 3; background: var(--panel-2); }
.grid-edit td.opcell .w-op { font-weight: 600; }
/* 有數據的列清楚、沒數據的列淡一點 */
.grid-edit tbody tr.no-data td:not(.opcell) { opacity: .45; }
.grid-edit tbody tr.no-data .w-op { font-weight: 400; color: var(--muted); }
.grid-edit tbody tr.no-data:hover td { opacity: 1; }
.grid-edit tbody tr.has-data td.idx { color: var(--accent); font-weight: 700; }
.grid-edit tbody tr:hover td.opcell { background: var(--panel-2); }
.grid-edit tbody tr td { border-bottom: 1px solid var(--border); }
.grid-edit td.opcell { min-width: 210px; }
.grid-edit td.opcell .w-op { min-width: 200px; }
.grid-edit .w-period { margin-top: 1px; padding: 1px 6px; }
.grid-edit td { padding-top: 3px; padding-bottom: 3px; }

/* 帳單：客戶（代理商）名稱放大、醒目 */
.doc .party { display: flex; flex-direction: column; justify-content: center; border-left: 4px solid var(--gold); }
.doc .party-name { font-size: 26px; font-weight: 650; color: var(--navy); letter-spacing: .02em; line-height: 1.15; }
.doc .party .lbl { margin-bottom: 6px; }

/* 帳單 SUMMARY：兩層表頭、幣別小計更醒目 */
.doc .sum-tbl thead th { white-space: nowrap; }
.doc .sum-tbl thead th { vertical-align: bottom; }
.doc .sum-tbl thead tr.h1 th { padding-bottom: 6px; }
.doc .sum-tbl thead tr.h1 th.hc { padding: 6px 8px 3px; border-bottom: 0; text-align: center; color: var(--navy); font-weight: 700; letter-spacing: .1em; }
.doc .sum-tbl thead tr.h1 th.hc::after { content: ""; display: block; height: 1.5px; background: var(--line-2); margin-top: 4px; }
.doc .sum-tbl thead tr.h2 th { padding-top: 2px; padding-bottom: 6px; text-align: right; }
.doc .sum-tbl thead tr.h2 th:nth-child(2n) { color: var(--navy); }
.doc .cur-head .cur-sum { display: flex; align-items: baseline; gap: 6px; }
.doc .cur-head .cur-sum-lbl { font-size: 9.5px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-right: 2px; }
.doc .cur-head .cur-sum-sep { color: var(--line-2); margin: 0 2px; }
.doc .tbl .sub-row.total-bar td { background: #eaf0fa; border-top: 2px solid var(--navy); font-size: 12px; padding-top: 8px; padding-bottom: 8px; }
.doc .tbl .sub-row.total-bar td:first-child { font-weight: 600; color: var(--soft); }
.doc .tbl .sub-row.total-bar td:first-child .cur-tag { margin-right: 6px; }
.doc .tbl .sub-row.total-bar td.num { font-size: 13px; color: var(--navy); }
.doc .cur-block .sum-tbl th { width: auto !important; }

/* 帳單上的負數：鮮紅色（深藍底的地方用亮一點的紅，才看得清楚） */
.doc .neg, .doc .tbl td.neg, .doc .tbl .neg { color: #e01e1e !important; font-weight: 600; }
.doc .due-card .neg, .doc .totals-box .row.grand .neg { color: #ff7a7a !important; }

/* 帳單：表頭文字一律靠下對齊，換行的欄位跟單行的欄位底線對齊 */
.doc .tbl thead th { vertical-align: bottom; }
.doc .details thead th { padding-top: 7px; padding-bottom: 7px; line-height: 1.3; }

/* 帳單（第 1 頁）與明細（第 2 頁起）分頁；畫面上用虛線標示分頁位置 */
.doc .page-split { display: flex; align-items: center; gap: 10px; margin: 34px 0 6px; color: var(--muted); font-size: 10px; letter-spacing: .08em; }
.doc .page-split::before, .doc .page-split::after { content: ""; flex: 1; border-top: 1.5px dashed var(--line-2); }
@media print {
  .doc .page-start { break-before: page; page-break-before: always; margin-top: 0; }
}

/* 明細：表頭下方的幣別 */
.doc .details thead th .th-cur { display: block; margin-top: 2px; font-size: 8.5px; font-weight: 700; letter-spacing: .06em; color: var(--gold); }

/* 帳單：不同幣別區塊之間拉開距離、每個區塊有自己的標題帶，客戶一眼分得出幣別 */
.doc .cur-block { border: 1px solid var(--line-2); border-left: 4px solid var(--gold); border-radius: 8px; box-shadow: 0 1px 0 rgba(20, 40, 75, .04); }
.doc .cur-block + .cur-block { margin-top: 26px; }
.doc .cur-head { background: linear-gradient(90deg, #eef2f9, #f8f9fc); padding: 9px 12px; border-bottom: 1px solid var(--line-2); font-size: 11px; }
.doc .cur-head .cur-tag { font-size: 13px; padding: 3px 12px; }
.doc .cur-head > span:not(.cur-tag):not(.cur-sum) { color: var(--soft); font-weight: 600; }
/* 營運商少的幣別（≤15 筆）整塊放同一頁，不會被切成兩頁 */
@media print { .doc .cur-block.small { break-inside: avoid; page-break-inside: avoid; } }

/* 代理商頁：營運中 / 停止營運 分頁 */
.page-head .seg a { display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px; color: var(--text); background: var(--panel); text-decoration: none; font-size: 13px; }
.page-head .seg a + a { border-left: 1px solid var(--border); }
.page-head .seg a.on { background: var(--accent); color: #fff; }
.page-head .seg a small { font-size: 11px; padding: 0 6px; border-radius: 999px; background: color-mix(in srgb, currentColor 14%, transparent); }

/* ================================================================
   手機版（寬度 860px 以下）：上方列 + 滑出式選單；表格變卡片；帳單等比縮小
   ================================================================ */
.topbar, .side-backdrop { display: none; }
@media screen and (max-width: 860px) {
  .layout { display: block; }
  .topbar {
    display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 30;
    height: 54px; padding: 0 12px; background: var(--side); box-shadow: 0 2px 10px rgba(0, 0, 0, .18);
  }
  .top-brand img { height: 34px; width: auto; display: block; }
  .menu-btn { display: flex; flex-direction: column; justify-content: center; gap: 5px; width: 40px; height: 40px; padding: 0 9px; border: 0; border-radius: 8px; background: transparent; cursor: pointer; }
  .menu-btn span { display: block; height: 2px; border-radius: 2px; background: #fff; transition: transform .2s, opacity .2s; }
  .menu-open .menu-btn span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  .menu-open .menu-btn span:nth-child(2) { opacity: 0; }
  .menu-open .menu-btn span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
  .side {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 40; width: min(280px, 84vw); height: auto;
    transform: translateX(-102%); transition: transform .22s ease; box-shadow: 4px 0 24px rgba(0, 0, 0, .3);
    padding-top: 16px; overscroll-behavior: contain;
  }
  .menu-open .side { transform: none; }
  .side-backdrop { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(10, 14, 20, .45); opacity: 0; pointer-events: none; transition: opacity .2s; }
  .menu-open .side-backdrop { opacity: 1; pointer-events: auto; }
  .menu-open { overflow: hidden; }
  .side a { padding: 11px 12px; font-size: 15px; }
  .side .side-agents a { padding: 8px 8px; font-size: 14px; }
  .side .brand img { max-width: 130px; }

  main { padding: 14px 12px 70px; }
  h1 { font-size: 18px; }
  .page-head { gap: 8px; margin-bottom: 14px; }
  .page-head input, .page-head select { flex: 1 1 100%; width: 100% !important; }
  .page-head .grow { display: none; }
  .panel { padding: 12px; }
  .panel-head { padding: 10px 12px; }

  /* 總覽 */
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi { padding: 10px 12px; }
  .kpi .value { font-size: 17px; overflow-wrap: anywhere; }
  .panel:has(> .bars), .panel:has(.bars) { overflow-x: auto; }
  .bars { min-width: 560px; }

  /* 分頁、按鈕列：放不下就橫向捲動 / 換行，不超出畫面 */
  .tabs { overflow-x: auto; scrollbar-width: none; }
  .tabs a { white-space: nowrap; padding: 9px 12px; }
  .toolbar, .doc-actions { flex-wrap: wrap; }
  .doc-actions { justify-content: flex-start; }
  .plan-bar .seg { max-width: 100%; overflow-x: auto; }
  .totals-bar { gap: 10px 18px; padding: 8px 12px; }
  .totals-bar .t span:last-child { font-size: 16px; }
  .modal-bg { padding: 12px 8px; }
  .modal .body { padding: 14px; }
  .toast { left: 12px; right: 12px; bottom: 12px; }

  /* 表格 → 卡片 */
  table.m-cards, .m-cards > tbody, .m-cards > tfoot, .m-cards > tbody > tr, .m-cards > tfoot > tr { display: block; width: 100%; }
  .m-cards > thead { display: none; }
  .m-cards > tbody > tr, .m-cards > tfoot > tr { padding: 10px 12px; border-bottom: 1px solid var(--border); }
  .m-cards > tbody > tr:hover > td { background: none; }
  .m-cards > tfoot > tr { background: var(--panel-2); }
  /* 欄位名稱靠左（浮動），內容整組靠右，同一格裡的多個元素（例如 MYR + 金額、狀態 + 鎖）不會被拆開 */
  .m-cards > tbody > tr > td, .m-cards > tfoot > tr > td {
    display: block; border: 0; padding: 2px 0; line-height: 24px; text-align: right; white-space: normal; overflow-wrap: anywhere; background: none;
  }
  .m-cards td::after { content: ""; display: block; clear: both; }
  .m-cards td[data-label]::before { content: attr(data-label); float: left; max-width: 48%; margin-right: 12px; text-align: left; color: var(--muted); font-size: 12px; font-weight: 400; white-space: normal; overflow-wrap: normal; }
  .m-cards td:not([data-label]) { text-align: center; }
  .m-cards td.m-empty { display: none; }
  .m-cards td:first-child { font-weight: 600; }
  .m-cards td input, .m-cards td select { width: 52%; max-width: 52%; padding: 5px 8px; border: 1px solid var(--border) !important; background: var(--panel) !important; text-align: right; }
  .m-cards td:not([data-label]) { text-align: right; }
  .m-cards td.actions { padding-top: 6px; text-align: right; }
  .m-cards td.actions::before { content: none; }
  .table-wrap { overflow-x: visible; }

  /* 帳單編輯表格：維持表格，橫向捲動 */
  .keep-table { min-width: 900px; }
  .table-wrap:has(.keep-table) { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .panel[style*="max-width"] { max-width: none !important; }

  /* 帳單 / 對帳單：保持 A4 版面，用 zoom 等比縮小（app.js fitDocs） */
  .doc { width: 210mm; max-width: none; padding: 12mm 10mm; }
}
@media print { .doc { zoom: 1 !important; } .topbar, .side-backdrop { display: none !important; } }

/* 平台商報表 */
.pf-bar { margin: -4px 0 14px; }
.pf-meta { font-size: 12px; }
.pf-table tr.pf-first td { border-top: 1px solid var(--border); }
.pf-table tr.pf-sub td { font-weight: 600; background: var(--panel-2); }
.pf-pct { font-size: 11px; }
.page-head .seg a { white-space: nowrap; }
@media screen and (max-width: 860px) {
  .pf-table.m-cards tr.pf-first td { border-top: 0; }
  .pf-table.m-cards tr.pf-first { border-top: 2px solid var(--border); }
}

/* 平台商報表：每個平台商（或每個月）一個區塊，區塊之間留空隙 */
.pf-table tbody tr.pf-gap td { height: 14px; padding: 0; border: 0; background: var(--bg); }
.pf-table tbody tr.pf-gap:hover td { background: var(--bg); }
.pf-table tbody tr.pf-head td { background: color-mix(in srgb, var(--accent) 8%, var(--panel)); border-top: 2px solid var(--accent); border-bottom: 1px solid var(--border); padding: 8px 10px; text-align: left; }
.pf-table tbody tr.pf-head:hover td { background: color-mix(in srgb, var(--accent) 8%, var(--panel)); }
.pf-table .pf-name { font-weight: 700; font-size: 15px; color: var(--text); }
.pf-table .pf-name a { color: var(--accent); }
.pf-table .pf-note { margin-left: 10px; color: var(--muted); font-size: 12px; }
.pf-table tr.pf-sub td { border-top: 1px solid var(--border); }
.pf-table tbody tr:not(.pf-head):not(.pf-gap):not(.pf-sub) td:first-child { padding-left: 18px; }
@media screen and (max-width: 860px) {
  .pf-table.m-cards tr.pf-gap { padding: 0; border: 0; height: 12px; background: var(--bg); }
  .pf-table.m-cards tr.pf-head { padding: 0; border-bottom: 0; }
  .pf-table.m-cards tr.pf-head td { text-align: left; padding: 10px 12px; }
  .pf-table.m-cards > tbody > tr:not(.pf-head):not(.pf-gap) > td:first-child { padding-left: 0; }
}
.pf-src { display: inline-block; margin-left: 6px; padding: 0 7px; border-radius: 99px; font-size: 11px; font-weight: 500; color: var(--muted); border: 1px solid var(--border); background: var(--panel); vertical-align: 1px; }
.pf-src.locked { color: var(--pos); border-color: color-mix(in srgb, var(--pos) 35%, transparent); background: color-mix(in srgb, var(--pos) 8%, var(--panel)); }

/* 負數：一律用最亮的紅色（網站畫面、報表、帳單 / 對帳單） */
.neg, td.neg, .kpi .neg, .value.neg { color: #ff0000 !important; }
.doc .neg, .doc .tbl td.neg, .doc .tbl .neg, .doc .due-card .neg, .doc .totals-box .row.grand .neg { color: #ff0000 !important; }

/* 平台商報表：每個區塊重複欄位標題；表格最上面的標題就不用了（手機版卡片仍會讀它當欄位名稱） */
.pf-table.pf-grouped > thead { display: none; }
.pf-table tr.pf-colhead th { position: static; background: var(--panel-2); font-size: 12px; font-weight: 600; color: var(--muted); padding: 6px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.pf-table tr.pf-colhead th:first-child { padding-left: 18px; }
.pf-table tbody tr.pf-colhead:hover th { background: var(--panel-2); }
@media screen and (max-width: 860px) { .pf-table.m-cards tr.pf-colhead { display: none; } }

/* 貨幣匯率 */
.rate-help { background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: var(--radius); padding: 10px 14px; margin: -6px 0 14px; font-size: 13px; line-height: 1.7; }
.rates-panel { max-width: 1100px; }
.rates-table td { vertical-align: middle; }
.rates-table .cur-code { display: inline-block; min-width: 58px; text-align: center; padding: 3px 8px; border-radius: 6px; background: var(--side); color: #fff; font-weight: 700; font-size: 12px; letter-spacing: .04em; }
.rates-table .rate-country { font-weight: 600; }
.rates-table .rate-name { font-size: 12px; }
.rates-table .rate-input { width: 120px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.rates-table .rate-was { font-size: 11px; color: var(--warn); margin-top: 2px; }
.rates-table tr.rate-changed td { background: color-mix(in srgb, var(--warn) 8%, var(--panel)); }
.rates-table tr.rate-changed .rate-input { border-color: var(--warn); }
.rates-table td.actions { white-space: nowrap; }
.rate-bar { margin-top: 12px; max-width: 1100px; }
@media screen and (max-width: 860px) {
  .rates-table.m-cards td .rate-input { width: 52%; }
  .rate-help { margin-top: 0; }
}
.pf-table td.pf-plat { font-weight: 600; white-space: nowrap; }

/* 平台商報表：列印 / PDF（A4 橫向） */
.print-title { display: none; }
@media print {
  .pf-printing .print-title { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; padding-bottom: 8px; border-bottom: 2px solid #14284b; }
  .pf-printing .print-title img { height: 36px; }
  .pf-printing .print-title b { font-size: 16px; color: #14284b; }
  .pf-printing .print-title span { font-size: 11px; color: #4b5563; }
  .pf-printing .page-head, .pf-printing .pf-bar, .pf-printing .topbar { display: none !important; }
  body.pf-printing, .pf-printing main { background: #fff; }
  .pf-printing .kpis { grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 8px; }
  .pf-printing .kpi { padding: 6px 10px; box-shadow: none; }
  .pf-printing .kpi .value { font-size: 15px; }
  .pf-printing .panel { border: 1px solid #d6dce6; box-shadow: none; break-inside: auto; }
  .pf-printing .table-wrap { overflow: visible !important; }
  .pf-printing table { font-size: 9.5px; }
  .pf-printing th, .pf-printing td { padding: 3px 5px !important; }
  .pf-printing tr { break-inside: avoid; }
  .pf-printing tr.pf-head, .pf-printing tr.pf-colhead { break-after: avoid; }
  .pf-printing .pf-table tbody tr.pf-gap td { height: 6px; background: #fff; }
  .pf-printing .pf-table tbody tr.pf-head td { padding: 4px 6px !important; }
  .pf-printing .pf-name { font-size: 11.5px; }
  .pf-printing, .pf-printing * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
@media print { .pf-printing tfoot { display: table-row-group; } }

/* ================================================================
   總覽
   ================================================================ */
.dash-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.dkpi { --c: var(--accent); display: flex; gap: 14px; align-items: flex-start; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.dkpi::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--c); }
.dkpi .ic { flex: 0 0 auto; width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center; background: color-mix(in srgb, var(--c) 14%, var(--panel)); color: var(--c); }
.dkpi .ic svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.dkpi .label { font-size: 12px; color: var(--muted); }
.dkpi .value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.25; margin-top: 2px; }
.dkpi .value small { font-size: 12px; font-weight: 500; color: var(--muted); }
.dkpi .value-sm { font-size: 17px; }
.dkpi .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.dkpi.c-blue { --c: #2456d6; } .dkpi.c-teal { --c: #0f9488; } .dkpi.c-gold { --c: #c9952b; } .dkpi.c-violet { --c: #7c4dd8; }
.trend { font-weight: 700; margin-left: 4px; }
.trend.up { color: var(--pos); } .trend.down { color: #ff0000; }

.dash-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; align-items: stretch; }
.dash-grid.even { grid-template-columns: 1fr 1fr; }
.dash-grid > .panel { margin-bottom: 16px; }
.dash-title { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.dash-title h2 { margin: 0; flex: 1; }
.legend { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.legend .lg { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-left: 6px; }
.lg.locked { background: linear-gradient(180deg, #4b7bec, #2456d6); }
.lg.open { background: repeating-linear-gradient(135deg, #f3b74f 0 3px, #fde6b8 3px 6px); }

.dbars { display: grid; grid-template-columns: repeat(12, 1fr); gap: 10px; align-items: end; height: 210px; }
.dbar { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 5px; cursor: default; }
.dbar .fill { width: 72%; max-width: 46px; min-height: 2px; border-radius: 6px 6px 2px 2px; background: var(--border); transition: filter .15s; }
.dbar.locked .fill { background: linear-gradient(180deg, #4b7bec, #2456d6); }
.dbar.open .fill { background: repeating-linear-gradient(135deg, #f3b74f 0 5px, #fbd58f 5px 10px); }
.dbar.latest .fill { box-shadow: 0 0 0 3px color-mix(in srgb, #2456d6 25%, transparent); }
.dbar:hover .fill { filter: brightness(1.12); }
.dbar .v { font-size: 11px; font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; }
.dbar .m { font-size: 12px; color: var(--muted); }
.dbar.latest .m { color: var(--accent); font-weight: 700; }

.close-row { padding: 10px 0; border-bottom: 1px solid var(--border); }
.close-row:last-child { border-bottom: 0; }
.close-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 7px; }
.progress { height: 8px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--border); overflow: hidden; }
.progress > div { height: 100%; border-radius: 99px; background: linear-gradient(90deg, #22a06b, #12804a); }
.close-sub { font-size: 12px; margin-top: 5px; }

.rank-row { display: grid; grid-template-columns: 22px 130px 1fr 92px 48px; align-items: center; gap: 10px; padding: 7px 4px; border-radius: 6px; color: var(--text); }
.rank-row:hover { background: var(--panel-2); text-decoration: none; }
.rank-no { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700; background: var(--panel-2); color: var(--muted); }
.rank-row:nth-of-type(-n+3) .rank-no { background: #c9952b; color: #fff; }
.rank-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-bar { height: 10px; border-radius: 99px; background: var(--panel-2); overflow: hidden; }
.rank-bar > span { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, #6f9bff, #2456d6); }
.rank-val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.rank-share { text-align: right; font-size: 12px; }
.owe-row { display: flex; justify-content: space-between; gap: 10px; padding: 9px 4px; border-bottom: 1px dashed var(--border); color: var(--text); }
.owe-row:last-child { border-bottom: 0; }
.owe-row:hover { background: var(--panel-2); text-decoration: none; }
.owe-row .num { font-weight: 600; }

@media screen and (max-width: 1100px) { .dash-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media screen and (max-width: 860px) {
  .dash-kpis { gap: 8px; }
  .dkpi { padding: 12px; gap: 10px; flex-direction: column; }
  .dkpi .ic { width: 34px; height: 34px; }
  .dkpi .value { font-size: 17px; }
  .dash-grid, .dash-grid.even { grid-template-columns: 1fr; gap: 0; }
  .dash-grid .panel:has(.dbars) { overflow-x: auto; }
  .dbars { min-width: 560px; }
  .rank-row { grid-template-columns: 22px 1fr 80px 42px; }
  .rank-bar { display: none; }
}

/* 使用者管理：權限標籤與說明 */
.role-tag { display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; border: 1px solid var(--border); background: var(--panel-2); color: var(--muted); margin-right: 6px; white-space: nowrap; }
.role-tag.super { background: linear-gradient(90deg, #c9952b, #e0b24f); border-color: #c9952b; color: #fff; }
.role-tag.admin { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, transparent); color: var(--accent); }
.role-help { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; margin: -6px 0 14px; font-size: 13px; line-height: 1.9; }
tr.locked-row { cursor: not-allowed; }
tr.locked-row td { color: var(--muted); }

/* 代理商列表：卡片 */
.agent-summary { display: flex; flex-wrap: wrap; gap: 8px; margin: -4px 0 16px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 5px 12px; border-radius: 99px; background: var(--panel); border: 1px solid var(--border); font-size: 13px; color: var(--muted); }
.chip b { color: var(--text); }
.view-seg button { padding: 6px 12px; }
.agent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.agent-card { display: flex; flex-direction: column; gap: 12px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; color: var(--text); box-shadow: var(--shadow); border-top: 3px solid var(--accent); transition: transform .12s, box-shadow .12s, border-color .12s; }
.agent-card:hover { text-decoration: none; transform: translateY(-2px); box-shadow: 0 8px 22px rgba(16, 24, 40, .1); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.agent-card.is-stopped { border-top-color: var(--muted); opacity: .8; }
.ac-top { display: flex; align-items: center; gap: 10px; }
.ac-code { flex: 0 0 auto; min-width: 34px; height: 26px; padding: 0 7px; border-radius: 7px; display: grid; place-items: center; background: var(--side); color: #fff; font-size: 12px; font-weight: 700; }
.ac-name { flex: 1; font-size: 16px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ac-cur { flex: 0 0 auto; padding: 2px 9px; border-radius: 99px; font-size: 11px; font-weight: 700; letter-spacing: .04em; background: var(--accent-soft); color: var(--accent); }
.ac-cur.cur-MYR { background: color-mix(in srgb, #c9952b 16%, var(--panel)); color: #a8771a; }
.ac-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; padding: 10px 12px; border-radius: 9px; background: var(--panel-2); }
.ac-stats > div { display: flex; flex-direction: column; min-width: 0; }
.ac-k { font-size: 11px; color: var(--muted); }
.ac-v { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.ac-v small { font-size: 11px; font-weight: 500; color: var(--muted); }
.ac-bal { font-size: 14px; }
.ac-bal-line { font-size: 12px; font-weight: 600; }
.ac-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 12px; }
.ac-tags { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.ac-note { font-size: 12px; color: var(--warn); background: color-mix(in srgb, var(--warn) 8%, var(--panel)); border-radius: 6px; padding: 5px 8px; }
@media screen and (max-width: 860px) {
  .agent-grid { grid-template-columns: 1fr; gap: 10px; }
  .view-seg { display: none; }
}

/* 刪除整個月帳務 */
.btn.danger { border-color: color-mix(in srgb, #ff0000 35%, var(--border)); }
.del-month ul { margin: 8px 0 12px; padding-left: 20px; line-height: 1.8; }
.del-month label { display: block; margin-bottom: 12px; }
.btn.primary.solid-danger { background: #e01e1e; border-color: #e01e1e; }

/* 對帳單：手動修改金額 */
.doc .stmt-edit { margin-left: 6px; border: 1px solid #d6dce6; background: #fff; color: #4b5563; border-radius: 5px; font-size: 11px; line-height: 1; padding: 3px 5px; cursor: pointer; }
.doc .stmt-edit:hover { border-color: #2456d6; color: #2456d6; }
.doc .stmt-orig { font-size: 9.5px; color: #b45309; font-weight: 600; }
