:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #fafbfc;
  --border: #e3e6ea;
  --text: #1c1f23;
  --muted: #7a828c;
  --accent: #d33a31;
  --accent-soft: #fdeceb;
  --ok: #1f9254;
  --ok-soft: #e8f6ee;
  --warn: #b8770a;
  --warn-soft: #fdf3e2;
  --err: #c62828;
  --err-soft: #fdecea;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 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;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--muted); font-size: 12px; }
.hidden { display: none !important; }
.mono { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; }

/* ---------- login ---------- */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #fdeceb 0%, #f5f6f8 45%, #eef1f5 100%);
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 26px 26px;
  box-shadow: 0 12px 32px rgba(16, 24, 40, .08);
}

.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700;
}
.brand h1 { font-size: 17px; }
.brand p { font-size: 12px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field textarea { resize: vertical; min-height: 84px; font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #bd3129; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--err); border-color: #f3c9c5; }
.btn.danger:hover { background: var(--err-soft); }
.btn.block { width: 100%; padding: 10px; font-size: 14px; }
.btn.sm { padding: 4px 9px; font-size: 12px; border-radius: 6px; }

.error { color: var(--err); font-size: 12px; min-height: 18px; margin-top: 10px; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1280px; margin: 0 auto; padding: 10px 20px;
  display: flex; align-items: center; gap: 14px;
}
.topbar .brand-mark { width: 32px; height: 32px; border-radius: 9px; font-size: 16px; }
.topbar h1 { font-size: 15px; }
.spacer { flex: 1; }

.tabs { display: flex; gap: 4px; }
.tab {
  padding: 6px 12px; border-radius: 8px; font-size: 13px;
  color: var(--muted); cursor: pointer; border: 1px solid transparent;
}
.tab:hover { background: var(--panel-2); }
.tab.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.container { max-width: 1280px; margin: 0 auto; padding: 20px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px; border-bottom: 1px solid var(--border);
}
.card-head h2 { font-size: 14px; }
.card-body { padding: 16px; }

.summary-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin-bottom: 16px;
}
.stat {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 15px; box-shadow: var(--shadow);
}
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 22px; font-weight: 600; margin-top: 3px; font-variant-numeric: tabular-nums; }
.stat .value small { font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 3px; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; font-weight: 600; font-size: 12px; color: var(--muted);
  padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
  background: var(--panel-2);
}
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--panel-2); }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.center { text-align: center; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 7px; border-radius: 20px; font-size: 11px; font-weight: 500;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--border);
  white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: #c8e6d4; }
.badge.run { background: #e8f0fe; color: #1a56c4; border-color: #cddcf8; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: #f0dcb8; }
.badge.err { background: var(--err-soft); color: var(--err); border-color: #f5cfcb; }

.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; display: inline-block; }
.dot.pulse { animation: pulse 1.4s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }

.acct-name { font-weight: 600; }
.acct-sub { font-size: 11px; color: var(--muted); }

.row-actions { display: flex; gap: 5px; flex-wrap: wrap; }

/* ---------- log ---------- */
.log-view {
  background: #16181c; color: #d6dae0;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px; line-height: 1.65;
  padding: 14px 16px; border-radius: 8px;
  max-height: 480px; overflow: auto; white-space: pre-wrap; word-break: break-word;
}
.log-view .ok { color: #6ee7a8; }
.log-view .err { color: #ff8f85; }

/* ---------- modal ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(16, 24, 40, .38);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 60;
}
.modal {
  background: var(--panel); border-radius: 12px; width: 100%; max-width: 560px;
  max-height: 88vh; display: flex; flex-direction: column;
  box-shadow: 0 20px 44px rgba(16, 24, 40, .2);
}
.modal.wide { max-width: 820px; }
.modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 15px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 15px; flex: 1; }
.modal-body { padding: 18px; overflow: auto; }
.modal-foot {
  padding: 13px 18px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: flex-end;
}
.icon-btn {
  border: none; background: transparent; font-size: 18px; line-height: 1;
  color: var(--muted); cursor: pointer; padding: 2px 6px; border-radius: 6px;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }

.steps { counter-reset: step; padding: 0; margin: 0 0 16px; list-style: none; }
.steps li {
  counter-increment: step; position: relative;
  padding-left: 26px; margin-bottom: 9px; font-size: 13px;
}
.steps li::before {
  content: counter(step);
  position: absolute; left: 0; top: 1px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}

.hint {
  background: var(--warn-soft); border: 1px solid #f0dcb8;
  border-radius: 8px; padding: 10px 12px; font-size: 12px; color: #7d5106;
  margin-bottom: 14px;
}

.toast-wrap {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 90; align-items: center;
}
.toast {
  background: #1c1f23; color: #fff; padding: 9px 16px; border-radius: 8px;
  font-size: 13px; box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
  animation: rise .2s ease-out;
}
.toast.err { background: var(--err); }
.toast.ok { background: var(--ok); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.search {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; font-family: inherit; outline: none; width: 180px;
}
.search:focus { border-color: var(--accent); }

.checkbox-cell { width: 34px; }
input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }

.empty {
  padding: 48px 20px; text-align: center; color: var(--muted); font-size: 13px;
}
.empty strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 6px; }

.proxy-grid {
  display: grid; gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
}
.proxy-item {
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
  font-size: 12px; background: var(--panel-2);
}
.proxy-item .port { font-weight: 600; font-variant-numeric: tabular-nums; }
.proxy-item.ok { border-color: #c8e6d4; background: var(--ok-soft); }
.proxy-item.bad { border-color: #f5cfcb; background: var(--err-soft); }

.spark { display: flex; align-items: flex-end; gap: 3px; height: 54px; }
.spark .bar { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .8; }
.spark .bar.zero { background: var(--border); }

@media (max-width: 720px) {
  .container { padding: 12px; }
  .topbar-inner { padding: 9px 12px; flex-wrap: wrap; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .hide-sm { display: none; }
}

/* ---------- segmented control ---------- */
.seg {
  display: flex; gap: 4px; padding: 3px;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 9px; margin-bottom: 18px;
}
.seg-item {
  flex: 1; text-align: center; padding: 7px 10px;
  border-radius: 7px; font-size: 13px; color: var(--muted); cursor: pointer;
  transition: background .15s, color .15s;
}
.seg-item:hover { color: var(--text); }
.seg-item.active {
  background: var(--panel); color: var(--accent); font-weight: 600;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .08);
}
