:root {
  --bg: #0b1220;
  --bg2: #111a2e;
  --card: #151f36;
  --line: #243250;
  --text: #e8eefc;
  --muted: #8fa3c8;
  --primary: #4f8cff;
  --primary2: #3b6fd9;
  --ok: #3ecf8e;
  --bad: #ff6b7a;
  --warn: #f0b429;
  --shadow: 0 10px 40px rgba(0,0,0,.35);
  --radius: 14px;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, #1a2b55 0%, transparent 50%),
    radial-gradient(900px 500px at 100% 0%, #1a3d3a 0%, transparent 45%),
    var(--bg);
  min-height: 100vh;
}
.hidden { display: none !important; }
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card { width: min(420px, 100%); }
.brand { text-align: center; margin-bottom: 18px; }
.brand h1 { margin: 10px 0 6px; font-size: 1.4rem; }
.brand p { margin: 0; color: var(--muted); font-size: .92rem; }
.logo {
  width: 56px; height: 56px; margin: 0 auto;
  display: grid; place-items: center;
  border-radius: 16px;
  background: linear-gradient(135deg, #4f8cff, #39c5bb);
  font-weight: 800; letter-spacing: .5px;
  box-shadow: var(--shadow);
}
.logo-sm {
  width: 32px; height: 32px; display:inline-grid; place-items:center;
  border-radius: 10px; background: linear-gradient(135deg, #4f8cff, #39c5bb);
  font-size: 12px; font-weight: 800; margin-right: 8px;
}
.card {
  background: color-mix(in srgb, var(--card) 92%, white 0%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
label { display: block; font-size: .9rem; color: var(--muted); margin: 10px 0; }
input, select, textarea {
  width: 100%;
  margin-top: 6px;
  background: var(--bg2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
.btn {
  border: 1px solid var(--line);
  background: var(--bg2);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
  font-weight: 600;
}
.btn:hover { border-color: var(--primary); }
.btn.primary { background: linear-gradient(135deg, var(--primary), var(--primary2)); border: none; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; margin-top: 12px; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.error { color: var(--bad); min-height: 1.2em; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-all; }
.box { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; overflow: auto; }
.mt { margin-top: 12px; }
#main-view { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  border-right: 1px solid var(--line);
  background: rgba(10, 16, 30, .7);
  backdrop-filter: blur(8px);
  padding: 18px 12px;
  display: flex; flex-direction: column; gap: 8px;
  position: sticky; top: 0; height: 100vh;
}
.brand-sm { display:flex; align-items:center; font-weight:700; padding: 8px 10px 16px; }
.sidebar nav { display:flex; flex-direction:column; gap:6px; flex:1; }
.nav {
  text-align:left; border: none; background: transparent; color: var(--muted);
  padding: 10px 12px; border-radius: 10px; cursor: pointer; font-weight: 600;
}
.nav.active, .nav:hover { background: rgba(79,140,255,.12); color: var(--text); }
.content { padding: 20px 24px 40px; }
.topbar { display:flex; justify-content:space-between; align-items:center; margin-bottom: 16px; }
.topbar h2 { margin: 0; }
.top-actions { display:flex; gap:10px; align-items:center; }
.badge {
  font-size: 12px; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted);
}
.badge.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 50%, var(--line)); }
.badge.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 50%, var(--line)); }
.stats { display:grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px;
}
.stat .k { color: var(--muted); font-size: .85rem; }
.stat .v { font-size: 1.35rem; font-weight: 700; margin-top: 6px; }
.grid-2 { display:grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row { display:flex; gap:10px; flex-wrap:wrap; align-items:end; }
.form-row .grow, .grow { flex: 1; min-width: 180px; }
.stack { display:flex; flex-direction:column; gap:10px; }
.toolbar { display:flex; gap:10px; flex-wrap:wrap; margin-bottom: 12px; }
.table-wrap { overflow:auto; width: 100%; }
table { width:100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align:left; vertical-align: middle; }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
tr:hover td { background: rgba(255,255,255,.02); }

/* === data tables (主订阅/子订阅) === */
table.data-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
}
.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: color-mix(in srgb, var(--card) 92%, #0b1220 8%);
  border-bottom: 1px solid var(--line);
  padding: 12px 12px;
  font-size: .82rem;
  letter-spacing: .02em;
  color: var(--muted);
}
.data-table tbody td {
  padding: 14px 12px;
  vertical-align: middle;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 85%, transparent);
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table .col-id { width: 64px; text-align: center; }
.data-table .col-name { width: auto; }
.data-table .col-nodes { width: 88px; text-align: center; }
.data-table .col-time { width: 168px; text-align: left; }
.data-table .col-status { width: 96px; text-align: center; }
.data-table .col-actions { width: 168px; text-align: right; }
.data-table th.col-id,
.data-table th.col-nodes,
.data-table th.col-status { text-align: center; }
.data-table th.col-actions { text-align: right; }
.id-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  border-radius: 8px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--line);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: .85rem;
}
.cell-name {
  font-weight: 700;
  line-height: 1.35;
  margin: 0 0 4px;
  word-break: break-word;
}
.cell-url {
  color: var(--muted);
  font-size: .8rem;
  line-height: 1.35;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.num-cell {
  display: inline-block;
  min-width: 2ch;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.time-cell {
  display: inline-block;
  white-space: nowrap;
  color: var(--text);
  font-size: .86rem;
  font-variant-numeric: tabular-nums;
}
.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid var(--line);
  line-height: 1.2;
}
.status-pill.ok {
  color: var(--ok);
  background: rgba(62,207,142,.12);
  border-color: rgba(62,207,142,.3);
}
.status-pill.bad {
  color: var(--bad);
  background: rgba(255,107,122,.12);
  border-color: rgba(255,107,122,.3);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: nowrap;
  width: 100%;
}
.btn.btn-sm {
  padding: 7px 12px;
  font-size: .86rem;
  white-space: nowrap;
  line-height: 1.2;
}
.master-table .col-name { min-width: 0; }
@media (max-width: 900px) {
  .data-table { table-layout: auto; min-width: 720px; }
}
.latency-ok { color: var(--ok); }
.latency-mid { color: var(--warn); }
.latency-bad { color: var(--bad); }
.picker {
  max-height: 220px; overflow:auto; border: 1px solid var(--line); border-radius: 10px;
  padding: 8px; background: var(--bg2);
  display:grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px;
}
.picker label { margin:0; color: var(--text); font-size: .86rem; display:flex; gap:8px; align-items:flex-start; }
.picker input { width:auto; margin: 3px 0 0; }
#toast {
  position: fixed; right: 16px; bottom: 16px; z-index: 50;
  display:flex; flex-direction:column; gap:8px;
}
.toast-item {
  background: var(--card); border: 1px solid var(--line); color: var(--text);
  padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); min-width: 200px;
}
.toast-item.bad { border-color: var(--bad); }
.toast-item.ok { border-color: var(--ok); }
@media (max-width: 900px) {
  #main-view { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .grid-2 { grid-template-columns: 1fr; }
}

/* === node cards === */
.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  align-items: center;
  padding: 12px 14px;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(8px);
}
.toolbar #node-q {
  flex: 1;
  min-width: 180px;
  margin: 0;
}
.toolbar .count-chip {
  font-size: 12px;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg2);
  white-space: nowrap;
}
.toolbar .btn-group { display: flex; gap: 8px; flex-wrap: wrap; }
.node-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
}
.node-card {
  position: relative;
  background: linear-gradient(165deg, rgba(79,140,255,.08), transparent 42%), var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 14px 12px;
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
  overflow: visible;
}
.node-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(79,140,255,.55), transparent);
  opacity: .7;
}
.node-card:hover {
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--primary) 45%, var(--line));
  box-shadow: 0 14px 32px rgba(0,0,0,.28);
}
.node-card {
  cursor: pointer;
  user-select: none;
}
.node-card.selected {
  border-color: #4f8cff;
  background:
    linear-gradient(165deg, rgba(79,140,255,.22), rgba(57,197,187,.08) 45%, transparent 70%),
    var(--card);
  box-shadow:
    0 0 0 2px rgba(79,140,255,.55),
    0 12px 28px rgba(79,140,255,.18),
    0 14px 32px rgba(0,0,0,.28);
  transform: translateY(-1px);
}
.node-card.selected::after {
  content: "✓";
  position: absolute;
  top: 10px;
  right: 10px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, #4f8cff, #39c5bb);
  box-shadow: 0 4px 12px rgba(79,140,255,.45);
  z-index: 2;
}
.node-card.selected .node-name { color: #dce9ff; }
.node-card.selected .latency-badge { margin-right: 26px; }
.node-check {
  width: 18px;
  height: 18px;
  margin: 3px 0 0;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
  pointer-events: auto;
}
.node-card.disabled-node { opacity: .62; filter: saturate(.75); }
.node-card-top { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 10px; }

.node-title-wrap { flex: 1; min-width: 0; }
.node-name {
  font-weight: 700; font-size: .95rem; line-height: 1.35;
  word-break: break-word; margin: 0 0 6px;
}
.node-meta-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 700; letter-spacing: .02em;
  padding: 3px 8px; border-radius: 999px;
  border: 1px solid var(--line); background: rgba(255,255,255,.03);
  color: var(--muted); text-transform: uppercase;
}
.pill.type-ss { color: #7dd3fc; border-color: rgba(125,211,252,.35); background: rgba(125,211,252,.08); }
.pill.type-vmess { color: #c4b5fd; border-color: rgba(196,181,253,.35); background: rgba(196,181,253,.08); }
.pill.type-vless { color: #6ee7b7; border-color: rgba(110,231,183,.35); background: rgba(110,231,183,.08); }
.pill.type-trojan { color: #fca5a5; border-color: rgba(252,165,165,.35); background: rgba(252,165,165,.08); }
.pill.type-hysteria2, .pill.type-hy2 { color: #fcd34d; border-color: rgba(252,211,77,.35); background: rgba(252,211,77,.08); }
.pill.type-tuic { color: #f9a8d4; border-color: rgba(249,168,212,.35); background: rgba(249,168,212,.08); }
.latency-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-weight: 800; font-size: 12px; padding: 5px 10px;
  border-radius: 999px; border: 1px solid transparent;
  white-space: nowrap; font-variant-numeric: tabular-nums; flex-shrink: 0;
}
.latency-badge .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor; box-shadow: 0 0 8px currentColor;
}
.latency-badge.ok { color: var(--ok); background: rgba(62,207,142,.12); border-color: rgba(62,207,142,.3); }
.latency-badge.mid { color: var(--warn); background: rgba(240,180,41,.12); border-color: rgba(240,180,41,.3); }
.latency-badge.bad { color: var(--bad); background: rgba(255,107,122,.12); border-color: rgba(255,107,122,.3); }
.latency-badge.na { color: var(--muted); background: rgba(143,163,200,.08); border-color: var(--line); }
.node-body {
  display: grid; gap: 8px; padding: 10px 0 4px;
  border-top: 1px dashed color-mix(in srgb, var(--line) 80%, transparent);
  border-bottom: 1px dashed color-mix(in srgb, var(--line) 80%, transparent);
  margin-bottom: 10px;
}
.node-row { display: flex; justify-content: space-between; gap: 10px; font-size: .84rem; }
.node-row .k { color: var(--muted); flex-shrink: 0; }
.node-row .v {
  color: var(--text); text-align: right;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  word-break: break-all;
}
.node-footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.switch { position: relative; width: 42px; height: 24px; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; cursor: pointer; inset: 0;
  background: #2a3654; border: 1px solid var(--line);
  border-radius: 999px; transition: .2s;
}
.switch .slider:before {
  content: ""; position: absolute; height: 18px; width: 18px;
  left: 2px; top: 2px; background: #c9d6f0; border-radius: 50%; transition: .2s;
}
.switch input:checked + .slider {
  background: linear-gradient(135deg, #3ecf8e, #2aa86c); border-color: transparent;
}
.switch input:checked + .slider:before { transform: translateX(18px); background: white; }
.enable-label {
  display: flex; align-items: center; gap: 8px;
  color: var(--muted); font-size: .82rem; margin: 0;
}
.node-empty {
  text-align: center; padding: 48px 20px; color: var(--muted);
  border: 1px dashed var(--line); border-radius: 16px; background: rgba(255,255,255,.02);
}
.node-empty strong { display:block; color: var(--text); margin-bottom: 8px; font-size: 1.05rem; }
.card.nodes-card { padding: 14px; background: transparent; border: none; box-shadow: none; }

/* 添加主订阅表单对齐 */
#master-form.form-row { align-items: center; }
#master-form input[name="name"] {
  width: 160px;
  min-width: 140px;
  flex: 0 0 160px;
  margin-top: 0;
}
#master-form input[name="url"] {
  margin-top: 0;
  min-width: 240px;
}
#master-form .btn { flex: 0 0 auto; white-space: nowrap; }

/* === dashboard usage === */
.card-head { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:12px; }
.card-head h3 { margin: 0; }
.usage-list { display: grid; gap: 12px; }
.usage-card {
  border: 1px solid var(--line); border-radius: 14px; padding: 14px;
  background: linear-gradient(145deg, rgba(79,140,255,.06), transparent 50%), var(--bg2);
}
.usage-card-top { display:flex; justify-content:space-between; gap:12px; align-items:flex-start; margin-bottom:10px; }
.usage-title { font-weight:750; font-size:1rem; margin:0 0 4px; }
.usage-sub { color: var(--muted); font-size:.82rem; }
.usage-tags { display:flex; flex-wrap:wrap; gap:6px; justify-content:flex-end; }
.status-pill { font-size:11px; font-weight:800; padding:4px 9px; border-radius:999px; border:1px solid var(--line); }
.status-pill.active { color: var(--ok); border-color: rgba(62,207,142,.35); background: rgba(62,207,142,.1); }
.status-pill.disabled { color: var(--muted); }
.status-pill.expired, .status-pill.exhausted, .status-pill.error {
  color: var(--bad); border-color: rgba(255,107,122,.35); background: rgba(255,107,122,.1);
}
.status-pill.warn { color: var(--warn); border-color: rgba(240,180,41,.35); background: rgba(240,180,41,.1); }
.usage-metrics { display:grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap:10px; margin:10px 0 12px; }
.metric { background: rgba(255,255,255,.03); border:1px solid rgba(255,255,255,.04); border-radius:10px; padding:8px 10px; }
.metric .mk { color: var(--muted); font-size:.75rem; margin-bottom:4px; }
.metric .mv { font-weight:700; font-size:.92rem; font-variant-numeric: tabular-nums; }
.progress { height:8px; border-radius:999px; background: rgba(255,255,255,.06); overflow:hidden; border:1px solid rgba(255,255,255,.04); }
.progress > i { display:block; height:100%; width:0; border-radius:inherit; background: linear-gradient(90deg,#4f8cff,#39c5bb); transition: width .25s ease; }
.progress.high > i { background: linear-gradient(90deg,#f0b429,#ff6b7a); }
.progress.full > i { background: linear-gradient(90deg,#ff6b7a,#ff3b4e); }
.progress-meta { display:flex; justify-content:space-between; gap:8px; margin-top:6px; color:var(--muted); font-size:.78rem; font-variant-numeric: tabular-nums; }
.notice-list { margin-top:10px; display:flex; flex-wrap:wrap; gap:6px; }
.notice-chip { font-size:12px; color:#d7e6ff; background:rgba(79,140,255,.12); border:1px solid rgba(79,140,255,.22); border-radius:999px; padding:4px 10px; }
.usage-empty { color:var(--muted); text-align:center; padding:22px 10px; border:1px dashed var(--line); border-radius:12px; }

.metric-remain .mv.highlight { color:#6ee7b7; font-size:1.08rem; }

/* nodes toolbar: keep count + select-all on one line */
.toolbar {
  flex-wrap: nowrap;
  align-items: center;
}
.toolbar #node-q {
  flex: 1 1 auto;
  min-width: 140px;
}
.toolbar-meta {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  white-space: nowrap;
}
.toolbar .count-chip {
  white-space: nowrap;
  flex-shrink: 0;
}
.toolbar .select-all-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 !important;
  color: var(--muted);
  font-size: .86rem;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
  user-select: none;
}
.toolbar .select-all-label input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--primary);
  flex-shrink: 0;
}
.toolbar .btn-group {
  flex: 0 0 auto;
  flex-wrap: nowrap;
}
@media (max-width: 900px) {
  .toolbar { flex-wrap: wrap; }
}


.region-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
}
.region-chip {
  border: 1px solid var(--line);
  background: var(--bg2);
  color: var(--text);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.region-chip span {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.region-chip.active {
  border-color: #4f8cff;
  background: rgba(79,140,255,.18);
  color: #dce9ff;
}
.region-section { margin-bottom: 18px; }
.region-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 4px 2px 10px;
}
.region-head h3 {
  margin: 0;
  font-size: 15px;
}
.region-head span { color: var(--muted); font-size: 12px; }
.picker-region {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 10px;
}
.picker-region-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
