/* ==========================================================================
   NetPulse — design tokens
   ========================================================================== */
:root {
  color-scheme: dark;

  /* Surfaces */
  --bg: #060a12;
  --bg-elevated: #0b1220;
  --bg-card: #0e1626;
  --bg-input: #0a1322;
  --bg-hover: rgba(148, 163, 184, 0.08);

  /* Lines */
  --border: rgba(148, 163, 184, 0.14);
  --border-strong: rgba(148, 163, 184, 0.26);

  /* Text */
  --text: #e8eef7;
  --text-dim: #c3cddb;
  --text-muted: #8a97ab;

  /* Accents */
  --accent: #38bdf8;
  --accent-2: #6366f1;
  --success: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --purple: #a78bfa;

  --accent-soft: rgba(56, 189, 248, 0.1);
  --accent-line: rgba(56, 189, 248, 0.34);
  --success-soft: rgba(52, 211, 153, 0.1);
  --success-line: rgba(52, 211, 153, 0.34);
  --warn-soft: rgba(251, 191, 36, 0.1);
  --warn-line: rgba(251, 191, 36, 0.34);
  --danger-soft: rgba(248, 113, 113, 0.1);
  --danger-line: rgba(248, 113, 113, 0.34);
  --purple-soft: rgba(167, 139, 250, 0.1);
  --purple-line: rgba(167, 139, 250, 0.34);

  /* Type */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Noto Sans CJK SC", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "WenQuanYi Micro Hei", "Noto Sans CJK SC", monospace;
  --fs-xs: 0.72rem;
  --fs-sm: 0.8rem;
  --fs-base: 0.875rem;
  --fs-md: 0.95rem;
  --fs-lg: 1.08rem;
  --fs-xl: clamp(1.12rem, 1rem + 0.5vw, 1.3rem);
  --fs-num: 1.06rem;

  /* Space */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;

  /* Shape */
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  /* Depth */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 10px 28px rgba(0, 0, 0, 0.32);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.5);
  --ring: 0 0 0 3px rgba(56, 189, 248, 0.22);

  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);
  --dur: 0.18s;

  --header-h: 60px;
}

/* ==========================================================================
   Base
   ========================================================================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-padding-top: calc(var(--header-h) + var(--sp-6));
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  color: var(--text);
  min-block-size: 100dvb;
  line-height: 1.55;
  background:
    radial-gradient(900px 520px at 12% -8%, rgba(56, 189, 248, 0.09), transparent 62%),
    radial-gradient(820px 520px at 92% 4%, rgba(99, 102, 241, 0.08), transparent 60%),
    radial-gradient(700px 480px at 60% 110%, rgba(52, 211, 153, 0.05), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3 {
  line-height: 1.3;
  letter-spacing: -0.01em;
}

code {
  font-family: var(--font-mono);
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

::selection {
  background: rgba(56, 189, 248, 0.3);
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-block-size: 34px;
  padding: 0 var(--sp-4);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: var(--fs-base);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  color: var(--text);
  text-decoration: none;
  user-select: none;
  transition:
    background-color var(--dur) var(--ease),
    border-color var(--dur) var(--ease),
    color var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease),
    transform var(--dur) var(--ease);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-sm {
  min-block-size: 28px;
  padding: 0 10px;
  font-size: var(--fs-sm);
  border-radius: 7px;
  gap: 6px;
}

.btn-primary {
  background: linear-gradient(180deg, #38bdf8, #0ea5e9);
  border-color: rgba(125, 211, 252, 0.55);
  color: #04121f;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.28) inset, 0 6px 16px rgba(14, 165, 233, 0.22);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #5ac8fa, #0ea5e9);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.32) inset, 0 8px 22px rgba(14, 165, 233, 0.3);
}

.btn-secondary {
  background: rgba(148, 163, 184, 0.1);
  border-color: var(--border-strong);
  color: var(--text-dim);
}

.btn-secondary:hover:not(:disabled) {
  background: rgba(148, 163, 184, 0.17);
  border-color: rgba(148, 163, 184, 0.38);
  color: var(--text);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.btn-spinner {
  width: 13px;
  height: 13px;
  border: 2px solid rgba(4, 18, 31, 0.25);
  border-top-color: #04121f;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.icon-btn {
  background: rgba(148, 163, 184, 0.08);
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}

.icon-btn:hover {
  color: var(--text);
  background: rgba(148, 163, 184, 0.16);
  border-color: var(--border-strong);
}

.icon-btn svg {
  width: 15px;
  height: 15px;
}

/* ==========================================================================
   Top bar (sticky)
   ========================================================================== */
.app-shell {
  max-inline-size: 1440px;
  margin-inline: auto;
  padding: var(--sp-4) var(--sp-5) var(--sp-8);
}

.topbar {
  position: sticky;
  inset-block-start: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-3) var(--sp-4);
  min-block-size: var(--header-h);
  padding: var(--sp-2) var(--sp-4);
  margin-inline: calc(var(--sp-5) * -1);
  margin-block-end: var(--sp-4);
  background: rgba(6, 10, 18, 0.72);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border-block-end: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-inline-size: 0;
}

.brand-icon {
  inline-size: 36px;
  block-size: 36px;
  border-radius: 10px;
  background: linear-gradient(140deg, rgba(56, 189, 248, 0.22), rgba(99, 102, 241, 0.24));
  border: 1px solid rgba(56, 189, 248, 0.38);
  box-shadow: 0 0 22px rgba(56, 189, 248, 0.16), 0 1px 0 rgba(255, 255, 255, 0.08) inset;
  display: grid;
  place-items: center;
  color: var(--accent);
  flex-shrink: 0;
}

.brand-icon svg {
  width: 20px;
  height: 20px;
}

.brand h1 {
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
}

.subtitle {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-inline-start: auto;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  block-size: 28px;
  padding: 0 var(--sp-3);
  border-radius: var(--radius-pill);
  background: var(--bg-input);
  border: 1px solid var(--border);
  font-size: var(--fs-sm);
  color: var(--text-muted);
  white-space: nowrap;
}

.status-pill .dot {
  inline-size: 7px;
  block-size: 7px;
  border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.14);
}

.status-pill.online .dot {
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.16);
}

.status-pill.offline .dot {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.16);
}

/* ==========================================================================
   Section navigation (pill tabs)
   ========================================================================== */
.main-tabs {
  display: flex;
  gap: var(--sp-1);
  flex-wrap: wrap;
  margin-block-end: var(--sp-5);
  padding: var(--sp-1);
  background: rgba(14, 22, 38, 0.7);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  inline-size: fit-content;
  max-inline-size: 100%;
}

.main-tab {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  block-size: 34px;
  padding: 0 var(--sp-4);
  border-radius: var(--radius-sm);
  font-size: var(--fs-base);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition:
    color var(--dur) var(--ease),
    background-color var(--dur) var(--ease),
    border-color var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease);
}

.main-tab::before {
  content: "";
  inline-size: 6px;
  block-size: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.45;
  transition: opacity var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.main-tab:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.main-tab.active {
  background: linear-gradient(180deg, rgba(56, 189, 248, 0.14), rgba(56, 189, 248, 0.06));
  border-color: var(--accent-line);
  color: var(--text);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05) inset;
}

.main-tab.active::before {
  background: var(--accent);
  opacity: 1;
  box-shadow: 0 0 8px var(--accent);
}

.tab-panel {
  display: none !important;
}

.tab-panel.active {
  display: grid !important;
}

/* ==========================================================================
   Grid & cards
   ========================================================================== */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: var(--sp-4);
}

.card {
  grid-column: span 12;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  min-inline-size: 0;
  padding: var(--sp-5);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.025), rgba(255, 255, 255, 0) 120px),
    var(--bg-card);
  box-shadow: var(--shadow);
  transition: border-color var(--dur) var(--ease);
}

.card::before {
  content: "";
  position: absolute;
  inset-inline: 18% 18%;
  inset-block-start: -1px;
  block-size: 1px;
  background: linear-gradient(90deg, transparent, rgba(125, 211, 252, 0.45), transparent);
  pointer-events: none;
}

.card:hover {
  border-color: var(--border-strong);
}

.card-full { grid-column: span 12; }
.card-speed { grid-column: span 7; }
.card-stability { grid-column: span 5; }

@media (max-width: 1180px) {
  .card-speed,
  .card-stability {
    grid-column: span 12;
  }
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-3) var(--sp-4);
  flex-wrap: wrap;
}

.card-header h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: var(--fs-lg);
  font-weight: 650;
  color: var(--text);
}

.card-header h2::before {
  content: "";
  inline-size: 3px;
  block-size: 15px;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.5);
  flex-shrink: 0;
}

.card-desc {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin-block-start: 4px;
  max-inline-size: 72ch;
}

.card-desc code {
  font-size: 0.94em;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(56, 189, 248, 0.18);
  padding: 0 5px;
  border-radius: 5px;
}

.label {
  display: block;
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-block-end: var(--sp-1);
  letter-spacing: 0.02em;
}

.hint-text {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  line-height: 1.6;
}

.hint-text code {
  font-size: 0.94em;
  color: var(--accent);
}

/* ==========================================================================
   Pills / badges
   ========================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-xs);
  font-weight: 600;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.badge::before {
  content: "";
  inline-size: 5px;
  block-size: 5px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.badge-ok {
  background: var(--success-soft);
  color: var(--success);
  border-color: var(--success-line);
}

.badge-warn {
  background: var(--warn-soft);
  color: var(--warn);
  border-color: var(--warn-line);
}

.badge-fail {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: var(--danger-line);
}

.badge-muted {
  background: rgba(148, 163, 184, 0.08);
  color: var(--text-muted);
}

.badge-accent {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent-line);
}

/* ==========================================================================
   Dual endpoint compare
   ========================================================================== */
.dual-compare-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 96px minmax(0, 1fr);
  gap: var(--sp-3);
  align-items: stretch;
}

@media (max-width: 960px) {
  .dual-compare-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .link-bridge {
    flex-direction: row;
    padding-block: var(--sp-1);
  }
  .bridge-line {
    block-size: 1px;
    inline-size: auto;
    flex: 1;
    background: linear-gradient(to right, rgba(56, 189, 248, 0.3), rgba(167, 139, 250, 0.3));
  }
}

.endpoint-box {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-4);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.022), transparent 90px),
    var(--bg-input);
  min-inline-size: 0;
}

.endpoint-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

.endpoint-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-xs);
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 6px;
  letter-spacing: 0.01em;
}

.endpoint-tag::before {
  content: "";
  inline-size: 6px;
  block-size: 6px;
  border-radius: 2px;
  background: currentColor;
}

.tag-client {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent-line);
}

.tag-server {
  background: var(--purple-soft);
  color: var(--purple);
  border: 1px solid var(--purple-line);
}

.link-bridge {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
}

.bridge-line {
  inline-size: 1px;
  flex: 1;
  background: linear-gradient(to bottom, rgba(56, 189, 248, 0.05), rgba(56, 189, 248, 0.3), rgba(167, 139, 250, 0.3), rgba(167, 139, 250, 0.05));
}

.bridge-pill {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--success-soft);
  color: var(--success);
  border: 1px solid var(--success-line);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.ip-value-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-inline-size: 0;
}

.ip-value {
  font-family: var(--font-mono);
  font-size: 1.24rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--accent);
  word-break: break-all;
  text-shadow: 0 0 20px rgba(56, 189, 248, 0.25);
}

.ip-value.server-ip {
  color: var(--purple);
  text-shadow: 0 0 20px rgba(167, 139, 250, 0.25);
}

.dual-stack-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-2);
}

@media (max-width: 560px) {
  .info-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

.info-item {
  background: rgba(255, 255, 255, 0.015);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  min-inline-size: 0;
  transition: border-color var(--dur) var(--ease);
}

.info-item:hover {
  border-color: var(--border-strong);
}

.info-item .label {
  margin-block-end: 2px;
}

.info-item .value {
  font-size: var(--fs-base);
  font-weight: 500;
  color: var(--text-dim);
  word-break: break-word;
}

/* ==========================================================================
   Speed test
   ========================================================================== */
.speed-body {
  display: grid;
  grid-template-columns: 196px minmax(0, 1fr);
  gap: var(--sp-4);
  align-items: center;
}

@media (max-width: 640px) {
  .speed-body {
    grid-template-columns: minmax(0, 1fr);
  }
}

.gauge-wrap {
  position: relative;
  inline-size: 196px;
  margin-inline: auto;
}

.gauge-svg {
  display: block;
  inline-size: 100%;
  block-size: auto;
}

.gauge-track {
  fill: none;
  stroke: rgba(148, 163, 184, 0.12);
  stroke-width: 14;
  stroke-linecap: round;
}

.gauge-fill {
  fill: none;
  stroke: url(#gaugeGrad);
  stroke-width: 14;
  stroke-linecap: round;
  stroke-dasharray: 283;
  stroke-dashoffset: 283;
  transition: stroke-dashoffset 0.2s ease-out;
  filter: drop-shadow(0 0 6px rgba(56, 189, 248, 0.45));
}

.gauge-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-block-end: 8px;
}

.gauge-phase {
  font-size: var(--fs-xs);
  color: var(--text-muted);
}

.gauge-number {
  font-size: 1.85rem;
  font-weight: 750;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.gauge-unit {
  font-size: var(--fs-xs);
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 0.06em;
}

.speed-metrics {
  display: grid;
  gap: var(--sp-2);
}

.metric-box {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-2);
  flex-wrap: wrap;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border);
}

.metric-box .label {
  margin: 0;
  flex: 1 1 140px;
}

.metric-val {
  font-size: var(--fs-num);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  margin-inline-start: auto;
}

.metric-sub {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.chart-wrap {
  padding: var(--sp-2);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border);
}

.chart-wrap canvas {
  display: block;
  inline-size: 100%;
}

/* ==========================================================================
   Stability
   ========================================================================== */
.stability-controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  align-items: center;
}

.custom-probe-bar {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

.custom-probe-bar input,
.custom-probe-bar select,
.stability-controls select,
.stability-controls input,
.selkies-settings-row select {
  block-size: 34px;
  min-inline-size: 0;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: var(--fs-sm);
  outline: none;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.custom-probe-bar input {
  flex: 1 1 200px;
}

.custom-probe-bar input::placeholder,
.stability-controls input::placeholder {
  color: var(--text-muted);
  opacity: 0.8;
}

.custom-probe-bar input:focus,
.custom-probe-bar select:focus,
.stability-controls select:focus,
.selkies-settings-row select:focus {
  border-color: var(--accent-line);
  box-shadow: var(--ring);
}

.custom-probe-bar input:focus-visible {
  outline: none;
}

.stability-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--sp-2);
}

@media (max-width: 520px) {
  .stability-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.stat-pill {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border);
  transition: border-color var(--dur) var(--ease);
}

.stat-pill:hover {
  border-color: var(--border-strong);
}

.stat-pill strong {
  font-size: var(--fs-md);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
}

.stability-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-2);
  font-size: var(--fs-sm);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.legend {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-3);
  font-size: var(--fs-xs);
}

.legend-dot {
  display: inline-block;
  inline-size: 7px;
  block-size: 7px;
  border-radius: 50%;
  margin-inline-end: 5px;
  vertical-align: middle;
}

.legend-dot.ok { background: var(--accent); }
.legend-dot.fail { background: var(--danger); }

/* ==========================================================================
   Server → 3rd-party probe wall
   ========================================================================== */
.srv-probe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: var(--sp-2);
}

.probe-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-inline-size: 0;
  padding: var(--sp-3);
  border-radius: var(--radius);
  background: var(--bg-input);
  border: 1px solid var(--border);
  transition: border-color var(--dur) var(--ease), background-color var(--dur) var(--ease);
}

.probe-card:hover {
  border-color: var(--border-strong);
  background: #0c1626;
}

.probe-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-2);
}

.probe-name {
  font-size: var(--fs-base);
  font-weight: 650;
  color: var(--text);
  line-height: 1.35;
}

.probe-cat {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-block-start: 1px;
}

.probe-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: var(--fs-xs);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.probe-err {
  font-size: var(--fs-xs);
  color: var(--danger);
  word-break: break-word;
}

/* ==========================================================================
   Hardware
   ========================================================================== */
.hw-actions {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

.hw-grid {
  container: hw / inline-size;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
  gap: var(--sp-3);
}

.hw-box {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: var(--sp-4);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(56, 189, 248, 0.035), transparent 70px),
    var(--bg-input);
  border: 1px solid var(--border);
  min-inline-size: 0;
}

.hw-box-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
}

.hw-box-head .label {
  margin: 0;
}

.hw-main {
  font-size: 1.18rem;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.hw-sub {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  word-break: break-word;
}

.progress-bar {
  inline-size: 100%;
  block-size: 6px;
  border-radius: var(--radius-pill);
  background: rgba(148, 163, 184, 0.12);
  overflow: hidden;
}

.progress-fill {
  block-size: 100%;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, #38bdf8, #34d399);
  transition: width 0.3s var(--ease);
}

/* ==========================================================================
   Auth gate
   ========================================================================== */
.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: var(--sp-5);
  background:
    radial-gradient(600px 400px at 50% 30%, rgba(56, 189, 248, 0.12), transparent 70%),
    rgba(6, 10, 18, 0.86);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.auth-card {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  inline-size: 100%;
  max-inline-size: 380px;
  padding: var(--sp-6);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(56, 189, 248, 0.06);
}

.auth-head h2 {
  font-size: var(--fs-xl);
  font-weight: 700;
}

.auth-head h2::before {
  content: "";
  display: inline-block;
  inline-size: 9px;
  block-size: 9px;
  margin-inline-end: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
  vertical-align: 2px;
}

.auth-head p {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin-block-start: 6px;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.auth-field input {
  block-size: 40px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: var(--fs-md);
  outline: none;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.auth-field input:focus {
  border-color: var(--accent-line);
  box-shadow: var(--ring);
}

.auth-error {
  color: var(--danger);
  font-size: var(--fs-sm);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  border: 1px solid var(--danger-line);
}

.auth-submit {
  inline-size: 100%;
  block-size: 40px;
  margin-block-start: var(--sp-1);
}

.auth-gate.hidden {
  display: none !important;
}

/* ==========================================================================
   WebShell
   ========================================================================== */
.shell-tabs {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  flex-wrap: wrap;
  padding: var(--sp-1);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border);
}

.shell-tabs:empty {
  display: none;
}

.shell-tab {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 4px 6px 4px 11px;
  border-radius: 7px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-family: var(--font-mono);
  cursor: pointer;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}

.shell-tab::before {
  content: "›_";
  font-weight: 700;
  color: currentColor;
  opacity: 0.6;
}

.shell-tab:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.shell-tab.active {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--text);
}

.shell-tab-close {
  display: grid;
  place-items: center;
  inline-size: 18px;
  block-size: 18px;
  border-radius: 5px;
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  opacity: 0.6;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease), opacity var(--dur) var(--ease);
}

.shell-tab-close:hover {
  opacity: 1;
  color: var(--danger);
  background: var(--danger-soft);
}

.shell-stage {
  position: relative;
  block-size: clamp(320px, 58dvh, 640px);
  min-block-size: 320px;
  overflow: hidden;
  padding: var(--sp-2);
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: #070b14;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4) inset;
}

.shell-stage:has(.xterm) {
  padding: 8px 4px 4px 10px;
}

.shell-pane {
  position: absolute;
  inset: var(--sp-2);
  display: none;
}

.shell-pane.active {
  display: block;
}

.shell-stage:has(.xterm) .shell-pane.active {
  inset: 8px 2px 2px 8px;
}

.shell-pane .xterm {
  block-size: 100%;
}

.shell-pane .xterm-viewport {
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.3) transparent;
  border-radius: 4px;
  overscroll-behavior: contain;
}

.shell-pane .xterm-viewport::-webkit-scrollbar {
  width: 10px;
}

.shell-pane .xterm-viewport::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.26);
  border-radius: 10px;
  border: 3px solid transparent;
  background-clip: padding-box;
}

.shell-empty {
  block-size: 100%;
  min-block-size: 220px;
  display: grid;
  place-items: center;
  padding: var(--sp-5);
  color: var(--text-muted);
  font-size: var(--fs-sm);
  text-align: center;
  background:
    radial-gradient(circle at 50% 40%, rgba(56, 189, 248, 0.06), transparent 60%);
}

/* ==========================================================================
   Selkies (WebRTC desktop)
   ========================================================================== */
.card-selkies.card-selkies {
  display: none;
  grid-column: span 12;
  gap: var(--sp-4);
  background:
    linear-gradient(135deg, rgba(52, 211, 153, 0.07), rgba(56, 189, 248, 0.05)),
    var(--bg-card);
}

.card-selkies.card-selkies.is-on {
  display: flex;
}

.selkies-url {
  flex: 1 1 240px;
  min-inline-size: 0;
  padding: 4px 9px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--accent);
  word-break: break-all;
}

.selkies-notice .badge {
  flex: none;
}

.selkies-endpoint-box {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-3);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border);
}

.selkies-settings-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-2) var(--sp-3);
}

.selkies-settings-row > .label {
  margin: 0;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.selkies-settings-row select {
  min-inline-size: 180px;
}

/* ==========================================================================
   noVNC
   ========================================================================== */
/* 左侧信息栏 4/12，右侧画面 8/12：工具栏有足够空间，信息卡不挤压 */
.card-vnc-side {
  display: none;
  grid-column: span 4;
}

.card-vnc-stage {
  grid-column: span 8;
  align-self: start;
}

.card-vnc-side.card-vnc-side.shown,
.card-vnc-stage.card-vnc-stage.shown-shifted {
  display: flex;
}

.card-vnc-stage.card-vnc-stage.shown-shifted {
  grid-column: span 12;
}

.card-vnc-stage .card-header {
  flex-wrap: nowrap;
  align-items: center;
}

.card-actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  padding-block-end: var(--sp-4);
  border-block-end: 1px solid var(--border);
}

.vnc-tool-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.vnc-tool-group > .label {
  margin: 0;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.vnc-action-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
}

.vnc-action-bar > select,
.vnc-action-bar > input {
  flex: 1 1 150px;
  min-inline-size: 0;
}

.vnc-tool-group .custom-probe-bar {
  flex-wrap: nowrap;
}

/* 屏幕控制工具栏：紧贴 vnc-screen 正上方，按钮只占一行，状态文字靠右 */
.vnc-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  margin-block-end: calc(var(--sp-3) * -1);
  padding: 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border);
}

.vnc-toolbar .btn {
  flex: 0 0 auto;
  white-space: nowrap;
}

.vnc-toolbar-status {
  flex: 1 1 140px;
  min-inline-size: 0;
  text-align: end;
  font-size: var(--fs-xs);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 900px) {
  .vnc-toolbar-status {
    order: 99;
    flex-basis: 100%;
    text-align: start;
    white-space: normal;
  }
}

@media (max-width: 1180px) {
  .card-vnc-side,
  .card-vnc-stage {
    grid-column: span 12;
  }

  .card-vnc-side {
    order: 1;
  }
}

@media (max-width: 720px) {
  .vnc-tool-group .custom-probe-bar {
    flex-wrap: wrap;
  }

  .card-vnc-stage .card-header {
    flex-wrap: wrap;
  }
}

.vnc-status-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-2) var(--sp-3);
  flex-wrap: wrap;
  padding: 10px var(--sp-3);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border);
}

.vnc-client-box {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(56, 189, 248, 0.06), rgba(167, 139, 250, 0.05)),
    var(--bg-input);
  border: 1px solid var(--border-strong);
}

.vnc-client-head {
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

.vnc-client-head strong {
  font-size: var(--fs-base);
  font-weight: 650;
}

.vnc-client-head strong::before {
  content: "";
  display: inline-block;
  inline-size: 7px;
  block-size: 7px;
  margin-inline-end: 7px;
  border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  vertical-align: 1px;
}

.vnc-client-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

.vnc-client-label {
  min-inline-size: 64px;
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.vnc-client-row code {
  flex: 1 1 200px;
  min-inline-size: 0;
  padding: 4px 9px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--accent);
  word-break: break-all;
}

.vnc-install-log {
  max-block-size: 180px;
  overflow: auto;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: #070b14;
  border: 1px solid var(--border);
  font-size: var(--fs-xs);
  font-family: var(--font-mono);
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-word;
  scrollbar-width: thin;
  overscroll-behavior: contain;
}

.vnc-screen {
  position: relative;
  block-size: clamp(380px, 58dvh, 720px);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-block-size: 380px;
  overflow: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: #05080f;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4) inset;
}

/* ==========================================================================
   Ports & mappings
   ========================================================================== */
.port-table {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-x: auto;
}

.port-row {
  display: grid;
  grid-template-columns: 96px minmax(120px, 1fr) minmax(100px, 1fr) 90px minmax(150px, auto);
  align-items: center;
  gap: var(--sp-2) var(--sp-3);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border);
  font-size: var(--fs-sm);
}

.port-row.proxy-row {
  grid-template-columns: minmax(120px, 1.2fr) 70px 110px minmax(110px, 1fr) 90px minmax(150px, 1fr);
}

.port-row-head {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
  font-size: var(--fs-xs);
  letter-spacing: 0.04em;
  padding-block: 2px;
}

.port-row .port-num {
  font-family: var(--font-mono);
  font-size: var(--fs-md);
  color: var(--accent);
}

.port-row .port-label {
  min-inline-size: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.port-row .port-cell-actions {
  display: flex;
  gap: var(--sp-2);
  justify-content: flex-end;
  flex-wrap: wrap;
}

.port-row.port-empty {
  display: block;
  text-align: center;
  color: var(--text-muted);
  padding: 18px;
}

.allowports-add-bar {
  flex-wrap: wrap;
}

.allowports-add-bar > input {
  flex: 1 1 220px;
}

.allowports-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.allowport-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px 4px 10px;
  border-radius: 999px;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--text-dim);
}

.allowport-chip button {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: var(--fs-md);
  line-height: 1;
  padding: 0 2px;
}

.allowport-chip button:hover {
  color: var(--danger);
}

.allowport-chip.is-conflict {
  border-color: var(--warn-line);
  background: var(--warn-soft);
}

.allowport-chip.is-partial {
  border-style: dashed;
  border-color: var(--warn-line);
}

.allowport-warn {
  font-family: var(--font-sans);
  font-size: var(--fs-xs);
  color: var(--warn);
}

@media (max-width: 900px) {
  .port-row,
  .port-row.proxy-row {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }

  .port-row-head {
    display: none;
  }
}

/* frps service config form */
.frps-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
  gap: var(--sp-3) var(--sp-4);
}

.frps-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-inline-size: 0;
}

.frps-field > span {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-dim);
}

.frps-field > input {
  block-size: 34px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: var(--fs-sm);
  outline: none;
}

.frps-field > input:focus {
  border-color: var(--accent-line);
  box-shadow: var(--ring);
}

.frps-field > input:disabled {
  opacity: 0.6;
}

.frps-field > small {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  line-height: 1.55;
}

.frps-field-wide {
  grid-column: 1 / -1;
}

.frps-inline {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
}

.frps-inline > input {
  flex: 1 1 auto;
  min-inline-size: 0;
  block-size: 34px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
}

.frps-advanced-toggle {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-sm);
  color: var(--text-dim);
  cursor: pointer;
}

.frps-toml {
  inline-size: 100%;
  margin-block-start: var(--sp-2);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: #070b14;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  line-height: 1.55;
  resize: vertical;
}

.frps-toml:disabled {
  opacity: 0.65;
}

.frps-verify-log {
  margin-block-start: var(--sp-2);
  max-block-size: 220px;
  overflow: auto;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  border: 1px solid var(--danger-line);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  white-space: pre-wrap;
}

.frps-save-row {
  align-items: center;
}

/* ==========================================================================
   Toast
   ========================================================================== */
.toast {
  position: fixed;
  inset-block-end: var(--sp-6);
  inset-inline-end: var(--sp-6);
  z-index: 100;
  max-inline-size: min(380px, calc(100% - 32px));
  padding: 10px var(--sp-4);
  border-radius: var(--radius-sm);
  background: rgba(23, 34, 54, 0.96);
  backdrop-filter: blur(10px);
  color: var(--text);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-base);
  animation: toast-in 0.22s var(--ease);
}

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

/* ==========================================================================
   Responsive tweaks
   ========================================================================== */
@media (max-width: 900px) {
  .app-shell {
    padding-inline: var(--sp-3);
  }

  .topbar {
    margin-inline: calc(var(--sp-3) * -1);
    padding-inline: var(--sp-3);
  }

  .subtitle {
    display: none;
  }

  .card {
    padding: var(--sp-4);
  }
}

@media (max-width: 640px) {
  .topbar-actions {
    inline-size: 100%;
  }

  .status-pill {
    order: -1;
  }

  #btn-run-all {
    margin-inline-start: auto;
  }

  .main-tabs {
    inline-size: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .main-tabs::-webkit-scrollbar {
    display: none;
  }

  .main-tab {
    padding-inline: 10px;
    font-size: var(--fs-sm);
  }

  .custom-probe-bar .btn {
    flex: 1 1 auto;
  }

  .toast {
    inset-inline: var(--sp-4);
    inset-block-end: var(--sp-4);
    max-inline-size: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
