:root {
  --bg: #f4f5f8;
  --panel: #ffffff;
  --panel-2: #fafbfd;
  --ink: #1d2330;
  --ink-2: #5b6474;
  --ink-3: #8c94a3;
  --line: #e4e7ee;
  --line-2: #eef0f5;
  --brand: #3d5afe;
  --brand-2: #6d7cff;
  --brand-soft: #edf0ff;
  --green: #138a5a;
  --green-soft: #e6f7ef;
  --red: #d33b4d;
  --red-soft: #fdecef;
  --amber: #a86500;
  --amber-soft: #fff5df;
  --cyan: #0b7285;
  --cyan-soft: #e3f7fb;
  --shadow: 0 1px 2px rgba(20, 28, 45, .05), 0 8px 24px rgba(20, 28, 45, .06);
  --shadow-lg: 0 20px 60px rgba(20, 28, 45, .18);
  --radius: 14px;
  --radius-sm: 9px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0 0 8px; }
pre, code { font-family: var(--mono); }
pre {
  margin: 0;
  padding: 14px;
  background: #171b26;
  color: #d7dcea;
  border-radius: var(--radius-sm);
  overflow: auto;
  font-size: 12px;
  line-height: 1.6;
  max-height: 520px;
}
.mono { font-family: var(--mono); }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--ink-3); }

/* ---------- auth / install ---------- */
.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(700px 420px at 12% 8%, #dfe5ff 0%, transparent 60%),
    radial-gradient(620px 420px at 92% 90%, #d9f5ef 0%, transparent 60%),
    var(--bg);
}
.auth-card {
  width: min(430px, 100%);
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, .8);
  box-shadow: var(--shadow-lg);
  border-radius: 22px;
  padding: 34px 32px;
}
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.logo {
  width: 44px; height: 44px; border-radius: 13px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, var(--brand), #7d5cff);
  color: #fff; font-weight: 800; font-size: 19px;
  box-shadow: 0 8px 20px rgba(61, 90, 254, .35);
}
.auth-brand h1 { font-size: 20px; }
.auth-brand p { margin: 0; color: var(--ink-3); font-size: 12px; }
.auth-card .field { margin-bottom: 14px; }
.auth-hint { margin-top: 14px; color: var(--ink-3); font-size: 12px; }
.auth-error { margin: 0 0 14px; padding: 10px 12px; border-radius: 9px; background: var(--red-soft); color: var(--red); font-size: 13px; }
.auth-wide { width: min(760px, 100%); }

/* ---------- layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 236px;
  flex: 0 0 236px;
  background: #141824;
  color: #c9cfdd;
  padding: 18px 12px 24px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 40;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand .logo { width: 36px; height: 36px; border-radius: 11px; font-size: 16px; }
.brand-name { color: #fff; font-weight: 650; font-size: 14px; }
.brand-sub { color: #7e879b; font-size: 11px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-section { margin-top: 16px; padding: 0 10px 5px; font-size: 10px; letter-spacing: .14em; color: #6c7489; text-transform: uppercase; }
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 10px;
  border-radius: 9px;
  color: #b9c0cf;
  font-size: 13px;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: #1e2433; color: #fff; text-decoration: none; }
.nav-item.active { background: linear-gradient(135deg, rgba(61,90,254,.95), rgba(109,124,255,.85)); color: #fff; box-shadow: 0 6px 16px rgba(61, 90, 254, .25); }
.nav-icon { width: 17px; text-align: center; opacity: .85; font-size: 14px; }
.sidebar-foot { margin-top: auto; padding: 16px 10px 0; color: #6c7489; font-size: 11px; }

.workspace { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 62px;
  display: flex; align-items: center; gap: 14px;
  padding: 0 24px;
  background: rgba(244, 245, 248, .86);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
.topbar h1 { font-size: 17px; }
.topbar .spacer { flex: 1; }
.menu-toggle { display: none; }
.user-chip { display: flex; align-items: center; gap: 9px; padding: 5px 6px 5px 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow); }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: 12px; }
.user-name { font-size: 12px; font-weight: 600; }
.user-role { font-size: 10px; color: var(--ink-3); }
#content { padding: 22px 24px 60px; max-width: 1500px; width: 100%; margin: 0 auto; }

/* ---------- cards / grids ---------- */
.page { display: flex; flex-direction: column; gap: 16px; }
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.card-head h2, .card-head h3 { flex: 1; }
.stat { padding: 16px 18px; }
.stat-label { color: var(--ink-3); font-size: 12px; }
.stat-value { font-size: 27px; font-weight: 700; letter-spacing: -.03em; margin-top: 4px; }
.stat-sub { color: var(--ink-3); font-size: 11px; margin-top: 2px; }
.stat-tone-brand { background: linear-gradient(160deg, #f2f4ff, #fff); border-color: #dfe4ff; }
.stat-tone-green { background: linear-gradient(160deg, #eefaf4, #fff); border-color: #d8f2e6; }
.stat-tone-amber { background: linear-gradient(160deg, #fff8e9, #fff); border-color: #f6e8c8; }
.stat-tone-red { background: linear-gradient(160deg, #fff0f2, #fff); border-color: #f7d8de; }
.section-title { font-size: 12px; color: var(--ink-3); letter-spacing: .08em; text-transform: uppercase; margin-bottom: 10px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 13px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: var(--brand); color: #fff;
  font-size: 13px; font-weight: 550;
  transition: filter .15s, transform .05s, box-shadow .15s;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.06); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: var(--panel); color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--panel-2); }
.btn.soft { background: var(--brand-soft); color: var(--brand); }
.btn.danger { background: var(--red); }
.btn.danger-soft { background: var(--red-soft); color: var(--red); }
.btn.success { background: var(--green); }
.btn.amber { background: var(--amber); }
.btn.sm { height: 28px; padding: 0 9px; font-size: 12px; border-radius: 7px; }
.btn.icon { width: 34px; padding: 0; }
.btn.link { background: transparent; color: var(--brand); padding: 0 4px; height: auto; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- forms ---------- */
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.one { grid-template-columns: 1fr; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .field-label { font-size: 12px; color: var(--ink-2); font-weight: 600; }
.field .hint { font-size: 11px; color: var(--ink-3); }
.input, select.input, textarea.input {
  width: 100%;
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(61, 90, 254, .12); }
textarea.input { min-height: 100px; resize: vertical; line-height: 1.5; }
.input.mono { font-family: var(--mono); font-size: 12px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }
.check input { width: 15px; height: 15px; accent-color: var(--brand); }
.switch-row { display: flex; align-items: center; gap: 8px; min-height: 36px; }
.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.toolbar .input { min-height: 34px; }
.toolbar .grow { flex: 1; min-width: 160px; }
.toolbar .spacer { flex: 1; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.table th { background: var(--panel-2); color: var(--ink-3); font-size: 11px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; }
.table tbody tr:hover { background: #fafbff; }
.table td.actions { white-space: nowrap; }
.table td.actions .btn { margin-right: 4px; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .check-col { width: 36px; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px; font-weight: 600;
  background: var(--line-2); color: var(--ink-2);
  white-space: nowrap;
}
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.blue { background: var(--brand-soft); color: var(--brand); }
.badge.cyan { background: var(--cyan-soft); color: var(--cyan); }
.badge.gray { background: var(--line-2); color: var(--ink-3); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tab {
  padding: 9px 13px; border: 0; background: transparent; color: var(--ink-3);
  border-bottom: 2px solid transparent; font-size: 13px; font-weight: 550; white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }

/* ---------- dashboard bits ---------- */
.bars { display: flex; align-items: flex-end; gap: 7px; height: 150px; padding-top: 8px; }
.bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 5px; min-width: 0; height: 100%; }
.bar-fill { width: 100%; min-height: 2px; background: linear-gradient(180deg, var(--brand-2), var(--brand)); border-radius: 6px 6px 2px 2px; }
.bar span { font-size: 10px; color: var(--ink-3); white-space: nowrap; }
.dist { display: flex; flex-direction: column; gap: 9px; }
.dist-row { display: grid; grid-template-columns: 72px 1fr 52px; align-items: center; gap: 10px; font-size: 12px; }
.dist-track { height: 8px; background: var(--line-2); border-radius: 999px; overflow: hidden; }
.dist-fill { height: 100%; background: var(--brand); border-radius: 999px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 7px 12px; font-size: 13px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; }
.timeline { display: flex; flex-direction: column; gap: 10px; }
.timeline-item { display: flex; gap: 10px; font-size: 12px; }
.timeline-dot { width: 7px; height: 7px; margin-top: 6px; border-radius: 50%; background: var(--brand); flex: 0 0 auto; }
.timeline-body { min-width: 0; }
.timeline-title { color: var(--ink); font-weight: 550; }
.timeline-meta { color: var(--ink-3); font-size: 11px; }

/* ---------- modal / toast ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 20, 32, .46);
  backdrop-filter: blur(3px);
  display: grid; place-items: center;
  padding: 20px;
}
.modal {
  width: min(620px, 100%);
  max-height: min(88vh, 900px);
  display: flex; flex-direction: column;
  background: var(--panel);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal.wide { width: min(920px, 100%); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 17px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { flex: 1; font-size: 16px; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 9px; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--panel-2); }
.modal .form-grid { gap: 13px; }
.icon-btn { width: 30px; height: 30px; border: 1px solid var(--line); background: #fff; border-radius: 8px; color: var(--ink-3); font-size: 17px; line-height: 1; }
.toast-wrap { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  min-width: 240px; max-width: 420px;
  padding: 11px 14px;
  border-radius: 10px;
  background: #1c2230; color: #fff;
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  animation: toast-in .18s ease-out;
}
.toast.error { background: var(--red); }
.toast.success { background: var(--green); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- misc ---------- */
.loading, .empty { padding: 44px 20px; text-align: center; color: var(--ink-3); }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 12px; flex-wrap: wrap; color: var(--ink-3); font-size: 12px; }
.pager-btns { display: flex; gap: 7px; }
.notice {
  padding: 11px 13px;
  border-radius: 9px;
  font-size: 13px;
  background: var(--amber-soft);
  color: var(--amber);
  border: 1px solid #f2dfb4;
}
.notice.blue { background: var(--brand-soft); color: var(--brand); border-color: #dbe1ff; }
.notice.red { background: var(--red-soft); color: var(--red); border-color: #f6d3da; }
.notice.green { background: var(--green-soft); color: var(--green); border-color: #cdeedd; }
.perm-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 16px; }
.perm-group { margin-bottom: 14px; }
.perm-group h4 { font-size: 12px; color: var(--ink-3); margin-bottom: 7px; text-transform: uppercase; letter-spacing: .06em; }
.perm-item { display: flex; align-items: center; gap: 7px; font-size: 12px; padding: 3px 0; }
.perm-item input { accent-color: var(--brand); }
.perm-item .danger-tag { color: var(--red); font-size: 10px; border: 1px solid #f0c4cc; background: var(--red-soft); border-radius: 4px; padding: 0 4px; }
.inline-code { font-family: var(--mono); font-size: 12px; background: var(--line-2); padding: 1px 5px; border-radius: 4px; }
.danger-zone { border-color: #f3ccd3; background: linear-gradient(180deg, #fff7f8, #fff); }
.danger-zone h2 { color: var(--red); }
.sep { height: 1px; background: var(--line); margin: 14px 0; }
.scroll-x { overflow-x: auto; }
.mt-0 { margin-top: 0; } .mt-8 { margin-top: 8px; } .mt-14 { margin-top: 14px; } .mt-20 { margin-top: 20px; }
.mb-0 { margin-bottom: 0; } .mb-8 { margin-bottom: 8px; } .mb-14 { margin-bottom: 14px; }
.flex { display: flex; align-items: center; gap: 8px; }
.flex-wrap { flex-wrap: wrap; }
.right { margin-left: auto; }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-102%); transition: transform .2s ease; box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar { transform: none; }
  .menu-toggle { display: inline-flex; }
  .topbar { padding: 0 14px; }
  #content { padding: 16px 14px 50px; }
  .grid-2, .grid-3, .grid-4, .form-grid, .perm-grid { grid-template-columns: 1fr; }
  .user-role { display: none; }
  .table th, .table td { padding: 9px 10px; }
}
@media (max-width: 560px) {
  .auth-card { padding: 26px 20px; border-radius: 18px; }
  .topbar h1 { font-size: 15px; }
  .user-name { display: none; }
  .modal-backdrop { padding: 10px; }
  .modal { max-height: 94vh; border-radius: 14px; }
}
