:root {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #172033;
  --border: #1f2937;
  --border-hi: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #10b981;
  --accent-hover: #059669;
  --accent-soft: rgba(16, 185, 129, 0.14);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.14);
  --warn: #f59e0b;
  --warn-soft: rgba(245, 158, 11, 0.14);
  --blue: #38bdf8;
  --blue-soft: rgba(56, 189, 248, 0.14);
  --radius: 12px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: var(--font-sans); font-size: 14px; line-height: 1.5; }
.hidden { display: none !important; }
a { color: inherit; text-decoration: none; }
code { font-family: var(--font-mono); font-size: 12.5px; background: rgba(148, 163, 184, 0.12); padding: 2px 6px; border-radius: 5px; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 4px 0 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.row-gap { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: radial-gradient(circle at 50% 0%, #172554 0%, var(--bg) 60%); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border-hi); border-radius: 16px; padding: 28px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45); }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-brand h1 { font-size: 19px; }
.login-brand p { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

/* Brand dot */
.brand-dot { width: 11px; height: 11px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); flex-shrink: 0; }
.brand-dot.down { background: var(--danger); box-shadow: 0 0 12px var(--danger); }

/* Topbar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 24px; background: rgba(11, 17, 32, 0.88); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.topbar-left { display: flex; align-items: center; gap: 12px; }
.brand-title { font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.brand-sub { font-size: 12px; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Layout */
.container { max-width: 1120px; margin: 0 auto; padding: 20px 20px 48px; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.stat-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.stat-value { font-size: 22px; font-weight: 700; }
.stat-meta { font-size: 12px; color: var(--muted); margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-actions { display: flex; gap: 8px; margin-top: 2px; }

/* Tabs */
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tab { background: none; border: none; color: var(--muted); padding: 10px 16px; font-size: 14px; font-weight: 500; cursor: pointer; border-bottom: 2px solid transparent; transition: color .15s, border-color .15s; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Panel header */
.panel-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.panel-header.compact { align-items: center; margin-bottom: 10px; }

/* Cards & Exits */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.two-col { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.exits-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }

.exit-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; transition: border-color .15s; }
.exit-card:hover { border-color: var(--border-hi); }
.exit-card.disabled { opacity: 0.72; border-style: dashed; }
.exit-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.exit-title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.exit-name { font-size: 16px; font-weight: 600; }
.exit-chain { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-family: var(--font-mono); font-size: 12.5px; color: var(--muted); background: var(--surface-2); padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border); }
.chain-arrow { color: var(--accent); font-weight: 700; }
.exit-meta-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 12.5px; }
.exit-ip-badge { display: inline-flex; align-items: center; gap: 6px; color: var(--blue); background: var(--blue-soft); padding: 4px 10px; border-radius: 999px; font-size: 12px; }
.exit-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-blue { background: var(--blue-soft); color: var(--blue); }
.badge-muted { background: rgba(148, 163, 184, 0.14); color: var(--muted); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent; border-radius: 8px; padding: 8px 14px; font-size: 13.5px; font-weight: 500; cursor: pointer; transition: background .15s, border-color .15s, opacity .15s; font-family: inherit; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #022c22; font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); color: #ecfdf5; }
.btn-ghost { background: var(--surface-2); color: var(--text); border-color: var(--border-hi); }
.btn-ghost:hover:not(:disabled) { background: #1e293b; border-color: #475569; }
.btn-danger { background: var(--danger-soft); color: #fca5a5; border-color: rgba(239, 68, 68, 0.35); }
.btn-danger:hover:not(:disabled) { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-xs { padding: 3px 8px; font-size: 12px; }
.btn-block { width: 100%; margin-top: 8px; padding: 10px; }
.icon-btn { background: none; border: none; color: var(--muted); font-size: 17px; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* Forms */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; flex: 1; min-width: 0; }
.field > span { font-size: 12.5px; color: var(--muted); }
input, select, textarea { width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--border-hi); border-radius: 8px; padding: 8px 11px; font-size: 13.5px; font-family: inherit; outline: none; transition: border-color .15s; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
.input-sm { width: auto; padding: 6px 10px; font-size: 12.5px; }
.form-row { display: flex; gap: 10px; }
.form-error { color: #fca5a5; background: var(--danger-soft); border: 1px solid rgba(239, 68, 68, 0.3); padding: 8px 12px; border-radius: 8px; font-size: 12.5px; margin-bottom: 10px; }
.smart-paste-box { background: var(--surface-2); border: 1px dashed var(--border-hi); border-radius: 10px; padding: 10px 12px 2px; margin-bottom: 14px; }
.smart-paste-box textarea { flex: 1; font-family: var(--font-mono); font-size: 12px; resize: vertical; }

/* Lists & Code */
.simple-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.simple-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; font-size: 13px; flex-wrap: wrap; }
.sub-links { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.sub-link-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sub-link-row code { flex: 1; min-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.code-box { background: #060b16; border: 1px solid var(--border); border-radius: 10px; padding: 14px; font-family: var(--font-mono); font-size: 12px; line-height: 1.55; color: #cbd5e1; overflow: auto; max-height: 360px; margin: 0; white-space: pre; }
.code-box.tall { max-height: 560px; white-space: pre-wrap; word-break: break-all; }
.code-box.small-box { max-height: 220px; }
.code-editor { width: 100%; min-height: 440px; font-family: var(--font-mono); font-size: 12.5px; line-height: 1.55; background: #060b16; border: 1px solid var(--border-hi); border-radius: 10px; padding: 14px; color: #e2e8f0; resize: vertical; tab-size: 2; }

.backup-list { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; max-height: 240px; overflow: auto; }
.backup-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; background: var(--surface-2); border-radius: 8px; font-size: 12.5px; flex-wrap: wrap; }

/* Alert */
.alert { padding: 10px 12px; border-radius: 8px; font-size: 12.5px; margin-bottom: 12px; white-space: pre-wrap; font-family: var(--font-mono); }
.alert-ok { background: var(--accent-soft); color: #6ee7b7; border: 1px solid rgba(16, 185, 129, 0.35); }
.alert-err { background: var(--danger-soft); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.35); }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(2, 6, 23, 0.72); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; padding: 16px; overflow-y: auto; }
.modal-card { width: 100%; max-width: 580px; background: var(--surface); border: 1px solid var(--border-hi); border-radius: 14px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55); overflow: hidden; }
.modal-card.narrow { max-width: 400px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 18px; }
.modal-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.qr-wrap { display: flex; justify-content: center; padding: 12px; background: #fff; border-radius: 12px; width: fit-content; margin: 0 auto; }

/* Empty state */
.empty-box { text-align: center; padding: 40px 20px; background: var(--surface); border: 1px dashed var(--border-hi); border-radius: var(--radius); color: var(--muted); }

/* Toast */
.toast-container { position: fixed; right: 18px; bottom: 18px; z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: 360px; }
.toast { background: var(--surface-2); color: var(--text); border: 1px solid var(--border-hi); padding: 10px 14px; border-radius: 10px; font-size: 13px; box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4); }
.toast.ok { border-color: var(--accent); }
.toast.err { border-color: var(--danger); color: #fecaca; }

@media (max-width: 860px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .stats-grid { grid-template-columns: 1fr; }
  .form-row { flex-direction: column; }
  .topbar { padding: 12px 14px; }
  .container { padding: 14px 12px 40px; }
}
