/* 寄頁管理主控台 — 與寄頁 App 同一套配色 (米白底、墨黑字、洋紅只用在主要動作與目前位置) */
:root {
  --bg: #f7f7f5; --panel: #ffffff; --sunk: #efefeb; --line: #e6e6e1; --line-2: #d6d6d0;
  --ink: #111110; --ink-2: #3d3d3a; --muted: #6b6b66;
  --mag: #d0106f; --mag-hover: #b00d5e; --mag-soft: #ffe1ee; --mag-text: #a00a55;
  --ok: #2b6a12; --ok-soft: #e6f8da; --warn: #8a5a00; --warn-soft: #fff1cc;
  --danger: #b42318; --danger-soft: #fde7e5; --info: #0b4f84; --info-soft: #e2f2fe;
  --r: 12px; --r-sm: 8px;
  --shadow: 0 1px 2px rgba(17,17,16,.04), 0 2px 8px rgba(17,17,16,.04);
  --font: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121211; --panel: #1b1b1a; --sunk: #242422; --line: #2c2c2a; --line-2: #3a3a37;
    --ink: #f2f2ee; --ink-2: #d0d0ca; --muted: #9a9a93;
    --mag: #ff5fa8; --mag-hover: #ff7fba; --mag-soft: #3a1426; --mag-text: #ff8cc0;
    --ok: #9fe07a; --ok-soft: #1d2e14; --warn: #f5c451; --warn-soft: #33290f;
    --danger: #ff8a80; --danger-soft: #3a1a17; --info: #8cc8f7; --info-soft: #132a3b;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.55 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--mag); outline-offset: 2px; }
code { font-family: var(--mono); font-size: 12.5px; background: var(--sunk); border-radius: 5px; padding: 1px 5px; }
h1, h2, h3 { margin: 0; letter-spacing: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }

/* ── 按鈕 ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px;
  border: 1px solid var(--line-2); border-radius: var(--r-sm); background: var(--panel); color: var(--ink);
  font-weight: 600; font-size: 13.5px; white-space: nowrap; transition: background .12s, border-color .12s; }
.btn:hover:not(:disabled) { background: var(--sunk); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-sm { height: 30px; padding: 0 11px; font-size: 13px; }
.btn-block { width: 100%; height: 40px; }
.btn-primary { background: var(--mag); border-color: var(--mag); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--mag-hover); border-color: var(--mag-hover); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line-2)); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); }
.btn-danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger.solid:hover:not(:disabled) { filter: brightness(.92); background: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.icon-btn { width: 30px; height: 30px; border: 0; border-radius: 7px; background: transparent; color: var(--muted);
  font-size: 20px; line-height: 1; display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--sunk); color: var(--ink); }
.link { color: var(--mag-text); text-decoration: none; font-size: 13px; font-weight: 600; }
.link:hover { text-decoration: underline; }

/* ── 版面 ── */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 18px;
  padding: 18px 12px; border-right: 1px solid var(--line); background: var(--panel); }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 6px; text-decoration: none; }
.brand span { display: flex; flex-direction: column; line-height: 1.2; }
.brand b { font-size: 16px; }
.brand small { color: var(--muted); font-size: 12px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; height: 36px; padding: 0 10px; border-radius: var(--r-sm);
  text-decoration: none; color: var(--ink-2); font-weight: 500; }
.nav a svg { width: 18px; height: 18px; fill: currentColor; opacity: .7; flex: none; }
.nav a:hover { background: var(--sunk); }
.nav a.on { background: var(--mag-soft); color: var(--mag-text); font-weight: 650; }
.nav a.on svg { opacity: 1; }
.nav .count { margin-left: auto; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.nav a.on .count { color: var(--mag-text); }
.side-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 8px 0; border-top: 1px solid var(--line); }
.who { display: flex; align-items: center; gap: 9px; min-width: 0; }
.who span:last-child { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.who b { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who small { color: var(--muted); font-size: 12px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--ink); color: var(--bg);
  display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; text-transform: uppercase; }

.main { padding: 28px 36px 64px; min-width: 0; outline: none; }
.view { max-width: 1200px; margin: 0 auto; }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.view-head h1 { font-size: 22px; font-weight: 700; }
.sub { margin: 4px 0 0; color: var(--muted); font-size: 13.5px; max-width: 70ch; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 18px 20px; }
.card + .card { margin-top: 14px; }
.card h2 { font-size: 15px; font-weight: 650; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; margin-top: 14px; }
.grid-2 > .card + .card { margin-top: 0; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 0; max-width: 72ch; }

/* ── 總覽 ── */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 18px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.kpi .value { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 4px; line-height: 1.15; }
.kpi .value small { font-size: 14px; font-weight: 600; color: var(--muted); margin-left: 3px; }
.kpi .foot { color: var(--muted); font-size: 12.5px; margin-top: 6px; }
.spark { display: flex; align-items: flex-end; gap: 3px; height: 26px; margin-top: 8px; }
.spark i { flex: 1; background: var(--line-2); border-radius: 2px; min-height: 2px; }
.spark i.today { background: var(--mag); }
.status-strip { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.status-strip a { text-decoration: none; }
.feed, .rank { list-style: none; margin: 0; padding: 0; }
.feed li { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 9px 0; border-top: 1px solid var(--line); }
.feed li:first-child { border-top: 0; }
.feed a { font-weight: 600; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed a:hover { color: var(--mag-text); }
.feed .meta { color: var(--muted); font-size: 12.5px; grid-column: 1; }
.feed .when { color: var(--muted); font-size: 12.5px; grid-row: 1 / span 2; grid-column: 2; align-self: center; white-space: nowrap; }
.rank li { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.rank li:first-child { border-top: 0; }
.rank .bar { grid-column: 1 / -1; height: 4px; background: var(--sunk); border-radius: 3px; overflow: hidden; }
.rank .bar i { display: block; height: 100%; background: var(--ink-2); border-radius: 3px; }
.rank b { font-weight: 600; }
.empty { color: var(--muted); padding: 22px 0; text-align: center; font-size: 13.5px; }

/* ── 標籤 ── */
.pill { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; background: var(--sunk); color: var(--ink-2); white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.off { background: var(--sunk); color: var(--muted); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.plain::before { display: none; }
.tag { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 1px 7px; border-radius: 5px; background: var(--sunk); color: var(--muted); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }

/* ── 工具列 / 表格 ── */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 12px; }
.search { position: relative; flex: 1 1 260px; max-width: 380px; }
.search svg { position: absolute; left: 10px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); fill: var(--muted); pointer-events: none; }
.search input { width: 100%; height: 34px; padding: 0 12px 0 34px; border: 1px solid var(--line-2); border-radius: var(--r-sm); background: var(--panel); }
.search input:focus { border-color: var(--ink-2); outline: none; }
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--sunk); border-radius: 9px; }
.seg button { height: 28px; padding: 0 11px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 600; }
.seg button.on { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.toolbar-meta { margin-left: auto; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.bulkbar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; margin-bottom: 10px; border-radius: var(--r-sm);
  background: var(--ink); color: var(--bg); font-size: 13.5px; font-weight: 600; }
.bulkbar span { margin-right: auto; }
.bulkbar .btn { background: transparent; color: var(--bg); border-color: rgba(255,255,255,.3); }
.bulkbar .btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
@media (prefers-color-scheme: dark) { .bulkbar .btn { border-color: rgba(0,0,0,.3); } }

.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th, .tbl td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl th.num, .tbl td.num { text-align: right; }
.tbl thead th { position: sticky; top: 0; background: var(--panel); color: var(--muted); font-size: 12.5px; font-weight: 600; white-space: nowrap; z-index: 1; }
.tbl th[data-sort] { cursor: pointer; user-select: none; }
.tbl th[data-sort]:hover { color: var(--ink); }
.tbl th[data-sort]::after { content: ""; display: inline-block; width: 0; margin-left: 4px; }
.tbl th.asc::after { content: "↑"; width: auto; }
.tbl th.desc::after { content: "↓"; width: auto; }
.tbl tbody tr:last-child > td { border-bottom: 0; }
.tbl tbody tr:hover > td { background: color-mix(in srgb, var(--sunk) 55%, transparent); }
.tbl tr.sel > td { background: var(--mag-soft) !important; }
.tbl .act { width: 1%; white-space: nowrap; text-align: right; }
.tbl .chk { width: 1%; padding-right: 0; }
.tbl input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--mag); vertical-align: middle; }
.tbl .empty-row td { text-align: center; color: var(--muted); padding: 36px; }
.cell-title { display: flex; flex-direction: column; min-width: 0; max-width: 420px; }
.cell-title a { font-weight: 600; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-title a:hover { color: var(--mag-text); text-decoration: underline; }
.cell-title small { color: var(--muted); font-size: 12px; }
.tok { display: inline-flex; align-items: center; gap: 2px; font-family: var(--mono); font-size: 12.5px; white-space: nowrap; }
.tok .icon-btn { width: 24px; height: 24px; font-size: 13px; }
.tok .icon-btn svg { width: 14px; height: 14px; fill: currentColor; }
.nowrap { white-space: nowrap; }
.row-btns { display: inline-flex; gap: 6px; }
.files-row td { background: var(--sunk) !important; padding: 10px 14px 12px 46px; }
.files { list-style: none; margin: 0; padding: 0; columns: 2 280px; column-gap: 24px; font-size: 12.5px; }
.files li { display: flex; justify-content: space-between; gap: 10px; padding: 2px 0; break-inside: avoid; }
.files li span:first-child { font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.files li span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 6px; margin-top: 12px; font-size: 13px; color: var(--muted); }
.pager span { margin-right: 8px; }

/* ── 開關 ── */
.switch { position: relative; display: inline-block; width: 40px; height: 24px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; background: var(--line-2); border-radius: 24px; transition: background .18s; }
.switch span::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .18s; }
.switch input:checked + span { background: var(--mag); }
.switch input:checked + span::before { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--mag); outline-offset: 2px; }
.switch input:disabled + span { opacity: .5; }
.switch.sm { width: 34px; height: 20px; }
.switch.sm span::before { width: 14px; height: 14px; }
.switch.sm input:checked + span::before { transform: translateX(14px); }

/* ── 表單 ── */
.setting h2 { margin-bottom: 2px; }
.setting-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; }
.setting-row + form, .setting-row + .deploy { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.group-title { font-size: 13px; font-weight: 650; margin: 18px 0 10px; color: var(--ink-2); }
.group-title small { font-weight: 400; color: var(--muted); margin-left: 6px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; max-width: 760px; }
.form-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-all { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span:first-child { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field small { color: var(--muted); font-size: 12px; }
.field input, .field select { height: 36px; padding: 0 11px; border: 1px solid var(--line-2); border-radius: var(--r-sm); background: var(--panel); width: 100%; }
.field input:focus { border-color: var(--ink-2); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--mag) 18%, transparent); }
.field input[aria-invalid=true] { border-color: var(--danger); }
.input-unit { display: flex; align-items: stretch; }
.input-unit input { border-top-right-radius: 0; border-bottom-right-radius: 0; font-variant-numeric: tabular-nums; }
.input-unit em { font-style: normal; display: grid; place-items: center; padding: 0 11px; border: 1px solid var(--line-2); border-left: 0;
  border-radius: 0 var(--r-sm) var(--r-sm) 0; background: var(--sunk); color: var(--muted); font-size: 12.5px; }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 16px; }
.form-grid .form-actions { margin-top: 0; grid-column: 1 / -1; }
.form-err { color: var(--danger); font-size: 13px; margin: 0; min-height: 0; }
.form-err:empty { display: none; }
.deploy { font-size: 13px; }
.deploy table { border-collapse: collapse; margin-top: 4px; }
.deploy td { padding: 4px 16px 4px 0; }

/* ── 對話框 ── */
.modal { border: 0; padding: 0; border-radius: 14px; background: var(--panel); color: var(--ink); width: min(480px, calc(100vw - 32px));
  box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal::backdrop { background: rgba(17,17,16,.42); }
.modal[open] { animation: pop .16s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98); } }
.modal-box header { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 6px 20px; }
.modal-box h2 { font-size: 16px; font-weight: 700; }
.modal-body { padding: 6px 20px 4px; display: flex; flex-direction: column; gap: 14px; }
.modal-body p { margin: 0; color: var(--ink-2); }
.modal-box footer { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 20px 18px; }
.modal .form-grid { gap: 12px 14px; }
.danger-zone { border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--line)); border-radius: var(--r-sm); padding: 12px 14px; }
.danger-zone h3 { font-size: 13px; color: var(--danger); margin-bottom: 8px; }
.danger-zone .row-btns { flex-wrap: wrap; }
.secret { display: flex; gap: 8px; align-items: center; padding: 10px 12px; border-radius: var(--r-sm); background: var(--sunk);
  font-family: var(--mono); font-size: 13px; word-break: break-all; }
.secret span { flex: 1; }
.callout { padding: 10px 12px; border-radius: var(--r-sm); background: var(--warn-soft); color: var(--warn); font-size: 13px; font-weight: 500; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* ── Toast ── */
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { display: flex; align-items: center; gap: 10px; min-width: 240px; max-width: 420px; padding: 11px 14px; border-radius: 10px;
  background: var(--ink); color: var(--bg); font-size: 13.5px; font-weight: 500; box-shadow: 0 8px 24px rgba(0,0,0,.18); animation: pop .16s ease-out; }
.toast.err { background: var(--danger); color: #fff; }
.toast::before { content: "✓"; font-weight: 700; }
.toast.err::before { content: "!"; }

/* ── 載入骨架 ── */
.skel { display: block; height: 14px; border-radius: 5px; background: linear-gradient(90deg, var(--sunk), var(--line), var(--sunk)); background-size: 200% 100%; animation: sh 1.2s infinite linear; }
@keyframes sh { to { background-position: -200% 0; } }

/* ── 登入頁 ── */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login { width: min(380px, 100%); }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.login-brand div { display: flex; flex-direction: column; line-height: 1.25; }
.login-brand b { font-size: 18px; }
.login-brand span { color: var(--muted); font-size: 13px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 24px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { font-size: 18px; }
.login-foot { color: var(--muted); font-size: 12.5px; margin-top: 16px; line-height: 1.7; }

/* ── 窄螢幕 ── */
@media (max-width: 1080px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: sticky; top: 0; z-index: 20; height: auto; flex-direction: row; align-items: center; gap: 8px; padding: 8px 12px;
    border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .brand span, .side-foot .who { display: none; }
  .nav { flex-direction: row; }
  .nav a { height: 32px; padding: 0 10px; white-space: nowrap; }
  .nav a svg, .nav .count { display: none; }
  .side-foot { margin: 0 0 0 auto; padding: 0; border: 0; }
  .main { padding: 20px 14px 56px; }
  .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
  .setting-row { gap: 14px; }
  .toolbar-meta { margin-left: 0; width: 100%; }
}
@media (prefers-reduced-motion: reduce) { *, *::before { animation: none !important; transition: none !important; } }

/* 漏斗 */
.funnel .fbar { display: flex; align-items: center; gap: 8px; min-width: 200px; }
.funnel .fbar i { display: block; height: 10px; border-radius: 5px; background: var(--mag); min-width: 2px; }
.funnel tr.ws td:first-child { padding-left: 22px; }
.funnel tr.sep td { background: var(--sunk); font-size: 12px; color: var(--muted); padding: 6px 14px; }
.fn-head { margin-top: 28px; } .fn-title { font-size: 17px; margin: 0; }
