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

:root {
  --bg: #0f1117;
  --bg2: #1a1d27;
  --bg3: #222536;
  --border: #2e3247;
  --text: #e2e8f0;
  --text2: #94a3b8;
  --accent: #6366f1;
  --accent-h: #4f52d4;
  --danger: #ef4444;
  --success: #22c55e;
  --warn: #f59e0b;
  --radius: 8px;
}

body { font-family: system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; height: 100vh; overflow: hidden; }

/* ── Auth ─────────────────────────────────────────────────────────────────── */
.screen { height: 100vh; }

#screen-auth { display: flex; align-items: center; justify-content: center; }

.auth-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 360px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.auth-box h1 { font-size: 22px; text-align: center; color: var(--text); }

#auth-form { display: flex; flex-direction: column; gap: 12px; }

/* ── Layout ───────────────────────────────────────────────────────────────── */
#screen-app { display: flex; height: 100vh; }

.sidebar {
  width: 200px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 0 20px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.nav-item {
  display: block;
  padding: 10px 20px;
  color: var(--text2);
  text-decoration: none;
  border-radius: 0;
  transition: background .15s, color .15s;
}
.nav-item:hover, .nav-item.active { background: var(--bg3); color: var(--text); }

.sidebar-bottom {
  margin-top: auto;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text2);
}

.content { flex: 1; overflow-y: auto; padding: 32px; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.page-header h2 { font-size: 20px; }
.header-actions { display: flex; gap: 10px; }

/* ── Table ────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }
thead tr { border-bottom: 1px solid var(--border); }
th { text-align: left; padding: 10px 12px; color: var(--text2); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; white-space: nowrap; }
td { padding: 12px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg2); }

.uuid-cell { font-family: monospace; font-size: 12px; color: var(--text2); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Status badges ────────────────────────────────────────────────────────── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; }
.badge-running { background: #14532d; color: var(--success); }
.badge-exited  { background: #450a0a; color: var(--danger); }
.badge-missing { background: #422006; color: var(--warn); }
.badge-direct  { background: #1e1b4b; color: #a5b4fc; }
.badge-socks5  { background: #172554; color: #93c5fd; }

/* ── IP page ──────────────────────────────────────────────────────────────── */
.ip-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.ip-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-family: monospace;
}
.add-ip-row { display: flex; gap: 10px; margin-top: 8px; }
.add-ip-row input { flex: 1; }

.msg { margin-top: 12px; padding: 10px 14px; border-radius: var(--radius); font-size: 13px; }
.msg.ok  { background: #14532d; color: var(--success); }
.msg.err { background: #450a0a; color: var(--danger); }

/* ── Inputs & buttons ─────────────────────────────────────────────────────── */
select {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
  cursor: pointer;
}
select:focus { border-color: var(--accent); }

input[type=text], input[type=password], input[type=number], textarea {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}
input:focus { border-color: var(--accent); }
textarea:focus { border-color: var(--accent); }
textarea {
  resize: vertical;
  min-height: 520px;
  line-height: 1.55;
  font-family: 'JetBrains Mono', 'Fira Mono', monospace;
}

label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text2); }

.input-row { display: flex; gap: 8px; }
.input-row input { flex: 1; }

.radio-row { display: flex; gap: 20px; padding: 6px 0; }
.radio-row label { flex-direction: row; align-items: center; gap: 6px; color: var(--text); cursor: pointer; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 9px 18px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background .15s;
  white-space: nowrap;
}
.btn-primary:hover { background: var(--accent-h); }

.btn-secondary {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 18px;
  cursor: pointer;
  font-size: 14px;
  transition: background .15s;
  white-space: nowrap;
}
.btn-secondary:hover { background: var(--border); }

.btn-small {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 9px 12px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}
.btn-small:hover { background: var(--border); }

.btn-link { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 12px; padding: 0; }
.btn-link:hover { text-decoration: underline; }

.btn-icon {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 13px;
  transition: background .15s, color .15s;
}
.btn-icon:hover { background: var(--bg3); color: var(--text); }
.btn-icon.danger:hover { background: #450a0a; color: var(--danger); }

.actions { display: flex; gap: 4px; }

.editor-hint {
  margin-bottom: 12px;
  color: var(--text2);
  font-size: 13px;
}

.template-editor {
  min-height: 620px;
}

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}

.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 460px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-wide { width: 680px; }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; }
.modal-close {
  background: none; border: none; color: var(--text2);
  cursor: pointer; font-size: 16px; padding: 2px 6px; border-radius: 4px;
}
.modal-close:hover { background: var(--bg3); color: var(--text); }

.modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  font-size: 12px;
  overflow: auto;
  max-height: 50vh;
  color: var(--text2);
  font-family: 'JetBrains Mono', 'Fira Mono', monospace;
  white-space: pre;
}

/* ── Utilities ────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.error { color: var(--danger); font-size: 13px; margin-top: 4px; }
.page { display: flex; flex-direction: column; }
.page.hidden { display: none; }
