:root {
  --bg: #0b0f17;
  --surface: #131a26;
  --surface-2: #1b2433;
  --border: #263244;
  --text: #e6edf6;
  --muted: #8a97aa;
  --primary: #3b82f6;
  --primary-hover: #2f6fe0;
  --green: #22c55e;
  --amber: #f59e0b;
  --orange: #fb923c;
  --red: #ef4444;
  --gray: #64748b;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error-text { color: var(--red); min-height: 1em; margin: 6px 0 0; font-size: 13px; }

/* ---- Login ---- */
.login-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.login-card h1 { margin: 0; font-size: 20px; }
.login-card p { margin: 0 0 12px; }
.login-card label { font-size: 13px; color: var(--muted); margin-top: 8px; }

/* ---- App shell chiều cao cố định (trang không cuộn) ---- */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ---- Topbar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}
.brand { font-weight: 600; font-size: 16px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }

/* ---- Layout ---- */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ---- App shell: sidebar + main ---- */
.layout {
  display: flex;
  align-items: stretch;
  gap: 20px;
  padding: 20px 24px;
  max-width: 1800px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.sidebar {
  width: 200px;
  flex-shrink: 0;
  align-self: flex-start;
}
.side-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
}
.nav-item {
  text-align: left;
  padding: 10px 14px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary); color: #fff; }
.main { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.view { display: flex; flex-direction: column; gap: 20px; flex: 1; min-height: 0; overflow-y: auto; }
.gateway-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 16px; }
.gateway-bar code {
  font-family: ui-monospace, monospace;
  font-size: 14px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 6px;
}
.proxy-card { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card h2 { margin: 0 0 14px; font-size: 15px; font-weight: 600; }
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.card-head h2 { margin: 0; }
.card-head-actions { display: flex; gap: 8px; }

/* ---- Forms ---- */
input, select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 9px 11px;
  font-size: 14px;
  outline: none;
}
input:focus, select:focus { border-color: var(--primary); }
.row-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.row-form input { flex: 1 1 180px; min-width: 140px; }
.row-form select { flex: 0 0 auto; }
.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
.settings-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}
.settings-grid button { grid-column: 1 / -1; justify-self: start; }

/* ---- Buttons ---- */
.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-mini {
  padding: 4px 10px;
  font-size: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
}
.btn-mini:hover { background: var(--border); }
.btn-danger { color: var(--red); border-color: var(--red); }
.btn-danger:hover { background: rgba(239, 68, 68, 0.12); }

/* ---- Accounts list ---- */
.list { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.acc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
}
.acc-meta { display: flex; align-items: center; gap: 10px; }
.acc-note { width: 240px; margin-left: auto; margin-right: 12px; }
.tag {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
}
.tag-nordvpn { background: rgba(59, 130, 246, 0.18); color: #7eb0ff; }
.tag-piavpn { background: rgba(34, 197, 94, 0.18); color: #6ee7a0; }
.tag-proxyfb { background: rgba(249, 115, 22, 0.18); color: #fdba74; }
.tag-shoplike { background: rgba(168, 85, 247, 0.18); color: #d8b4fe; }
.tag-kiotproxy { background: rgba(20, 184, 166, 0.18); color: #5eead4; }

/* ---- Table ---- */
.table-wrap { flex: 1; min-height: 0; overflow: auto; }
.proxy-table { width: 100%; border-collapse: collapse; }
.proxy-table th, .proxy-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.proxy-table th {
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
  box-shadow: inset 0 -1px 0 var(--border);
}
.endpoint { display: flex; align-items: center; gap: 6px; font-family: ui-monospace, monospace; font-size: 13px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ---- Status badge ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
}
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.s-connected .dot { background: var(--green); }
.s-starting .dot { background: var(--amber); }
.s-degraded .dot { background: var(--orange); }
.s-error .dot { background: var(--red); }
.s-stopped .dot { background: var(--gray); }

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 100;
}

@media (max-width: 640px) {
  .settings-grid { grid-template-columns: 1fr; }
  .layout { flex-direction: column; padding: 12px; }
  .sidebar { width: 100%; position: static; }
  .side-nav { flex-direction: row; flex-wrap: wrap; }
}
