:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e8ecf4;
  --line-strong: #d9e0ec;
  --brand: #4f7cff;
  --brand-2: #7c3aed;
  --brand-weak: #eef3ff;
  --danger: #e5484d;
  --danger-weak: #fff1f1;
  --ok: #12a594;
  --ok-weak: #e9fbf7;
  --warn: #d97706;
  --warn-weak: #fff7ed;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 12px 32px rgba(15, 23, 42, .06);
  --shadow-lg: 0 24px 60px rgba(15, 23, 42, .16);
  --sidebar: 252px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "tnum";
}

body.anon {
  background:
    radial-gradient(900px 500px at 15% 10%, rgba(79, 124, 255, .35), transparent 60%),
    radial-gradient(700px 500px at 85% 85%, rgba(124, 58, 237, .3), transparent 60%),
    linear-gradient(160deg, #070d1a 0%, #0b1428 55%, #101a33 100%);
}

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

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.sub { color: var(--muted); font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.legend { margin: 0 0 14px; }

code {
  background: #f1f5f9;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

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

.sidebar {
  width: var(--sidebar);
  flex: 0 0 var(--sidebar);
  background:
    radial-gradient(420px 260px at 15% 0%, rgba(79, 124, 255, .22), transparent 65%),
    radial-gradient(380px 260px at 90% 100%, rgba(124, 58, 237, .16), transparent 70%),
    linear-gradient(180deg, #0a1120 0%, #0c1528 100%);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  padding: 22px 16px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid rgba(148, 163, 184, .08);
}

.brand { display: flex; align-items: center; gap: 12px; padding: 4px 6px 22px; color: #fff; }
.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #4f7cff, #7c3aed);
  box-shadow: 0 8px 20px rgba(79, 124, 255, .35);
  color: #fff;
  flex: 0 0 38px;
}
.brand-mark svg { width: 21px; height: 21px; }
.brand-mark.lg { width: 52px; height: 52px; border-radius: 16px; }
.brand-mark.lg svg { width: 28px; height: 28px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 15px; letter-spacing: .01em; }
.brand-text em {
  font-style: normal;
  font-size: 9px;
  letter-spacing: .22em;
  color: rgba(203, 213, 225, .55);
  margin-top: 4px;
}

.side-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.side-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  color: #94a3b8;
  font-size: 13.5px;
  font-weight: 500;
  position: relative;
  transition: background .18s ease, color .18s ease;
}
.side-nav a svg { width: 18px; height: 18px; opacity: .85; }
.side-nav a:hover { background: rgba(148, 163, 184, .08); color: #e2e8f0; }
.side-nav a.active {
  background: linear-gradient(90deg, rgba(79, 124, 255, .22), rgba(79, 124, 255, .05));
  color: #fff;
}
.side-nav a.active::before {
  content: "";
  position: absolute;
  left: -16px;
  top: 9px;
  bottom: 9px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: linear-gradient(180deg, #4f7cff, #7c3aed);
  box-shadow: 0 0 12px rgba(79, 124, 255, .8);
}
.side-nav a.active svg { opacity: 1; color: #8fb0ff; }

.side-foot { border-top: 1px solid rgba(148, 163, 184, .12); padding-top: 14px; display: flex; flex-direction: column; gap: 12px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 0 4px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(148, 163, 184, .16);
  border: 1px solid rgba(148, 163, 184, .22);
  color: #e2e8f0; font-weight: 700; font-size: 13px;
}
.user-chip div { display: flex; flex-direction: column; line-height: 1.3; }
.user-chip strong { color: #e2e8f0; font-size: 13px; }
.user-chip small { color: #64748b; font-size: 11px; }

.sidebar .btn.ghost { color: #cbd5e1; border-color: rgba(148, 163, 184, .22); background: transparent; }
.sidebar .btn.ghost:hover { background: rgba(148, 163, 184, .1); border-color: rgba(148, 163, 184, .3); }

.shell { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 30px;
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(244, 246, 251, .78);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(232, 236, 244, .9);
}
.crumb { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.crumb i { font-style: normal; color: #cbd5e1; }
.crumb strong { color: var(--text); font-weight: 600; }
.pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 11px; border-radius: 999px; font-size: 12px;
  background: var(--card); border: 1px solid var(--line); color: var(--muted);
}
.pill-live { color: var(--ok); border-color: #c7f0e8; background: #f3fdfa; }
.pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px rgba(18, 165, 148, .15); }

.content { padding: 28px 30px 40px; max-width: 1320px; width: 100%; margin: 0 auto; }

.foot {
  display: flex; justify-content: space-between;
  max-width: 1320px; width: 100%; margin: 0 auto;
  padding: 0 30px 26px;
  color: #94a3b8; font-size: 12px;
}
body.anon .foot { display: none; }

/* ---------- page head ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 18px; margin-bottom: 22px; }
.page-head h1 { margin: 4px 0 4px; font-size: 26px; letter-spacing: -.02em; font-weight: 650; }
.page-head p { margin: 0; }
.back { font-size: 12.5px; color: var(--muted); }
.back:hover { color: var(--brand); }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; margin-bottom: 22px; }
.stats-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  transition: transform .18s ease, box-shadow .18s ease;
}
.stat:hover { transform: translateY(-2px); box-shadow: 0 18px 40px rgba(15, 23, 42, .09); }
.stat::before {
  content: ""; position: absolute; left: 0; top: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, #4f7cff, #7c3aed);
  opacity: .85;
}
.stat .k { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; letter-spacing: .02em; }
.stat strong { font-size: 26px; font-weight: 650; letter-spacing: -.02em; }
.stat strong.small { font-size: 14px; font-weight: 600; letter-spacing: 0; }
.stat-high::before { background: linear-gradient(90deg, #e5484d, #f97316); }
.stat-warn::before { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.stat-ok::before { background: linear-gradient(90deg, #12a594, #34d399); }

/* ---------- cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.card.flush { padding: 0; overflow: hidden; }
.card.narrow { max-width: 660px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 12px; }
.card-head h2 { font-size: 15.5px; margin: 0; font-weight: 650; letter-spacing: -.01em; }

.meta-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 24px; }
.meta-grid > div { display: flex; flex-direction: column; gap: 3px; }
.meta-grid .k { color: var(--muted); font-size: 12px; }
.meta-grid strong { font-weight: 600; }

/* ---------- tables ---------- */
.grid { width: 100%; border-collapse: collapse; }
.grid th, .grid td { padding: 12px 16px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.grid th {
  font-size: 11px; color: var(--muted); font-weight: 600;
  letter-spacing: .06em; text-transform: uppercase;
  background: #f8fafc; white-space: nowrap;
}
.grid tbody tr { transition: background .12s ease; }
.grid tbody tr:hover { background: #f8faff; }
.grid tbody tr:last-child td { border-bottom: none; }
.grid td.actions { white-space: nowrap; }
.grid td.actions .btn { margin-right: 4px; }
.grid.accounts td { vertical-align: top; }

.db-link { font-weight: 600; color: var(--text); }
.db-link:hover { color: var(--brand); }

/* ---------- tags & badges ---------- */
.tag {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 500; background: #f1f5f9; color: var(--muted);
  white-space: nowrap; margin-top: 3px;
}
.tag-local { background: var(--warn-weak); color: var(--warn); }
.tag-remote { background: var(--brand-weak); color: var(--brand); }
.tag-ip { background: var(--ok-weak); color: var(--ok); }

.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.badge-high { background: var(--danger-weak); color: var(--danger); }
.badge-warn { background: var(--warn-weak); color: var(--warn); }
.badge-ok { background: var(--ok-weak); color: var(--ok); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line-strong);
  background: var(--card);
  color: var(--text);
  padding: 8px 15px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all .16s ease;
  white-space: nowrap;
}
.btn:hover { border-color: #c3cdde; box-shadow: 0 4px 12px rgba(15, 23, 42, .06); }
.btn.primary {
  background: linear-gradient(135deg, #4f7cff, #7c3aed);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 8px 20px rgba(79, 124, 255, .25);
}
.btn.primary:hover { filter: brightness(1.06); box-shadow: 0 10px 26px rgba(79, 124, 255, .35); }
.btn.ghost { background: transparent; }
.btn.link { border: none; background: none; color: var(--brand); padding: 0 2px; box-shadow: none; }
.btn.link:hover { text-decoration: underline; }
.btn.danger { background: linear-gradient(135deg, #e5484d, #c62a30); border-color: transparent; color: #fff; }
.btn.danger:hover { filter: brightness(1.05); }
.btn.sm { padding: 5px 11px; font-size: 12px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn.lg { padding: 11px 18px; font-size: 14px; border-radius: 11px; }

/* ---------- forms ---------- */
.stack { display: flex; flex-direction: column; gap: 15px; }
.stack.tight { gap: 9px; margin-top: 9px; min-width: 270px; }
.stack label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
input[type="text"], input[type="password"], select {
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 9px 12px;
  font: inherit;
  color: var(--text);
  background: #fff;
  width: 100%;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(79, 124, 255, .12);
}

.flash { padding: 11px 15px; border-radius: 11px; margin-bottom: 16px; font-size: 13px; border: 1px solid transparent; }
.flash.ok { background: var(--ok-weak); color: #0b7a6d; border-color: #c7f0e8; }
.flash.bad { background: var(--danger-weak); color: var(--danger); border-color: #fbd5d5; }

.empty { padding: 34px; text-align: center; color: var(--muted); }

.grants { max-width: 400px; }
.grant { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.pwrow { display: flex; align-items: center; gap: 7px; }
.pw { letter-spacing: 2px; }

/* popover forms */
.pop { display: inline-block; position: relative; }
.pop summary { list-style: none; display: inline-block; }
.pop summary::-webkit-details-marker { display: none; }
.pop[open] summary { border-color: var(--brand); color: var(--brand); }
.pop form {
  position: fixed;
  right: 28px;
  top: 84px;
  z-index: 80;
  width: 320px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow-lg);
}

.inline-form { display: flex; gap: 10px; max-width: 500px; align-items: center; }
.inline-form input { flex: 1; }
.inline-form button { flex: 0 0 auto; }
.narrow-form { max-width: 580px; }

.table-scroll { overflow: auto; max-height: 70vh; }
.grid.data td { white-space: nowrap; max-width: 380px; overflow: hidden; text-overflow: ellipsis; }
.grid.data th { position: sticky; top: 0; z-index: 1; }
.rownum { width: 52px; color: var(--muted); text-align: right; }
.null { color: #9ca3af; font-style: italic; }

pre.value {
  margin: 0;
  padding: 16px;
  background: #0b1220;
  color: #e2e8f0;
  border-radius: 12px;
  overflow: auto;
  max-height: 60vh;
  white-space: pre-wrap;
  word-break: break-all;
  font-size: 12px;
  line-height: 1.7;
}

.pager { display: flex; align-items: center; gap: 12px; justify-content: center; margin: 20px 0 34px; }

.card.danger { border-color: #fbd5d5; background: linear-gradient(180deg, #fffdfd, #fff); }
.card.danger h2 { color: var(--danger); }

/* security checks */
.check-list { display: flex; flex-direction: column; }
.check-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 4px;
  border-bottom: 1px solid var(--line);
}
.check-item:last-child { border-bottom: none; }
.check-dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 7px; flex: 0 0 9px; }
.check-high .check-dot { background: var(--danger); box-shadow: 0 0 0 4px var(--danger-weak); }
.check-warn .check-dot { background: var(--warn); box-shadow: 0 0 0 4px var(--warn-weak); }
.check-ok .check-dot { background: var(--ok); box-shadow: 0 0 0 4px var(--ok-weak); }
.check-body { flex: 1; min-width: 0; }
.check-title { font-weight: 600; margin-bottom: 2px; }
.check-detail { color: var(--muted); font-size: 12.5px; word-break: break-word; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 40px 20px; }
.login-card {
  width: 100%;
  max-width: 400px;
  background: rgba(255, 255, 255, .97);
  border: 1px solid rgba(255, 255, 255, .6);
  border-radius: 22px;
  padding: 34px 32px 26px;
  box-shadow: 0 40px 100px rgba(2, 6, 23, .55);
  backdrop-filter: blur(20px);
}
.login-brand { text-align: center; margin-bottom: 26px; }
.login-brand .brand-mark { margin: 0 auto 14px; }
.login-brand h1 { margin: 0 0 4px; font-size: 21px; letter-spacing: -.02em; }
.login-brand .muted { margin: 0; font-size: 12.5px; }
.input-wrap { position: relative; }
.input-wrap svg {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 17px; height: 17px; color: #94a3b8; pointer-events: none;
}
.input-wrap input { padding-left: 38px; height: 42px; }
.login-note { text-align: center; color: #94a3b8; font-size: 11.5px; margin: 18px 0 0; }

/* hero */
.hero {
  position: relative;
  overflow: hidden;
  border-radius: 22px;
  padding: 28px 32px;
  margin-bottom: 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  color: #fff;
  background:
    radial-gradient(600px 300px at 85% -40%, rgba(124, 58, 237, .55), transparent 65%),
    radial-gradient(500px 260px at 0% 120%, rgba(79, 124, 255, .35), transparent 65%),
    linear-gradient(115deg, #0a1326 0%, #131f3d 48%, #2b1d52 100%);
  box-shadow: 0 22px 55px rgba(11, 18, 32, .28);
}
.hero-glow {
  position: absolute;
  right: -80px;
  top: -140px;
  width: 380px;
  height: 380px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(139, 92, 246, .35), transparent 65%);
  filter: blur(6px);
  pointer-events: none;
}
.hero-text { position: relative; z-index: 1; }
.eyebrow {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .3em;
  color: #9db4ff;
}
.hero h1 { font-size: 30px; letter-spacing: -.025em; margin: 8px 0 6px; font-weight: 680; }
.hero p { margin: 0; color: #aebada; font-size: 13px; }
.hero p strong { color: #fff; font-weight: 650; }
.hero-actions { position: relative; z-index: 1; flex: 0 0 auto; }
.hero-btn {
  background: rgba(255, 255, 255, .1);
  border: 1px solid rgba(255, 255, 255, .22);
  color: #fff;
  backdrop-filter: blur(8px);
  box-shadow: none;
}
.hero-btn:hover { background: rgba(255, 255, 255, .18); box-shadow: 0 8px 24px rgba(0, 0, 0, .25); }

/* stat icons */
.stat-ico {
  position: absolute;
  right: 16px;
  top: 16px;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, rgba(79, 124, 255, .12), rgba(124, 58, 237, .12));
  color: #4f7cff;
  transition: transform .2s ease;
}
.stat:hover .stat-ico { transform: translateY(-2px) scale(1.04); }
.stat-ico svg { width: 19px; height: 19px; }
.stat strong { display: block; max-width: calc(100% - 44px); white-space: nowrap; }
.stat strong.small { white-space: normal; max-width: calc(100% - 38px); }

/* account chips */
.acc { display: inline-flex; align-items: baseline; gap: 1px; font-weight: 500; }
.acc-host { color: var(--muted); font-size: 11px; font-weight: 400; }

/* horizontal table scroll */
.table-wrap { width: 100%; overflow-x: auto; }
.table-wrap .grid { min-width: 760px; }

/* sidebar status */
.side-status {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 10px 2px 12px;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, .14);
  background: rgba(148, 163, 184, .05);
  color: #94a3b8;
  font-size: 12px;
}

/* motion */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(9px); }
  to { opacity: 1; transform: translateY(0); }
}
.content > section, .login-card, .content > .page-head {
  animation: fadeUp .4s cubic-bezier(.22, 1, .36, 1) both;
}
.content > section:nth-child(2) { animation-delay: .04s; }
.content > section:nth-child(3) { animation-delay: .08s; }
.content > section:nth-child(4) { animation-delay: .12s; }
.content > section:nth-child(5) { animation-delay: .16s; }

.btn:focus-visible, a:focus-visible, summary:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

::-webkit-scrollbar { height: 10px; width: 10px; }
::-webkit-scrollbar-thumb {
  background: #c7d2e4;
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-track { background: transparent; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* responsive */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .meta-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%; flex: none; height: auto; position: static;
    padding: 14px 16px; gap: 10px;
  }
  .brand { padding: 0 4px 10px; }
  .side-nav { flex-direction: row; overflow-x: auto; padding-bottom: 4px; }
  .side-nav a { white-space: nowrap; padding: 8px 11px; }
  .side-nav a.active::before { display: none; }
  .side-foot { flex-direction: row; align-items: center; justify-content: space-between; padding-top: 10px; }
  .side-foot form { width: auto; }
  .side-foot .btn { width: auto !important; }
  .user-chip { display: none; }
  .topbar { padding: 0 16px; height: 56px; }
  .content { padding: 18px 16px 32px; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .hero { flex-direction: column; align-items: flex-start; padding: 22px; gap: 16px; }
  .hero h1 { font-size: 24px; }
  .stats, .stats-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.dash th:nth-child(3), .grid.dash td:nth-child(3) { display: none; }
  .pop form { position: fixed; right: 16px; left: 16px; top: auto; bottom: 16px; width: auto; }
  .foot { display: none; }
}

@media (max-width: 560px) {
  .stats, .stats-3 { grid-template-columns: 1fr 1fr; }
  .page-head h1 { font-size: 22px; }
  .meta-grid { grid-template-columns: 1fr; }
  .card { padding: 16px; }
}
