:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --line: #d2d2d7;
  --line2: #e8e8ed;
  --blue: #0071e3;
  --blue2: #147ce5;
  --ok: #248a3d;
  --okbg: #e4f8e9;
  --warn: #9a6700;
  --warnbg: #fff4d6;
  --bad: #d70015;
  --rail: 232px;
  --top: 52px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 13px/1.4 var(--sans);
  color: var(--ink);
  background: var(--bg);
  letter-spacing: -0.01em;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }
.app { display: grid; grid-template-columns: var(--rail) 1fr; height: 100%; min-width: 1024px; }
body[data-view="login"] .app { grid-template-columns: 1fr; }
body[data-view="login"] .rail,
body[data-view="login"] .top,
body[data-view="login"] .fa { display: none; }
.rail {
  background: #ececef; border-right: 1px solid var(--line2);
  padding: 16px 12px; display: flex; flex-direction: column;
}
.brand { padding: 4px 10px 18px; }
.brand b { display: block; font-size: 14px; font-weight: 650; letter-spacing: -0.03em; }
.brand small { color: var(--muted); font-size: 11px; }
.nav { display: grid; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 9px; color: var(--ink); text-decoration: none;
}
.nav a:hover { background: rgba(0,0,0,.04); }
.nav a.on { background: #fff; box-shadow: 0 1px 1px rgba(0,0,0,.04); font-weight: 560; }
.nav .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.nav a.on .dot { background: var(--blue); }
.rail-foot { margin-top: auto; padding: 10px; color: var(--muted); font-size: 11px; display: grid; gap: 8px; min-width: 0; }
.rail-foot > * { min-width: 0; }
.rail-foot .mono { display: block; overflow-wrap: anywhere; }
label.remember {
  display: flex; align-items: center; gap: 8px;
  color: var(--muted); font-size: 12px; user-select: none;
}
label.remember input { width: 14px; height: 14px; accent-color: var(--blue); }
.main { display: grid; grid-template-rows: var(--top) auto 1fr; min-width: 0; min-height: 0; }
body[data-view="login"] .main { grid-template-rows: 1fr; }
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 20px; background: rgba(245,245,247,.86); backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line2); overflow: hidden;
}
.runpill {
  display: flex; align-items: center; gap: 8px; min-width: 0;
  font-family: var(--mono); font-size: 12px;
}
.runpill #run-label { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.led { flex-shrink: 0; width: 8px; height: 8px; border-radius: 50%; background: #c7c7cc; }
.led.on { background: #30d158; box-shadow: 0 0 0 3px rgba(48,209,88,.18); }
.led.warn { background: #ffd60a; box-shadow: 0 0 0 3px rgba(255,214,10,.25); }
.led.bad { background: var(--bad); box-shadow: 0 0 0 3px rgba(215,0,21,.16); }
.top-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.fa {
  display: none; margin: 0; padding: 10px 20px;
  background: var(--warnbg); border-bottom: 1px solid #f0d78c;
  align-items: center; gap: 12px; flex-wrap: wrap; row-gap: 6px;
}
.fa b { white-space: nowrap; }
body.need2fa .fa { display: flex; }
.fa b { color: var(--warn); }
.digits { display: flex; gap: 6px; }
.digits input {
  width: 34px; height: 40px; text-align: center; font-size: 18px; font-family: var(--mono);
  border: 1px solid #e3c56b; border-radius: 8px; background: #fff;
}
/* .fa is display:none until 2FA, so it yields no grid item; pin .view to
   the 1fr row or it auto-places into the content-sized `auto` row. */
.view { grid-row: 3; padding: 18px 20px 24px; overflow: auto; min-height: 0; transition: opacity .15s ease; }
body[data-view="login"] .view {
  grid-row: 1; display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(900px 400px at 50% -10%, #dbeafe 0%, transparent 55%),
    var(--bg);
}
h2.page { margin: 0; font-size: 22px; font-weight: 650; letter-spacing: -0.03em; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--card); border: 1px solid var(--line2); border-radius: 14px; padding: 12px 14px; min-width: 0; }
.kpi .k { color: var(--muted); font-size: 11px; }
.kpi .v { font-size: 20px; font-weight: 650; letter-spacing: -0.03em; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kpi .s { color: var(--muted); font-size: 11px; margin-top: 2px; font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.split { display: grid; grid-template-columns: 1.4fr .8fr; gap: 12px; }
body[data-view="console"] .view { display: flex; flex-direction: column; }
body[data-view="console"] .split { flex: 1; min-height: 0; }
body[data-view="console"] .split .card { display: flex; flex-direction: column; min-height: 0; }
body[data-view="tasks"] .view { display: flex; flex-direction: column; }
body[data-view="tasks"] .view > .fill { flex: 1; min-height: 160px; overflow: auto; }
body[data-view="tasks"] .split { flex: none; margin-top: 14px; grid-auto-rows: clamp(240px, 38vh, 420px); }
body[data-view="tasks"] .split .card { display: flex; flex-direction: column; min-height: 0; }
body[data-view="tasks"] .split .log { min-height: 0; }
.card .scroll { flex: 1; min-height: 0; overflow: auto; }
.card {
  background: var(--card); border: 1px solid var(--line2); border-radius: 14px; overflow: hidden;
}
.table-wrap { overflow-x: auto; }
th.ops, td.ops {
  white-space: nowrap; text-align: right; width: 1%;
  position: sticky; right: 0;
  background: var(--card);
  box-shadow: -8px 0 10px -8px rgba(0,0,0,.12);
}
td.ops .toggle { margin-right: 8px; vertical-align: middle; }
td.ops .btn + .btn, td.ops .bigpay + .btn { margin-left: 6px; }

.card h3 {
  margin: 0; padding: 10px 14px; font-size: 13px; font-weight: 600;
  border-bottom: 1px solid var(--line2); display: flex; justify-content: space-between; align-items: center;
}
.log {
  margin: 0; padding: 12px 14px; flex: 1; min-height: 240px; overflow: auto;
  background: #111214; color: #d5d8de; font: 12px/1.55 var(--mono); white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.log .ln { min-height: 1.55em; }
.log .yes { color: #32d74b; }
.log .no { color: #8e8e93; }
.log .err { color: #ff453a; }
.log .hit { color: #64d2ff; }
.log .order { color: #32d74b; font-weight: 600; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line2); vertical-align: middle; }
th { font-size: 11px; color: var(--muted); font-weight: 560; }
td.mono, .mono { font-family: var(--mono); font-size: 12px; }
td.item { max-width: 280px; line-height: 1.35; }
td.item .note { margin-top: 2px; }
td.nowrap { white-space: nowrap; }
.pill {
  display: inline-flex; align-items: center; height: 20px; padding: 0 8px;
  border-radius: 999px; font-size: 11px; font-weight: 560; white-space: nowrap;
}
.pill.on { background: var(--okbg); color: var(--ok); }
.pill.off { background: #eeeef0; color: var(--muted); }
.pill.mode { background: #eaf3ff; color: #0058b0; }
.pill.pay { background: #f3e8ff; color: #6d28d9; }
.pill.bad { background: #fdeaea; color: var(--bad); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 12px; }
.note { font-size: 11px; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  height: 28px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--line);
  background: #fff; display: inline-flex; align-items: center;
}
.chip.on { border-color: var(--blue); background: #eaf3ff; color: #0058b0; }
.login-card {
  width: 420px; background: var(--card); border-radius: 18px;
  padding: 36px; box-shadow: var(--shadow); border: 1px solid var(--line2);
}
.login-card h1 { font-size: 22px; font-weight: 650; margin: 0 0 6px; letter-spacing: -0.03em; }
.login-card .sub { color: var(--muted); margin: 0 0 22px; }
.mc {
  background: #f2f2f7; border-radius: 10px; padding: 10px 12px; margin: 0 0 18px;
  font-family: var(--mono); font-size: 12px; word-break: break-all;
}
.mc span { display: block; color: var(--muted); font-family: var(--sans); font-size: 11px; margin-bottom: 4px; }
label.f { display: block; font-size: 12px; color: var(--muted); margin: 0 0 6px; }
input.t, select.t, textarea.t {
  width: 100%; height: 36px; border: 1px solid var(--line); border-radius: 10px;
  padding: 0 12px; background: #fff; outline: none;
}
textarea.t { height: auto; min-height: 88px; padding: 10px 12px; resize: vertical; }
input.t:focus, select.t:focus, textarea.t:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0,113,227,.18); }
.stack { display: grid; gap: 12px; }
.btn {
  height: 36px; border: 0; border-radius: 10px; padding: 0 14px;
  background: var(--blue); color: #fff; font-weight: 560; white-space: nowrap; flex-shrink: 0;
}
.btn:hover:not(:disabled) { background: var(--blue2); }
.btn.ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.ghost:hover:not(:disabled) { background: #f2f2f7; }
.btn.danger { background: var(--bad); color: #fff; }
.btn.danger:hover:not(:disabled) { background: #b80012; }
.btn.ok { background: #1f8a44; }
.btn.sm { height: 28px; border-radius: 8px; padding: 0 10px; font-size: 12px; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
a.btn { display: inline-flex; align-items: center; text-decoration: none; }
.err { color: var(--bad); min-height: 18px; font-size: 12px; margin: 8px 0 0; }
.payurl { color: var(--blue); text-decoration: none; font-family: var(--mono); font-size: 12px; }
.bigpay {
  display: inline-flex; align-items: center; height: 28px; padding: 0 10px; white-space: nowrap;
  border-radius: 8px; background: var(--blue); color: #fff; text-decoration: none; font-weight: 560;
}
.toggle {
  position: relative; width: 36px; height: 22px; padding: 0;
  background: #d1d1d6; border-radius: 99px; border: 0; flex-shrink: 0;
}
.toggle:after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px; background: #fff; border-radius: 50%;
  transition: left .15s ease;
}
.toggle.on { background: #34c759; }
.toggle.on:after { left: 16px; }

.groups { display: grid; grid-template-columns: 220px 1fr; gap: 12px; min-height: 480px; }
.gitem {
  padding: 10px 12px; border-radius: 10px; display: flex; justify-content: space-between; gap: 8px;
  width: 100%; background: transparent; border: 0; text-align: left;
}
.gitem.on { background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.gitem .n { font-weight: 560; }
.gitem .c { color: var(--muted); font-family: var(--mono); font-size: 11px; }
.chkbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 14px; border-bottom: 1px solid var(--line2);
}
th.chk, td.chk { width: 36px; padding-right: 4px; }
input.box { width: 16px; height: 16px; accent-color: var(--blue); display: block; }
/* 批量修改抽屉：每行一个字段，未勾选的行压暗且点不动，勾了才算进 PATCH。 */
.brow { padding: 10px 0; border-bottom: 1px solid var(--line2); }
.brow:last-child { border-bottom: 0; padding-bottom: 0; }
.brow .ctl { margin-top: 8px; }
.brow .ctl .note:empty { display: none; }
.brow.off .ctl { opacity: .4; pointer-events: none; }
.import-card { max-width: 720px; }
textarea.t.tall { min-height: 280px; font-family: var(--mono); font-size: 12px; }
label.check { display: flex; align-items: center; gap: 8px; font-size: 13px; }
label.check input { width: 16px; height: 16px; accent-color: var(--blue); }
.pager {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 14px; border-top: 1px solid var(--line2);
}
.pager select.t { width: auto; height: 28px; padding: 0 8px; }
.drawer-bg {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.28);
  justify-content: flex-end; z-index: 20;
}
body.drawer-open .drawer-bg { display: flex; }
.drawer {
  width: 560px; height: 100%; background: #fff; display: flex; flex-direction: column;
  box-shadow: -12px 0 40px rgba(0,0,0,.12);
}
.drawer-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: 20px 22px 12px; border-bottom: 1px solid var(--line2); flex-shrink: 0;
}
.drawer-head h2 { margin: 0 0 4px; font-size: 20px; }
.drawer.wide { width: 840px; }
.drawer-body { flex: 1; min-height: 0; overflow: auto; padding: 0 22px 22px; }
.drawer-body.flush { padding: 0; display: flex; flex-direction: column; overflow: hidden; }
.drawer-body.flush .log { flex: 1; min-height: 0; }
.drawer-foot {
  flex-shrink: 0; padding: 10px 22px 16px; border-top: 1px solid var(--line2); background: #fff;
}
.drawer-foot .err { margin: 0 0 8px; }
.sec { margin-top: 18px; }
.sec h4 { margin: 0 0 8px; font-size: 12px; color: var(--muted); font-weight: 560; letter-spacing: .04em; text-transform: uppercase; }
code { font-family: var(--mono); font-size: 12px; background: #f2f2f7; padding: 1px 5px; border-radius: 4px; }
.picker { position: relative; }
.picker-box { position: relative; }
.picker-list {
  position: absolute; z-index: 5; left: 0; right: 0; top: 40px; max-height: 300px; overflow: auto;
  background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 4px 0;
}
.picker-g { padding: 8px 12px 3px; font-size: 11px; color: var(--muted); font-weight: 560; }
.picker-i { padding: 7px 12px; cursor: pointer; font-size: 13px; display: flex; justify-content: space-between; gap: 10px; }
.picker-i .v { font-family: var(--mono); font-size: 11px; color: var(--muted); white-space: nowrap; }
.picker-i.on { background: #eaf3ff; font-weight: 560; }
.picker-i:hover, .picker-i.hi { background: #eaf3ff; }
.picker-none { padding: 8px 12px; color: var(--muted); font-size: 12px; }
.picker-sel { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 8px; }
.picker-sel[hidden] { display: none; }
.picker-chip {
  border: 1px solid var(--line); background: #f5f5f7; border-radius: 999px;
  padding: 3px 8px 3px 10px; font-size: 12px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.picker-chip .x { color: var(--muted); font-size: 14px; line-height: 1; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #1d1d1f; color: #fff; padding: 8px 14px; border-radius: 10px; z-index: 30;
  font-size: 12px; max-width: 70%;
}

.progress {
  position: fixed; top: 0; left: 0; z-index: 50;
  height: 2px; width: 100%; pointer-events: none; opacity: 0;
  overflow: hidden; transition: opacity .15s;
}
body.working .progress { opacity: 1; }
.progress::after {
  content: ""; display: block; height: 100%; width: 38%;
  background: var(--blue); border-radius: 2px;
  animation: progress-slide 1s ease-in-out infinite;
}
@keyframes progress-slide {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(320%); }
}

.spin {
  width: 22px; height: 22px;
  border: 2px solid var(--line); border-top-color: var(--blue);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.view-load {
  grid-row: 3; display: none; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  z-index: 6;
}
body[data-view="login"] .view-load { grid-row: 1; }
body.view-loading .view-load { display: flex; }
body.view-loading .view { opacity: .45; pointer-events: none; }

.btn.is-busy { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-busy::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.35); border-top-color: #fff;
  animation: spin .7s linear infinite;
}
.btn.ghost.is-busy::after,
.btn.danger.is-busy::after {
  border-color: rgba(0,0,0,.12); border-top-color: var(--blue);
}
.btn.danger.is-busy::after { border-top-color: var(--bad); }
.btn.sm.is-busy::after { width: 12px; height: 12px; }
