:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --line: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --brand: #1d4ed8;
  --brand-2: #0ea5e9;
  --sidebar: #0b1224;
  --sidebar-text: #cbd5e1;
  --ok: #047857;
  --ok-bg: #ecfdf5;
  --warn: #b45309;
  --warn-bg: #fffbeb;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.55;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}
code {
  background: #eef2ff;
  border: 1px solid #e0e7ff;
  border-radius: 6px;
  padding: 1px 5px;
  font-size: 0.92em;
  word-break: break-all;
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.05rem; }
p { margin: 0.4rem 0; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.hidden { display: none !important; }
.mt { margin-top: 18px; }
.mb { margin-bottom: 18px; }

/* boot */
.boot, .loading-inline {
  min-height: 60vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
}
.loading-inline { min-height: 220px; }
.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid #dbeafe;
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* auth */
.auth-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(1000px 500px at 15% 0%, #dbeafe 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 100%, #e0f2fe 0%, transparent 50%), var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 28px;
}
.auth-card h1 { margin: 16px 0 4px; }
.auth-foot { color: var(--muted); font-size: 0.8rem; margin-top: 16px; }
.auth-switch { text-align: center; margin-top: 18px; color: var(--muted); font-size: 0.9rem; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-size: 1.05rem;
}
.brand em { font-style: normal; color: var(--brand-2); margin-left: 2px; }
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
  font-weight: 900;
  font-size: 0.95rem;
}
.sidebar .brand { color: #fff; }

/* forms */
.form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 0.86rem; font-weight: 600; color: #334155; }
.form input, .form select, .form textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.95rem;
  outline: none;
}
.form input:focus, .form select:focus, .form textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px #dbeafe; }
.form textarea { resize: vertical; min-height: 58px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.82rem; }
.form .hint { font-weight: 400; color: var(--muted); font-size: 0.76rem; }
.form-inline {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
}
.form-inline label { flex: 1 1 160px; }
.form-inline label.grow { flex: 2 1 320px; }
.form-inline input, .form-inline select { min-width: 0; }
.form-error { color: var(--danger); font-size: 0.85rem; min-height: 0; margin: 0; }
.check { flex-direction: row !important; align-items: center; gap: 8px !important; font-weight: 500 !important; }
.check input { width: auto; }

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.9rem;
  font-weight: 650;
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; filter: brightness(0.98); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, var(--brand), #2563eb); color: #fff; }
.btn-secondary { background: #eff6ff; border-color: #dbeafe; color: #1e40af; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 11px; font-size: 0.82rem; }
.btn-xs { padding: 4px 8px; font-size: 0.76rem; border-radius: 7px; }

/* layout */
.layout { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-section { color: #64748b; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; margin: 16px 8px 4px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--sidebar-text);
  padding: 9px 10px;
  border-radius: 9px;
  font-size: 0.9rem;
  font-weight: 500;
}
.nav-item:hover { background: #16203a; color: #fff; text-decoration: none; }
.nav-item.active { background: linear-gradient(135deg, #1e3a8a, #0c4a6e); color: #fff; }
.nav-icon { width: 20px; text-align: center; opacity: 0.85; font-size: 0.85rem; }
.sidebar-foot { margin-top: auto; color: #64748b; font-size: 0.72rem; padding: 8px; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 28px 12px;
}
.eyebrow { color: var(--muted); font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; }
.page-title { font-size: 1.55rem; margin-top: 2px; }
.userbox { display: flex; align-items: center; gap: 12px; }
.user-meta { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.25; }
.user-meta strong { font-size: 0.86rem; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.user-meta span { color: var(--muted); font-size: 0.74rem; }
.view { padding: 8px 28px 40px; }

/* cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat-label { color: var(--muted); font-size: 0.78rem; font-weight: 600; }
.stat-value { font-size: 1.7rem; font-weight: 800; margin: 4px 0; letter-spacing: -0.03em; }
.stat-value.small { font-size: 1rem; word-break: break-all; }
.stat-hint { color: var(--muted); font-size: 0.76rem; }
.link { font-size: 0.82rem; font-weight: 600; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
th { text-align: left; color: var(--muted); font-weight: 650; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.04em; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
.row-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.detail { max-width: 340px; word-break: break-all; color: var(--muted); }

/* badges */
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 2px 8px; font-size: 0.72rem; font-weight: 700; white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-neutral { background: #f1f5f9; color: #475569; }

/* events */
.event-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.event-list li { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid #f1f5f9; }
.event-list li:last-child { border-bottom: none; }
.event-list p { margin: 0; color: var(--muted); font-size: 0.84rem; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; margin-top: 7px; flex: 0 0 auto; }
.dot-error { background: var(--danger); }
.dot-warn { background: var(--warn); }
.dot-info { background: var(--brand-2); }

/* misc */
.note-list { display: flex; flex-direction: column; gap: 8px; }
.note-list p { color: var(--muted); font-size: 0.87rem; }
.placeholder {
  border: 1px dashed #cbd5e1;
  border-radius: 12px;
  padding: 28px;
  margin-top: 16px;
  text-align: center;
  background: var(--surface-2);
}
.placeholder-mark {
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  margin: 0 auto 10px; background: #e0f2fe; color: var(--brand); font-weight: 900;
}
.kv { display: grid; grid-template-columns: 96px 1fr; gap: 8px 12px; margin: 0; }
.kv dt { color: var(--muted); font-size: 0.82rem; }
.kv dd { margin: 0; font-size: 0.9rem; word-break: break-all; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.result-box { margin-top: 14px; padding: 14px; border-radius: 10px; background: #f0fdf4; border: 1px solid #bbf7d0; }
.result-box p { margin: 4px 0; }

/* 2FA */
.setup-secret { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin: 16px 0; }
.setup-secret .label { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-top: 8px; }
.setup-secret .label:first-child { margin-top: 0; }
.setup-secret code { display: block; margin-top: 4px; background: #fff; }
.setup-secret .uri { font-size: 0.76rem; }
.recovery-codes {
  background: #0f172a; color: #e2e8f0; border-radius: 12px; padding: 16px;
  font-size: 0.9rem; line-height: 1.8; margin: 16px 0; white-space: pre-wrap; word-break: break-all;
}
.recovery-codes + .btn { margin-top: 8px; }

/* toast */
.toast-root { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast {
  background: #0f172a; color: #fff; padding: 10px 14px; border-radius: 10px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.25); font-size: 0.86rem; max-width: 360px;
  transition: opacity 0.2s, transform 0.2s;
}
.toast-success { background: #065f46; }
.toast-error { background: #991b1b; }
.toast-out { opacity: 0; transform: translateY(6px); }
.noscript { padding: 24px; text-align: center; }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; overflow-x: auto; padding: 12px; }
  .sidebar .brand { display: none; }
  .nav { flex-direction: row; gap: 4px; }
  .nav-section { display: none; }
  .nav-item { white-space: nowrap; padding: 7px 9px; font-size: 0.82rem; }
  .nav-icon { display: none; }
  .sidebar-foot { display: none; }
  .topbar { padding: 16px 16px 8px; align-items: flex-start; }
  .view { padding: 8px 16px 28px; }
  .grid-2, .grid-4 { grid-template-columns: 1fr; }
  .user-meta strong { max-width: 140px; }
  .page-title { font-size: 1.25rem; }
  .auth-card { padding: 20px; }
}
