:root {
  --bg: #0b0e14;
  --bg-elev: #141823;
  --bg-soft: #1a1f2c;
  --border: #232a3a;
  --border-soft: #1c2230;
  --text: #e8ebf2;
  --text-soft: #c4cad6;
  --muted: #8c93a3;
  --muted-2: #6b7283;
  --accent: #5b8cff;
  --accent-hover: #729fff;
  --green: #4ade80;
  --green-bg: rgba(74,222,128,0.12);
  --red: #f87171;
  --red-bg: rgba(248,113,113,0.12);
  --amber: #fbbf24;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

body.centered {
  display: grid;
  place-items: center;
  min-height: 100vh;
}

/* ---------- Login ---------- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px;
  width: 380px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.4);
}
.card h1 { margin: 0 0 28px; font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.card label { display: block; margin-bottom: 18px; font-size: 12px; color: var(--muted); font-weight: 500; letter-spacing: 0.02em; text-transform: uppercase; }
.card input {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 11px 14px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  transition: border-color 0.15s;
}
.card input:focus { outline: none; border-color: var(--accent); }
.card button { width: 100%; margin-top: 8px; }

button {
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
}
button:hover { background: var(--accent-hover); }
button.link { background: transparent; color: var(--muted); padding: 6px 10px; font-weight: 400; }
button.link:hover { color: var(--text); background: var(--bg-soft); }
button.danger { background: var(--red); }
button.danger:hover { background: #fa8585; }
button.ghost {
  background: transparent;
  color: var(--text-soft);
  border: 1px solid var(--border);
}
button.ghost:hover { background: var(--bg-soft); border-color: #34405a; }
button.small { padding: 5px 10px; font-size: 12px; }
button.primary { background: var(--accent); }
button.copy { background: var(--bg-soft); color: var(--text-soft); padding: 5px 10px; font-size: 11px; border: 1px solid var(--border); }
button.copy:hover { background: var(--border); }
button.copy.copied { background: var(--green-bg); color: var(--green); border-color: var(--green); }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.inline { display: inline; margin: 0; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.brand-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}
.brand-sub { color: var(--muted); font-size: 12px; margin-left: 4px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }

.badge {
  font-size: 11px;
  font-weight: 500;
  padding: 4px 10px;
  background: var(--bg-soft);
  border-radius: 999px;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.badge.on { background: var(--green-bg); color: var(--green); }
.badge.off { background: var(--red-bg); color: var(--red); }

main { padding: 28px; max-width: 1280px; margin: 0 auto; }

/* ---------- Stats ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
}
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px; }
.stat-value { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.stat-sub { font-size: 11px; color: var(--muted-2); margin-top: 4px; }

/* ---------- Panel + Table ---------- */
.panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-soft);
}
.panel-head h2 { margin: 0; font-size: 14px; font-weight: 600; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  text-align: left;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-soft);
}
th { color: var(--muted); font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; background: var(--bg-soft); }
tbody tr { transition: background 0.1s; }
tbody tr:hover { background: var(--bg-soft); }
tbody tr:last-child td { border-bottom: none; }
.actions-col { width: 1%; white-space: nowrap; }

.status-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
}
.status-dot.on { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.off { background: var(--red); }

.client-id {
  display: flex; flex-direction: column; gap: 2px;
}
.client-id .label-row { display: flex; align-items: center; gap: 8px; }
.client-id input.label-edit {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  width: 200px;
}
.client-id input.label-edit:hover { border-color: var(--border); }
.client-id input.label-edit:focus { border-color: var(--accent); outline: none; background: var(--bg); }
.client-id input.label-edit::placeholder { color: var(--muted-2); font-style: italic; }
.client-id .sub { font-size: 11px; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.actions { display: flex; gap: 6px; justify-content: flex-end; }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--text-soft);
}

/* ---------- Dialog ---------- */
dialog {
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  min-width: 480px;
  max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
dialog::backdrop { background: rgba(0,0,0,0.6); backdrop-filter: blur(2px); }
dialog h2 { margin: 0 0 6px; font-size: 18px; }
dialog .muted { margin: 0 0 18px; }

.kv { margin-bottom: 14px; }
.kv label { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px; }
.copyrow {
  display: flex;
  align-items: stretch;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 4px 4px 10px;
}
.copyrow code {
  flex: 1;
  background: transparent;
  padding: 6px 0;
  user-select: all;
  overflow-x: auto;
  white-space: nowrap;
  font-size: 13px;
}
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

dialog .kv input[type="password"],
dialog .kv input[type="text"] {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
}
dialog .kv input:focus { outline: none; border-color: var(--accent); }

.error-msg {
  margin: 0 0 4px;
  padding: 8px 12px;
  background: var(--red-bg);
  color: var(--red);
  border-radius: 8px;
  font-size: 12px;
}

#empty { padding: 40px 20px; color: var(--muted); }

/* ---------- Server status ---------- */
.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0;
}
.status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13px;
  gap: 16px;
}
.status-row:nth-last-child(-n+3) { border-bottom: none; }
.status-key { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.status-val { color: var(--text); font-weight: 500; text-align: right; }

/* ---------- Maintenance ---------- */
.maintenance { padding: 4px 0; }
.maint-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-soft);
}
.maint-row:last-child { border-bottom: none; }
.maint-title { font-size: 13px; font-weight: 500; margin-bottom: 2px; }
.maint-action { display: flex; align-items: center; gap: 8px; }
.maint-action input[type="number"] {
  width: 70px;
  padding: 6px 10px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  text-align: right;
}
.maint-action input[type="number"]:focus { outline: none; border-color: var(--accent); }

main > section + section { margin-top: 20px; }
