:root {
  --bg: #0f1117;
  --surface: #181b24;
  --surface-2: #1f232f;
  --border: #2a2f3c;
  --text: #e6e8ee;
  --muted: #8b91a1;
  --primary: #5b8cff;
  --primary-hover: #4a7bf0;
  --green: #34c759;
  --red: #ff453a;
  --amber: #ff9f0a;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.hidden { display: none !important; }

/* Login */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 40px 36px;
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-card h1 { font-size: 24px; text-align: center; }
.login-card .subtitle { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.login-card input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--text);
  font-size: 14px;
}
.login-card input:focus { outline: none; border-color: var(--primary); }
.pass-wrap { position: relative; display: flex; }
.pass-wrap input { flex: 1; padding-right: 40px; }
.pass-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  background: none; border: none; font-size: 18px; cursor: pointer;
  padding: 6px; line-height: 1; opacity: 0.5; transition: opacity .15s;
}
.pass-toggle:hover { opacity: 1; }

/* Buttons */
button { cursor: pointer; font-size: 14px; border-radius: 8px; border: none; }
.btn-primary { background: var(--primary); color: #fff; padding: 10px 16px; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--muted); padding: 8px 14px; border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); }
.login-card button[type="submit"] { background: var(--primary); color: #fff; padding: 11px; }

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 600; font-size: 18px; }
.top-right { display: flex; align-items: center; gap: 14px; }
.top-right #whoami { color: var(--muted); font-size: 13px; }

.badge { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); }
.badge.up { color: var(--green); border-color: var(--green); }
.badge.down { color: var(--red); border-color: var(--red); }

.container { max-width: 1100px; margin: 0 auto; padding: 24px; }

/* Stat cards */
.cards { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 24px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.card-label { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.card-value { font-size: 22px; font-weight: 600; }

/* Panels */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px; margin-bottom: 24px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.panel-head h2 { font-size: 16px; font-weight: 600; }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
tbody tr:hover { background: var(--surface-2); }

.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.status-dot.on { background: var(--green); }
.status-dot.off { background: var(--muted); }
.status-dot.online { background: var(--green); box-shadow: 0 0 6px var(--green); }

.row-actions { display: flex; gap: 6px; }
.row-actions button { padding: 5px 9px; font-size: 12px; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.row-actions button:hover { border-color: var(--primary); }
.row-actions button.danger:hover { border-color: var(--red); color: var(--red); }

.usage-bar { width: 90px; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 3px; }
.usage-bar > span { display: block; height: 100%; background: var(--primary); }
.usage-bar.warn > span { background: var(--amber); }
.usage-bar.over > span { background: var(--red); }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 24px; width: 440px; max-width: 92vw; }
.modal-card h3 { margin-bottom: 16px; }
.modal-card label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.modal-card input { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; color: var(--text); font-size: 14px; }
.modal-card input:focus { outline: none; border-color: var(--primary); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

.config-modal-wide { width: 640px; max-width: 95vw; }
.config-loading, .config-error { text-align: center; color: var(--muted); padding: 24px; font-size: 14px; }
.config-error { color: var(--red); }
.config-list { max-height: 70vh; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.cfg-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.cfg-item-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.cfg-node-name { font-weight: 600; font-size: 14px; color: var(--text); }
.cfg-tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(91,140,255,.15);
  color: var(--primary);
  border: 1px solid rgba(91,140,255,.3);
}
.cfg-endpoint { font-size: 12px; color: var(--muted); margin-left: auto; font-family: "SF Mono", Menlo, Consolas, monospace; }
.cfg-item-body { display: flex; gap: 14px; padding: 12px 14px; align-items: flex-start; }
.cfg-qr { width: 130px; height: 130px; border-radius: 8px; background: #fff; padding: 5px; flex-shrink: 0; }
.cfg-text {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 11px;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 200px;
  overflow: auto;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  color: var(--muted);
  margin: 0;
}
.cfg-item-actions { padding: 8px 14px 12px; display: flex; gap: 8px; justify-content: flex-end; }
.cfg-dl-btn { display: inline-block; text-decoration: none; font-size: 13px; padding: 8px 16px; }

/* old single config (kept for admin) */
.config-body { display: flex; gap: 16px; align-items: flex-start; }
.qr { width: 180px; height: 180px; border-radius: 8px; background: #fff; padding: 6px; }
#config-text { flex: 1; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; font-size: 12px; white-space: pre-wrap; word-break: break-all; max-height: 260px; overflow: auto; font-family: "SF Mono", Menlo, Consolas, monospace; }

.error { color: var(--red); font-size: 13px; text-align: center; }

/* Register / login switch link */
.switch-line { text-align: center; font-size: 13px; color: var(--muted); margin-top: 4px; }
.switch-line a { color: var(--primary); text-decoration: none; }
.switch-line a:hover { text-decoration: underline; }

/* Step bar */
.step-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  position: relative;
}
.step-bar::before {
  content: "";
  position: absolute;
  top: 21px; left: 30px; right: 30px;
  height: 2px;
  background: var(--border);
  z-index: 0;
}
.step-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex: 1;
  position: relative;
  z-index: 1;
}
.step-dot {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 2px solid var(--border);
  color: var(--muted);
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.step-label {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  white-space: nowrap;
}
.step-label .qq-inline { color: var(--primary); font-weight: 700; font-size: 13px; }
@media (max-width: 600px) {
  .step-bar { flex-wrap: wrap; gap: 12px; }
  .step-bar::before { display: none; }
  .step-item { flex: 0 0 45%; }
}

/* Empty hint */
.empty-hint { color: var(--muted); font-size: 14px; padding: 16px; background: var(--surface-2); border-radius: 8px; margin-bottom: 12px; }
.empty-hint strong { color: var(--primary); }

/* Region selector (portal) */
.region-hint { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.region-selector { display: flex; gap: 10px; flex-wrap: wrap; }
.region-chip {
  padding: 10px 22px;
  background: var(--surface-2);
  border: 2px solid var(--border);
  border-radius: 12px;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all .15s;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}
.region-chip:hover { border-color: var(--primary); color: var(--text); }
.region-chip.active { border-color: var(--primary); color: var(--primary); background: rgba(91,140,255,.1); }
.region-check { font-size: 12px; font-weight: 700; }
.region-saved { font-size: 12px; color: var(--green); }

/* Selection summary panel */
.selection-body { }
.selection-row { display: flex; gap: 14px; flex-wrap: wrap; }
.sel-block {
  flex: 1;
  min-width: 220px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: border-color .15s;
}
.sel-block:hover { border-color: var(--primary); }
.sel-label { font-size: 13px; color: var(--muted); white-space: nowrap; flex-shrink: 0; }
.sel-content { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; flex: 1; }
.sel-empty { color: var(--muted); font-size: 13px; }
.sel-tag {
  display: inline-block;
  padding: 3px 10px;
  background: rgba(91,140,255,.12);
  color: var(--primary);
  border: 1px solid rgba(91,140,255,.25);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
}
.sel-plan-name { font-size: 14px; font-weight: 600; color: var(--text); }
.sel-plan-row { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.sel-plan-cycle {
  font-size: 11px;
  padding: 1px 7px;
  background: rgba(52,199,89,.12);
  color: var(--green);
  border: 1px solid rgba(52,199,89,.25);
  border-radius: 4px;
  white-space: nowrap;
}
.sel-plan-meta { display: flex; gap: 14px; flex-wrap: wrap; }
.sel-plan-data, .sel-plan-expiry { font-size: 12px; color: var(--muted); }
.sel-plan-expiry { color: var(--amber); }
.sel-action { flex-shrink: 0; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* Download grid (portal) */
.download-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.download-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  transition: border-color .15s;
}
.download-card:hover { border-color: var(--primary); }
.download-card .dl-platform { font-size: 18px; font-weight: 600; }
.download-card .dl-icon { font-size: 32px; }
.download-card .dl-btn {
  display: inline-block;
  padding: 8px 18px;
  background: var(--primary);
  color: #fff;
  border-radius: 8px;
  text-decoration: none;
  font-size: 13px;
  margin-top: 4px;
  transition: background .15s;
}
.download-card .dl-btn:hover { background: var(--primary-hover); }
.download-card .dl-btn.store { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); }
.download-card .dl-btn.store:hover { border-color: var(--primary); }
.download-card .dl-btn.disabled { background: var(--surface-2); color: var(--muted); cursor: not-allowed; opacity: 0.5; }
.download-card .dl-note { font-size: 11px; color: var(--muted); }

/* Cycle tabs (segmented control) */
.cycle-tabs { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.cycle-tab { background: transparent; color: var(--muted); padding: 6px 14px; font-size: 13px; border-radius: 7px; transition: background .15s, color .15s; }
.cycle-tab:hover { color: var(--text); }
.cycle-tab.active { background: var(--primary); color: #fff; }

/* Plan cards */
.plan-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; }
.plan-card {
  position: relative;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform .15s, border-color .15s, box-shadow .15s;
}
.plan-card:hover { transform: translateY(-3px); border-color: var(--primary); }
.plan-card.recommended {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary), 0 8px 24px rgba(91, 140, 255, .18);
}
.plan-card.selected {
  border-color: var(--green);
  box-shadow: 0 0 0 1px var(--green), 0 8px 24px rgba(52, 199, 89, .22);
  cursor: pointer;
}
.plan-card { cursor: pointer; }
.plan-badge {
  position: absolute;
  top: -10px; left: 50%; transform: translateX(-50%);
  background: var(--primary); color: #fff;
  font-size: 11px; font-weight: 600;
  padding: 3px 12px; border-radius: 999px;
  white-space: nowrap;
}
.plan-badge-ok {
  background: var(--green);
  top: 14px;
}
.plan-name { font-size: 15px; font-weight: 600; color: var(--text); }
.plan-price { display: flex; align-items: baseline; gap: 4px; }
.plan-amount { font-size: 26px; font-weight: 700; color: var(--primary); }
.plan-unit { font-size: 13px; color: var(--muted); }
.plan-permonth { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.plan-discount { color: var(--green); border: 1px solid var(--green); border-radius: 6px; padding: 1px 6px; font-size: 11px; }
.plan-data { font-size: 14px; font-weight: 600; color: var(--text); margin-top: 2px; }
.plan-features { list-style: none; padding: 0; margin: 4px 0 0; display: flex; flex-direction: column; gap: 5px; }
.plan-features li { font-size: 12px; color: var(--muted); padding-left: 16px; position: relative; }
.plan-features li::before { content: "✓"; position: absolute; left: 0; color: var(--green); font-weight: 700; }
.plan-cta { margin-top: auto; padding-top: 12px; font-size: 12px; color: var(--primary); text-align: center; border-top: 1px solid var(--border); }

.plan-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; margin-top: 16px; font-size: 13px; color: var(--muted); }
.plan-foot strong { color: var(--primary); }
.plan-referral-highlight {
  color: var(--amber) !important;
  font-weight: 600;
  background: rgba(255, 159, 10, .1);
  border: 1px solid rgba(255, 159, 10, .3);
  border-radius: 8px;
  padding: 6px 14px;
  display: inline-block;
}

@media (max-width: 960px) {
  .plan-grid { grid-template-columns: repeat(2, 1fr); }
  .download-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 520px) {
  .plan-grid { grid-template-columns: 1fr; }
  .download-grid { grid-template-columns: 1fr; }
}

/* Select inputs in modals */
.modal-card select { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; color: var(--text); font-size: 14px; }
.modal-card select:focus { outline: none; border-color: var(--primary); }
.owner-region { font-size: 12px; color: var(--primary); font-weight: 500; margin-left: 4px; display: inline; }
.node-select-hint { font-weight: 400; color: var(--muted); font-size: 11px; }
.node-check-list { display: flex; flex-direction: column; gap: 4px; max-height: 180px; overflow-y: auto; margin-top: 4px; }

/* Cycle chips (in modal) */
.cycle-group { display: flex; gap: 6px; margin-bottom: 4px; }
.cycle-chip {
  padding: 5px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  transition: all .15s;
}
.cycle-chip:hover { border-color: var(--primary); color: var(--text); }
.cycle-chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.cycle-info { font-weight: 400; color: var(--muted); font-size: 11px; }

/* Auto-config notice (in modal) */
.auto-notice {
  background: rgba(52,199,89,.08);
  border: 1px solid rgba(52,199,89,.2);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 8px;
}
.auto-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  font-size: 12px;
  color: var(--muted);
}
.auto-tag {
  color: var(--green);
  font-weight: 600;
  display: block;
  width: 100%;
  margin-bottom: 2px;
}
.node-check-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: border-color .15s;
}
.node-check-label:hover { border-color: var(--primary); }
.node-check-label.match { border-color: rgba(91,140,255,.3); background: rgba(91,140,255,.06); }
.node-check-label input[type="checkbox"] { accent-color: var(--primary); }

@media (max-width: 720px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
  .config-body { flex-direction: column; }
}
