/* luma-proxy 管理后台 · manus 风格翻新（批次 UI-1）
 * 设计参考：D:\manus\web（manus2api-console，GitHub 风双主题）
 * 令牌体系：亮/夜双主题 CSS 变量，html[data-theme='dark'] 覆盖
 */
:root {
  font-family: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}
:root, html[data-theme='light'] {
  color-scheme: light;
  --bg: #f6f8fa; --panel: #ffffff; --panel-2: #f3f4f6; --head: #f6f8fa;
  --border: #d0d7de; --border-2: #afb8c1;
  --text: #24292f; --text-strong: #1f2328; --text-mute: #57606a; --text-faint: #8c959f;
  --hover: #eaeef2;
  --accent: #0969da; --accent-hover: #218bff; --accent-contrast: #ffffff;
  --ok: #1a7f37; --ok-bg: #dafbe1; --ok-border: #a9d5b6;
  --warn: #9a6700; --warn-bg: #fff8c5; --warn-border: #e3c56b;
  --err: #cf222e; --err-bg: #ffebe9; --err-border: #f2c1c7;
  --purple: #8250df; --purple-bg: #fbefff; --purple-border: #d2c5f5;
  --idle: #57606a; --idle-bg: #eef1f4; --idle-border: #d0d7de;
  --sel: #0969da1a;
  --input-bg: #ffffff; --placeholder: #8c959f;
  --shadow-sm: 0 1px 2px rgba(31,35,40,0.04);
}
html[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0d1117; --panel: #161b22; --panel-2: #21262d; --head: #10161f;
  --border: #30363d; --border-2: #484f58;
  --text: #c9d1d9; --text-strong: #ffffff; --text-mute: #8b949e; --text-faint: #6b7280;
  --hover: #30363d;
  --accent: #1f6feb; --accent-hover: #388bfd; --accent-contrast: #ffffff;
  --ok: #4ec9b0; --ok-bg: #1b47214d; --ok-border: #1b4721;
  --warn: #e3b341; --warn-bg: #e3b3411a; --warn-border: #e3b34166;
  --err: #f85149; --err-bg: #7d1d1d4d; --err-border: #7d1d1d;
  --purple: #ab7df8; --purple-bg: #8250df22; --purple-border: #8250df55;
  --idle: #8b949e; --idle-bg: #21262d; --idle-border: #30363d;
  --sel: #1f6feb1a;
  --input-bg: #0d1117; --placeholder: #6b7280;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-size: 0.875rem; line-height: 1.45rem;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--panel-2); border-radius: 4px; padding: 1px 5px; font-size: 12px; }
.mono, .mono b { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; }
.muted { color: var(--text-mute); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- 布局骨架：左侧 sidebar + 主区 ---------- */
.app { display: flex; width: 100%; height: 100%; }
.sidebar {
  display: flex; flex-direction: column; flex-shrink: 0;
  width: 232px; background: var(--panel);
  border-right: 1px solid var(--border);
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  height: 56px; padding: 0 14px; border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand h1 { margin: 0; font-size: 15px; font-weight: 700; color: var(--text-strong); white-space: nowrap; }
.brand h1 b { color: var(--accent); }
.health-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px var(--ok-bg); flex-shrink: 0; }
.health-dot.bad { background: var(--err); box-shadow: 0 0 0 3px var(--err-bg); }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; padding: 0; border: 1px solid var(--border);
  border-radius: 6px; background: transparent; color: var(--text-mute); cursor: pointer;
}
.icon-btn:hover { color: var(--text-strong); background: var(--panel-2); }
.icon-btn svg { width: 15px; height: 15px; }
html[data-theme='light'] .theme-moon { display: none; }
html[data-theme='dark'] .theme-sun { display: none; }

.side-nav { display: flex; flex-direction: column; gap: 2px; padding: 10px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 8px 12px; border: 0; border-radius: 6px; background: transparent;
  color: var(--text-mute); font-size: 13.5px; text-align: left; cursor: pointer;
  transition: background .12s, color .12s;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-item:hover { background: var(--panel-2); color: var(--text-strong); }
.nav-item.active { background: var(--accent); color: var(--accent-contrast); }

.side-foot { border-top: 1px solid var(--border); padding: 12px 14px; }
.side-foot .foot-label { font-size: 11px; color: var(--text-mute); margin-bottom: 4px; }
.side-foot .foot-num { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.side-foot .foot-num b { font-size: 18px; font-family: ui-monospace, Menlo, monospace; color: var(--text-strong); }
.side-foot .foot-num span { font-size: 11.5px; color: var(--text-mute); }
.side-foot .foot-row { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--text-mute); margin-top: 3px; }
.side-foot .foot-row .mono { color: var(--text); }
.side-foot .btn-block { width: 100%; margin-top: 10px; justify-content: center; }

.main { flex: 1; min-width: 0; overflow-y: auto; padding: 18px 22px 40px; }

/* ---------- 面板：通栏铺满、左对齐（manus 排版） ---------- */
.panel { display: none; }
.panel.active { display: block; }
.panel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.panel-head h2 { margin: 0; font-size: 17px; font-weight: 700; color: var(--text-strong); display: flex; align-items: center; gap: 8px; }
.panel-head h2 svg { width: 17px; height: 17px; color: var(--text-mute); }
.panel-head .spacer { flex: 1; }

.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow-sm);
}
.card h2 {
  display: flex; align-items: center; gap: 8px; margin: 0 0 6px;
  font-size: 14.5px; font-weight: 600; color: var(--text-strong);
}
.card h2 svg { width: 15px; height: 15px; color: var(--text-mute); }
.card .sub { color: var(--text-mute); font-size: 12.5px; margin-bottom: 12px; line-height: 1.5; }
.card h2 .head-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* ---------- 指标卡 ---------- */
.stats-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 14px; box-shadow: var(--shadow-sm); min-width: 0; cursor: default;
}
.stat-card .num { font-size: 22px; font-weight: 700; font-family: ui-monospace, Menlo, monospace; color: var(--text-strong); line-height: 1.2; }
.stat-card .label { font-size: 12px; color: var(--text-mute); margin-top: 2px; }
.stat-card .muted { font-size: 11px; }
.stat-green .num { color: var(--ok); }
.stat-yellow .num { color: var(--warn); }
.stat-red .num { color: var(--err); }
.stat-purple .num { color: var(--purple); }
.stat-accent { border-color: var(--accent); }
.stat-accent .num { color: var(--accent); }

/* 总览页：manus 同款 4×2 大卡 */
#overview-cards { grid-template-columns: repeat(4, 1fr); gap: 12px; }
#overview-cards .stat-card { padding: 14px 18px; }
#overview-cards .stat-card .num { font-size: 27px; }
#overview-cards .stat-card .label { font-size: 12.5px; margin-top: 4px; }
#overview-cards .stat-card .muted { font-size: 11.5px; margin-top: 2px; line-height: 1.5; }
@media (max-width: 1100px) { #overview-cards { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px) { #overview-cards { grid-template-columns: 1fr; } }

/* ---------- 工具条 / 表单 ---------- */
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--panel); color: var(--text); font-size: 13px; cursor: pointer;
  transition: background .12s, border-color .12s, color .12s; white-space: nowrap;
}
.btn svg { width: 14px; height: 14px; }
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-secondary { background: var(--panel-2); }
.btn-danger { color: var(--err); border-color: var(--err-border); }
.btn-danger:hover { background: var(--err-bg); border-color: var(--err); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-mute); }
.btn-ghost:hover { background: var(--panel-2); color: var(--text-strong); }
.btn-sm { padding: 3px 8px; font-size: 12px; }
.btn-toggle-on { background: var(--sel); border-color: var(--accent); color: var(--accent); }
.btn-toggle-on:hover { background: var(--sel); }

input[type="text"], input[type="number"], input[type="password"], select, textarea {
  background: var(--input-bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 9px; font-size: 13px; font-family: inherit; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--sel); }
textarea { width: 100%; resize: vertical; font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
input[type="checkbox"] { accent-color: var(--accent); }
.filter-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.filter-bar .search { min-width: 200px; flex: 1; max-width: 340px; }
.filter-bar label { font-size: 12px; color: var(--text-mute); white-space: nowrap; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
.table-wrap.scroll-y { max-height: calc(100vh - 310px); overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--head); color: var(--text-mute);
  text-align: left; font-weight: 600; font-size: 11.5px;
  padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
thead th.right, td.right { text-align: right; }
tbody td { padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--hover); }
td.wrap, th.wrap { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.error-cell { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--err); font-size: 12px; }
.accounts-empty { display: none; text-align: center; color: var(--text-mute); padding: 32px 0; }

/* ---------- 徽章 ---------- */
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; line-height: 18px; white-space: nowrap;
  border: 1px solid var(--idle-border); background: var(--idle-bg); color: var(--idle);
}
.badge-completed, .badge-active, .badge-ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-border); }
.badge-failed, .badge-invalid, .badge-err { background: var(--err-bg); color: var(--err); border-color: var(--err-border); }
.badge-exhausted, .badge-warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-border); }
.badge-disabled, .badge-pending, .badge-idle { background: var(--idle-bg); color: var(--idle); border-color: var(--idle-border); }
.badge-waf_blocked, .badge-purple { background: var(--purple-bg); color: var(--purple); border-color: var(--purple-border); }
.badge-running { background: var(--sel); color: var(--accent); border-color: transparent; }
.badge-451 { background: var(--err-bg); color: var(--err); border-color: var(--err); font-weight: 700; }

/* ---------- 进度条 / 分页 ---------- */
.progress { height: 4px; border-radius: 2px; background: var(--panel-2); margin: 3px 0; max-width: 120px; overflow: hidden; }
.progress > div { height: 100%; background: var(--ok); border-radius: 2px; }
.progress.warn > div { background: var(--warn); }
.progress.danger > div { background: var(--err); }

.accounts-pager { display: none; align-items: center; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.pager-total { font-size: 12px; }
.pager-spacer { flex: 1; }
#acc-jump { width: 64px; }

/* ---------- 配置页 ---------- */
.cfg-row {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 18px;
  padding: 10px 2px; border-bottom: 1px solid var(--border);
}
.cfg-row:last-child { border-bottom: 0; }
.cfg-row > div:first-child { min-width: 0; flex: 1; }
.cfg-row select, .cfg-row input { width: 320px; max-width: 45%; flex-shrink: 0; }
.cfg-row textarea { width: 380px; max-width: 50%; flex-shrink: 0; }
.cfg-key { font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; color: var(--text-strong); font-weight: 600; }
.cfg-desc { font-size: 11.5px; color: var(--text-mute); margin-top: 2px; line-height: 1.5; }
/* 长 JSON 的折叠交互：默认单行预览 + 展开按钮 */
.cfg-fold { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; width: 440px; max-width: 52%; flex-shrink: 0; }
.cfg-fold textarea { width: 100%; max-width: 100%; }
.cfg-preview {
  width: 100%; font-size: 11.5px; color: var(--text-mute); text-align: left;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 9px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------- 弹窗 ---------- */
.modal-mask {
  display: none; position: fixed; inset: 0; z-index: 100;
  background: rgba(1,4,9,0.55); align-items: flex-start; justify-content: center;
  padding: 8vh 16px 16px; overflow-y: auto;
}
.modal-mask.show { display: flex; }
.modal {
  width: 100%; max-width: 560px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 10px; padding: 20px;
  box-shadow: 0 16px 40px rgba(1,4,9,0.3);
}
.modal h3 { margin: 0 0 14px; font-size: 15px; color: var(--text-strong); }
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 12.5px; color: var(--text-mute); margin-bottom: 5px; }
.form-group input, .form-group textarea { width: 100%; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.alert { padding: 9px 12px; border-radius: 6px; font-size: 12.5px; }
.alert-error { background: var(--err-bg); color: var(--err); border: 1px solid var(--err-border); }

/* ---------- Toast ---------- */
#toast {
  position: fixed; top: 18px; right: 18px; z-index: 999;
  padding: 10px 18px; border-radius: 8px; font-size: 13px;
  background: var(--ok); color: #fff; box-shadow: var(--shadow-sm);
  opacity: 0; transition: opacity .25s; pointer-events: none; max-width: 420px;
}
#toast.err { background: var(--err); }

/* ---------- 登录页（login.html） ---------- */
.login-wrap { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; }
.login-card { width: 360px; padding: 28px; }
.login-card .brand { justify-content: center; font-size: 20px; font-weight: 700; color: var(--text-strong); }
.accent { color: var(--accent); }
.tagline { text-align: center; color: var(--text-mute); font-size: 12.5px; margin: 6px 0 18px; }
.btn-block { width: 100%; justify-content: center; }

/* ---------- 响应式：窄屏 sidebar 折叠为顶部横条 ---------- */
@media (max-width: 768px) {
  body { flex-direction: column; }
  .sidebar { width: 100%; border-right: 0; border-bottom: 1px solid var(--border); }
  .side-nav { flex-direction: row; overflow-x: auto; padding: 6px; }
  .nav-item { width: auto; white-space: nowrap; }
  .side-foot { display: none; }
  .main { padding: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
