:root {
  --bg: #0d0f12;
  --panel: #15181d;
  --panel-2: #1c2027;
  --line: #262b33;
  --text: #e6e8eb;
  --muted: #8a93a0;
  --accent: #4f8cff;
  --accent-2: #3a6fd8;
  --ok: #3ccf91;
  --warn: #f2b84b;
  --bad: #ef5b5b;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
}

button, input, select, textarea { font: inherit; color: inherit; }

button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { border-color: #3a414c; background: #222731; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-2); }
button.ghost { background: transparent; border-color: transparent; }
button.ghost:hover { background: var(--panel-2); }
button.on { background: rgba(79, 140, 255, .18); border-color: var(--accent); color: #cfe0ff; }
button.danger:hover { border-color: var(--bad); color: var(--bad); }

input[type=text], input[type=password], textarea, select {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
  width: 100%;
}
input:focus, textarea:focus { border-color: var(--accent); }

.app {
  display: grid;
  grid-template-rows: auto 1fr;
  grid-template-columns: 1fr auto;
  height: 100dvh;
}

header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  min-width: 0;
}

.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; min-width: 0; }
.brand strong { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand .sub { color: var(--muted); font-size: 12px; white-space: nowrap; }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 8px rgba(60, 207, 145, .6); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }

.toolbar { display: flex; gap: 6px; align-items: center; flex-wrap: nowrap; overflow-x: auto; }
.toolbar .sep { width: 1px; height: 22px; background: var(--line); margin: 0 2px; }

main { position: relative; overflow: hidden; background: #000; min-width: 0; }

#screen { position: absolute; inset: 0; }
#screen > div { background: #000 !important; }
#screen canvas { cursor: default !important; }
#screen.actual-size canvas { image-rendering: pixelated; }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: radial-gradient(ellipse at center, #141821 0%, #07080a 70%);
  z-index: 5;
}
.overlay[hidden] { display: none; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px;
  width: min(380px, 100%);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}
.card h2 { margin: 0 0 4px; font-size: 18px; }
.card p { margin: 0 0 16px; color: var(--muted); }
.card label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
.card .row { display: flex; gap: 8px; margin-top: 16px; justify-content: flex-end; }
.card .error { color: var(--bad); font-size: 13px; min-height: 18px; margin-top: 10px; }
.app-icon { display: block; width: 64px; height: 64px; margin: 0 0 8px -6px; }
.card[style*="center"] .app-icon { margin: 0 auto 8px; }

aside {
  width: 320px;
  border-left: 1px solid var(--line);
  background: var(--panel);
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
aside[hidden] { display: none; }

section.box {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}
section.box h3 {
  margin: 0 0 10px;
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stat { margin-bottom: 10px; }
.stat:last-child { margin-bottom: 0; }
.stat .label { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.stat .label span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; }
.bar { height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 3px; transition: width .4s ease; }
.bar > i.warn { background: var(--warn); }
.bar > i.bad { background: var(--bad); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.list { display: flex; flex-direction: column; gap: 2px; }
.svc, .proc {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 4px;
  border-radius: 6px;
  font-size: 13px;
}
.svc:hover { background: rgba(255, 255, 255, .03); }
.svc .name, .proc .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.svc .meta, .proc .meta { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.svc button { padding: 2px 8px; font-size: 12px; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

.type-row { display: flex; gap: 6px; }
.mods { display: flex; gap: 6px; align-items: center; margin-top: 8px; }
.mods button { min-width: 38px; font-size: 15px; padding: 4px 8px; }
.mods .hint { font-size: 11px; color: var(--muted); line-height: 1.3; }
.type-row input { flex: 1; }

dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0;
  width: min(900px, calc(100vw - 32px));
  max-height: calc(100dvh - 64px);
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog header { border-radius: 14px 14px 0 0; }
dialog pre {
  margin: 0;
  padding: 12px 16px;
  max-height: 70dvh;
  overflow: auto;
  font: 12px/1.45 ui-monospace, "SF Mono", Menlo, monospace;
  white-space: pre-wrap;
  word-break: break-all;
}

.toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: 8px 14px;
  border-radius: 8px;
  z-index: 50;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .4);
}
.toast[hidden] { display: none; }

.login-page { display: flex; align-items: center; justify-content: center; min-height: 100dvh; padding: 16px; }

.hide-sm { }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
  aside {
    width: auto;
    border-left: none;
    border-top: 1px solid var(--line);
    max-height: 45dvh;
  }
  .hide-sm { display: none; }
  .brand .sub { display: none; }
}
