/* 平台管理後台：內部工具，密集、中性配色 */
:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --line: #e2e4e8;
  --line-2: #eef0f3;
  --ink: #1d2129;
  --ink-2: #4e5562;
  --ink-3: #8a909c;
  --accent: #2f5d8a;
  --accent-ink: #ffffff;
  --accent-soft: #e8eff6;
  --danger: #b3261e;
  --danger-soft: #fbeceb;
  --warn: #a35d00;
  --warn-soft: #fdf3e3;
  --ok: #2e7d4f;
  --ok-soft: #e7f4ec;
  --muted-soft: #eef0f3;
  --side: #1f2530;
  --side-ink: #c9ced8;
  --side-active: #2c3442;
  --radius: 6px;
  --shadow: 0 8px 30px rgba(15, 20, 30, .18);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 13px/1.5 "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 18px; }
h2 { font-size: 14px; }
h3 { font-size: 13px; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
[hidden] { display: none !important; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.red { color: var(--danger); }

/* ---------- 按鈕與表單 ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--ink);
  font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f7f8fa; border-color: #cfd3da; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #284f75; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { background: #9a2019; }
.btn.ghost-danger { color: var(--danger); }
.btn.sm { height: 26px; padding: 0 9px; font-size: 12px; }
.btn.link { border: 0; background: none; color: var(--accent); padding: 0; height: auto; }
input, select, textarea {
  font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  height: 30px; padding: 0 9px; width: 100%; min-width: 0;
}
textarea { height: auto; min-height: 64px; padding: 6px 9px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label.field { display: flex; flex-direction: column; gap: 4px; }
label.field > span { font-size: 12px; color: var(--ink-2); font-weight: 500; }
label.field > small { color: var(--ink-3); font-size: 11px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 12px; }
.span2 { grid-column: span 2; }
.span3 { grid-column: 1 / -1; }
.err { color: var(--danger); background: var(--danger-soft); border-radius: var(--radius); padding: 7px 10px; font-size: 12px; }
.note { background: var(--warn-soft); color: #6b4300; border-radius: var(--radius); padding: 8px 10px; font-size: 12px; }
.info { background: var(--accent-soft); color: #1e3f61; border-radius: var(--radius); padding: 8px 10px; font-size: 12px; }

/* ---------- 登入 ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login {
  width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 24px; display: flex; flex-direction: column; gap: 12px;
}
.login .brand { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.login .brand b { font-size: 16px; }
.logo-mark { width: 26px; height: 26px; border-radius: 6px; background: var(--side); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.secret { font-family: ui-monospace, Menlo, monospace; font-size: 15px; letter-spacing: .5px; background: var(--muted-soft); padding: 8px 10px; border-radius: var(--radius); word-break: break-all; user-select: all; }
.qr { display: grid; place-items: center; padding: 8px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); min-height: 40px; }
.qr img, .qr canvas { display: block; }
.otp-input { font-family: ui-monospace, Menlo, monospace; font-size: 18px; letter-spacing: 6px; text-align: center; height: 38px; }

/* ---------- 版面 ---------- */
.app { display: grid; grid-template-columns: 196px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.side .brand { display: flex; align-items: center; gap: 8px; padding: 14px 14px 12px; color: #fff; }
.side .brand .logo-mark { background: #3a4456; }
.side .brand small { display: block; color: #8b93a3; font-size: 11px; }
.side nav { display: flex; flex-direction: column; padding: 4px 8px; gap: 1px; }
.side nav a { color: var(--side-ink); padding: 7px 10px; border-radius: 5px; text-decoration: none; display: flex; justify-content: space-between; align-items: center; }
.side nav a:hover { background: var(--side-active); color: #fff; }
.side nav a.on { background: var(--side-active); color: #fff; font-weight: 600; box-shadow: inset 2px 0 0 #7ea6cf; }
.side .me { margin-top: auto; padding: 12px 14px; border-top: 1px solid #2d3441; font-size: 12px; }
.side .me .who { color: #fff; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side .me .mail { color: #8b93a3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 8px; }
.side .me .row { display: flex; gap: 6px; flex-wrap: wrap; }
.side .me .btn { background: transparent; border-color: #3a4352; color: var(--side-ink); height: 26px; font-size: 12px; padding: 0 8px; }
.side .me .btn:hover { background: var(--side-active); color: #fff; }
.role { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 3px; line-height: 18px; font-weight: 600; vertical-align: 1px; margin-left: 4px; }
.role.admin { background: #3c5f86; color: #fff; }
.role.support { background: #8a6d1e; color: #fff; }

.main { min-width: 0; padding: 18px 22px 40px; }
.page-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h1 { margin-right: auto; }
.crumb { font-size: 12px; color: var(--ink-3); margin-bottom: 4px; }
.banner { margin-bottom: 12px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; margin-bottom: 14px; min-width: 0; }
.panel > header { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line-2); }
.panel > header h2 { margin-right: auto; }
.panel > .body { padding: 12px 14px; }
.panel > .body.flush { padding: 0; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; align-items: start; }
.cols > .panel { margin-bottom: 0; }
.stack > * + * { margin-top: 14px; }

/* ---------- 數字卡 ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; display: block; color: inherit; }
a.card:hover { border-color: #c5cbd4; text-decoration: none; }
.card .k { font-size: 12px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.card .v { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; }
.card .v small { font-size: 12px; font-weight: 400; color: var(--ink-3); margin-left: 2px; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; background: var(--ink-3); }

/* ---------- 表格 ---------- */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.tbl th { font-size: 12px; font-weight: 600; color: var(--ink-2); background: #fafbfc; white-space: nowrap; position: sticky; top: 0; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: #f6f8fb; }
.tbl td .sub { display: block; color: var(--ink-3); font-size: 12px; }
.tbl .empty { text-align: center; color: var(--ink-3); padding: 24px; }
.tbl td.actions { white-space: nowrap; text-align: right; }
.tbl td.actions .btn + .btn { margin-left: 4px; }

/* ---------- 狀態標籤 ---------- */
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; line-height: 20px; padding: 0 8px; border-radius: 999px; background: var(--muted-soft); color: var(--ink-2); white-space: nowrap; font-weight: 500; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.pill.active, .pill.paid { background: var(--ok-soft); color: var(--ok); }
.pill.building, .pill.pending { background: var(--accent-soft); color: var(--accent); }
.pill.overdue { background: var(--warn-soft); color: var(--warn); }
.pill.suspended, .pill.deleting { background: var(--danger-soft); color: var(--danger); }
.pill.deleted, .pill.cancelled, .pill.off { background: var(--muted-soft); color: var(--ink-3); }
.tag { display: inline-block; font-size: 11px; line-height: 18px; padding: 0 6px; border-radius: 3px; background: var(--muted-soft); color: var(--ink-2); white-space: nowrap; }
.tag.manual { background: #efe9f7; color: #5b3f8a; }

/* ---------- 篩選 ---------- */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip { height: 28px; padding: 0 11px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); font: inherit; font-size: 12px; cursor: pointer; color: var(--ink-2); }
.chip:hover { border-color: #c5cbd4; }
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip b { font-weight: 600; margin-left: 3px; }
.toolbar .search { width: 240px; }
.toolbar .grow { flex: 1; }

/* ---------- 詳情 ---------- */
dl.kv { display: grid; grid-template-columns: 96px 1fr; gap: 6px 10px; margin: 0; }
dl.kv dt { color: var(--ink-3); font-size: 12px; padding-top: 1px; }
dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.actions-bar { display: flex; flex-wrap: wrap; gap: 6px; }
.progress { height: 6px; border-radius: 3px; background: var(--muted-soft); overflow: hidden; margin: 4px 0 10px; }
.progress > i { display: block; height: 100%; background: var(--ok); }
ul.check { list-style: none; margin: 0; padding: 0; }
ul.check li { display: flex; gap: 8px; align-items: center; padding: 3px 0; }
ul.check li .mk { width: 16px; height: 16px; border-radius: 50%; display: grid; place-items: center; font-size: 10px; flex: none; border: 1px solid var(--line); color: transparent; }
ul.check li.done .mk { background: var(--ok); border-color: var(--ok); color: #fff; }
ul.check li.done span { color: var(--ink-3); }
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: grid; grid-template-columns: 112px 1fr; gap: 8px; padding: 6px 14px; border-bottom: 1px solid var(--line-2); font-size: 12px; }
.feed li:last-child { border-bottom: 0; }
.feed .t { color: var(--ink-3); white-space: nowrap; font-variant-numeric: tabular-nums; }
.feed .d { color: var(--ink-3); overflow-wrap: anywhere; }
.feed .empty { display: block; text-align: center; color: var(--ink-3); padding: 18px; }

/* ---------- 對話框與提示 ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(20, 24, 32, .45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--panel); border-radius: 10px; box-shadow: var(--shadow); width: 100%; max-width: 460px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.modal.wide { max-width: 620px; }
.modal > header { padding: 14px 16px 10px; display: flex; align-items: center; }
.modal > header h2 { font-size: 15px; margin-right: auto; }
.modal > header .x { border: 0; background: none; font-size: 18px; color: var(--ink-3); cursor: pointer; line-height: 1; padding: 2px 4px; }
.modal > .body { padding: 2px 16px 12px; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.modal > footer { padding: 10px 16px 14px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--line-2); }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 8px 14px; border-radius: 6px; font-size: 13px; z-index: 60; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
.loading { color: var(--ink-3); padding: 30px 0; text-align: center; }

/* ---------- 手機 ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .tbl td > b:first-child { white-space: nowrap; }
  .side { position: static; height: auto; }
  .side .brand { padding: 10px 16px 6px; }
  .side nav { flex-direction: row; overflow-x: auto; padding: 0 10px 8px; gap: 2px; }
  .side nav a { white-space: nowrap; padding: 6px 10px; }
  .side nav a.on { box-shadow: inset 0 -2px 0 #7ea6cf; }
  .side .me { margin: 0; padding: 8px 16px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; border-top: 1px solid #2d3441; }
  .side .me .mail { display: none; }
  .side .me .who { margin-right: auto; }
  .main { padding: 14px 16px 32px; }
  .toolbar .search { width: 100%; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .cols { grid-template-columns: 1fr; }
  .feed li { grid-template-columns: 1fr; gap: 0; }
  dl.kv { grid-template-columns: 84px 1fr; }
}
.tbl .sub.mono { white-space: nowrap; }
.tbl td { white-space: nowrap; }
.tbl td.wrap { white-space: normal; min-width: 220px; }
