:root {
  /* 设计令牌 */
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e6eaf1;
  --border-strong: #d8dee9;
  --text: #1a2333;
  --text-2: #4b5563;
  --muted: #8a94a6;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-soft: #eef2ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --ok: #16a34a;
  --ok-soft: #f0fdf4;
  --sidebar-bg: #1b2437;
  --sidebar-border: #2a3548;
  --sidebar-text: #b8c2d4;
  --radius-lg: 12px;
  --radius: 10px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, .08), 0 2px 4px rgba(16, 24, 40, .05);
  --focus-ring: 0 0 0 3px rgba(79, 70, 229, .14);
  --h-control: 36px;
  --h-control-sm: 30px;
  --h-control-mini: 26px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
::selection { background: rgba(79, 70, 229, .18); }

/* ---------------- 布局 ---------------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 20px 18px 18px;
  border-bottom: 1px solid var(--sidebar-border);
}
.brand-logo {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 10px rgba(79, 70, 229, .35);
  flex-shrink: 0;
}
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-title { font-size: 15px; font-weight: 700; color: #fff; letter-spacing: .3px; white-space: nowrap; }
.brand-sub { font-size: 11.5px; color: #7d8aa3; margin-top: 2px; white-space: nowrap; }

.nav { padding: 14px 12px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 13px; margin-bottom: 3px;
  border-radius: var(--radius-sm);
  cursor: pointer; color: var(--sidebar-text);
  font-size: 13.5px; user-select: none; position: relative;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: #232e44; color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; font-weight: 600; box-shadow: 0 4px 12px rgba(79, 70, 229, .35); }
.sidebar-foot {
  padding: 14px 18px; font-size: 11px; color: #6d7b93;
  border-top: 1px solid var(--sidebar-border); line-height: 1.5;
  display: flex; flex-direction: column; gap: 10px;
}
.sidebar-foot-text { line-height: 1.5; }
.logout-btn {
  width: 100%; height: 28px;
  color: var(--sidebar-text); border-color: var(--sidebar-border);
  background: transparent;
}
.logout-btn:hover { background: #232e44; color: #fff; border-color: #3a465c; }

.main { flex: 1; padding: 0 32px 72px; min-width: 0; }

/* ---------------- 页头（网格对齐 + 悬浮） ---------------- */
.page-head {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "title action" "sub action";
  align-items: center;
  column-gap: 20px;
  row-gap: 3px;
  margin-bottom: 18px;
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg);
  padding: 22px 0 16px;
}
.page-head h2 { grid-area: title; margin: 0; font-size: 20px; font-weight: 700; letter-spacing: .2px; }
.page-head .sub { grid-area: sub; margin: 0; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page-head .btn { grid-area: action; }

/* ---------------- 卡片 ---------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  margin-bottom: 16px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 16px;
}
.card-head h3 { margin: 0; font-size: 15px; font-weight: 600; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 8px; }
.text-danger { color: var(--danger); font-weight: 600; }
.loading, .empty { padding: 32px; text-align: center; color: var(--muted); font-size: 13px; }

/* ---------------- 按钮 ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--h-control);
  padding: 0 15px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  cursor: pointer; font-size: 13px; font-weight: 500; line-height: 1;
  transition: all .15s; white-space: nowrap; vertical-align: middle;
}
.btn:hover { border-color: #c3cbdb; background: var(--surface-2); }
.btn:active { transform: translateY(.5px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn.danger { color: var(--danger); border-color: #f0c4c4; }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.small { height: var(--h-control-sm); padding: 0 12px; font-size: 12.5px; }
.btn.mini { height: var(--h-control-mini); padding: 0 10px; font-size: 12px; border-radius: 7px; }

/* ---------------- 输入 ---------------- */
.input {
  height: var(--h-control);
  padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-size: 13px; background: var(--surface); color: var(--text);
  outline: none; transition: border-color .15s, box-shadow .15s;
  min-width: 0;
}
.input:focus { border-color: var(--primary); box-shadow: var(--focus-ring); }
.input.search { min-width: 240px; }
select.input { padding-right: 30px; }
.w-40 { width: 40px; }
.w-90 { width: 90px; }
.w-120 { width: 120px; }

.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form .input { width: 220px; }

/* ---------------- 表格 ---------------- */
.table-scroll { max-height: calc(100vh - 212px); overflow-y: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td {
  padding: 11px 13px;
  text-align: left; vertical-align: middle;
  border-bottom: 1px solid var(--border);
  line-height: 1.45;
}
.table th {
  font-size: 12px; color: var(--muted); font-weight: 600;
  background: var(--surface-2);
  white-space: nowrap; letter-spacing: .2px;
  position: sticky; top: 0; z-index: 2;
  box-shadow: 0 1px 0 var(--border);
  text-align: left;
}
.table th:first-child { border-top-left-radius: var(--radius-sm); }
.table th:last-child { border-top-right-radius: var(--radius-sm); }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: #fbfcfe; }
.table .num { text-align: center; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table th:last-child { text-align: center; }
.table .ta-c { text-align: center; }
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--primary); }

/* 操作按钮组（避免挤在一起） */
.row-actions { display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: nowrap; }

/* ---------------- 标签页 ---------------- */
.tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.tab {
  height: var(--h-control-sm); padding: 0 16px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); cursor: pointer; font-size: 13px; color: var(--text-2);
  transition: all .15s;
}
.tab:hover { border-color: #c3cbdb; background: var(--surface-2); }
.tab.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 500; }

/* ---------------- 徽章 ---------------- */
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; line-height: 1.5; white-space: nowrap;
}
.badge.battle { background: #fef2f2; color: #b91c1c; }
.badge.production { background: #e0eaff; color: #1d4ed8; }
.badge.warehouse { background: #dcfce7; color: #047857; }

/* ---------------- 标签 chips ---------------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 5px 8px 5px 13px; font-size: 13px; color: var(--text-2);
}
.chip-x {
  border: none; background: none; color: var(--muted); cursor: pointer;
  font-size: 12px; padding: 2px 4px; border-radius: 50%; line-height: 1;
  transition: all .12s;
}
.chip-x:hover { color: var(--danger); background: var(--danger-soft); }

.chips.toggle .toggle-chip { cursor: pointer; padding: 6px 9px 6px 13px; user-select: none; transition: all .15s; }
.chips.toggle .toggle-chip .chip-state { font-size: 11px; color: var(--muted); background: var(--surface); border-radius: 999px; padding: 1px 7px; }
.chips.toggle .toggle-chip.on { background: var(--ok-soft); border-color: #86efac; color: #166534; }
.chips.toggle .toggle-chip.on .chip-state { background: var(--ok); color: #fff; }

/* ---------------- 筛选栏 ---------------- */
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; align-items: center; }

/* ---------------- 目录 / 标签布局 ---------------- */
.catalog-grid { display: grid; grid-template-columns: 340px 1fr; gap: 16px; align-items: start; }
.cat-tree { display: flex; flex-direction: column; gap: 10px; }
.cat-top { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; }
.cat-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 3px 0; }
.cat-row.child { margin-left: 16px; border-top: 1px dashed var(--border); margin-top: 5px; padding-top: 7px; }
.cat-name { font-size: 13.5px; color: var(--text); }
.cat-link { cursor: pointer; padding: 2px 6px; margin-left: -6px; border-radius: 6px; transition: background .12s, color .12s; }
.cat-link:hover { background: var(--primary-soft); color: var(--primary); }
.cat-link.active { background: var(--primary); color: #fff; font-weight: 600; }
.cat-ops { display: flex; gap: 4px; }
.filter-hint { font-size: 12.5px; color: var(--muted); margin-bottom: 12px; }
.filter-hint b { color: var(--primary); }

/* ---------------- 通行证（层级列表） ---------------- */
.account-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.tree-toggle {
  border: 1px solid var(--border-strong); background: var(--surface);
  width: 26px; height: 26px; border-radius: 7px; cursor: pointer; color: var(--muted);
  font-size: 11px; display: inline-flex; align-items: center; justify-content: center;
  transition: transform .15s, background .15s; flex-shrink: 0;
}
.tree-toggle:hover { background: var(--surface-2); color: var(--text); }
.tree-toggle.open { transform: rotate(90deg); }
.acct-name { font-size: 15px; font-weight: 600; }
.pwd { font-family: ui-monospace, "SF Mono", "Consolas", monospace; }
.stat { font-size: 12.5px; color: var(--muted); }
.stat b { color: var(--text); font-size: 13px; font-weight: 600; }
.account-ops { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.account-body { margin-top: 14px; padding: 14px 0 4px 30px; border-top: 1px solid var(--border); }

.sub-list { display: flex; flex-direction: column; gap: 10px; }
.sub-item {
  border-left: 3px solid var(--primary);
  padding: 10px 14px; background: var(--surface-2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  transition: opacity .15s, box-shadow .15s, transform .15s;
}
.sub-item.dragging { opacity: .45; }
.sub-item.drag-over { box-shadow: 0 0 0 2px var(--primary) inset; }
.sub-head { display: flex; align-items: center; gap: 10px; }
.drag-handle {
  flex-shrink: 0; width: 12px; height: 18px; cursor: grab;
  background-image: radial-gradient(circle, #9aa4b5 1.5px, transparent 1.5px);
  background-size: 5px 5px; background-repeat: repeat-y; background-position: center;
}
.drag-handle:active { cursor: grabbing; }
.sub-name { font-weight: 600; font-size: 14px; word-break: break-all; }
.sub-ops { margin-left: auto; display: flex; gap: 6px; flex-shrink: 0; }
.char-slots { display: flex; gap: 8px; margin-top: 9px; flex-wrap: wrap; }
.char-slot {
  height: var(--h-control-mini);
  border: 1px solid var(--border-strong); border-radius: 7px; background: var(--surface);
  padding: 0 12px; font-size: 12.5px; cursor: pointer; transition: all .12s;
  display: inline-flex; align-items: center;
}
.char-slot.none { color: var(--muted); border-style: dashed; }
.char-slot.none:hover { color: var(--primary); border-color: var(--primary); }
.char-slot.has { font-weight: 600; }
.char-slot.has.battle { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }
.char-slot.has.production { background: #e0eaff; border-color: #bfdbfe; color: #1d4ed8; }
.char-slot.has.warehouse { background: #dcfce7; border-color: #a7f3d0; color: #047857; }

/* ---------------- 表单 ---------------- */
.form { display: flex; flex-direction: column; gap: 15px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-2); font-weight: 500; }
.form label .muted { font-weight: 400; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px 15px; }
.form-grid > label { min-width: 0; }
.form-grid .input { width: 100%; min-width: 0; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.five { grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; padding-top: 14px; border-top: 1px solid var(--border); }
.skill-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.skill-row .input:first-child { flex: 1; }
.skills-head { font-size: 13px; font-weight: 600; margin: 4px 0 10px; display: flex; align-items: center; gap: 10px; }
.type-section { padding: 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
.storage-hint.over { color: var(--danger); font-weight: 600; }

/* ---------------- 详情 ---------------- */
.detail-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.char-name { font-size: 18px; font-weight: 700; cursor: pointer; }
.char-name:hover { color: var(--primary); }
.detail-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.ditem { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 11px 13px; }
.ditem span { display: block; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.ditem b { font-size: 14px; font-weight: 600; }
.ditem.wide { grid-column: 1 / -1; }

/* ---------------- 统计 ---------------- */
.stats-search { display: flex; gap: 10px; margin-bottom: 18px; }
.stats-search .input { flex: 1; max-width: 520px; }
.stat-summary { display: flex; gap: 14px; margin-bottom: 18px; }
.stat-box {
  flex: 1; max-width: 220px; text-align: center;
  border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px 12px; background: var(--surface-2);
}
.stat-box .num { font-size: 26px; font-weight: 700; color: var(--primary); font-variant-numeric: tabular-nums; }
.stat-box .lbl { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* ---------------- 弹窗 ---------------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 7vh 20px 24px; z-index: 100; overflow-y: auto;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--surface); border-radius: 14px;
  box-shadow: 0 24px 60px rgba(16, 24, 40, .28);
  width: 100%; max-width: 560px; animation: pop .18s cubic-bezier(.2,.9,.3,1.2);
  overflow: hidden;
}
.modal.wide { max-width: 720px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 22px; border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 16px; font-weight: 700; }
.modal-close {
  border: none; background: none; font-size: 16px; color: var(--muted); cursor: pointer;
  width: 28px; height: 28px; border-radius: 7px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center; transition: all .12s;
}
.modal-close:hover { color: var(--danger); background: var(--danger-soft); }
.modal-body { padding: 20px 22px; max-height: 68vh; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--border); background: var(--surface-2); }
.confirm-text { margin: 0; font-size: 14px; color: var(--text-2); }
@keyframes pop { from { opacity: 0; transform: translateY(-10px) scale(.98); } to { opacity: 1; transform: none; } }

/* ---------------- toast ---------------- */
.toast {
  position: fixed; top: 22px; left: 50%; transform: translateX(-50%) translateY(-6px);
  background: #111827; color: #fff; padding: 10px 18px; border-radius: 9px;
  font-size: 13.5px; box-shadow: 0 10px 28px rgba(0,0,0,.28); z-index: 200;
  opacity: 0; transition: opacity .18s, transform .18s; pointer-events: none;
  display: flex; align-items: center; gap: 8px;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); }

/* ---------------- 登录 ---------------- */
.login-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: linear-gradient(135deg, #1b2437 0%, #28334e 55%, #33405f 100%);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-box {
  background: #fff; border-radius: 16px;
  padding: 38px 36px 32px; width: 100%; max-width: 380px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .35);
  display: flex; flex-direction: column; gap: 14px;
  animation: pop .2s ease;
}
.login-logo {
  width: 52px; height: 52px; margin: 0 auto;
  border-radius: 14px;
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: #fff; font-size: 24px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 20px rgba(79, 70, 229, .35);
}
.login-title { margin: 0; text-align: center; font-size: 19px; font-weight: 700; }
.login-sub { margin: -6px 0 2px; text-align: center; color: var(--muted); font-size: 13px; }
.login-field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-2); font-weight: 500; }
.login-field .input { height: 40px; }
.login-btn { width: 100%; height: 40px; font-size: 14px; margin-top: 4px; }
.login-error { color: var(--danger); font-size: 13px; text-align: center; min-height: 18px; }

/* ---------------- 响应式 ---------------- */
@media (max-width: 1100px) {
  .catalog-grid { grid-template-columns: 1fr; }
  .main { padding: 20px 20px 60px; }
}
