/* 审批网页：手机优先，跟随系统明暗色，不依赖任何外部资源。 */
:root {
  color-scheme: light dark;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #efefec;
  --line: #deded9;
  --ink: #1b1b19;
  --ink-2: #4a4a46;
  --ink-3: #75756f;
  --accent: #1d4ed8;
  --accent-ink: #ffffff;
  --accent-soft: #e3eaff;
  /* 状态色只配合图标和文字出现，不单独表达含义。 */
  --good: #0ca30c;
  --good-ink: #006300;
  --good-soft: #e3f5e3;
  --warn: #fab219;
  --warn-ink: #7a4f00;
  --warn-soft: #fff1d1;
  --bad: #d03b3b;
  --bad-ink: #a82222;
  --bad-soft: #fbe5e5;
  --diff-add: #dcf5dc;
  --diff-add-strong: #a8e3a8;
  --diff-del: #fbe1e1;
  --diff-del-strong: #f2b0b0;
  --diff-hunk: #e8eefc;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 2px 8px rgb(0 0 0 / 4%);
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --nav-h: 60px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #242422;
    --line: #34342f;
    --ink: #ececea;
    --ink-2: #b9b9b3;
    --ink-3: #8b8b85;
    --accent: #6d9bff;
    --accent-ink: #0b1430;
    --accent-soft: #1d2a4d;
    --good-ink: #3ccf3c;
    --good-soft: #13301a;
    --warn-ink: #fab219;
    --warn-soft: #3a2c0c;
    --bad-ink: #ff7a7a;
    --bad-soft: #3d1717;
    --diff-add: #15331b;
    --diff-add-strong: #1f5c2a;
    --diff-del: #3a1a1a;
    --diff-del-strong: #6b2626;
    --diff-hunk: #1d2640;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC",
        "Source Han Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
}
body.anon { padding-bottom: 0; }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; color: var(--ink-2); }
[hidden] { display: none !important; }
code, pre, .mono { font-family: var(--mono); }

/* 顶栏与导航：手机上导航固定在底部，宽屏移到顶部 */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  border-bottom: 1px solid var(--line);
}
/* 毛玻璃放在伪元素上：直接给顶栏加 backdrop-filter 会让手机底部的固定导航以顶栏为定位基准 */
.topbar::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
}
.brand { font-weight: 700; color: var(--ink); font-size: 17px; }
.brand-sub { font-weight: 400; color: var(--ink-3); margin-left: 6px; font-size: 14px; }
.logout { margin-left: auto; }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabs a {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  color: var(--ink-3); font-size: 12px;
}
.tabs a.active { color: var(--accent); font-weight: 600; }
.tab-icon { display: inline-flex; width: 22px; height: 22px; }
.tab-icon svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.badge {
  position: absolute; top: 6px; left: calc(50% + 8px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--bad); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}
@media (min-width: 760px) {
  body { padding-bottom: 32px; }
  .tabs {
    position: static; display: flex; gap: 4px; height: auto; padding: 0;
    background: none; border: 0; backdrop-filter: none; -webkit-backdrop-filter: none; margin-left: 16px;
  }
  .tabs a { flex-direction: row; gap: 6px; padding: 6px 12px; border-radius: 999px; font-size: 14px; }
  .tabs a.active { background: var(--accent-soft); }
  .tab-icon { width: 16px; height: 16px; }
  .badge { position: static; }
}

.demo-banner {
  background: var(--warn-soft); color: var(--warn-ink);
  padding: 8px 16px; font-size: 13px; text-align: center; border-bottom: 1px solid var(--line);
}

.page { max-width: 1080px; margin: 0 auto; padding: 16px; }
.page-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin: 4px 0 14px; }
.page-head .sub { color: var(--ink-3); font-size: 13px; }
.back { display: inline-block; margin-bottom: 8px; font-size: 14px; }
.loading, .empty { color: var(--ink-3); text-align: center; padding: 32px 0; }

.grid { display: grid; gap: 12px; }
@media (min-width: 760px) {
  .grid.two { grid-template-columns: 1fr 1fr; }
  .grid.side { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); align-items: start; }
}
.stack { display: grid; gap: 12px; align-content: start; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); min-width: 0;
}
.card > h2 { margin-bottom: 10px; display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 8px; }
.card > h2 .aside { margin-left: auto; font-size: 13px; font-weight: 400; color: var(--ink-3); text-align: right; }
.card p { margin: 0 0 10px; }
.card p:last-child { margin-bottom: 0; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.pre-wrap { white-space: pre-wrap; word-break: break-word; }

/* 状态提示条 */
.alert {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 14px; border-radius: 12px; margin-bottom: 12px; font-size: 14px;
  border: 1px solid transparent;
}
.alert .icon { font-weight: 700; }
.alert.bad { background: var(--bad-soft); color: var(--bad-ink); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.alert.warn { background: var(--warn-soft); color: var(--warn-ink); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.alert.info { background: var(--accent-soft); color: var(--ink); }

/* 状态徽标：图标 + 文字 + 颜色 */
.pill {
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
  padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--ink-2);
}
.pill.good { background: var(--good-soft); color: var(--good-ink); }
.pill.warn { background: var(--warn-soft); color: var(--warn-ink); }
.pill.bad { background: var(--bad-soft); color: var(--bad-ink); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.pill.big { font-size: 14px; padding: 4px 12px; }

/* 总览 */
.hero {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
}
.hero-strategy { font-size: 24px; font-weight: 700; letter-spacing: .2px; }
.hero-strategy .ver { color: var(--ink-3); font-weight: 500; margin-left: 4px; }
.hero-meta { width: 100%; color: var(--ink-3); font-size: 13px; }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 760px) { .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow); min-width: 0;
}
.tile-label { font-size: 13px; color: var(--ink-3); }
.tile-value { font-size: 24px; font-weight: 600; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-note { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.up { color: var(--good-ink); }
.down { color: var(--bad-ink); }

.estop {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; min-height: 64px; border: 0; border-radius: var(--radius);
  background: var(--bad); color: #fff; font-size: 20px; font-weight: 700; letter-spacing: 2px;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--bad) 35%, transparent);
  cursor: pointer; font-family: inherit;
}
.estop:active { transform: translateY(1px); }
.estop .estop-icon {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  background: rgb(255 255 255 / 22%); font-size: 16px; letter-spacing: 0;
}
.estop-note { color: var(--ink-3); font-size: 12px; text-align: center; margin-top: 6px; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 14px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; text-align: right; min-width: 0; overflow-wrap: anywhere; }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 10px 0; border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; padding-top: 2px; }
.row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .end { margin-left: auto; text-align: right; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 按钮 */
.btn {
  appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 0 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.good { background: var(--good-ink); border-color: var(--good-ink); color: #fff; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost-danger { background: transparent; border-color: color-mix(in srgb, var(--bad) 55%, transparent); color: var(--bad-ink); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 140px; }
.link-button { border: 0; background: none; color: var(--accent); font: inherit; padding: 4px 6px; cursor: pointer; }
.actions-bar {
  position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 8px); z-index: 5;
  display: flex; gap: 10px; margin-top: 12px; padding: 10px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 4px 18px rgb(0 0 0 / 12%);
}
.actions-bar .btn { flex: 1; }
@media (min-width: 760px) { .actions-bar { bottom: 12px; } }

/* 表单 */
label.field { display: grid; gap: 6px; font-size: 14px; color: var(--ink-2); margin-bottom: 12px; }
input[type="password"], input[type="text"], textarea {
  width: 100%; padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  font: inherit; font-size: 16px; /* 16px 防止 iOS 聚焦时自动放大 */
}
textarea { min-height: 72px; resize: vertical; }
input:focus-visible, textarea:focus-visible, .btn:focus-visible, a:focus-visible, .estop:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; margin: 4px 0 12px; }
.check input { width: 20px; height: 20px; margin: 1px 0 0; flex: none; }

/* 登录 */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login { width: 100%; max-width: 380px; }
.login .logo { display: block; width: 52px; height: 52px; margin: 0 auto 12px; }
.login h1 { text-align: center; margin-bottom: 4px; }
.login .muted { text-align: center; margin: 0 0 18px; font-size: 13px; }
.form-error { color: var(--bad-ink); font-size: 14px; min-height: 20px; margin: 0 0 8px; }

/* 申请列表 */
.proposal-item { display: block; color: inherit; }
.proposal-item .title { font-weight: 600; }
.proposal-item .meta { font-size: 12px; color: var(--ink-3); }
.proposal-item .chev { color: var(--ink-3); font-size: 18px; }
.filters { display: flex; gap: 8px; margin-bottom: 12px; overflow-x: auto; }
.filters button { flex: none; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  border-radius: 999px; padding: 6px 14px; font: inherit; font-size: 13px; cursor: pointer;
}
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* 指标表 */
.table-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
table.metrics { width: 100%; border-collapse: collapse; font-size: 14px; }
table.metrics th, table.metrics td { padding: 7px 8px; border-top: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.metrics thead th { border-top: 0; color: var(--ink-3); font-weight: 500; font-size: 12px; }
table.metrics th:first-child, table.metrics td:first-child { text-align: left; color: var(--ink-2); padding-left: 0; }
table.metrics td { font-variant-numeric: tabular-nums; }
table.metrics .cand { font-weight: 600; }
.cmp { font-size: 11px; margin-left: 3px; }
.cmp.better { color: var(--good-ink); }
.cmp.worse { color: var(--bad-ink); }
.legend { font-size: 12px; color: var(--ink-3); margin-top: 8px; }

/* 闸门 */
.gates { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.gates li { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; }
.gates .mark {
  flex: none; display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px;
  font-size: 13px; font-weight: 700;
}
.gates .mark.ok { background: var(--good-soft); color: var(--good-ink); }
.gates .mark.no { background: var(--bad-soft); color: var(--bad-ink); }
.gates .mark.na { background: var(--surface-2); color: var(--ink-3); }
.gates .main { font-weight: 600; }

/* 代码差异 */
.diff-tools { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; font-size: 13px; color: var(--ink-3); flex-wrap: wrap; }
.diff-stat .add { color: var(--good-ink); font-weight: 600; }
.diff-stat .del { color: var(--bad-ink); font-weight: 600; }
.diff {
  border: 1px solid var(--line); border-radius: 10px; overflow: auto; max-height: 70vh;
  font-family: var(--mono); font-size: 12px; line-height: 1.55; background: var(--bg);
}
.diff table { border-collapse: collapse; min-width: 100%; }
.diff td { padding: 0 8px; vertical-align: top; }
.diff td.ln {
  width: 1%; min-width: 34px; text-align: right; color: var(--ink-3); user-select: none;
  -webkit-user-select: none; border-right: 1px solid var(--line); font-variant-numeric: tabular-nums;
}
.diff td.sign { width: 1%; padding: 0 2px 0 6px; user-select: none; -webkit-user-select: none; color: var(--ink-3); }
.diff td.code { white-space: pre; }
.diff.wrap td.code { white-space: pre-wrap; word-break: break-all; }
.diff tr.add td { background: var(--diff-add); }
.diff tr.del td { background: var(--diff-del); }
.diff tr.add td.sign { color: var(--good-ink); }
.diff tr.del td.sign { color: var(--bad-ink); }
.diff tr.add mark { background: var(--diff-add-strong); color: inherit; border-radius: 2px; }
.diff tr.del mark { background: var(--diff-del-strong); color: inherit; border-radius: 2px; }
.diff tr.hunk td { background: var(--diff-hunk); color: var(--ink-3); }
.diff tr.file td { background: var(--surface-2); color: var(--ink-2); font-weight: 600; }
details.code-full { margin-top: 10px; }
details.code-full summary { cursor: pointer; color: var(--accent); font-size: 14px; }
details.code-full pre {
  margin: 8px 0 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); overflow: auto; max-height: 70vh; font-size: 12px; line-height: 1.55;
}

/* 历史 */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 22px; }
.timeline li::before {
  content: ""; position: absolute; left: 5px; top: 8px; bottom: -6px; width: 2px; background: var(--line);
}
.timeline li:last-child::before { display: none; }
.timeline .dot {
  position: absolute; left: 0; top: 4px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--accent);
}
.timeline .dot.rollback { border-color: var(--warn); }
.timeline .dot.mode { border-color: var(--bad); }
.timeline .when { font-size: 12px; color: var(--ink-3); }

/* 实盘开关 */
.confirm-word {
  display: inline-block; padding: 1px 8px; border-radius: 6px; background: var(--surface-2);
  font-weight: 700; color: var(--ink); user-select: all; -webkit-user-select: all;
}
.limits-table td:last-child { font-weight: 600; }
.steps { margin: 0; padding-left: 20px; font-size: 14px; color: var(--ink-2); }
.steps li { margin: 4px 0; }

/* 对话框 */
.dialog {
  width: min(460px, calc(100vw - 24px)); max-height: calc(100dvh - 48px);
  padding: 0; border: 1px solid var(--line); border-radius: 18px;
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgb(0 0 0 / 30%);
}
.dialog::backdrop { background: rgb(0 0 0 / 45%); }
.dialog form { padding: 18px; }
.dialog h2 { font-size: 18px; margin-bottom: 10px; }
#dialog-body { font-size: 14px; color: var(--ink-2); }
#dialog-body p { margin: 0 0 10px; }
.dialog-actions { display: flex; gap: 10px; margin-top: 16px; }
.dialog-actions .btn { flex: 1; }
@media (max-width: 759px) {
  .dialog { margin: auto auto calc(env(safe-area-inset-bottom) + 12px); }
}

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); z-index: 50;
  max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 12px;
  background: var(--ink); color: var(--bg); font-size: 14px; box-shadow: 0 6px 24px rgb(0 0 0 / 25%);
}
.toast.bad { background: var(--bad); color: #fff; }
@media (min-width: 760px) { .toast { bottom: 24px; } }

.busy { opacity: .6; pointer-events: none; }

@media (prefers-reduced-motion: no-preference) {
  .tile, .card { transition: border-color .15s; }
}
@media (forced-colors: active) {
  .pill, .gates .mark, .estop { border: 1px solid CanvasText; }
}
@media (min-width: 760px) {
  .grid.side.detail { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); }
}
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.stack > .alert { margin-bottom: 0; }
