:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --neutral-bg: #e5e7eb;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  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.55;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  height: 56px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 700; font-size: 15px; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--primary); display: inline-block; }

.topbar nav { display: flex; gap: 18px; flex: 1; overflow-x: auto; }
.topbar nav a { color: var(--muted); padding: 18px 0; border-bottom: 2px solid transparent; white-space: nowrap; }
.topbar nav a:hover { color: var(--text); text-decoration: none; }
.topbar nav a.active { color: var(--text); border-bottom-color: var(--primary); font-weight: 600; }

.who { display: flex; align-items: center; gap: 10px; color: var(--muted); white-space: nowrap; }

.container { max-width: 1120px; margin: 24px auto 60px; padding: 0 20px; }

.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.page-head h1 { font-size: 22px; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.right { text-align: right; }
.inline { display: inline; margin: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
  overflow-x: auto;
}

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h2 { font-size: 16px; margin: 0; }

.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat { margin: 0; }
.stat-label { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.stat-value { font-size: 22px; font-weight: 700; }
.stat-hint { color: var(--muted); font-size: 12px; margin-top: 6px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.neutral { background: var(--neutral-bg); color: #374151; }

.tag { display: inline-block; padding: 1px 7px; border-radius: 6px; font-size: 12px; background: #f3f4f6; color: #374151; }
.tag-user_conn { background: #dbeafe; color: #1e40af; }
.tag-client_login { background: #dcfce7; color: #166534; }
.tag-login_fail { background: #fee2e2; color: #991b1b; }
.tag-non_tls { background: #fef3c7; color: #92400e; }
.tag-proxy_up { background: #e0e7ff; color: #3730a3; }
.tag-proxy_down, .tag-work_conn_closed { background: #f3f4f6; color: #4b5563; }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert.err { background: var(--bad-bg); color: var(--bad); }

.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 12px; }

.btn {
  display: inline-block;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  line-height: 1.4;
}
.btn:hover { background: #f9fafb; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { background: #b91c1c; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn-link { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 0; }
.btn-link:hover { color: var(--text); }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 9px 10px; border-bottom: 1px solid #f1f3f5; vertical-align: top; }
tr:last-child td { border-bottom: 0; }

label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: #374151; }
input[type="text"], input[type="password"], input[type="number"], select {
  padding: 8px 10px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
  min-width: 0;
}
input:focus, select:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }

.filters { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; }
.filters label { min-width: 150px; flex: 1; }
.filters .btn { height: 38px; }

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-span { grid-column: 1 / -1; display: flex; align-items: center; gap: 14px; }
.hint { color: var(--muted); font-size: 12px; }
.ip-input { min-width: 260px; flex: 1; max-width: 340px; }

/* 端口控制模块 */
.gate-card { overflow: visible; }
.gate-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.gate-head h2 { margin: 0; font-size: 16px; }
.gate-intro { margin: 0 0 14px; }
.gate-state {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
}
.countdown {
  font-size: 30px;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: .02em;
  font-variant-numeric: tabular-nums;
}
.progress {
  height: 8px;
  margin: 14px 0 16px;
  background: #eef2f7;
  border-radius: 999px;
  overflow: hidden;
}
.progress > span {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #2563eb, #60a5fa);
  transition: width .6s linear;
}
.ip-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 12px; }
.ip-chip {
  padding: 4px 12px;
  border-radius: 999px;
  background: #eef2ff;
  color: #3730a3;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.gate-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.gate-actions.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.gate-action {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfcfe;
}
.gate-action h3 { margin: 0; font-size: 14px; }
.gate-action p { margin: 0; color: var(--muted); font-size: 12px; }
.gate-action form { margin-top: auto; }
.gate-action .btn { width: 100%; }
.gate-action.primary { border-color: #bfdbfe; background: #eff6ff; }
.gate-action.warn { border-color: #fecaca; background: #fff5f5; }
.ip-strong { font-weight: 700; color: var(--text); font-size: 14px; word-break: break-all; }
.manual-block { margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--line); }
.manual-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.manual-row { display: flex; gap: 10px; }
.manual-row input { flex: 1; min-width: 0; }
.detect-result { min-height: 18px; margin-top: 6px; color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 14px; }

.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 78vh; }
.login-card { width: 100%; max-width: 380px; }
.login-card h1 { font-size: 22px; margin: 0 0 4px; }
.login-card p { margin-top: 0; }
.login-card code { font-size: 12px; word-break: break-all; }

.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 16px; }

.totp-grid { display: grid; grid-template-columns: 180px 1fr; gap: 24px; align-items: start; }
.qr { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.qr svg { width: 160px; height: 160px; display: block; margin: auto; }
.secret { background: #f3f4f6; padding: 8px 10px; border-radius: 8px; word-break: break-all; }

@media (max-width: 860px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .gate-actions, .gate-actions.two { grid-template-columns: 1fr; }
  .totp-grid { grid-template-columns: 1fr; }
  .page-head { flex-wrap: wrap; }
}

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 2px 12px; }
  .brand { order: 1; }
  .who { order: 2; margin-left: auto; gap: 8px; }
  .who span { display: none; }
  .topbar nav { order: 3; flex: 1 0 100%; gap: 16px; overflow-x: auto; padding: 0; }
  .topbar nav a { padding: 8px 0; font-size: 13px; }
  .container { padding: 0 12px; margin: 14px auto 40px; }
  .page-head { align-items: flex-start; gap: 4px; margin-bottom: 12px; }
  .page-head h1 { font-size: 20px; }
  .card { padding: 14px; border-radius: 10px; }
  .stat-value { font-size: 20px; }
  .stat-hint { font-size: 11px; }
  .countdown { font-size: 26px; }
  .gate-state { gap: 10px; }
  .manual-head { align-items: flex-start; flex-direction: column; }
  .manual-row { flex-direction: column; }
  .manual-row input, .manual-row .btn { width: 100%; }
  .manual-row .btn { min-height: 42px; }
  .detect-result { font-size: 12px; }
  .row { flex-direction: column; align-items: stretch; }
  .row form, .row .btn { width: 100%; }
  .filters { flex-direction: column; align-items: stretch; }
  .filters label { min-width: 0; }
  .filters .btn { width: 100%; height: auto; min-height: 42px; }
  .btn { min-height: 42px; }
  input[type="text"], input[type="password"], input[type="number"], select { font-size: 16px; }
  table { font-size: 12.5px; }
  th, td { padding: 8px 6px; }
  .card { -webkit-overflow-scrolling: touch; }
  .pager { flex-wrap: wrap; }
  .login-card { padding: 18px; }
}
