:root {
  --bg: #0f1419;
  --card: #171e26;
  --card-hover: #1c2530;
  --border: #26303b;
  --text: #e6edf3;
  --muted: #8b98a5;
  --ok: #2ea043;
  --warn: #d29922;
  --crit: #f85149;
  --bar-bg: #232d38;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background: radial-gradient(1200px 600px at 20% -10%, #17222d 0%, var(--bg) 55%) fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- 登录页 ---------- */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  padding: 32px 28px 24px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  text-align: center;
}

.login-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 12px rgba(46, 160, 67, 0.8);
}

.login-card h1 {
  margin: 14px 0 4px;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.login-sub {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 13px;
}

.login-error {
  margin: 0 0 14px;
  padding: 8px 10px;
  border: 1px solid rgba(248, 81, 73, 0.42);
  border-radius: 8px;
  background: rgba(248, 81, 73, 0.1);
  color: #ffb3ae;
  font-size: 13px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-form input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0f151c;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease;
}

.login-form input:focus {
  border-color: #3d7eff;
}

.login-form button,
.toast-close {
  cursor: pointer;
}

.login-form button {
  padding: 11px 12px;
  border: 1px solid #2f6feb;
  border-radius: 8px;
  background: #2f6feb;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.15s ease;
}

.login-form button:hover {
  background: #3d7eff;
}

.login-hint {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 12px;
}

/* ---------- 顶栏 ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 24px;
  padding: 14px 24px;
  background: rgba(15, 20, 25, 0.88);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}

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

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 10px rgba(46, 160, 67, 0.75);
}

.brand h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.summary {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.last-refresh {
  color: var(--muted);
  font-size: 12px;
}

.logout-form {
  margin: 0;
}

.ghost {
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.ghost:hover {
  border-color: #3d4b5a;
  background: #1a222c;
}

.conn-error {
  margin: 16px 24px 0;
  padding: 10px 12px;
  border: 1px solid rgba(210, 153, 34, 0.4);
  border-radius: 8px;
  background: rgba(210, 153, 34, 0.09);
  color: #e3b341;
  font-size: 13px;
}

/* ---------- 卡片网格 ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 18px;
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--muted);
  border-radius: 10px;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.card:hover {
  transform: translateY(-2px);
  background: var(--card-hover);
  border-color: #33404d;
}

.card.state-ok {
  border-left-color: var(--ok);
}

.card.state-warning {
  border-left-color: var(--warn);
}

.card.state-critical {
  border-left-color: var(--crit);
  box-shadow: 0 0 0 1px rgba(248, 81, 73, 0.14);
}

.card.state-offline {
  border-left-color: var(--crit);
  opacity: 0.72;
}

.card-head {
  display: flex;
  align-items: baseline;
  gap: 9px;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
  align-self: center;
}

.state-ok .dot {
  background: var(--ok);
  box-shadow: 0 0 8px rgba(46, 160, 67, 0.7);
}

.state-warning .dot {
  background: var(--warn);
  box-shadow: 0 0 8px rgba(210, 153, 34, 0.7);
}

.state-critical .dot,
.state-offline .dot {
  background: var(--crit);
  box-shadow: 0 0 8px rgba(248, 81, 73, 0.7);
}

.name {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.last-seen {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.ip-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  padding: 7px 10px;
  border-radius: 7px;
  background: #121920;
  font-size: 12.5px;
}

.ip-row.ip-mismatch {
  background: rgba(248, 81, 73, 0.1);
  border: 1px solid rgba(248, 81, 73, 0.35);
}

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

.ip-value {
  color: var(--text);
}

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

.ip-expected {
  margin-left: auto;
  color: #ffb3ae;
  font-size: 12px;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
}

.metrics {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.metric {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.metric-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-size: 12.5px;
}

.metric-head > span:first-child {
  color: var(--muted);
}

.metric-value {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.bar {
  height: 6px;
  border-radius: 999px;
  background: var(--bar-bg);
  overflow: hidden;
}

.bar-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--ok);
  transition: width 0.35s ease, background 0.2s ease;
}

.bar-fill.warn {
  background: var(--warn);
}

.bar-fill.crit {
  background: var(--crit);
}

.bar-fill.muted {
  background: #3a4856;
}

.issues {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.issue {
  font-size: 12px;
  line-height: 1.45;
}

.issue::before {
  content: "!";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  margin-right: 7px;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  color: #10151b;
  vertical-align: 1px;
}

.issue-warning {
  color: #e3b341;
}

.issue-warning::before {
  background: var(--warn);
}

.issue-critical {
  color: #ffb3ae;
}

.issue-critical::before {
  background: var(--crit);
}

.card-foot {
  margin-top: auto;
  padding-top: 2px;
  color: var(--muted);
  font-size: 11.5px;
}

/* ---------- 右下角弹窗 ---------- */

.toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(360px, calc(100vw - 32px));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  background: #1d2631;
  border: 1px solid var(--border);
  border-left: 3px solid var(--warn);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  animation: toast-in 0.18s ease-out;
}

.toast-critical {
  border-left-color: var(--crit);
}

.toast-text {
  flex: 1;
  min-width: 0;
}

.toast-text strong {
  display: block;
  font-size: 13px;
}

.toast-text p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12.5px;
}

.toast-close {
  flex: none;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
}

.toast-close:hover {
  background: #2a3542;
  color: var(--text);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 600px) {
  .topbar {
    padding: 12px 16px;
  }

  .summary {
    order: 3;
    width: 100%;
  }

  .controls {
    margin-left: auto;
  }

  .last-refresh {
    display: none;
  }

  .grid {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .conn-error {
    margin: 12px 16px 0;
  }

  .toasts {
    right: 16px;
    bottom: 16px;
  }
}

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