/* === TOKENS === */
:root {
  color-scheme: light;
  --bg: #eef1f8;
  --surface: #ffffff;
  --surface-2: #f6f8fc;
  --surface-hover: #f0f3f9;
  --border: rgba(0, 0, 0, 0.07);
  --border-strong: rgba(0, 0, 0, 0.12);
  --sidebar-bg: #ffffff;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05), 0 4px 12px rgba(0,0,0,0.06);
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 8px 24px rgba(0,0,0,0.07);
  --accent: #4f7fff;
  --accent-dim: rgba(79, 127, 255, 0.1);
  --accent-hover: rgba(79, 127, 255, 0.16);
  --active: #16a34a;
  --active-dim: rgba(22, 163, 74, 0.1);
  --warn: #d97706;
  --warn-dim: rgba(217, 119, 6, 0.1);
  --danger: #dc2626;
  --danger-dim: rgba(220, 38, 38, 0.1);
  --text: #111827;
  --text-muted: #6b7280;
  --text-faint: #b0b8c8;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

/* === RESET === */
*, *::before, *::after { box-sizing: border-box; }
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

/* === BASE === */
body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: radial-gradient(ellipse 60% 40% at 20% 0%, rgba(79, 127, 255, 0.07) 0%, transparent 55%);
  pointer-events: none;
  z-index: 0;
}

#app { position: relative; z-index: 1; }

/* === LOGIN === */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  width: min(420px, 100%);
  padding: 32px;
  border-radius: 22px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 28px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: var(--accent-dim);
  border: 1px solid rgba(79, 127, 255, 0.18);
  color: var(--accent);
  flex-shrink: 0;
}

.brand-mark svg { width: 24px; height: 24px; }
.brand-name { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; color: var(--text); }
.brand-sub { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.login-title { font-size: 14px; color: var(--text-muted); margin-bottom: 20px; }

.field { display: grid; gap: 7px; margin-top: 14px; }

.field-label {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

input, select {
  width: 100%;
  min-height: 46px;
  border: 1.5px solid var(--border-strong);
  border-radius: 12px;
  padding: 0 14px;
  background: var(--surface-2);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

input:focus, select:focus { border-color: var(--accent); }

.login-actions { display: grid; gap: 10px; margin-top: 22px; }
.login-message { min-height: 20px; margin-top: 12px; font-size: 14px; color: var(--text-muted); text-align: center; }
.login-message.error { color: var(--danger); }

/* === BUTTONS === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  border: 0;
  border-radius: 10px;
  padding: 0 16px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  transition: opacity 0.12s;
}

.btn:hover { opacity: 0.88; }
.btn:active { opacity: 0.76; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn svg { width: 15px; height: 15px; flex-shrink: 0; }

.btn.secondary {
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  color: var(--text);
}

.btn.danger {
  background: var(--danger-dim);
  border: 1px solid rgba(220, 38, 38, 0.18);
  color: var(--danger);
}

.btn.full { width: 100%; min-height: 48px; font-size: 15px; }

/* === LAYOUT === */
.layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px 1fr;
}

/* === SIDEBAR === */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  border-right: 1px solid var(--border);
  background: var(--sidebar-bg);
  box-shadow: 4px 0 16px rgba(0, 0, 0, 0.04);
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.sidebar-brand-name { font-size: 17px; font-weight: 800; letter-spacing: -0.02em; color: var(--text); }
.sidebar-brand-sub { color: var(--text-muted); font-size: 12px; margin-top: 1px; }

.sidebar-section {
  color: var(--text-faint);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 0 10px;
  margin: 8px 0 6px;
}

.nav { display: flex; flex-direction: column; gap: 3px; }

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  border: 0;
  border-radius: 11px;
  padding: 0 12px;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  transition: color 0.12s, background 0.12s;
}

.nav-btn:hover { background: var(--surface-hover); color: var(--text); }
.nav-btn.active { background: var(--accent-dim); color: var(--accent); }
.nav-icon { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  margin-bottom: 8px;
}

.sidebar-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 1.5px solid rgba(79, 127, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  color: var(--accent);
  flex-shrink: 0;
}

.sidebar-user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-logout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  min-height: 38px;
  border: 1.5px solid var(--border-strong);
  border-radius: 10px;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  transition: color 0.12s, background 0.12s, border-color 0.12s;
}

.btn-logout:hover { background: var(--danger-dim); color: var(--danger); border-color: rgba(220, 38, 38, 0.18); }
.btn-logout svg { width: 14px; height: 14px; }

/* === MAIN === */
.main { display: flex; flex-direction: column; min-height: 100vh; overflow: hidden; }

/* === TOPBAR === */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
}

.topbar-title { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; color: var(--text); }
.topbar-sub { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.topbar-actions { display: flex; gap: 10px; flex-shrink: 0; }

/* === CONTENT === */
#content { padding: 24px 28px 40px; flex: 1; }

/* === STAT GRID === */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  border-radius: 16px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.stat-card-label { color: var(--text-muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; }
.stat-card-value { margin-top: 10px; font-size: 30px; font-weight: 800; letter-spacing: -0.03em; line-height: 1; color: var(--text); }
.stat-card-sub { color: var(--text-muted); font-size: 12px; margin-top: 6px; }

/* === TOOLBAR === */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.toolbar-title { font-size: 17px; font-weight: 700; color: var(--text); }
.toolbar-actions { display: flex; align-items: center; gap: 8px; }

/* === TABLE (users) === */
.table-wrap {
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

table { width: 100%; min-width: 760px; border-collapse: collapse; }

thead tr { background: var(--surface-2); border-bottom: 1px solid var(--border); }

th {
  padding: 12px 16px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  text-align: left;
}

td { padding: 14px 16px; border-bottom: 1px solid var(--border); vertical-align: top; font-size: 14px; line-height: 1.5; }
tr:last-child td { border-bottom: 0; }
tbody tr { transition: background 0.1s; }
tbody tr:hover { background: var(--surface-hover); }

.cell-primary { font-size: 14px; font-weight: 600; color: var(--text); }
.cell-sub { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.muted { color: var(--text-muted); font-size: 13px; }

/* === BADGES === */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 22px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 11px;
  font-weight: 700;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  white-space: nowrap;
}

.badge::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.badge.good { background: rgba(22, 163, 74, 0.1); color: var(--active); border-color: rgba(22, 163, 74, 0.2); }
.badge.warn { background: rgba(217, 119, 6, 0.1); color: var(--warn); border-color: rgba(217, 119, 6, 0.2); }
.badge.bad { background: rgba(220, 38, 38, 0.1); color: var(--danger); border-color: rgba(220, 38, 38, 0.2); }

/* === ROW ACTIONS === */
.row-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.row-actions .btn { min-height: 30px; padding: 0 10px; font-size: 12px; border-radius: 8px; }

/* === FORM PANEL === */
.form-panel {
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.form-panel-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.field span {
  display: block;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 7px;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

/* === NODE CARDS === */
.node-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 16px;
}

.node-card {
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: box-shadow 0.15s;
}

.node-card:hover { box-shadow: 0 4px 6px rgba(0,0,0,0.06), 0 16px 40px rgba(0,0,0,0.1); }

/* Card header */
.node-card-top {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 20px 20px 14px;
}

.node-card-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--accent-dim);
  border: 1px solid rgba(79, 127, 255, 0.15);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.node-card-icon.inactive {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text-faint);
}

.node-card-icon svg { width: 26px; height: 26px; }

.node-card-info { flex: 1; min-width: 0; }

.node-card-name {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.node-card-sub {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 3px;
  line-height: 1.4;
}

/* Target rows — like in Shadowsocks Monitor */
.node-targets {
  padding: 0 20px 12px;
  display: grid;
  gap: 7px;
}

.target-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 12px;
  border-radius: 11px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.target-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.target-dot.green { background: #22c55e; box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.2); }
.target-dot.red { background: #ef4444; box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2); }
.target-dot.gray { background: var(--text-faint); }

.target-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  min-width: 46px;
  flex-shrink: 0;
}

.target-host {
  flex: 1;
  font-size: 12px;
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.node-error-row {
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(220, 38, 38, 0.07);
  border: 1px solid rgba(220, 38, 38, 0.15);
  color: var(--danger);
  font-size: 12px;
  line-height: 1.4;
}

/* Resource meta strip */
.node-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 10px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 12px;
  color: var(--text-muted);
}

.node-meta-row span { font-weight: 600; color: var(--text); }

.node-card-actions {
  margin-left: auto;
  display: flex;
  gap: 6px;
  align-items: center;
}

.empty-msg {
  grid-column: 1 / -1;
  padding: 48px 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 15px;
}

/* Settings toggle button */
.node-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  border: 0;
  border-top: 1px solid var(--border);
  background: transparent;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s;
}

.node-toggle:hover { background: var(--surface-hover); }
.node-toggle.expanded { background: var(--accent-dim); }

.node-toggle-icon {
  width: 18px;
  height: 18px;
  transition: transform 0.2s;
  flex-shrink: 0;
}

.node-toggle.expanded .node-toggle-icon { transform: rotate(180deg); }

/* Expanded settings section */
.node-settings {
  border-top: 1px solid var(--border);
  padding: 18px 20px;
  background: var(--surface-2);
}

.node-settings-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 14px;
}

.node-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 11px;
  margin-bottom: 0;
}

.node-settings .field span {
  display: block;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 6px;
}

.node-settings input {
  width: 100%;
  min-height: 38px;
  border: 1.5px solid var(--border-strong);
  border-radius: 9px;
  padding: 0 10px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  font-size: 13px;
  transition: border-color 0.12s;
}

.node-settings input:focus { border-color: var(--accent); }

.node-settings .form-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

/* === CARDS (payments / settings) === */
.card {
  border-radius: 16px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.card h2 { font-size: 16px; font-weight: 700; color: var(--text); }
.settings-list { display: grid; gap: 14px; }

.empty-row td { color: var(--text-muted); text-align: center; padding: 32px; }

/* === SCROLLBAR === */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.1); border-radius: 999px; }

/* === MEDIA === */
@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  }

  .sidebar-brand { padding-bottom: 0; border-bottom: none; margin-bottom: 0; }
  .nav { flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .sidebar-section, .sidebar-footer { display: none; }
  .topbar { padding: 14px 18px; }
  #content { padding: 16px 18px 32px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .node-cards { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .stat-grid { grid-template-columns: 1fr; }
  .form-grid, .form-grid-2, .node-form-grid { grid-template-columns: 1fr; }
  .node-cards { grid-template-columns: 1fr; }
}
