:root {
  --bg-app: #0e1015;
  --bg-panel: #161a22;
  --bg-card: #1d222c;
  --bg-input: #232936;
  --bg-hover: #2b3242;
  --accent: #5b8def;
  --accent-hv: #4a7de0;
  --ok: #5bbf7d;
  --danger: #e2696b;
  --text-1: #e8ecf4;
  --text-2: #8b95ab;
  --text-3: #5a6377;
  --border: #262c3a;
  --radius: 10px;
}

* { box-sizing: border-box; }

/* hidden 属性必须压过任何 display 规则，否则「隐藏单选」会失效 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-app);
  color: var(--text-1);
  font-family: "Microsoft YaHei UI", "PingFang SC", -apple-system, system-ui, sans-serif;
  font-size: 14px;
}

button, input, textarea { font-family: inherit; }

/* ---------- 按钮 ---------- */
.btn {
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .15s, opacity .15s;
  font-size: 13px;
  color: var(--text-1);
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  height: 42px;
  width: 100%;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hv); }

/* 危险操作：删除账号等不可逆确认 */
.btn-danger {
  background: #c92a2a;
  color: #fff;
  font-weight: 600;
  height: 42px;
  width: 100%;
}
.btn-danger:hover:not(:disabled) { background: #e03131; }

.btn-ghost {
  background: var(--bg-input);
  height: 34px;
  padding: 0 14px;
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); }

/* ---------- 登录 ---------- */
.login-wrap {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
}
.login-title { font-size: 20px; font-weight: 700; margin: 0; }
.login-sub { font-size: 12px; color: var(--text-3); margin: 4px 0 24px; }

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 12px;
  color: var(--text-2);
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-1);
  font-size: 14px;
  outline: none;
}
.field input:focus { border-color: var(--accent); }

.alert {
  display: none;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
  background: rgba(226, 105, 107, .12);
  color: #f0a3a4;
  border: 1px solid rgba(226, 105, 107, .3);
}
.alert.show { display: block; }
.alert.info {
  background: rgba(91, 141, 239, .12);
  color: #a8c2f5;
  border-color: rgba(91, 141, 239, .3);
}

/* ---------- 主布局 ---------- */
.layout { display: flex; height: 100%; }

.sidebar {
  width: 280px;
  flex: 0 0 280px;
  background: var(--bg-panel);
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.brand { font-size: 17px; font-weight: 700; }
.brand-sub { font-size: 11px; color: var(--text-3); margin-bottom: 12px; }
.divider { height: 1px; background: var(--border); margin: 12px 0; }

.section-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-2);
  margin: 12px 0 6px;
}
.section-hint { font-size: 10px; color: var(--text-3); font-weight: 400; }

select, input[type="text"], input[type="number"] {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-1);
  font-size: 13px;
  outline: none;
}
select:focus, input:focus { border-color: var(--accent); }

/* 选项按钮组：选项多或字多时自动换行，不再挤成一条把字压变形 */
.seg {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  background: var(--bg-input);
  padding: 5px;
  border-radius: 8px;
}
.seg button {
  /* flex-basis: auto → 按钮至少按内容宽度排；grow 让同一行的按钮等分撑满 */
  flex: 1 1 auto;
  min-width: 62px;
  min-height: 32px;
  padding: 5px 8px;
  white-space: nowrap; /* 宁可换行也不把一个词拆成两行 */
  line-height: 1.35;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-2);
  font-size: 12px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.seg button:hover { color: var(--text-1); background: var(--bg-hover); }
.seg button.active { background: var(--accent); color: #fff; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 22px 10px;
}
.topbar h1 { font-size: 16px; margin: 0; font-weight: 700; }
.topbar .sub { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.user-box { display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--text-2); }
.badge {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 10px;
}

.result-wrap {
  flex: 1;
  margin: 0 22px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  min-height: 0;
}
#result {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  color: var(--text-1);
  font-size: 14px;
  line-height: 1.8;
  font-family: inherit;
}

.actions { display: flex; gap: 8px; margin-left: auto; }

/* ---------- 顶部导航 ---------- */
.nav {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 22px;
  height: 54px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.nav-brand { font-size: 15px; font-weight: 700; white-space: nowrap; }
.nav-links { display: flex; gap: 4px; flex: 1; min-width: 0; overflow-x: auto; }
.nav-links a {
  color: var(--text-2);
  text-decoration: none;
  font-size: 13px;
  padding: 7px 12px;
  border-radius: 8px;
  white-space: nowrap;
}
.nav-links a:hover { background: var(--bg-hover); color: var(--text-1); }
.nav-links a.active { background: var(--bg-input); color: var(--text-1); }
.nav-right { display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--text-2); }
.shell { display: flex; flex-direction: column; height: 100%; }
.shell > .layout { flex: 1; min-height: 0; }
.page {
  flex: 1;
  overflow-y: auto;
  padding: 22px;
}
.page-narrow { max-width: 1100px; margin: 0 auto; }

/* ---------- 卡片与栅格 ---------- */
.grid { display: grid; gap: 14px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 900px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}
.card-title { font-size: 13px; color: var(--text-2); margin-bottom: 8px; }
.stat-value { font-size: 26px; font-weight: 700; line-height: 1.2; }
.stat-sub { font-size: 11px; color: var(--text-3); margin-top: 4px; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.section-head h2 { font-size: 15px; margin: 0; }

/* ---------- 表格 ---------- */
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th, table.tbl td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.tbl th { color: var(--text-3); font-weight: 500; font-size: 12px; }
table.tbl td { color: var(--text-1); }
table.tbl tr:hover td { background: rgba(255, 255, 255, .02); }
.table-wrap { overflow-x: auto; }

/* 行内下拉菜单：盒子写在表格行里，但用 fixed 定位，避免被 .table-wrap 的 overflow 裁掉。
   top/left 由 JS 按按钮位置算，最后一行的菜单会自动往上翻。 */
.row-menu {
  position: fixed;
  z-index: 200;
  min-width: 176px;
  padding: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .5);
}
.row-menu button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  height: 34px;
  padding: 0 10px;
  background: transparent;
  border: 0;
  border-radius: 8px;
  color: var(--text-1);
  font-size: 13px;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
}
.row-menu button:hover { background: var(--bg-hover); }
.row-menu button.danger { color: var(--danger); }
.row-menu .muted { font-size: 12px; }

/* ---------- 标签 ---------- */
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-2);
}
.tag.ok { color: #86d3a0; border-color: rgba(91, 191, 125, .35); }
.tag.warn { color: #e8c47a; border-color: rgba(232, 196, 122, .35); }
.tag.err { color: #f0a3a4; border-color: rgba(226, 105, 107, .35); }
.tag.acc { color: #a8c2f5; border-color: rgba(91, 141, 239, .35); }

/* ---------- 表单行 ---------- */
.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.form-row .field { margin-bottom: 0; flex: 1; min-width: 150px; }
.field select {
  width: 100%;
  height: 40px;
  padding: 0 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-1);
  font-size: 13px;
  outline: none;
}

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal-mask.show { display: flex; }
.modal {
  width: 100%;
  max-width: 520px;
  max-height: 86vh;
  overflow-y: auto;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
}
.modal h3 { margin: 0 0 16px; font-size: 16px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* ---------- 提示条 ---------- */
.toast {
  position: fixed;
  left: 50%;
  top: 66px;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-1);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  z-index: 100;
  max-width: 90vw;
}
.toast.show { opacity: 1; }
.toast.err { border-color: rgba(226, 105, 107, .5); color: #f0a3a4; }
.toast.ok { border-color: rgba(91, 191, 125, .5); color: #9ad8b3; }

.muted { color: var(--text-3); font-size: 12px; }
.mono { font-family: ui-monospace, Consolas, monospace; }
.empty { padding: 40px; text-align: center; color: var(--text-3); font-size: 13px; }

.code-box {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
  line-height: 1.7;
  max-height: 260px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

textarea.input {
  width: 100%;
  min-height: 90px;
  padding: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-1);
  font-size: 13px;
  line-height: 1.6;
  outline: none;
  resize: vertical;
}
textarea.input:focus { border-color: var(--accent); }

/* ---------- 手机自适应 ---------- */
@media (max-width: 768px) {
  .nav { padding: 0 12px; gap: 10px; height: 50px; }
  .nav-brand { font-size: 14px; }
  .page { padding: 14px; }
}
