/* RJ Dispatcher 控制台样式。颜色、间距、圆角都走 :root 变量，深色模式只改变量。 */
:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f2f4f7;
  --border: #e3e6eb;
  --border-strong: #cfd4dc;
  --text: #171b22;
  --text-2: #4b5462;
  --text-3: #7a8494;
  --accent: #2458d6;
  --accent-hover: #1c48b4;
  --accent-soft: #eaf0fd;
  --ok: #18794e;
  --ok-soft: #e7f5ee;
  --warn: #a35a00;
  --warn-soft: #fdf3e2;
  --bad: #c0362c;
  --bad-soft: #fdecea;
  --log-bg: #0f131a;
  --log-text: #d6dbe3;
  --log-dim: #7c8697;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-pop: 0 12px 32px rgba(16, 24, 40, .16);
  --radius: 8px;
  --radius-lg: 10px;
  --sidebar: 232px;
  --font: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0e1116;
    --surface: #161a21;
    --surface-2: #1d222b;
    --border: #2a303b;
    --border-strong: #3a4250;
    --text: #e8ebf0;
    --text-2: #b3bac6;
    --text-3: #838c9b;
    --accent: #6b94f5;
    --accent-hover: #86a8f7;
    --accent-soft: #1d2a47;
    --ok: #4cc38a;
    --ok-soft: #12291f;
    --warn: #e5a54b;
    --warn-soft: #2e2312;
    --bad: #f07368;
    --bad-soft: #341917;
    --log-bg: #0a0d12;
    --shadow: none;
    --shadow-pop: 0 12px 32px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; }
p { margin: 0; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- 外壳 ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100dvh; }
.sidebar {
  position: sticky; top: 0; height: 100dvh;
  display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 16px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; }
.brand-mark {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 13px; letter-spacing: .5px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 15px; }
.brand-text small { color: var(--text-3); font-size: 12px; }
.nav { flex: 1; overflow-y: auto; }
.nav-group { margin-bottom: 18px; }
.nav-title { padding: 0 10px 6px; color: var(--text-3); font-size: 12px; }
.nav a {
  display: block; padding: 7px 10px; margin: 1px 0; border-radius: 6px;
  color: var(--text-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.account {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  border-top: 1px solid var(--border); padding: 12px 4px 0 10px;
}
.account-name { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mobile-bar { display: none; }
.scrim { display: none; }

.main { min-width: 0; }
.page { max-width: 1240px; margin: 0 auto; padding: 28px 32px 48px; outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-head h1 { font-size: 22px; line-height: 1.3; }
.page-head p { color: var(--text-3); margin-top: 4px; }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.stack { display: grid; gap: 16px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 16px; align-items: start; }

/* ---------- 按钮与表单 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 6px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--bad); }
.btn-danger:hover { background: var(--bad-soft); border-color: var(--bad); }
.btn-danger-solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-danger-solid:hover { filter: brightness(.95); background: var(--bad); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-ghost.btn-danger { color: var(--bad); }
.btn-ghost.btn-danger:hover { background: var(--bad-soft); border-color: transparent; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-icon { width: 34px; padding: 0; }

.input, .select, .textarea {
  height: 34px; padding: 0 10px; border-radius: 6px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; min-width: 0;
}
.textarea { height: auto; min-height: 84px; padding: 8px 10px; resize: vertical; line-height: 1.5; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.mono { font-size: 13px; }
.field { display: grid; gap: 6px; align-content: start; }
.field > span { font-weight: 500; color: var(--text-2); font-size: 13px; }
.field .req { color: var(--bad); margin-left: 2px; }
.field small { color: var(--text-3); font-size: 12px; }
.password-wrap { position: relative; display: flex; }
.password-wrap .input { flex: 1; padding-right: 56px; }
.password-wrap .btn { position: absolute; right: 3px; top: 3px; height: 28px; }

.seg { display: inline-flex; padding: 2px; border-radius: 7px; background: var(--surface-2); border: 1px solid var(--border); }
.seg button {
  height: 28px; padding: 0 12px; border: 0; border-radius: 5px; background: transparent;
  color: var(--text-2); font: inherit; font-weight: 500; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(16, 24, 40, .12); }
.switch { display: inline-flex; align-items: center; gap: 8px; color: var(--text-2); cursor: pointer; user-select: none; }
.switch input { appearance: none; width: 30px; height: 18px; border-radius: 9px; background: var(--border-strong); position: relative; margin: 0; cursor: pointer; transition: background .15s; }
.switch input::after { content: ""; position: absolute; left: 2px; top: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(12px); }

/* ---------- 卡片 ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); min-width: 0; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.card-head h2 { font-size: 15px; }
.card-head .meta { color: var(--text-3); font-size: 13px; }
.card-body { padding: 16px; }
.card-foot { padding: 10px 16px; border-top: 1px solid var(--border); color: var(--text-3); font-size: 12.5px; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar .grow { flex: 1; min-width: 160px; }
.card-head > .toolbar { flex: 1; }
.input.search { width: min(320px, 100%); }
.page-head p { max-width: 760px; }

/* 服务状态横幅 */
.service { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 20px; }
.service-main { display: flex; align-items: center; gap: 14px; min-width: 0; }
.service-icon { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; flex: none; }
.service-icon::before { content: ""; width: 12px; height: 12px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 4px color-mix(in srgb, currentColor 20%, transparent); }
.service-icon.ok { background: var(--ok-soft); color: var(--ok); }
.service-icon.bad { background: var(--bad-soft); color: var(--bad); }
.service-icon.neutral { background: var(--surface-2); color: var(--text-3); }
.service h2 { font-size: 17px; }
.service-meta { display: flex; flex-wrap: wrap; gap: 4px 16px; color: var(--text-3); margin-top: 3px; font-size: 13px; }
.service-meta b { color: var(--text-2); font-weight: 500; }
.service-actions { display: flex; gap: 8px; flex: none; }

/* 指标 */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.kpi { padding: 14px 16px; }
.kpi-label { color: var(--text-3); font-size: 13px; }
.kpi-value { font-size: 26px; font-weight: 600; line-height: 1.2; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi-value small { font-size: 15px; color: var(--text-3); font-weight: 500; margin-left: 2px; }
.kpi-sub { color: var(--text-3); font-size: 12.5px; margin-top: 4px; }

/* ---------- 状态标签 ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px;
  border-radius: 11px; font-size: 12.5px; font-weight: 500; white-space: nowrap;
  background: var(--surface-2); color: var(--text-2);
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.plain::before { display: none; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.info { background: var(--accent-soft); color: var(--accent); }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); margin-right: 6px; vertical-align: 1px; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }
.tag { display: inline-block; padding: 0 6px; border-radius: 4px; font-size: 12px; line-height: 18px; background: var(--warn-soft); color: var(--warn); margin-left: 6px; }
.muted { color: var(--text-3); }
.sub { display: block; color: var(--text-3); font-size: 12.5px; }
.ok-text { color: var(--ok); } .warn-text { color: var(--warn); } .bad-text { color: var(--bad); }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-weight: 500; color: var(--text-3); font-size: 12.5px;
  padding: 9px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; overflow-wrap: anywhere; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.table tbody tr[aria-selected="true"] td { background: var(--accent-soft); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; width: 1%; }
.table .nowrap { white-space: nowrap; }
.table .clip { max-width: 280px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- 告警列表 ---------- */
.alerts { list-style: none; margin: 0; padding: 0; }
.alerts li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: start; padding: 11px 16px; border-bottom: 1px solid var(--border); }
.alerts li:last-child { border-bottom: 0; }
.alerts .msg { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.alerts .when { color: var(--text-3); font-size: 12.5px; white-space: nowrap; text-align: right; }

/* ---------- 提示条 / 空状态 ---------- */
.banner { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; padding: 12px 14px; border-radius: var(--radius); border: 1px solid; font-size: 13.5px; }
.banner.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 30%, transparent); color: var(--text); }
.banner.bad { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 30%, transparent); color: var(--text); }
.banner.info { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 25%, transparent); color: var(--text); }
.banner .banner-actions { display: flex; gap: 6px; flex-wrap: wrap; flex: none; }
.empty { padding: 40px 16px; text-align: center; color: var(--text-3); }
.empty strong { display: block; color: var(--text-2); font-weight: 500; margin-bottom: 4px; }
.loading { padding: 32px 16px; text-align: center; color: var(--text-3); }
.skeleton { height: 14px; border-radius: 4px; background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; margin: 10px 16px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- 日志 ---------- */
.log-view {
  background: var(--log-bg); color: var(--log-text);
  font: 12.5px/1.6 var(--mono); padding: 10px 0; height: calc(100dvh - 300px); min-height: 360px; overflow: auto;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.log-view.wrap .log-msg { white-space: pre-wrap; overflow-wrap: anywhere; }
.log-line { display: grid; grid-template-columns: 128px 52px minmax(0, 1fr); gap: 10px; padding: 0 16px; }
.log-line:hover { background: rgba(255, 255, 255, .04); }
.log-time { color: var(--log-dim); white-space: nowrap; }
.log-level { font-weight: 600; }
.log-msg { white-space: pre; }
.lv-ERROR .log-level, .lv-ERROR .log-msg { color: #ff8a80; }
.lv-WARN .log-level { color: #f5c26b; }
.lv-WARN .log-msg { color: #f3dca6; }
.lv-INFO .log-level { color: #8ab4f8; }
.lv-EVENT .log-level { color: #c3a6f5; }
.lv-DEBUG .log-level, .lv-DEBUG .log-msg { color: var(--log-dim); }
.log-status { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* ---------- 打包进度 ---------- */
.progress { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width .4s; }
.progress.indeterminate > span { width: 30%; animation: slide 1.3s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(340%); } }
.job-stats { display: flex; flex-wrap: wrap; gap: 6px 20px; color: var(--text-3); font-size: 13px; margin-top: 10px; }
.job-stats b { color: var(--text); font-weight: 500; font-variant-numeric: tabular-nums; }
.tail { margin-top: 12px; background: var(--surface-2); border-radius: 6px; padding: 8px 10px; font: 12px/1.55 var(--mono); color: var(--text-2); max-height: 180px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
.result { display: flex; align-items: center; justify-content: space-between; gap: 16px; }

/* ---------- 令牌 ---------- */
.kv { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 10px 16px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; }
.kv dd.cred-value { display: flex; align-items: center; gap: 8px; min-width: 0; }
.kv dd.cred-value .mono { overflow-wrap: anywhere; user-select: all; }
.code-block { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; font: 12.5px/1.6 var(--mono); overflow-x: auto; white-space: pre; }
.reveal { display: flex; gap: 8px; align-items: center; }
.reveal .input { flex: 1; font-family: var(--mono); }
details.more summary { cursor: pointer; color: var(--text-2); font-weight: 500; }
details.more[open] summary { margin-bottom: 12px; }

/* ---------- 对话框 ---------- */
dialog {
  border: 1px solid var(--border); border-radius: 12px; padding: 0; background: var(--surface); color: var(--text);
  width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); box-shadow: var(--shadow-pop);
}
dialog::backdrop { background: rgba(15, 20, 30, .45); }
.dialog-head { padding: 18px 20px 0; }
.dialog-head h2 { font-size: 16px; }
.dialog-body { padding: 14px 20px 4px; color: var(--text-2); display: grid; gap: 14px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 20px 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
.form-grid .wide { grid-column: 1 / -1; }
.form-error { color: var(--bad); font-size: 13px; }
.form-error:empty { display: none; }

/* ---------- 轻提示 ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 50; display: grid; gap: 8px; }
.toast {
  min-width: 220px; max-width: min(420px, calc(100vw - 40px)); padding: 10px 14px; border-radius: 8px;
  background: var(--text); color: var(--surface); box-shadow: var(--shadow-pop); font-size: 13.5px;
  animation: rise .18s ease-out;
}
.toast.bad { background: var(--bad); color: #fff; }
@keyframes rise { from { transform: translateY(6px); opacity: 0; } }

/* ---------- 登录页 ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(380px, 100%); }
.login-card .brand { padding: 0 0 24px; }
.login-card .card { padding: 24px; }
.login-card h1 { font-size: 18px; }
.login-card p.muted { margin: 4px 0 20px; }
.login-card form { display: grid; gap: 14px; }
.login-card .btn-primary { height: 38px; margin-top: 4px; }
.login-foot { text-align: center; color: var(--text-3); font-size: 12.5px; margin-top: 16px; }

/* ---------- 窄屏 ---------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; z-index: 40; left: 0; top: 0; width: 260px; height: 100dvh;
    transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow-pop);
  }
  .sidebar.open { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 39; background: rgba(15, 20, 30, .4); }
  .mobile-bar {
    display: flex; align-items: center; gap: 8px; position: sticky; top: 0; z-index: 20;
    height: 52px; padding: 0 8px; background: var(--surface); border-bottom: 1px solid var(--border);
  }
  .page { padding: 18px 16px 40px; }
  .page-head { flex-direction: column; align-items: stretch; gap: 12px; }
  .page-head h1 { font-size: 19px; }
  .page-actions { justify-content: flex-start; }
  .kpis { gap: 10px; }
  .kpi-value { font-size: 22px; }
  .service { flex-direction: column; align-items: stretch; }
  .service-actions .btn { flex: 1; }
  .form-grid { grid-template-columns: 1fr; }
  .toolbar .grow { flex-basis: 100%; }
  .card-head { flex-wrap: wrap; }
  .input.search { width: 100%; }
  .log-view { height: calc(100dvh - 360px); }
  .log-line { grid-template-columns: auto minmax(0, 1fr); column-gap: 10px; padding: 4px 12px; border-bottom: 1px solid rgba(255, 255, 255, .05); }
  .log-msg { grid-column: 1 / -1; white-space: pre-wrap; overflow-wrap: anywhere; }
  .banner { flex-direction: column; }
  .alerts li { grid-template-columns: auto minmax(0, 1fr); }
  .alerts .when { grid-column: 2; text-align: left; }
  .result { flex-direction: column; align-items: stretch; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 10px; }

  /* 表格转卡片：单元格用 data-label 作字段名，不重复渲染两套结构。 */
  table.table.stackable thead { display: none; }
  table.table.stackable, .stackable tbody, .stackable tr, .stackable td { display: block; width: 100%; }
  .stackable tr { padding: 12px 14px; border-bottom: 1px solid var(--border); }
  .stackable tbody tr:last-child { border-bottom: 0; }
  .stackable td { border: 0; padding: 3px 0; display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 10px; }
  .stackable td::before { content: attr(data-label); color: var(--text-3); font-size: 12.5px; }
  .stackable td.primary { grid-template-columns: minmax(0, 1fr); font-weight: 600; padding-bottom: 6px; }
  .stackable td.primary::before { display: none; }
  .stackable td.actions { width: 100%; display: flex; gap: 8px; padding-top: 8px; }
  .stackable td.actions .btn { border-color: var(--border-strong); }
  .stackable td.actions::before { display: none; }
  .stackable td.num { text-align: left; }
  .stackable .clip { max-width: none; white-space: normal; }
  .table tbody tr:hover td { background: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
