:root {
  --bg: #0b1220;
  --bg-elev: #121a2b;
  --bg-soft: #172033;
  --line: #243049;
  --line-soft: #1c2740;
  --text: #e8eef8;
  --muted: #8b9bb8;
  --accent: #3b82f6;
  --accent-2: #22c55e;
  --danger: #f87171;
  --warn: #fbbf24;
  --ok: #34d399;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  --radius: 14px;
  --font: "DM Sans", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: "IBM Plex Mono", "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(59, 130, 246, 0.16), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(34, 197, 94, 0.08), transparent 50%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* Login */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(420px, 100%);
  background: linear-gradient(180deg, rgba(255,255,255,0.03), transparent), var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.login-card .brand {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 4px;
}
.login-card .hint { color: var(--muted); margin: 0 0 20px; font-size: 0.92rem; line-height: 1.5; }
.login-card label { display: block; font-size: 0.82rem; color: var(--muted); margin: 10px 0 6px; }
.login-card input { width: 100%; margin: 0 0 8px; }
.login-card .primary { width: 100%; margin-top: 12px; }

/* Shell */
.layout {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}
.side {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 14px;
  background: rgba(12, 18, 32, 0.92);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
}
.side .brand-wrap { padding: 4px 10px 18px; }
.side h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.side .sub { color: var(--muted); font-size: 0.78rem; margin-top: 4px; }
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  margin: 0;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  color: #c9d4e8;
  cursor: pointer;
  font: inherit;
  transition: 0.15s ease;
}
.nav button .ico {
  width: 1.4rem;
  text-align: center;
  opacity: 0.85;
  font-size: 0.95rem;
}
.nav button.active,
.nav button:hover {
  background: rgba(59, 130, 246, 0.12);
  border-color: rgba(59, 130, 246, 0.35);
  color: #fff;
}
.nav-badge {
  margin-left: auto;
  min-width: 1.35rem;
  height: 1.25rem;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--warn);
  color: #1a1400;
  font-size: 0.72rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.nav .spacer { flex: 1; }
.nav #logoutBtn {
  color: #f0a8a8;
  border-color: transparent;
}
.nav #logoutBtn:hover {
  background: rgba(248, 113, 113, 0.12);
  border-color: rgba(248, 113, 113, 0.3);
}

.main {
  padding: 22px 26px 40px;
  min-width: 0;
}
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.page-head h2 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.page-head .desc {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
  max-width: 720px;
}
.live-dot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
}
.live-dot::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.15);
  animation: pulse 1.6s ease infinite;
}
@keyframes pulse {
  50% { opacity: 0.45; }
}

.panel {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0 0 14px;
  box-shadow: var(--shadow);
}
.panel.flat { box-shadow: none; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

input, button, select, textarea {
  margin: 0;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid #334561;
  background: #0e1626;
  color: var(--text);
  font: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: rgba(59, 130, 246, 0.7);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.18);
}
button { cursor: pointer; }
button.primary {
  background: linear-gradient(180deg, #4b8dff, #2f6fed);
  border-color: #2f6fed;
  color: #fff;
  font-weight: 600;
}
button.primary:hover { filter: brightness(1.06); }
button.ghost {
  background: transparent;
  border-color: #3a4f6d;
  color: #d7e2f0;
}
button.ghost:hover { background: rgba(255,255,255,0.04); }
button.sm { padding: 6px 10px; font-size: 0.82rem; border-radius: 8px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.form-grid {
  display: grid;
  gap: 14px;
  max-width: 640px;
}
.form-grid label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 6px;
}
.form-grid input { width: 100%; }

.msg { color: var(--danger); }
.ok { color: var(--ok); }
.meta { color: var(--muted); font-size: 0.9rem; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.card {
  background: linear-gradient(180deg, rgba(255,255,255,0.03), transparent), var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
}
.card .n {
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.card .l { color: var(--muted); font-size: 0.82rem; margin-top: 4px; }

/* Table */
.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg-elev);
}
table.data {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
}
table.data th,
table.data td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}
table.data th {
  position: sticky;
  top: 0;
  background: #151e31;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  z-index: 1;
}
table.data tr:hover td { background: rgba(59, 130, 246, 0.05); }
table.data tr:last-child td { border-bottom: none; }
.mono { font-family: var(--mono); font-size: 0.84rem; }
.cell-main { font-weight: 600; }
.cell-sub { color: var(--muted); font-size: 0.8rem; margin-top: 3px; line-height: 1.4; }
.cell-fail { color: #ffb4b4; font-size: 0.8rem; margin-top: 4px; max-width: 360px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; white-space: nowrap; }
.empty {
  padding: 36px 16px;
  text-align: center;
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  background: #243140;
  color: #d7e2ea;
  white-space: nowrap;
}
.badge.on, .badge.success { background: rgba(34, 197, 94, 0.15); color: #86efac; }
.badge.off, .badge.fail { background: rgba(248, 113, 113, 0.15); color: #fca5a5; }
.badge.wait { background: rgba(59, 130, 246, 0.15); color: #93c5fd; }
.badge.warn { background: rgba(251, 191, 36, 0.15); color: #fde68a; }
.badge.reason { font-weight: 700; }

.presence {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.86rem;
  margin-bottom: 12px;
}

/* Modal */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 16, 0.65);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
  backdrop-filter: blur(4px);
}
.modal {
  width: min(720px, 100%);
  max-height: min(82vh, 900px);
  overflow: auto;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--bg-elev);
}
.modal-head h3 { margin: 0; font-size: 1rem; }
.modal-body { padding: 16px; }
.kv {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 8px 12px;
  font-size: 0.9rem;
  margin-bottom: 14px;
}
.kv .k { color: var(--muted); }
.kv .v { word-break: break-all; font-family: var(--mono); font-size: 0.84rem; }
.event-list {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.55;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.85rem;
}
.pager button[disabled] { opacity: 0.4; cursor: default; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .side {
    position: relative;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav button { width: auto; }
  .nav .spacer { display: none; }
}
