:root {
  --bg: #0B0E14;
  --bg-soft: #131720;
  --card: #191D25;
  --card-hover: #20252F;
  --line: #2A313C;
  --text: #E6EDF3;
  --text-dim: #8B949E;
  --accent: #3C8AF1;
  --accent-2: #2E6FD0;
  --accent-soft: rgba(60,138,241,.16);
  --ok: #3FB950;
  --warn: #D29922;
  --danger: #F85149;
  --danger-soft: rgba(248,81,73,.14);
  --purple: #A471F8;
  --radius: 14px;
  --radius-sm: 10px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; overflow: hidden;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select { font-family: inherit; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #2A313C; border-radius: 4px; }

/* ---------- 登录闸口 ---------- */
.gate {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 20% -10%, rgba(164,113,248,.18), transparent 60%),
    radial-gradient(700px 420px at 90% 110%, rgba(60,138,241,.12), transparent 60%);
}
.gate-card {
  width: 100%; max-width: 360px; background: var(--card);
  border: 1px solid var(--line); border-radius: 20px; padding: 30px 24px;
  box-shadow: 0 24px 64px rgba(0,0,0,.55);
}
.gate-logo {
  width: 64px; height: 64px; margin: 0 auto 18px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 18px; background: linear-gradient(135deg, var(--purple), var(--accent));
  font-size: 18px; font-weight: 800; color: #fff; letter-spacing: 1px;
}
.gate-card h1 { text-align: center; font-size: 24px; margin-bottom: 8px; }
.gate-sub { text-align: center; font-size: 12.5px; color: var(--text-dim); margin-bottom: 22px; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: flex; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; height: 42px; padding: 0 12px;
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: var(--radius-sm); color: var(--text); font-size: 14px; outline: none;
}
.field input:focus, .field select:focus { border-color: var(--accent); }
.field.compact { margin-bottom: 0; }
#gate-code { height: 54px; text-align: center; font-size: 19px; letter-spacing: 5px; }

.btn-primary {
  width: 100%; height: 46px; border-radius: var(--radius-sm);
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  color: #fff; font-size: 15px; font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary.sm { width: auto; height: 38px; padding: 0 20px; font-size: 13.5px; margin-top: 12px; }

.btn-ghost {
  height: 38px; padding: 0 14px; background: var(--bg-soft);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: 13px; color: #C9D1D9; white-space: nowrap;
}
.btn-ghost:hover { background: var(--card-hover); border-color: #3D4653; }
.btn-ghost.sm { height: 32px; padding: 0 12px; font-size: 12px; }
.btn-ghost.danger { color: var(--danger); border-color: rgba(248,81,73,.35); }

.hint { min-height: 18px; margin-top: 10px; font-size: 12.5px; color: var(--warn); text-align: center; }
.link-subtle { display: block; width: 100%; margin-top: 14px; padding: 6px; font-size: 12px; color: #5A6270; text-align: center; }
.link-subtle:hover { color: var(--text-dim); }
.advanced-box { margin-top: 10px; padding-top: 12px; border-top: 1px solid var(--line); }

/* ---------- 主框架 ---------- */
.shell { display: flex; height: 100%; }

.sidebar {
  width: 220px; flex: none; display: flex; flex-direction: column;
  background: var(--bg-soft); border-right: 1px solid var(--line);
}
.side-brand { padding: 18px 18px 14px; display: flex; align-items: baseline; gap: 8px; }
.side-logo {
  font-size: 20px; font-weight: 800; letter-spacing: 2px;
  background: linear-gradient(120deg, #58A6FF, #A471F8);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.side-tag { font-size: 10.5px; color: var(--text-dim); letter-spacing: 1px; }

.nav { flex: 1; padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 9px;
  font-size: 13.5px; color: var(--text-dim); text-align: left; width: 100%;
  transition: .12s;
}
.nav-item:hover { background: var(--card); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-ico { font-size: 14px; width: 18px; text-align: center; }

.side-foot { padding: 14px; border-top: 1px solid var(--line); }
.side-user { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.side-user-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 110px; }
.role-badge { font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 5px; background: var(--card); color: var(--text-dim); border: 1px solid var(--line); }
.role-badge.owner { background: var(--purple); color: #fff; border-color: transparent; }
.role-badge.admin { background: var(--accent); color: #fff; border-color: transparent; }
.role-badge.agent { background: var(--ok); color: #fff; border-color: transparent; }
.side-logout { width: 100%; padding: 8px; border-radius: 8px; font-size: 12.5px; color: var(--danger); background: var(--card); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.main-head {
  height: 60px; flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; border-bottom: 1px solid var(--line);
}
.main-head h2 { font-size: 18px; font-weight: 700; }
.main-head-right { display: flex; align-items: center; gap: 12px; }
.muted-sm { font-size: 12px; color: var(--text-dim); }
.main-body { flex: 1; overflow-y: auto; padding: 20px 24px 60px; }
.page { max-width: 1100px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }

/* ---------- 卡片 ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 12px; }
.card-head h3 { font-size: 14px; font-weight: 600; }
.head-actions { display: flex; gap: 8px; align-items: center; }
.search {
  height: 32px; padding: 0 12px; background: var(--bg-soft);
  border: 1px solid var(--line); border-radius: 8px; color: var(--text); font-size: 13px; outline: none; width: 200px;
}
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.toolbar input { flex: 1; height: 38px; padding: 0 12px; background: var(--bg-soft); border: 1px solid var(--line); border-radius: 8px; color: var(--text); font-size: 13.5px; outline: none; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}
.stat-val { font-size: 26px; font-weight: 700; font-family: ui-monospace, Menlo, monospace; }
.stat-lab { font-size: 11.5px; color: var(--text-dim); margin-top: 5px; }
.stat.good .stat-val { color: var(--ok); }
.stat.warn .stat-val { color: var(--warn); }
.stat.bad .stat-val { color: var(--danger); }
.stat.purple .stat-val { color: var(--purple); }

/* ---------- 列表行 ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 11px 13px; font-size: 13px;
}
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-sub { font-size: 11.5px; color: var(--text-dim); margin-top: 3px; word-break: break-all; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.row-actions button { font-size: 11.5px; padding: 5px 10px; border-radius: 6px; background: var(--card); border: 1px solid var(--line); color: #C9D1D9; }
.row-actions button:hover { background: var(--card-hover); }
.row-actions button.danger { color: var(--danger); border-color: rgba(248,81,73,.32); }
.row-actions button.ok { color: var(--ok); border-color: rgba(63,185,80,.32); }

.mono { font-family: ui-monospace, Menlo, monospace; }
.code-chip {
  font-family: ui-monospace, Menlo, monospace; font-size: 14px; font-weight: 700;
  letter-spacing: 2px; color: var(--accent); cursor: pointer;
}
.code-chip:hover { text-decoration: underline; }
.tag { font-size: 10.5px; padding: 2px 7px; border-radius: 5px; font-weight: 600; }
.tag.active { background: rgba(63,185,80,.16); color: var(--ok); }
.tag.invalid { background: var(--danger-soft); color: var(--danger); }
.tag.owner { background: var(--purple); color: #fff; }
.tag.admin { background: var(--accent); color: #fff; }
.tag.agent { background: var(--ok); color: #fff; }
.tag.user { background: var(--card); color: var(--text-dim); border: 1px solid var(--line); }

.kv { display: flex; flex-direction: column; gap: 8px; }
.kv-row { display: flex; justify-content: space-between; gap: 16px; padding: 9px 12px; background: var(--bg-soft); border: 1px solid var(--line); border-radius: 8px; font-size: 13px; }
.kv-row span:first-child { color: var(--text-dim); }
.kv-row span:last-child { font-family: ui-monospace, Menlo, monospace; font-size: 12px; text-align: right; word-break: break-all; }

.perm-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px; margin-top: 8px; }
.perm-item { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-dim); }
.perm-item input { width: 16px; height: 16px; accent-color: var(--accent); }

.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; background: var(--bg-soft); border: 1px solid var(--line); border-radius: 8px; font-size: 13px; }
.switch { width: 44px; height: 24px; appearance: none; background: var(--line); border-radius: 12px; position: relative; cursor: pointer; transition: .2s; }
.switch:checked { background: var(--ok); }
.switch::after { content: ''; position: absolute; width: 18px; height: 18px; border-radius: 50%; background: #fff; top: 3px; left: 3px; transition: .2s; }
.switch:checked::after { left: 23px; }

.detail { display: flex; flex-direction: column; gap: 10px; }
.empty { font-size: 13px; color: var(--text-dim); padding: 14px 2px; text-align: center; }

/* ---------- Toast / Modal ---------- */
.toast-wrap { position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 999; pointer-events: none; }
.toast { background: rgba(0,0,0,.9); color: #fff; font-size: 13px; padding: 10px 18px; border-radius: 10px; border: 1px solid rgba(255,255,255,.08); }
.toast.ok { background: rgba(63,185,80,.95); }
.toast.error { background: rgba(248,81,73,.95); }
.modal-wrap { position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,.68); display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { width: 100%; max-width: 420px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 20px; }
.modal h3 { font-size: 16px; margin-bottom: 10px; }
.modal p { font-size: 13px; color: var(--text-dim); line-height: 1.7; white-space: pre-wrap; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.modal-actions button { padding: 9px 18px; border-radius: 9px; font-size: 13.5px; }
.modal-actions .cancel { background: var(--bg-soft); border: 1px solid var(--line); color: #C9D1D9; }
.modal-actions .confirm { background: var(--accent); color: #fff; font-weight: 600; }
.modal-actions .confirm.danger { background: var(--danger); }

@media (max-width: 820px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 100; transform: translateX(-100%); transition: .2s; }
  .sidebar.open { transform: none; }
  .main-head { padding: 0 16px; }
  .main-body { padding: 14px 14px 60px; }
}

/* 发放模式切换 */
.mode-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.mode-tab {
  padding: 7px 16px; border-radius: 8px; font-size: 13px;
  color: var(--text-dim); background: var(--bg-soft); border: 1px solid var(--line);
}
.mode-tab:hover { color: var(--text); }
.mode-tab.active { background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 600; }
.issue-foot { display: flex; align-items: center; gap: 14px; margin-top: 14px; flex-wrap: wrap; }
#issue-preview { font-family: ui-monospace, Menlo, monospace; font-size: 12px; color: var(--accent); letter-spacing: 1px; }

