:root {
  --bg: #0d1017;
  --panel: #151a23;
  --panel-2: #1b212c;
  --border: #262d3a;
  --text: #e6e9ef;
  --muted: #8b93a5;
  --accent: #22c55e;
  --accent-ink: #04210f;
  --blue: #3b82f6;
  --violet: #a78bfa;
  --amber: #f59e0b;
  --red: #ef4444;
  --track: #232a37;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --mono: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f5f9; --panel: #ffffff; --panel-2: #f6f8fb; --border: #e1e5ee; --text: #151a23;
    --muted: #667085; --track: #e8ecf3; --accent: #16a34a; --accent-ink: #fff;
    --shadow: 0 10px 30px rgba(20, 30, 50, .12); color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
h2 { margin: 0; font-size: 16px; font-weight: 600; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }

/* buttons & inputs */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  padding: 7px 12px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { border-color: color-mix(in srgb, var(--muted) 60%, var(--border)); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.icon { padding: 6px 9px; }
.btn.wide { width: 100%; justify-content: center; padding: 10px; }

input, textarea, select {
  width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font: inherit;
}
textarea { font-family: var(--mono); font-size: 12.5px; resize: vertical; min-height: 60px; }
input:focus, textarea:focus, select:focus, .btn:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 1px;
}
label { display: grid; gap: 5px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
label.check { display: flex; align-items: flex-start; gap: 8px; color: var(--text); font-weight: 400; font-size: 13.5px; }
label.check input { width: auto; margin-top: 3px; accent-color: var(--accent); }

/* layout */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px;
  padding: 12px 24px; background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand.big { font-size: 22px; justify-content: center; }
.logo {
  width: 26px; height: 26px; border-radius: 8px; background: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 20%, transparent);
  position: relative;
}
.logo::after { content: ""; position: absolute; inset: 8px 6px; border: 2px solid var(--accent-ink); border-radius: 5px; }
.host { display: flex; align-items: center; gap: 10px; }
.dot-sep { width: 4px; height: 4px; border-radius: 50%; background: var(--border); }
.spacer { flex: 1; }
main { max-width: 1280px; margin: 0 auto; padding: 24px; display: grid; gap: 20px; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.stat { padding: 16px 18px; display: flex; flex-direction: column; gap: 8px; min-height: 196px; }
.stat-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.stat-head .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.label { text-transform: uppercase; letter-spacing: .08em; font-size: 11px; font-weight: 700; color: var(--muted); }
.stat-value { font-size: 32px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat-value small { font-size: 16px; color: var(--muted); font-weight: 600; margin-left: 2px; }
.spark { width: 100%; height: 44px; display: block; overflow: visible; }
.cores { display: flex; gap: 2px; height: 16px; align-items: flex-end; }
.cores span { flex: 1; background: var(--track); border-radius: 2px; position: relative; height: 100%; overflow: hidden; }
.cores span i { position: absolute; left: 0; right: 0; bottom: 0; background: var(--accent); border-radius: 2px; }
.bar { height: 6px; background: var(--track); border-radius: 99px; overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--blue); border-radius: 99px; transition: width .4s; }
.bar.warn span { background: var(--amber); }
.bar.crit span { background: var(--red); }
.net-values { display: grid; gap: 2px; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.net-values .arrow { display: inline-block; width: 20px; font-weight: 800; }
.arrow.rx { color: var(--accent); } .arrow.tx { color: var(--violet); }
.legend { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.legend i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.legend i.rx { background: var(--accent); } .legend i.tx { background: var(--violet); margin-left: 6px; }
.disks { display: grid; gap: 12px; overflow: auto; max-height: 150px; }
.disk-row { display: grid; gap: 5px; }
.disk-row .top { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; }
.disk-row .top b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.section { padding: 18px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.search { max-width: 260px; }

/* servers */
.servers { display: grid; gap: 10px; }
.server {
  display: grid; grid-template-columns: auto minmax(0, 1.6fr) minmax(0, 1.4fr) 92px 92px 84px auto auto;
  align-items: center; gap: 16px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--panel-2);
}
.badge {
  width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center;
  font-weight: 800; font-size: 13px; color: #fff; letter-spacing: .02em;
}
.server .name { font-weight: 600; font-size: 14.5px; display: flex; align-items: center; gap: 8px; min-width: 0; }
.server .name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.server .sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.server .msg { font-size: 12px; color: var(--amber); }
.metric .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.metric .v { font-variant-numeric: tabular-nums; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  font-family: var(--mono); font-size: 11.5px; padding: 2px 7px; border-radius: 6px;
  border: 1px solid var(--border); color: var(--muted); background: var(--panel); display: inline-flex; align-items: center; gap: 5px;
}
.chip.up { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.chip.up::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.chip.extra { border-style: dashed; }
.pill { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; text-transform: uppercase; letter-spacing: .05em; flex: none; }
.pill.running { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.pill.stopped { background: var(--track); color: var(--muted); }
.pill.stopping, .pill.installing { background: color-mix(in srgb, var(--amber) 18%, transparent); color: var(--amber); }
.pill.crashed { background: color-mix(in srgb, var(--red) 18%, transparent); color: var(--red); }
.actions { display: flex; gap: 6px; }

.switch { position: relative; width: 46px; height: 26px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; width: 100%; height: 100%; }
.switch span {
  position: absolute; inset: 0; border-radius: 99px; background: var(--track); border: 1px solid var(--border);
  transition: background .2s;
}
.switch span::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.switch input:checked + span { background: var(--accent); border-color: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:disabled { cursor: wait; }
.switch input:disabled + span { opacity: .55; }
.switch input:focus-visible + span { outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }
.switch.busy span::after { animation: pulse 1s infinite ease-in-out; }
@keyframes pulse { 50% { opacity: .4; } }

.empty { text-align: center; padding: 36px 16px; border: 1px dashed var(--border); border-radius: 12px; }
.empty h3 { margin: 0 0 4px; }
.empty p { margin: 0 0 14px; }

.notice {
  border: 1px solid color-mix(in srgb, var(--amber) 40%, var(--border)); background: color-mix(in srgb, var(--amber) 8%, transparent);
  color: var(--text); padding: 10px 12px; border-radius: 10px; margin-bottom: 12px; font-size: 13px;
}

/* ports table */
.table-wrap { overflow: auto; max-height: 420px; border: 1px solid var(--border); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--panel-2); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
tbody tr:last-child td { border-bottom: 0; }
td.port { font-family: var(--mono); font-weight: 600; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 5px; background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); margin-left: 6px; font-weight: 600; }

/* menus, modals, toasts */
.menu {
  position: fixed; z-index: 50; min-width: 180px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow); padding: 5px;
}
.menu button {
  display: block; width: 100%; text-align: left; background: none; border: 0; color: var(--text); padding: 8px 10px;
  border-radius: 6px; font: inherit; cursor: pointer;
}
.menu button:hover { background: var(--panel-2); }
.menu button.danger { color: var(--red); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }

.overlay { position: fixed; inset: 0; z-index: 40; background: rgba(5, 8, 14, .6); display: grid; place-items: center; padding: 16px; }
.modal {
  width: min(720px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--panel);
  border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column;
}
.modal.wide { width: min(1000px, 100%); }
.modal.narrow { width: min(440px, 100%); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-head h2 { flex: 1; }
.modal-body { padding: 18px; display: grid; gap: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--border); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.hint { font-size: 12px; color: var(--muted); font-weight: 400; }
details summary { cursor: pointer; color: var(--muted); font-weight: 500; }
details[open] summary { margin-bottom: 12px; }
.error { color: var(--red); font-size: 13px; min-height: 0; }
.error:empty { display: none; }

.templates { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.template {
  display: flex; gap: 12px; align-items: flex-start; text-align: left; padding: 12px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text); cursor: pointer; font: inherit;
}
.template:hover { border-color: var(--accent); }
.template .badge { width: 36px; height: 36px; flex: none; }
.template b { display: block; margin-bottom: 2px; }
.template span { font-size: 12px; color: var(--muted); }

.console {
  background: #07090d; color: #d7dde8; font-family: var(--mono); font-size: 12.5px; line-height: 1.5;
  height: min(60vh, 560px); overflow: auto; padding: 12px 14px; margin: 0; white-space: pre-wrap; word-break: break-word;
  border-radius: 10px; border: 1px solid var(--border);
}
.console .gp { color: #f5b942; }
.console-input { display: flex; gap: 8px; }
.console-input input { font-family: var(--mono); }

.toasts { position: fixed; bottom: 16px; right: 16px; z-index: 60; display: grid; gap: 8px; }
.toast {
  background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--accent); padding: 10px 14px;
  border-radius: 10px; box-shadow: var(--shadow); max-width: 360px; animation: slide .2s ease-out;
}
.toast.err { border-left-color: var(--red); }
@keyframes slide { from { transform: translateY(8px); opacity: 0; } }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 28px; display: grid; gap: 14px; box-shadow: var(--shadow); }
.login-card p { margin: 0; text-align: center; }

@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .server { grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "badge info switch" "ports ports ports" "metrics metrics actions"; }
  .server .badge { grid-area: badge; }
  .server .info { grid-area: info; }
  .server .chips { grid-area: ports; }
  .server .switch { grid-area: switch; }
  .server .actions { grid-area: actions; }
  .server .metrics-row { grid-area: metrics; display: flex; gap: 18px; }
}
@media (min-width: 1101px) { .server .metrics-row { display: contents; } }
@media (max-width: 640px) {
  main { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .host { display: none; }
  .stats { grid-template-columns: 1fr; }
  .grid2 { grid-template-columns: 1fr; }
  .search { max-width: none; }
  .server .metrics-row { gap: 12px; }
}
