:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --bg-deep: #eef4f9;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-muted: #f1f5f9;
  --line: #e3eaf2;
  --line-strong: #cbd5e1;
  --text: #0f172a;
  --text-soft: #334155;
  --muted: #52637a;
  --muted-2: #64748b;
  --accent: #0f9f8f;
  --accent-text: #0f766e;
  --accent-strong: #0b6b62;
  --accent-soft: #e8f7f4;
  --accent-line: #b7ebe4;
  --blue: #2563eb;
  --blue-soft: #eff6ff;
  --danger: #dc2626;
  --danger-text: #b91c1c;
  --danger-soft: #fef2f2;
  --amber: #b45309;
  --amber-soft: #fffbeb;
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 6px 18px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 12px 34px rgba(15, 23, 42, 0.07);
  --shadow-lg: 0 30px 80px rgba(15, 23, 42, 0.15);
  --radius: 16px;
  --mono: "SFMono-Regular", "Cascadia Code", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(1000px 560px at 4% -10%, rgba(20, 184, 166, 0.15), transparent 55%),
    radial-gradient(840px 480px at 100% 0%, rgba(59, 130, 246, 0.1), transparent 52%),
    linear-gradient(180deg, #f9fcfd 0%, var(--bg) 44%, #f7f9fc 100%);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(15, 159, 143, 0.18); }

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

a { color: var(--accent-text); text-decoration: none; }
a:hover { color: var(--accent-strong); text-decoration: underline; }

.bg-grid {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(15, 23, 42, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15, 23, 42, 0.035) 1px, transparent 1px);
  background-size: 56px 56px;
  -webkit-mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.8), transparent 76%);
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.8), transparent 76%);
}

.muted { color: var(--muted); }
.small-text { font-size: 12px; }
.eyebrow {
  margin: 0 0 7px;
  color: var(--accent-text);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.2em;
}

/* ---------- 登录 ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  position: relative;
  overflow: hidden;
}

.login-card {
  position: relative;
  width: min(420px, 100%);
  padding: 38px 34px 28px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: linear-gradient(180deg, #ffffff, #fbfdff);
  box-shadow: 0 30px 80px rgba(15, 23, 42, 0.1), 0 4px 14px rgba(15, 23, 42, 0.04);
  animation: rise 0.45s ease both;
}
.login-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: linear-gradient(90deg, #0f766e, #14b8a6 55%, #60a5fa);
}

.logo-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  margin-bottom: 22px;
  border: 1px solid var(--accent-line);
  border-radius: 15px;
  color: var(--accent-text);
  background: linear-gradient(145deg, #ecfdf9, #e0f2fe);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.7), 0 8px 20px rgba(15, 118, 110, 0.08);
}
.logo-mark svg { width: 30px; height: 30px; }

.login-card h1 {
  margin: 0;
  color: var(--text);
  font-size: 28px;
  letter-spacing: -0.03em;
}
.login-sub { margin: 6px 0 26px; font-size: 13px; }
.login-foot {
  margin: 20px 0 0;
  color: var(--muted-2);
  font-size: 11px;
  text-align: center;
}

label {
  display: block;
  margin: 0 0 7px;
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

input, select, textarea {
  width: 100%;
  padding: 11px 12px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
input::placeholder, textarea::placeholder { color: #6b7c93; }
input:hover, select:hover, textarea:hover { border-color: #b8c4d4; }
input:focus, select:focus, textarea:focus {
  background: var(--surface);
  border-color: #14b8a6;
  box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.14);
}
select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, #64748b 50%), linear-gradient(135deg, #64748b 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}
textarea { resize: vertical; min-height: 70px; }
input[type="checkbox"] { width: auto; accent-color: var(--accent); }

#loginForm { display: grid; gap: 12px; }
#loginForm label { margin: 0; }
#loginForm .btn { margin-top: 6px; }

.form-error {
  margin: 2px 0 0;
  padding: 9px 11px;
  color: var(--danger-text);
  background: var(--danger-soft);
  border: 1px solid #fecaca;
  border-radius: 9px;
  font-size: 12px;
}

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 8px 14px;
  color: var(--text-soft);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: var(--shadow-xs);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}
.btn:hover {
  color: var(--text);
  background: var(--surface-soft);
  border-color: #b8c4d4;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.06);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: wait; }
.btn.primary {
  color: #ffffff;
  background: linear-gradient(135deg, #0b5f59, #0f766e 58%, #0f8278);
  border-color: transparent;
  box-shadow: 0 8px 20px rgba(13, 118, 110, 0.2);
}
.btn.primary:hover {
  color: #ffffff;
  background: linear-gradient(135deg, #094f4a, #0b665f 58%, #0c746b);
  border-color: transparent;
  box-shadow: 0 10px 24px rgba(13, 118, 110, 0.26);
}
.btn.ghost { background: rgba(255, 255, 255, 0.72); }
.btn.ghost:hover { background: var(--surface-soft); }
.btn.danger {
  color: var(--danger-text);
  background: var(--surface);
  border-color: #fecaca;
}
.btn.danger:hover { background: var(--danger-soft); border-color: #fca5a5; }
.btn.small { min-height: 30px; padding: 5px 9px; font-size: 12px; }
.btn.wide { width: 100%; }
.plus { font-size: 18px; line-height: 1; margin-top: -1px; }

.icon-btn {
  width: 32px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
  font-size: 14px;
}
.icon-btn:hover { color: var(--text); background: var(--surface-muted); border-color: var(--line); }

.mini-btn {
  padding: 4px 8px;
  color: var(--accent-text);
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  border-radius: 7px;
  cursor: pointer;
  font-size: 11px;
  white-space: nowrap;
}
.mini-btn:hover { color: var(--accent-strong); background: #d9f3ee; }

/* ---------- 框架 ---------- */
.app-shell { min-height: 100vh; animation: fade 0.35s ease both; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px max(22px, calc((100vw - 1180px) / 2));
  background: rgba(255, 255, 255, 0.84);
  border-bottom: 1px solid rgba(226, 232, 240, 0.9);
  box-shadow: 0 1px 12px rgba(15, 23, 42, 0.03);
  backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(15, 159, 143, 0.12);
  flex: none;
}
.brand-name { color: var(--text); font-family: var(--mono); font-size: 13px; font-weight: 800; letter-spacing: 0.16em; }
.brand-sep { color: #b6c2d1; }
.brand-sub { color: var(--muted); font-size: 12px; }
.top-actions { display: flex; align-items: center; gap: 8px; }

.server-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 11px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
}
.server-pill:hover { color: var(--text); border-color: var(--line-strong); background: #ffffff; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: #94a3b8; flex: none; }
.server-pill.ok .dot { background: var(--accent); box-shadow: 0 0 0 3px rgba(15, 159, 143, 0.14); }
.server-pill.bad .dot { background: var(--danger); box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12); }
.server-pill.ok { color: var(--accent-text); border-color: #b7ebe4; background: #effbf8; }
.server-pill.bad { color: var(--danger-text); border-color: #fecaca; background: var(--danger-soft); }

.container {
  width: min(1180px, calc(100% - 44px));
  margin: 0 auto;
  padding: 44px 0 34px;
}

.hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
}
.hero h1 {
  margin: 0;
  color: #0f172a;
  font-size: clamp(30px, 4vw, 42px);
  font-weight: 750;
  line-height: 1.12;
  letter-spacing: -0.045em;
}
.hero-sub { max-width: 580px; margin: 10px 0 0; font-size: 13px; }

.stats {
  display: grid;
  grid-template-columns: 1fr 1.35fr 1.6fr 1.2fr;
  gap: 12px;
  margin-bottom: 20px;
}
.stat {
  position: relative;
  min-width: 0;
  padding: 17px 18px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.stat::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: linear-gradient(90deg, #14b8a6, #60a5fa);
  opacity: 0.7;
}
.stat-label { display: block; margin-bottom: 7px; color: var(--muted); font-size: 11px; }
.stat-value { display: flex; align-items: baseline; gap: 5px; }
.stat-value strong { color: var(--text); font-size: 30px; line-height: 1; letter-spacing: -0.04em; }
.stat-value small { color: var(--muted-2); font-size: 12px; }
.stat-strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); font-family: var(--mono); font-size: 15px; }
.stat-url-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.stat-url {
  display: block;
  overflow: hidden;
  padding: 2px 7px;
  color: var(--accent-text);
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  border-radius: 6px;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
}
.stat-hint { display: block; margin-top: 7px; color: var(--muted-2); font-size: 11px; }

.panel {
  padding: 22px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow-md);
}
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.panel-head h2 { margin: 0; color: var(--text); font-size: 17px; letter-spacing: -0.02em; }
.panel-sub { margin: 4px 0 0; font-size: 12px; }

.tunnel-list { display: grid; gap: 11px; }

.tunnel-card {
  position: relative;
  display: grid;
  gap: 12px;
  padding: 16px 17px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid #cbd5e1;
  border-radius: 13px;
  box-shadow: var(--shadow-xs);
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}
.tunnel-card:hover {
  border-color: #cfdae7;
  box-shadow: 0 3px 10px rgba(15, 23, 42, 0.05), 0 12px 30px rgba(15, 23, 42, 0.04);
  transform: translateY(-1px);
}
.tunnel-card.on { border-left-color: var(--accent); }
.tunnel-card.err { border-left-color: var(--danger); }
.tunnel-card.off { border-left-color: #cbd5e1; }

.tunnel-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.tunnel-head h3 { margin: 0; overflow: hidden; color: var(--text); text-overflow: ellipsis; white-space: nowrap; font-size: 15px; font-weight: 650; letter-spacing: -0.01em; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; flex: none; }
.status-dot.on { background: var(--accent); box-shadow: 0 0 0 3px rgba(15, 159, 143, 0.13); }
.status-dot.err { background: var(--danger); box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1); }
.status-text { color: var(--muted); font-size: 11px; white-space: nowrap; }
.status-text.on { color: var(--accent-text); }
.status-text.err { color: var(--danger-text); }

.badge {
  display: inline-flex;
  align-items: center;
  height: 21px;
  padding: 0 7px;
  color: #52637a;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 10px;
  white-space: nowrap;
}
.badge.public { color: var(--amber); border-color: #fde68a; background: var(--amber-soft); }
.badge.loop { color: #1d4ed8; border-color: #bfdbfe; background: var(--blue-soft); }

.spacer { flex: 1; }

.route {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  color: var(--muted-2);
  font-family: var(--mono);
  font-size: 11px;
}
.route code {
  padding: 2px 7px;
  color: var(--text-soft);
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: var(--mono);
}
.route .arrow { color: var(--accent-text); font-size: 13px; }

.tunnel-url-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.tunnel-url {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  padding: 3px 8px;
  color: var(--accent-text);
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  border-radius: 6px;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 11px;
}
.tunnel-url:hover { color: var(--accent-strong); background: #d9f3ee; text-decoration: none; }
.tunnel-url.empty { color: var(--muted-2); }

.meta-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; color: var(--muted-2); font-size: 11px; }
.meta-row .err-text { max-width: 100%; overflow: hidden; color: var(--danger-text); text-overflow: ellipsis; white-space: nowrap; }

.tunnel-foot { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; padding-top: 2px; }
.tunnel-actions { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.action-btn {
  padding: 5px 9px;
  color: #52637a;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
  font-size: 11px;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.action-btn:hover { color: var(--text); background: var(--surface-soft); border-color: var(--line-strong); }
.action-btn.stop:hover { color: var(--danger-text); background: var(--danger-soft); border-color: #fecaca; }
.action-btn.danger { color: #7f1d1d; }
.action-btn.danger:hover { color: var(--danger-text); background: var(--danger-soft); border-color: #fecaca; }

.switch { position: relative; display: inline-flex; width: 38px; height: 22px; flex: none; }
.switch input { position: absolute; z-index: 1; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.switch span {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #e2e8f0;
  border: 1px solid #cbd5e1;
  transition: background 0.18s ease, border-color 0.18s ease;
}
.switch span::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.2);
  transition: transform 0.18s ease;
}
.switch input:checked + span { background: var(--accent); border-color: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.18); }
.switch-label { color: var(--muted-2); font-size: 10px; }

.empty { padding: 44px 20px 38px; text-align: center; }
.empty-icon {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  margin: 0 auto 12px;
  color: var(--accent-text);
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  border-radius: 15px;
  font-size: 24px;
}
.empty h3 { margin: 0 0 6px; color: var(--text); font-size: 16px; }
.empty p { margin: 0 0 16px; font-size: 12px; }

.footer { display: flex; justify-content: space-between; gap: 12px; padding: 22px 2px 0; color: var(--muted-2); font-family: var(--mono); font-size: 10px; }

/* ---------- 弹窗 ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, 0.32); backdrop-filter: blur(5px); }
.modal-card {
  position: relative;
  width: min(560px, calc(100vw - 30px));
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  padding: 22px;
  background: linear-gradient(180deg, #ffffff, #fbfdff);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  animation: rise 0.22s ease both;
}
.modal-wide { width: min(780px, calc(100vw - 30px)); }
.modal-small { width: min(420px, calc(100vw - 30px)); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 17px; }
.modal-head h2 { margin: 0; color: var(--text); font-size: 20px; letter-spacing: -0.025em; }
.modal-head-actions { display: flex; gap: 5px; align-items: center; }
.modal-card h2 { letter-spacing: -0.02em; }
.modal-card form { display: grid; gap: 11px; }
.modal-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.modal-actions .hint { margin-right: auto; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.form-grid.three { grid-template-columns: 1fr 1fr 1fr; }
.label-hint { color: var(--muted-2); font-weight: 400; }
.check-row { display: flex; align-items: center; gap: 9px; margin: 3px 0; color: var(--text-soft); font-size: 12px; cursor: pointer; }
.check-row input { accent-color: var(--accent); }
.hint { margin: 0; color: var(--muted-2); font-size: 11px; line-height: 1.6; }
.section-title { margin: 2px 0 4px; color: var(--text); font-size: 13px; letter-spacing: 0.01em; }
.rule { margin: 20px 0; border: 0; border-top: 1px solid var(--line); }
.terminal {
  min-height: 360px;
  max-height: 54vh;
  margin: 0;
  padding: 14px;
  overflow: auto;
  color: #334155;
  background:
    linear-gradient(rgba(15, 23, 42, 0.022) 1px, transparent 1px) 0 0 / 100% 24px,
    var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 11px;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.03);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 24px;
  white-space: pre-wrap;
  word-break: break-word;
}
.terminal .log-err { color: var(--danger-text); }

#confirmMessage { margin: 0 0 6px; font-size: 13px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  z-index: 90;
  transform: translateX(-50%) translateY(8px);
  max-width: min(520px, calc(100vw - 36px));
  padding: 10px 16px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.16);
  font-size: 12px;
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { color: var(--danger-text); background: #fff7f7; border-color: #fecaca; }
.toast.ok { color: var(--accent-text); background: #f4fdfb; border-color: var(--accent-line); }

/* ---------- 动画 ---------- */
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- 响应式 ---------- */
@media (max-width: 980px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .stat-wide { grid-column: span 2; }
}
@media (max-width: 680px) {
  .container { width: calc(100% - 28px); padding-top: 28px; }
  .topbar { padding: 12px 14px; flex-wrap: wrap; }
  .brand-sub, .brand-sep { display: none; }
  .top-actions { width: 100%; justify-content: space-between; }
  .server-pill { flex: 1; justify-content: center; }
  .hero { align-items: flex-start; flex-direction: column; gap: 16px; }
  .hero h1 { font-size: 30px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat { padding: 14px; }
  .stat-wide { grid-column: span 2; }
  .panel { padding: 15px; border-radius: 16px; }
  .panel-head { align-items: center; }
  .tunnel-card { padding: 14px; }
  .tunnel-head { flex-wrap: wrap; }
  .form-grid, .form-grid.three { grid-template-columns: 1fr; }
  .modal { padding: 10px; }
  .modal-card { padding: 17px; max-height: calc(100vh - 20px); }
  .footer { flex-direction: column; gap: 5px; }
  .terminal { min-height: 280px; }
}

/* ---------- 紧凑隧道行（表格式） ---------- */
.panel {
  --tunnel-cols: minmax(230px, 1.35fr) minmax(220px, 1fr) minmax(200px, 1.05fr) minmax(285px, auto);
}
.tunnel-list-head {
  display: grid;
  grid-template-columns: var(--tunnel-cols);
  gap: 16px;
  padding: 0 17px 8px;
  color: var(--muted-2);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.tunnel-list { display: flex; flex-direction: column; gap: 8px; }
.tunnel-card {
  display: grid;
  grid-template-columns: var(--tunnel-cols);
  align-items: center;
  gap: 16px;
  min-height: 64px;
  padding: 10px 14px;
  border-radius: 11px;
}
.tunnel-id { display: flex; align-items: flex-start; gap: 9px; min-width: 0; }
.tunnel-id .status-dot { margin-top: 5px; }
.tunnel-id-text { flex: 1; min-width: 0; }
.tunnel-title-row { display: flex; align-items: center; gap: 7px; min-width: 0; }
.tunnel-title-row h3 {
  margin: 0;
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 650;
  line-height: 1.35;
  letter-spacing: -0.01em;
}
.tunnel-title-row .status-text,
.tunnel-title-row .badge { flex: none; }
.tunnel-meta {
  margin-top: 2px;
  overflow: hidden;
  color: var(--muted-2);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10px;
  line-height: 1.4;
}
.tunnel-meta.warn { color: var(--amber); }
.tunnel-route {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  overflow: hidden;
  color: var(--muted-2);
  font-family: var(--mono);
  font-size: 10px;
  white-space: nowrap;
}
.tunnel-route code { padding: 2px 5px; font-size: 10px; }
.tunnel-route .arrow { flex: none; color: var(--accent-text); font-size: 12px; }
.tunnel-endpoint { display: flex; align-items: center; gap: 6px; min-width: 0; }
.tunnel-endpoint .tunnel-url { min-width: 0; padding: 3px 7px; font-size: 10px; }
.tunnel-endpoint .mini-btn { flex: none; padding: 3px 6px; font-size: 10px; }
.tunnel-controls { display: flex; align-items: center; justify-content: flex-end; gap: 7px; min-width: 0; }
.tunnel-controls .switch { width: 34px; height: 20px; }
.tunnel-controls .switch span::after { width: 14px; height: 14px; }
.tunnel-controls .switch input:checked + span::after { transform: translateX(14px); }
.tunnel-controls .switch-label { font-size: 10px; }
.tunnel-controls .tunnel-actions { margin-left: 3px; gap: 4px; flex-wrap: nowrap; }
.tunnel-controls .action-btn { padding: 4px 7px; font-size: 10px; }
.tunnel-error {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  margin-top: -2px;
  padding: 5px 8px;
  color: var(--danger-text);
  background: var(--danger-soft);
  border: 1px solid #fecaca;
  border-radius: 7px;
  font-size: 10px;
}
.tunnel-error span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.error-mark {
  width: 14px;
  height: 14px;
  display: inline-grid;
  place-items: center;
  flex: none;
  border-radius: 50%;
  background: #fee2e2;
  font-size: 9px;
  font-weight: 700;
}

@media (max-width: 1100px) {
  .tunnel-list-head { display: none; }
  .tunnel-card {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "id controls"
      "route endpoint";
    align-items: start;
    gap: 6px 14px;
    padding: 12px 14px;
  }
  .tunnel-id { grid-area: id; }
  .tunnel-controls { grid-area: controls; align-self: center; }
  .tunnel-route { grid-area: route; align-self: center; }
  .tunnel-endpoint { grid-area: endpoint; justify-self: end; align-self: center; }
  .tunnel-error { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
  .tunnel-card {
    grid-template-columns: 1fr;
    grid-template-areas:
      "id"
      "route"
      "endpoint"
      "controls";
    gap: 7px;
  }
  .tunnel-route { flex-wrap: wrap; white-space: normal; }
  .tunnel-endpoint { justify-self: start; }
  .tunnel-controls { justify-content: flex-start; flex-wrap: wrap; }
  .tunnel-controls .tunnel-actions { flex-wrap: wrap; }
  .tunnel-error { grid-column: 1; }
}
