:root {
  --bg: #0b0f14;
  --panel: #121820;
  --panel-2: #18202a;
  --line: #243040;
  --text: #e6edf3;
  --muted: #8b98a8;
  --accent: #3ddc84;
  --accent-ink: #062b16;
  --warn: #f0a33a;
  --bad: #f2555a;
  --info: #58a6ff;
  --radius: 12px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, textarea { font: inherit; color: inherit; }

/* ---------- buttons & inputs */
.btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 12px; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: #202a36; border-color: #34465c; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { background: #5be59a; }
.btn.warn { border-color: #5a4320; color: #ffc879; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 9px; font-size: 12.5px; }
.btn.icon { width: 52px; padding: 6px 0; font-size: 15px; }
.btn.wide { width: 100%; }
input[type=text], input[type=number], input:not([type]), input[type=password], textarea {
  background: #0d1218; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; outline: none; min-width: 0;
}
input:focus, textarea:focus { border-color: var(--info); }

/* ---------- top bar */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center;
  padding: 10px 16px; background: rgba(11,15,20,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; }
.host-stats { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.global-url { display: flex; gap: 6px; flex: 1 1 320px; }
.global-url input { flex: 1; }
.global-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- grid of instances */
.grid { display: grid; gap: 16px; padding: 16px; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); align-items: start; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.card-head { display: flex; align-items: center; gap: 8px; }
.card-head h2 { margin: 0; font-size: 16px; }
.badges { display: flex; gap: 4px; }
.badge { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 7px; }
.spacer { flex: 1; }
.state { font-size: 12px; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #555; box-shadow: 0 0 0 3px rgba(255,255,255,.04); }
.dot.ok { background: var(--accent); }
.dot.wait { background: var(--warn); }
.dot.bad { background: var(--bad); }

.stats { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.stats div { background: var(--panel-2); border-radius: 8px; padding: 5px 7px; min-width: 0; }
.stats span { display: block; font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stats b { display: block; font-weight: 600; font-size: 12.5px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.url-bar { display: flex; gap: 6px; }
.url-bar input { flex: 1; }

/* ---------- screen */
.screen-wrap { display: flex; justify-content: center; background: #05080b; border-radius: 10px; padding: 8px; }
.screen { position: relative; display: inline-flex; line-height: 0; max-width: 100%; }
.screen canvas {
  display: block; max-width: 100%; max-height: calc(100vh - 290px); min-height: 240px; width: auto; height: auto;
  background: #000; border-radius: 6px; touch-action: none; outline: none; cursor: default;
  image-rendering: auto;
}
.screen canvas:focus { box-shadow: 0 0 0 2px var(--info); }
.overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center;
  background: rgba(5,8,11,.72); color: var(--muted); font-size: 14px; line-height: 1.4; padding: 20px; border-radius: 6px; pointer-events: none;
}
.overlay[hidden] { display: none; }
.ime { position: absolute; left: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; padding: 0; border: 0; resize: none; }
.fs-bar { display: none; }

.navbar { display: flex; justify-content: center; gap: 10px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; }
.clip-panel { display: flex; flex-direction: column; gap: 6px; }
.clip-panel textarea { width: 100%; resize: vertical; }
.row { display: flex; gap: 6px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }

/* fullscreen */
.screen-wrap:fullscreen { background: #000; align-items: center; padding: 0; }
.screen-wrap:fullscreen .screen canvas { max-height: calc(100vh - 56px); max-width: 100vw; border-radius: 0; }
.screen-wrap:fullscreen .screen { flex-direction: column; align-items: center; }
.screen-wrap:fullscreen .fs-bar { display: flex; gap: 10px; justify-content: center; padding: 8px; line-height: 1.4; }

/* ---------- dialog */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; width: min(460px, 94vw); }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h3 { margin: 0 0 10px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 0 0 12px; padding: 10px 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
legend { color: var(--muted); font-size: 12px; padding: 0 4px; }
fieldset label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
fieldset .btn { grid-column: 1 / -1; }

/* ---------- toasts */
.toast-wrap { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: min(420px, 90vw); }
.toast { background: var(--panel-2); border: 1px solid var(--line); border-left: 4px solid var(--info); border-radius: 8px; padding: 9px 12px; box-shadow: 0 6px 24px rgba(0,0,0,.4); animation: in .15s ease-out; }
.toast.ok { border-left-color: var(--accent); }
.toast.err { border-left-color: var(--bad); }
@keyframes in { from { opacity: 0; transform: translateY(6px); } }

/* ---------- login */
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: min(360px, 92vw); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 26px; }
.login-card .brand { margin-bottom: 18px; font-size: 17px; }
.login-card form { display: flex; flex-direction: column; gap: 8px; }
.login-card label { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.login-card button { margin-top: 12px; }
.login-error { color: var(--bad); min-height: 1.4em; margin: 6px 0 0; font-size: 13px; }

@media (max-width: 860px) {
  .grid { grid-template-columns: 1fr; padding: 10px; }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .screen canvas { max-height: 78vh; }
}
