:root {
  --bg: #0d1117;
  --bg-soft: #161b22;
  --bg-raised: #1c2330;
  --border: #2a3242;
  --text: #e6edf3;
  --text-dim: #8b96a5;
  --accent: #4f9cf9;
  --accent-dim: #2b5c8f;
  --green: #3fb950;
  --red: #f85149;
  --amber: #d29922;
  --blue: #4f9cf9;
  --gray: #6e7681;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.brand-mark { color: var(--accent); font-size: 18px; }
.nav { display: flex; gap: 16px; }
.nav a { color: var(--text-dim); padding: 4px 8px; border-radius: 6px; }
.nav a.active, .nav a:hover { color: var(--text); background: var(--bg-raised); text-decoration: none; }
.health { font-size: 12px; color: var(--text-dim); }
.health.ok { color: var(--green); }
.health.bad { color: var(--red); }

/* ---------- Resource monitor ---------- */
.sysmon { margin-left: auto; display: flex; align-items: center; gap: 16px; }
.sysmon-item { font-size: 12px; color: var(--text-dim); white-space: nowrap; }
.sysmon-item b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.sysmon-item b.warn { color: var(--amber); }
.sysmon-item b.crit { color: var(--red); }

/* ---------- Layout ---------- */
.container { max-width: 1200px; margin: 0 auto; padding: 24px; }
.card {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.card h2 { margin: 0 0 16px; font-size: 16px; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.section-title h2 { margin: 0; }

.row { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; }
.field.grow { flex: 1; min-width: 220px; }

input[type="text"], input[type="password"], input[type="number"], select, textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
input[readonly] { color: var(--text-dim); }
textarea { resize: vertical; font-family: var(--mono); font-size: 13px; width: 100%; }

/* ---------- Buttons ---------- */
button, .btn {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
button:hover, .btn:hover { background: #232c3d; border-color: var(--accent-dim); }
button:disabled, .btn:disabled { opacity: .45; cursor: not-allowed; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #04121f; font-weight: 600; }
button.primary:hover { background: #6db0ff; }
button.danger { color: var(--red); }
button.small { padding: 4px 10px; font-size: 12px; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid;
  letter-spacing: .02em;
}
.badge-green { color: var(--green); border-color: var(--green); background: rgba(63,185,80,.1); }
.badge-red { color: var(--red); border-color: var(--red); background: rgba(248,81,73,.1); }
.badge-amber { color: var(--amber); border-color: var(--amber); background: rgba(210,153,34,.1); }
.badge-blue { color: var(--blue); border-color: var(--blue); background: rgba(79,156,249,.1); }
.badge-gray { color: var(--gray); border-color: var(--gray); background: rgba(110,118,129,.1); }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; }
tr:hover td { background: var(--bg-raised); }
.mono { font-family: var(--mono); font-size: 13px; }

/* ---------- Batch grid ---------- */
.batch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.batch {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.batch-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.batch-files { font-size: 12px; color: var(--text-dim); margin-bottom: 10px; }
.batch-files ul { margin: 4px 0 0; padding-left: 18px; }
.batch-links { display: flex; flex-wrap: wrap; gap: 6px; }
.batch-actions { display: flex; gap: 6px; margin-bottom: 10px; }
.batch-error { color: var(--red); font-size: 12px; margin-top: 8px; }

/* ---------- Logs ---------- */
.logs {
  background: #0a0e14;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  font-family: var(--mono);
  font-size: 12px;
  max-height: 60vh;
  min-height: 240px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-gutter: stable;
  white-space: pre-wrap;
  word-break: break-word;
}
.log-line { display: flex; gap: 8px; }
.log-time { color: var(--text-dim); flex-shrink: 0; }
.log-INFO { color: var(--text); }
.log-WARN { color: var(--amber); }
.log-ERROR { color: var(--red); }

/* ---------- Misc ---------- */
.muted { color: var(--text-dim); }
.small { font-size: 12px; }
.spacer { flex: 1; }
.empty { color: var(--text-dim); text-align: center; padding: 32px 0; }
.stat { font-size: 26px; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; }
.stat-box { background: var(--bg-raised); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px; min-width: 120px; }

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--bg-raised);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0,0,0,.4);
  z-index: 100;
}
.toast.error { border-color: var(--red); }

.loading { color: var(--text-dim); font-style: italic; }

/* ---------- Settings ---------- */
.settings-group {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin: 0 0 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.key-row { display: flex; gap: 8px; }
.key-row input { flex: 1; }

/* ---------- Proxy lists ---------- */
.proxy-list {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
}
.proxy-name-row { display: flex; gap: 10px; align-items: flex-end; }
.proxy-list .field { margin-top: 10px; width: 100%; }
.proxy-list textarea { width: 100%; }

/* ---------- Toggle switch ---------- */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { display: none; }
.switch-track {
  width: 40px; height: 22px; border-radius: 999px;
  background: var(--bg); border: 1px solid var(--border);
  position: relative; transition: background .15s, border-color .15s; flex-shrink: 0;
}
.switch-thumb {
  position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--text-dim); transition: transform .15s, background .15s;
}
.switch input:checked + .switch-track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(18px); background: #fff; }
.switch-label { font-size: 13px; }

/* ---------- Login ---------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 24px; }
.login-card {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 360px;
  max-width: 100%;
}
.login-brand { font-size: 18px; margin-bottom: 4px; }
.login-error { color: var(--red); margin-top: 12px; font-size: 13px; }
.logout-btn { color: var(--text-dim); }
.logout-btn:hover { color: var(--red); border-color: var(--red); }
