:root {
  --ink: #12202a;
  --ink-soft: #3d5563;
  --muted: #6b8493;
  --line: rgba(18, 32, 42, 0.1);
  --paper: rgba(255, 252, 247, 0.78);
  --paper-solid: #fffdf9;
  --teal: #0d7a6f;
  --teal-deep: #065f58;
  --cyan: #1aa6a0;
  --amber: #c47a12;
  --rose: #c23b4a;
  --ok: #1f8a55;
  --ok-bg: rgba(31, 138, 85, 0.12);
  --down-bg: rgba(194, 59, 74, 0.12);
  --unk-bg: rgba(107, 132, 147, 0.14);
  --shadow: 0 18px 50px rgba(18, 48, 56, 0.1);
  --radius: 14px;
  --font: "DM Sans", "PingFang SC", "Noto Sans SC", sans-serif;
  --display: "Syne", "DM Sans", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(26, 166, 160, 0.22), transparent 55%),
    radial-gradient(900px 500px at 95% 0%, rgba(196, 122, 18, 0.14), transparent 50%),
    linear-gradient(165deg, #e8f3f1 0%, #f7f3eb 42%, #eef6f4 100%);
  line-height: 1.45;
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(13, 122, 111, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(13, 122, 111, 0.05) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at center, black 30%, transparent 75%);
  z-index: 0;
  animation: grid-drift 28s linear infinite;
}
.bg-glow {
  position: fixed;
  width: 420px;
  height: 420px;
  right: -80px;
  bottom: -100px;
  background: radial-gradient(circle, rgba(26, 166, 160, 0.2), transparent 70%);
  filter: blur(10px);
  pointer-events: none;
  z-index: 0;
  animation: glow-pulse 8s ease-in-out infinite;
}

@keyframes grid-drift {
  from { transform: translateY(0); }
  to { transform: translateY(48px); }
}
@keyframes glow-pulse {
  0%, 100% { opacity: 0.55; transform: scale(1); }
  50% { opacity: 0.9; transform: scale(1.08); }
}
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.topbar, .wrap { position: relative; z-index: 1; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.75rem;
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
  background: rgba(255, 253, 249, 0.55);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 0.9rem; }
.top-nav {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem;
  border-radius: 12px;
  background: rgba(13, 122, 111, 0.08);
  border: 1px solid var(--line);
}
.nav-link {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-weight: 650;
  padding: 0.5rem 1.05rem;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.15s;
}
.nav-link:hover {
  color: var(--ink);
  background: rgba(255, 253, 249, 0.65);
}
.nav-link.active {
  background: linear-gradient(135deg, var(--teal), var(--teal-deep));
  color: #fff;
  box-shadow: 0 6px 14px rgba(13, 122, 111, 0.25);
}
.page[hidden] { display: none !important; }
.page.active { animation: rise 0.35s ease both; }
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background:
    conic-gradient(from 210deg, var(--teal), var(--cyan), #e8c07a, var(--teal));
  box-shadow: inset 0 0 0 3px rgba(255,255,255,0.45), 0 8px 20px rgba(13,122,111,0.25);
  animation: glow-pulse 6s ease-in-out infinite;
}
.brand h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.55rem;
  letter-spacing: -0.03em;
  font-weight: 800;
}
.brand p {
  margin: 0.1rem 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}
.topbar-actions { display: flex; gap: 0.6rem; }

.wrap {
  width: min(1180px, calc(100% - 2rem));
  margin: 1.4rem auto 3rem;
  animation: rise 0.55s ease both;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.85rem;
  margin-bottom: 1rem;
}
.stat {
  padding: 1rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
  transition: transform 0.2s ease;
}
.stat:hover { transform: translateY(-2px); }
.stat-label {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 0.35rem;
}
.stat-value {
  font-family: var(--display);
  font-size: 1.85rem;
  letter-spacing: -0.03em;
}
.stat.up { background: rgba(31, 138, 85, 0.1); }
.stat.blocked { background: rgba(196, 122, 18, 0.12); }
.stat.lost { background: rgba(194, 59, 74, 0.1); }
.stat.up .stat-value { color: var(--ok); }
.stat.blocked .stat-value { color: var(--amber); }
.stat.lost .stat-value { color: var(--rose); }
.stat-label .dot {
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  margin-right: 0.35rem;
  vertical-align: 0.05rem;
  background: currentColor;
}
.stat.up .stat-label { color: var(--ok); }
.stat.blocked .stat-label { color: var(--amber); }
.stat.lost .stat-label { color: var(--rose); }

.overview-shell {
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 2px);
  background: var(--paper);
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
  overflow: hidden;
  animation: rise 0.5s ease both;
}
.overview-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.95rem 1.1rem 0.55rem;
  border-bottom: 1px solid var(--line);
}
.overview-head h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}
.hint-inline {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}
.overview-scroll { overflow: auto; }
table.overview {
  width: 100%;
  border-collapse: collapse;
  min-width: 520px;
}
table.overview th,
table.overview td {
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--line);
  text-align: center;
  white-space: nowrap;
}
table.overview th:first-child,
table.overview td:first-child {
  text-align: left;
  position: sticky;
  left: 0;
  background: rgba(255, 253, 249, 0.96);
  font-weight: 600;
  color: var(--ink-soft);
  min-width: 7.5rem;
  z-index: 1;
}
table.overview thead th {
  font-size: 0.82rem;
  background: rgba(13, 122, 111, 0.06);
  color: var(--ink);
  font-weight: 700;
}
.group-rename {
  font: inherit;
  color: inherit;
  border: 1px dashed transparent;
  border-radius: 6px;
  background: none;
  padding: 0.1rem 0.35rem;
  cursor: pointer;
  transition: border-color 0.18s ease, color 0.18s ease;
}
.group-rename:hover,
.group-rename:focus-visible {
  border-color: rgba(13, 122, 111, 0.5);
  color: var(--teal-deep);
  outline: none;
}
table.overview tbody tr:nth-child(even) td { background: rgba(13, 122, 111, 0.03); }
table.overview tbody tr:nth-child(even) td:first-child { background: rgba(246, 250, 249, 0.98); }
table.overview .num { font-weight: 700; font-variant-numeric: tabular-nums; }
table.overview .c-up { color: var(--ok); }
table.overview .c-blocked { color: var(--amber); }
table.overview .c-lost { color: var(--rose); }
table.overview .c-conflict { color: #7a4bb8; }
table.overview .c-rate-ok { color: var(--ok); font-weight: 700; }
table.overview .c-rate-warn { color: var(--amber); font-weight: 700; }
table.overview .empty td {
  text-align: center;
  color: var(--muted);
  padding: 1.4rem;
}

.toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 0.8rem;
  margin-bottom: 0.85rem;
}
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  flex: 1;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 120px;
}
.field.grow { flex: 1; min-width: 180px; }
.field span, legend {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.02em;
}
input, select, textarea {
  font: inherit;
  color: var(--ink);
  border: 1px solid var(--line);
  background: var(--paper-solid);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  border-color: rgba(13, 122, 111, 0.55);
  box-shadow: 0 0 0 3px rgba(26, 166, 160, 0.16);
}
textarea { resize: vertical; font-family: var(--mono); font-size: 0.86rem; }

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.55rem 0.95rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s, border-color 0.15s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.primary {
  background: linear-gradient(135deg, var(--teal), var(--teal-deep));
  color: #fff;
  box-shadow: 0 8px 18px rgba(13, 122, 111, 0.28);
}
.btn.ghost {
  background: rgba(255,253,249,0.7);
  border-color: var(--line);
  color: var(--ink);
}
.btn.danger { color: var(--rose); }
.btn.small { padding: 0.35rem 0.65rem; font-size: 0.85rem; }

.table-shell {
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 2px);
  background: var(--paper);
  box-shadow: var(--shadow);
  overflow: auto;
}
table.targets {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}
th, td {
  padding: 0.85rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: rgba(13, 122, 111, 0.05);
  position: sticky;
  top: 0;
}
tbody tr {
  transition: background 0.15s;
}
/* 仅首次进入 / 切页时播放，避免轮询刷新整表重绘闪屏 */
tbody tr.row-enter {
  animation: rise 0.4s ease both;
}
tbody tr:hover { background: rgba(26, 166, 160, 0.06); }
tbody tr.empty td {
  text-align: center;
  color: var(--muted);
  padding: 2.5rem 1rem;
}
.name-cell { font-weight: 600; }
.ip-cell {
  font-family: var(--mono);
  font-size: 0.88rem;
}
.ip-cell small {
  display: block;
  color: var(--muted);
  margin-top: 0.15rem;
  font-family: var(--font);
}
.mono { font-family: var(--mono); font-size: 0.88rem; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}
.badge::before {
  content: "";
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: currentColor;
}
.badge.up { color: var(--ok); background: var(--ok-bg); }
.badge.down, .badge.blocked { color: var(--amber); background: rgba(196, 122, 18, 0.14); }
.badge.lost { color: var(--rose); background: var(--down-bg); }
.badge.conflict { color: #7a4bb8; background: rgba(122, 75, 184, 0.12); }
.badge.unknown, .badge.disabled { color: var(--ink-soft); background: var(--unk-bg); }

.actions { display: flex; gap: 0.4rem; }

dialog.modal {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0;
  width: min(480px, calc(100vw - 2rem));
  background: var(--paper-solid);
  box-shadow: 0 30px 80px rgba(18, 48, 56, 0.22);
}
dialog.modal.wide { width: min(720px, calc(100vw - 2rem)); }
dialog::backdrop {
  background: rgba(12, 28, 34, 0.45);
  backdrop-filter: blur(4px);
}
dialog form, dialog > form { padding: 1.35rem 1.4rem 1.2rem; }
dialog h2 {
  margin: 0 0 0.35rem;
  font-family: var(--display);
  letter-spacing: -0.02em;
}
.hint {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}
.hint code, code {
  font-family: var(--mono);
  font-size: 0.84em;
  background: rgba(13,122,111,0.08);
  padding: 0.1em 0.35em;
  border-radius: 5px;
}
.row { display: flex; gap: 0.7rem; }
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.9rem;
}
fieldset {
  border: 1px solid var(--line);
  border-radius: 12px;
  margin: 0 0 0.8rem;
  padding: 0.8rem;
}
.check {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0.6rem 0;
  color: var(--ink-soft);
}
.check.end { align-self: end; margin-bottom: 0.15rem; }
.modal-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-top: 1rem;
}
.spacer { flex: 1; }
.form-msg {
  margin-top: 0.7rem;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  background: rgba(13,122,111,0.08);
  color: var(--ink-soft);
  font-size: 0.9rem;
}
.form-msg.error { background: var(--down-bg); color: var(--rose); }

.detail-modal {
  inset: 0;
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  background: #f7f8fa;
  box-shadow: none;
  overflow: hidden;
}
.detail-modal::backdrop {
  background: #f7f8fa;
}
.detail-panel {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  height: 100vh;
  padding: 1.5rem 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.detail-close {
  position: absolute;
  top: 1rem;
  right: 1.25rem;
  z-index: 2;
  border: none;
  background: rgba(18, 32, 42, 0.06);
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 999px;
  font-size: 1.45rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}
.detail-eyebrow {
  margin: 0 0 0.35rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--teal);
  flex-shrink: 0;
}
.detail-panel h2 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.5rem, 2.4vw, 1.9rem);
  letter-spacing: -0.03em;
  color: #1a1f24;
  flex-shrink: 0;
}
.detail-sub {
  margin: 0.35rem 0 1.15rem;
  color: var(--muted);
  font-size: 0.95rem;
  flex-shrink: 0;
}
.detail-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.85rem;
  margin-bottom: 0.85rem;
  flex-shrink: 0;
}
.detail-card {
  background: #fff;
  border: 1px solid rgba(18, 32, 42, 0.08);
  border-radius: 14px;
  padding: 0.95rem 1rem;
}
.detail-card-label {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 0.4rem;
}
.detail-card-value {
  display: block;
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: #161a1f;
  line-height: 1.1;
}
.detail-card-note {
  display: block;
  margin-top: 0.45rem;
  font-size: 0.82rem;
  color: var(--rose);
  font-weight: 600;
}
.detail-card-note.muted {
  color: var(--muted);
  font-weight: 500;
}
.detail-card-note.ok {
  color: var(--ok);
}
.detail-footnote {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.82rem;
  flex-shrink: 0;
}
.detail-table-wrap {
  background: #fff;
  border: 1px solid rgba(18, 32, 42, 0.08);
  border-radius: 14px;
  flex: 1;
  min-height: 0;
  overflow: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.detail-table-wrap::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}
table.detail-faults {
  width: 100%;
  border-collapse: collapse;
  min-width: 0;
}
table.detail-faults th,
table.detail-faults td {
  padding: 0.85rem 1rem;
  text-align: left;
  border-bottom: 1px solid rgba(18, 32, 42, 0.06);
}
table.detail-faults th {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
  background: #fafbfc;
  position: sticky;
  top: 0;
  z-index: 1;
}
table.detail-faults td {
  font-size: 0.92rem;
  color: #1a1f24;
}
table.detail-faults .duration-hot {
  color: var(--rose);
  font-weight: 700;
}
table.detail-faults .empty td {
  text-align: center;
  color: var(--muted);
  padding: 1.6rem;
}
.badge.fault-blocked {
  color: #b42318;
  background: rgba(180, 35, 24, 0.1);
  border-radius: 8px;
  padding: 0.28rem 0.55rem;
  font-size: 0.8rem;
  font-weight: 700;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.4rem;
  transform: translateX(-50%);
  z-index: 50;
  background: var(--ink);
  color: #fff;
  padding: 0.7rem 1.1rem;
  border-radius: 999px;
  font-size: 0.9rem;
  box-shadow: 0 12px 30px rgba(0,0,0,0.2);
  animation: rise 0.25s ease both;
}

@media (max-width: 860px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .topbar { flex-direction: column; align-items: flex-start; }
  .top-nav { width: 100%; }
  .nav-link { flex: 1; text-align: center; }
  .topbar-actions { width: 100%; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .grid-2 { grid-template-columns: 1fr; }
  .brand h1 { font-size: 1.35rem; }
  .detail-cards { grid-template-columns: 1fr; }
  .detail-panel h2 { font-size: 1.4rem; }
}
