:root {
  --bg: #f6f7f9;
  --panel: #fff;
  --tx: #1a1f27;
  --tx2: #6b7480;
  --bd: #e5e8ee;
  --pri: #1f6feb;
  --pri-d: #1a5fd0;
  --danger: #d92d20;
  --ok: #0e9f6e;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --panel: #171a20;
    --tx: #e9edf3;
    --tx2: #8f98a6;
    --bd: #262b34;
    --pri: #4d8dff;
    --pri-d: #3a7ae6;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--tx);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
.hidden { display: none !important; }
a { color: var(--pri); text-decoration: none; }
code { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; background: var(--bg); padding: 2px 6px; border-radius: 5px; }

/* ---------- 按钮 ---------- */
.btn {
  appearance: none; border: 1px solid var(--bd); background: var(--panel); color: var(--tx);
  padding: 8px 14px; border-radius: 8px; font-size: 13.5px; font-weight: 500; cursor: pointer;
  transition: all .15s; font-family: inherit; white-space: nowrap;
}
.btn:hover { border-color: var(--pri); color: var(--pri); }
.btn.primary { background: var(--pri); border-color: var(--pri); color: #fff; }
.btn.primary:hover { background: var(--pri-d); border-color: var(--pri-d); color: #fff; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 8%, transparent); border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.dashed { border-style: dashed; color: var(--tx2); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.block { width: 100%; padding: 10px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- 登录 ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-box {
  background: var(--panel); border: 1px solid var(--bd); border-radius: 16px;
  padding: 34px 30px; width: 100%; max-width: 340px; box-shadow: 0 8px 30px rgba(16, 24, 40, .07);
}
.brand { font-size: 24px; font-weight: 800; letter-spacing: 1px; text-align: center; }
.brand span { color: var(--pri); }
.brand.sm { font-size: 16px; }
.brand em { font-style: normal; font-weight: 500; font-size: 13px; color: var(--tx2); margin-left: 8px; letter-spacing: 0; }
.login-tip { text-align: center; color: var(--tx2); font-size: 13px; margin: 6px 0 20px; }
.login-box input {
  width: 100%; padding: 11px 12px; border: 1px solid var(--bd); border-radius: 9px;
  font-size: 14px; margin-bottom: 12px; background: var(--bg); color: var(--tx); font-family: inherit;
}
.login-box input:focus { outline: none; border-color: var(--pri); }
.err { color: var(--danger); font-size: 12.5px; text-align: center; min-height: 18px; margin: 10px 0 0; }

/* ---------- 布局 ---------- */
.topbar {
  height: 54px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px; background: var(--panel); border-bottom: 1px solid var(--bd); position: sticky; top: 0; z-index: 20;
}
.top-right { display: flex; align-items: center; gap: 10px; }
.hint { font-size: 12.5px; color: var(--ok); opacity: 0; transition: opacity .2s; }
.hint.show { opacity: 1; }
.layout { display: flex; align-items: flex-start; gap: 16px; padding: 16px; max-width: 1180px; margin: 0 auto; }

.side { width: 214px; flex: 0 0 214px; position: sticky; top: 70px; }
.side-head { font-size: 12px; font-weight: 600; color: var(--tx2); letter-spacing: .5px; margin: 0 0 8px 4px; }
.code-list { display: flex; flex-direction: column; gap: 5px; margin-bottom: 8px; max-height: calc(100vh - 180px); overflow: auto; }
.code-item {
  padding: 9px 11px; border-radius: 9px; cursor: pointer; border: 1px solid transparent; background: transparent;
  display: flex; flex-direction: column; gap: 2px; transition: all .12s;
}
.code-item:hover { background: var(--panel); border-color: var(--bd); }
.code-item.active { background: var(--panel); border-color: var(--pri); box-shadow: 0 1px 6px rgba(31, 111, 235, .12); }
.code-item b { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.code-item small { font-size: 11.5px; color: var(--tx2); font-family: ui-monospace, Consolas, monospace; }
.code-item .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); display: inline-block; margin-right: 5px; }
.code-item .dot.off { background: #b9c0cb; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.empty { text-align: center; color: var(--tx2); padding: 80px 20px; }
.empty-ico { font-size: 42px; opacity: .25; margin-bottom: 10px; }

.panel { background: var(--panel); border: 1px solid var(--bd); border-radius: 13px; padding: 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.panel-head h2 { font-size: 14.5px; margin: 0; font-weight: 650; }
.badge { font-size: 11.5px; color: var(--tx2); font-family: ui-monospace, Consolas, monospace; background: var(--bg); padding: 3px 8px; border-radius: 99px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.f { display: flex; flex-direction: column; gap: 5px; }
.f.full { grid-column: 1 / -1; }
.f > span { font-size: 12px; color: var(--tx2); font-weight: 500; }
.f input, .f textarea, .f select {
  border: 1px solid var(--bd); border-radius: 8px; padding: 8px 10px; font-size: 13.5px;
  background: var(--bg); color: var(--tx); font-family: inherit; width: 100%; resize: vertical;
}
.f input:focus, .f textarea:focus, .f select:focus { outline: none; border-color: var(--pri); background: var(--panel); }
.f input[type=color] { padding: 3px; height: 36px; max-width: 110px; cursor: pointer; }
.input-row { display: flex; align-items: center; border: 1px solid var(--bd); border-radius: 8px; background: var(--bg); overflow: hidden; }
.input-row .pfx { font-size: 12px; color: var(--tx2); padding: 0 6px 0 10px; white-space: nowrap; font-family: ui-monospace, Consolas, monospace; }
.input-row input { border: none; background: transparent; padding: 8px 10px 8px 2px; }

.row-btns { display: flex; align-items: center; gap: 9px; margin-top: 16px; }
.row-btns .spacer { flex: 1; }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; color: var(--tx2); user-select: none; }
.switch input { display: none; }
.switch i {
  width: 34px; height: 20px; border-radius: 99px; background: var(--bd); position: relative; transition: background .18s; flex: 0 0 34px;
}
.switch i::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; transition: transform .18s; box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
}
.switch input:checked + i { background: var(--ok); }
.switch input:checked + i::after { transform: translateX(14px); }

/* ---------- 二维码 ---------- */
.qr-wrap { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; }
.qr-box { background: #fff; border: 1px solid var(--bd); border-radius: 10px; padding: 8px; line-height: 0; }
.qr-box svg { width: 168px; height: 168px; display: block; }
.qr-info { flex: 1; min-width: 260px; display: flex; flex-direction: column; gap: 10px; }
.kv { display: flex; gap: 10px; font-size: 12.5px; color: var(--tx2); align-items: baseline; }
.kv > span { flex: 0 0 60px; }
.kv b { color: var(--tx); font-weight: 500; }
.kv code { word-break: break-all; }

/* ---------- 条目列表 ---------- */
.tip { font-size: 12px; color: var(--tx2); margin: -6px 0 12px; }
.item-list { display: flex; flex-direction: column; gap: 7px; }
.item-row {
  display: flex; align-items: center; gap: 10px; border: 1px solid var(--bd); border-radius: 9px; padding: 9px 11px; background: var(--bg);
}
.item-row.dragging { opacity: .4; }
.item-row .handle { cursor: grab; color: var(--tx2); font-size: 15px; letter-spacing: -2px; user-select: none; }
.item-row .kind { font-size: 15px; }
.item-row .info { flex: 1; min-width: 0; }
.item-row .info b { font-size: 13.5px; font-weight: 600; display: block; }
.item-row .info small { font-size: 11.5px; color: var(--tx2); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-row .grp { font-size: 11px; color: var(--tx2); border: 1px solid var(--bd); padding: 1px 7px; border-radius: 99px; white-space: nowrap; }
.item-row .off { text-decoration: line-through; opacity: .5; }
.item-row .acts { display: flex; gap: 4px; }
.icon-btn {
  border: none; background: transparent; cursor: pointer; color: var(--tx2); font-size: 13px; padding: 4px 6px; border-radius: 6px;
}
.icon-btn:hover { background: var(--bd); color: var(--tx); }
.icon-btn.del:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }

/* ---------- 统计 ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--bg); border-radius: 10px; padding: 14px; }
.stat .n { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12px; color: var(--tx2); margin-top: 2px; }

/* ---------- 弹窗 ---------- */
dialog {
  border: none; border-radius: 14px; padding: 0; background: var(--panel); color: var(--tx);
  width: min(560px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(16, 24, 40, .45); backdrop-filter: blur(2px); }
dialog form { padding: 22px; }
dialog h3 { margin: 0 0 16px; font-size: 15.5px; }
.dlg-btns { display: flex; justify-content: flex-end; gap: 9px; margin-top: 18px; }

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .side { width: 100%; flex: none; position: static; }
  .code-list { flex-direction: row; overflow-x: auto; max-height: none; }
  .code-item { flex: 0 0 auto; border: 1px solid var(--bd); background: var(--panel); }
  .grid2 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
}
