:root {
  --bg: #f3f5fb;
  --bg-2: #eef1f9;
  --panel: #ffffff;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --faint: #94a3b8;
  --line: #e6e9f2;
  --line-2: #eef1f7;
  --primary: #5b5bd6;
  --primary-2: #7c3aed;
  --primary-soft: #eef0ff;
  --green: #0b8f63;
  --green-soft: #e5f8f0;
  --amber: #b7791f;
  --amber-soft: #fff5dd;
  --red: #d33d3d;
  --red-soft: #fdecec;
  --slate: #64748b;
  --slate-soft: #eef2f7;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 12px 32px rgba(15, 23, 42, 0.07);
  --shadow-lg: 0 24px 64px rgba(15, 23, 42, 0.16);
  --radius: 16px;
  --mono: "SFMono-Regular", "Cascadia Code", "JetBrains Mono", Consolas, monospace;
  --sans: "Inter", "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", system-ui, -apple-system,
    "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--primary); text-decoration: none; }

button, input, select { font: inherit; color: inherit; }

code, .mono { font-family: var(--mono); }

.bg-orbs {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}
.bg-orbs span {
  position: absolute;
  display: block;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.5;
}
.bg-orbs span:nth-child(1) {
  width: 460px; height: 460px;
  top: -180px; right: -120px;
  background: radial-gradient(circle, #c7d2fe, transparent 70%);
}
.bg-orbs span:nth-child(2) {
  width: 420px; height: 420px;
  top: 30%; left: -200px;
  background: radial-gradient(circle, #ddd6fe, transparent 70%);
}
.bg-orbs span:nth-child(3) {
  width: 380px; height: 380px;
  bottom: -160px; right: 20%;
  background: radial-gradient(circle, #bfdbfe, transparent 70%);
}

/* ============ 登录页 ============ */

.auth-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  background:
    radial-gradient(1000px 600px at 50% -10%, #e6e9ff 0%, transparent 60%),
    var(--bg);
}

.auth-wrap { width: 100%; max-width: 420px; }

.auth-card {
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 24px;
  padding: 42px 36px 30px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.auth-card h1 {
  font-size: 24px;
  letter-spacing: -0.02em;
  margin: 18px 0 6px;
}

.auth-card .muted { margin: 0 0 30px; }

.auth-card form { text-align: left; }

.auth-foot {
  margin: 26px 0 0;
  font-size: 12px;
  color: var(--faint);
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: linear-gradient(140deg, #6366f1, #8b5cf6 60%, #a855f7);
  box-shadow: 0 8px 18px rgba(99, 102, 241, 0.35);
  flex: none;
}
.brand-mark svg { width: 24px; height: 24px; }
.brand-mark.big {
  width: 60px; height: 60px;
  border-radius: 18px;
  margin: 0 auto;
}
.brand-mark.big svg { width: 32px; height: 32px; }

/* ============ 表单 ============ */

.field { display: block; margin-bottom: 16px; }
.field > span {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 8px;
}

input[type="text"],
input[type="password"],
input[type="date"],
input[type="number"],
input:not([type]) {
  width: 100%;
  height: 46px;
  border: 1px solid var(--line);
  background: #fbfcff;
  border-radius: 12px;
  padding: 0 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
input:focus {
  border-color: #a5b4fc;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.12);
}
input::placeholder { color: #a8b3c7; }

.password-wrap { position: relative; }
.password-wrap input { padding-right: 64px; }
.peek {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
}
.peek:hover { background: var(--primary-soft); }

.form-error {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--red-soft);
  color: var(--red);
  font-size: 13px;
  line-height: 1.5;
}

/* ============ 按钮 ============ */

.btn {
  --btn-bg: #fff;
  --btn-ink: var(--ink);
  --btn-line: var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 40px;
  padding: 0 15px;
  border-radius: 11px;
  border: 1px solid var(--btn-line);
  background: var(--btn-bg);
  color: var(--btn-ink);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.12s, box-shadow 0.15s, background 0.15s, border-color 0.15s;
  user-select: none;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn.primary {
  border-color: transparent;
  background: linear-gradient(135deg, #6366f1, #7c3aed);
  color: #fff;
  box-shadow: 0 8px 20px rgba(99, 102, 241, 0.28);
}
.btn.primary:hover { box-shadow: 0 12px 26px rgba(99, 102, 241, 0.36); }

.btn.ghost:hover { background: #f8faff; border-color: #d7dcf0; }
.btn.danger {
  background: var(--red-soft);
  border-color: transparent;
  color: var(--red);
}
.btn.danger:hover { background: #fbdcdc; }

.btn.sm { height: 32px; padding: 0 11px; font-size: 13px; border-radius: 9px; }
.btn.block { width: 100%; height: 48px; font-size: 15px; }

.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}
.icon-btn:hover { background: var(--slate-soft); color: var(--ink); }

/* ============ 后台框架 ============ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px clamp(18px, 4vw, 40px);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(230, 233, 242, 0.9);
}

.brand { display: flex; align-items: center; gap: 13px; min-width: 0; }
.brand h1 {
  margin: 0;
  font-size: 17px;
  letter-spacing: -0.01em;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand p { margin: 3px 0 0; font-size: 12px; color: var(--muted); }

.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.upstream-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 13px;
  border-radius: 999px;
  background: #f6f8fd;
  border: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--ink-2);
  white-space: nowrap;
}
.upstream-chip .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--faint);
  box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.16);
}
.upstream-chip.ok .dot { background: #10b981; box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.16); }
.upstream-chip.warn .dot { background: #f59e0b; box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.18); }
.upstream-chip.bad .dot { background: #ef4444; box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.16); }

.container {
  width: min(1240px, 100%);
  margin: 0 auto;
  padding: 28px clamp(18px, 4vw, 40px) 48px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.stat::after {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--accent, var(--primary));
  opacity: 0.85;
}
.stat .label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.stat .value {
  margin-top: 8px;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.stat .hint { margin-top: 8px; font-size: 11.5px; color: var(--faint); }
.stat.total { --accent: #6366f1; }
.stat.ok { --accent: #10b981; }
.stat.soon { --accent: #f59e0b; }
.stat.dead { --accent: #ef4444; }
.stat.off { --accent: #94a3b8; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 20px 22px;
  border-bottom: 1px solid var(--line-2);
  flex-wrap: wrap;
}
.panel-head h2 { margin: 0; font-size: 17px; letter-spacing: -0.01em; }
.panel-head p { margin: 4px 0 0; font-size: 12.5px; color: var(--muted); }

.tools { display: flex; align-items: center; gap: 10px; }

.search { position: relative; }
.search svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--faint);
}
.search input {
  width: 230px;
  height: 40px;
  padding-left: 36px;
  border-radius: 11px;
  background: #f8faff;
}
.search input:focus { width: 260px; }

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}
thead th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--faint);
  padding: 12px 22px;
  background: #fbfcff;
  border-bottom: 1px solid var(--line-2);
  white-space: nowrap;
}
tbody td {
  padding: 15px 22px;
  border-bottom: 1px solid var(--line-2);
  vertical-align: middle;
  font-size: 13.5px;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background 0.12s; }
tbody tr:hover { background: #fafbff; }
td.right, th.right { text-align: right; }

.user-cell { display: flex; align-items: center; gap: 11px; min-width: 0; }
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  background: linear-gradient(140deg, #818cf8, #a78bfa);
  flex: none;
}
.avatar.alt { background: linear-gradient(140deg, #38bdf8, #6366f1); }
.avatar.warm { background: linear-gradient(140deg, #fbbf24, #f97316); }
.user-cell strong { display: block; font-size: 14px; line-height: 1.3; }
.user-cell small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px;
  max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.pill.active { color: var(--green); background: var(--green-soft); }
.pill.expiring { color: var(--amber); background: var(--amber-soft); }
.pill.expired { color: var(--red); background: var(--red-soft); }
.pill.disabled { color: var(--slate); background: var(--slate-soft); }

.expiry strong { display: block; font-weight: 600; font-variant-numeric: tabular-nums; }
.expiry small { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }

.sub-cell { display: flex; align-items: center; gap: 8px; max-width: 330px; }
.sub-cell code {
  flex: 1;
  min-width: 0;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11.5px;
  color: var(--muted);
  background: #f6f8fd;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  padding: 7px 9px;
}
.copy-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 600;
  height: 30px;
  padding: 0 9px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}
.copy-btn:hover { border-color: #c7cdf0; background: var(--primary-soft); color: var(--primary); }

.access small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }

.row-actions { display: flex; gap: 7px; justify-content: flex-end; }

.empty {
  padding: 64px 24px;
  text-align: center;
  color: var(--muted);
}
.empty .art {
  width: 76px;
  height: 76px;
  margin: 0 auto 16px;
  border-radius: 24px;
  display: grid;
  place-items: center;
  background: linear-gradient(140deg, #eef0ff, #f5f3ff);
  color: #a5b4fc;
}
.empty h3 { margin: 0 0 6px; color: var(--ink); font-size: 16px; }
.empty p { margin: 0 0 18px; font-size: 13px; }

.foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 18px;
  color: var(--faint);
  font-size: 12px;
}

/* ============ 弹窗 ============ */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(3px);
  animation: fade 0.18s ease;
}
.modal-card {
  position: relative;
  width: 100%;
  max-width: 470px;
  max-height: calc(100vh - 40px);
  overflow: auto;
  background: #fff;
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  animation: pop 0.2s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
.modal-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 22px 6px;
}
.modal-card header h3 { margin: 0; font-size: 18px; letter-spacing: -0.01em; }
.modal-card form { padding: 14px 22px 22px; }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(0.98); } }

.seg {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  background: #f7f8fd;
  border: 1px solid var(--line-2);
  padding: 5px;
  border-radius: 12px;
  margin-bottom: 10px;
}
.seg button {
  border: 0;
  background: transparent;
  border-radius: 8px;
  height: 34px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.seg button:hover { color: var(--ink); }
.seg button.on {
  background: #fff;
  color: var(--primary);
  box-shadow: var(--shadow-sm), inset 0 0 0 1px #e2e5f7;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0 4px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-2);
}
.switch-row input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-row i {
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: #d8dceb;
  position: relative;
  transition: background 0.18s;
  cursor: pointer;
  flex: none;
}
.switch-row i::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.25);
  transition: transform 0.18s;
}
.switch-row input:checked + i { background: linear-gradient(135deg, #6366f1, #7c3aed); }
.switch-row input:checked + i::after { transform: translateX(18px); }
.switch-row input:focus-visible + i { box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.18); }

.modal-card footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 20px;
  margin-top: 18px;
  border-top: 1px solid var(--line-2);
}
.modal-card footer .spacer { flex: 1; }

.quick-extend {
  display: flex;
  gap: 6px;
  margin: -4px 0 14px;
  flex-wrap: wrap;
}
.quick-extend .btn { height: 30px; padding: 0 10px; font-size: 12px; }

.confirm-body { padding: 6px 22px 18px; }
.confirm-body p {
  margin: 0;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.7;
}
.confirm-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 22px 22px;
}
.confirm-actions .spacer { flex: 1; }

/* ============ Toast ============ */

.toasts {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.toast {
  min-width: 240px;
  max-width: 360px;
  background: #0f172a;
  color: #f8fafc;
  border-radius: 12px;
  padding: 12px 15px;
  font-size: 13px;
  line-height: 1.5;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.28);
  display: flex;
  align-items: flex-start;
  gap: 9px;
  animation: toast-in 0.22s ease;
  pointer-events: auto;
}
.toast.ok { background: #065f46; }
.toast.err { background: #991b1b; }
.toast.leaving { animation: toast-out 0.2s ease forwards; }
.toast .t-icon { flex: none; margin-top: 1px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-8px); } }

.muted { color: var(--muted); }

/* ============ 响应式 ============ */

@media (max-width: 1080px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stat.total { grid-column: span 1; }
}

@media (max-width: 760px) {
  .topbar { align-items: flex-start; flex-direction: column; gap: 12px; }
  .topbar-right { width: 100%; justify-content: space-between; }
  .upstream-chip { overflow: hidden; text-overflow: ellipsis; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat .value { font-size: 26px; }
  .panel-head { align-items: stretch; }
  .tools { width: 100%; }
  .search { flex: 1; }
  .search input, .search input:focus { width: 100%; }
  .container { padding-top: 20px; }
  .auth-card { padding: 34px 24px 24px; }
}

@media (max-width: 430px) {
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 14px; }
  .stat .hint { display: none; }
  .topbar-right .btn { padding: 0 11px; }
}
