:root {
  color-scheme: dark;
  --bg: #14181d;
  --panel: #1b2027;
  --raised: #232a33;
  --line: #303946;
  --text: #dfe4ea;
  --muted: #8c97a5;
  --accent: #f5b04c;
  --accent-ink: #1b1508;
  --green: #3fb97f;
  --red: #e5534b;
  --blue: #6db3f2;
  --mono: ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); }
h1, h2, h3, p { margin: 0; }
a { color: var(--blue); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); }
.right { text-align: right; }
.spacer { flex: 1; }

button, .button {
  display: inline-block; padding: 6px 12px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--raised); color: var(--text); font: inherit; text-decoration: none; cursor: pointer;
  white-space: nowrap;
}
button:hover:not(:disabled), .button:hover { border-color: var(--muted); }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.warn { background: transparent; border-color: var(--accent); color: var(--accent); }
button.active { border-color: var(--blue); color: var(--blue); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover:not(:disabled) { color: var(--text); border-color: var(--line); }
button.ghost.danger:hover:not(:disabled) { color: var(--red); border-color: var(--red); }
button.small { padding: 1px 6px; font-size: 12px; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }

input, select, textarea {
  width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--text); font: inherit;
}
textarea.mono { font: 12.5px/1.45 var(--mono); resize: vertical; }

.brand { font: 700 18px var(--mono); letter-spacing: -.5px; color: var(--text); text-decoration: none; }
.brand span { color: var(--accent); }

.topbar { display: flex; align-items: center; gap: 8px; height: 52px; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.lab-title { width: 260px; margin-left: 12px; background: transparent; border-color: transparent; font-weight: 600; font-size: 15px; }
.lab-title:hover, .lab-title:focus { border-color: var(--line); }

.badge { display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: 12px; background: var(--raised); color: var(--muted); }
.badge.running { background: rgb(63 185 127 / .16); color: var(--green); }
.badge.failed { background: rgb(229 83 75 / .16); color: var(--red); }
.badge.busy { background: rgb(245 176 76 / .16); color: var(--accent); }

/* Login */
.login-page { display: grid; place-items: center; padding: 16px; }
.login-card { display: grid; gap: 14px; width: min(320px, 100%); padding: 28px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.login-card label { display: grid; gap: 4px; color: var(--muted); }
.form-error { min-height: 1.4em; color: var(--red); }

/* Home */
.home { display: grid; gap: 36px; max-width: 1040px; margin: 0 auto; padding: 28px 16px 60px; }
.home section { display: grid; gap: 12px; }
.section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.home h2 { font-size: 18px; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { width: 220px; }
.lab-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.lab-card { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: center; padding: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; color: inherit; text-decoration: none; }
.lab-card:hover { border-color: var(--muted); }
.lab-card strong { grid-column: 1 / -1; font-size: 15px; overflow-wrap: anywhere; }
.lab-card .badge { justify-self: start; }
.lab-card button { grid-column: 2; grid-row: 2 / 4; }
.table { width: 100%; border-collapse: collapse; }
.table td { padding: 8px 10px; border-bottom: 1px solid var(--line); }
.progress { position: relative; height: 24px; border-radius: 6px; background: var(--raised); overflow: hidden; }
.progress div { height: 100%; width: 0; background: rgb(245 176 76 / .4); }
.progress span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 12px; }

/* Lab editor */
.lab-page { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
.workspace { flex: 1; display: grid; grid-template-columns: 240px minmax(0, 1fr) 320px; min-height: 0; }
.palette, .inspector { overflow-y: auto; padding: 12px; background: var(--panel); }
.palette { display: flex; flex-direction: column; gap: 8px; border-right: 1px solid var(--line); }
.inspector { display: flex; flex-direction: column; gap: 12px; border-left: 1px solid var(--line); }
.palette h3 { margin: 12px 0 4px; color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
.palette-item { display: block; width: 100%; margin-bottom: 4px; padding: 7px 9px; text-align: left; white-space: normal; cursor: grab; }
.palette-item strong { display: block; font: 600 12.5px var(--mono); overflow-wrap: anywhere; }
.palette-item small { display: block; color: var(--muted); font-size: 11.5px; line-height: 1.3; }

.canvas-wrap { position: relative; min-width: 0; background-color: var(--bg); background-image: radial-gradient(#2a323d 1px, transparent 1px); background-size: 24px 24px; }
#canvas { position: absolute; inset: 0; }
.canvas-hint { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); pointer-events: none; }
.connect-hint { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); padding: 5px 14px; border: 1px solid var(--blue); border-radius: 99px; background: var(--panel); color: var(--blue); font-size: 13px; pointer-events: none; }

.inspector h2 { font: 600 17px var(--mono); overflow-wrap: anywhere; }
.inspector h3 { margin-top: 2px; font-size: 13px; }
.state-row { margin-bottom: 8px; }
.button-row { display: flex; flex-wrap: wrap; gap: 6px; }
.note { padding: 7px 9px; border-radius: 6px; background: var(--raised); color: var(--muted); font-size: 12.5px; }
.note.warn { color: var(--accent); }
#node-actions .note { margin-bottom: 8px; }
.field { display: grid; gap: 3px; }
.field > span { color: var(--muted); font-size: 12.5px; }
.field small { color: var(--muted); font-size: 11.5px; }
.field-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.link-list { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; font-size: 13px; }
.link-list li { display: flex; align-items: center; gap: 5px; }
.link-list button { margin-left: auto; }
.help { display: grid; gap: 6px; margin: 0; padding: 0; color: var(--muted); list-style: none; font-size: 13px; }
kbd { padding: 0 5px; border: 1px solid var(--line); border-radius: 4px; font: 11.5px var(--mono); }

.logs { width: min(900px, calc(100vw - 32px)); height: min(640px, calc(100dvh - 32px)); padding: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--text); }
.logs[open] { display: flex; flex-direction: column; }
.logs::backdrop { background: rgb(0 0 0 / .55); }
.logs header { display: flex; align-items: center; justify-content: space-between; padding: 8px 14px; border-bottom: 1px solid var(--line); }
.logs pre { flex: 1; margin: 0; padding: 12px 14px; overflow: auto; font: 12.5px/1.5 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }

.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; width: min(420px, calc(100vw - 32px)); z-index: 10; }
.toast { padding: 10px 14px; border: 1px solid var(--red); border-radius: 8px; background: var(--panel); overflow-wrap: anywhere; }
.toast.ok { border-color: var(--green); }

/* Console */
.console-page { display: flex; flex-direction: column; height: 100dvh; background: #0d1014; overflow: hidden; }
.console-bar { display: flex; align-items: center; gap: 12px; min-height: 36px; padding: 2px 12px; background: var(--panel); border-bottom: 1px solid var(--line); font-size: 13px; }
.console-bar strong { font-family: var(--mono); }
.console-screen { flex: 1; min-height: 0; padding: 4px; }
.console-screen .xterm { height: 100%; }

@media (max-width: 900px) {
  .workspace { grid-template-columns: minmax(0, 1fr); grid-template-rows: 150px minmax(280px, 1fr) minmax(0, 40%); }
  .palette { border-right: 0; border-bottom: 1px solid var(--line); }
  .inspector { border-left: 0; border-top: 1px solid var(--line); }
  .topbar { overflow-x: auto; }
  .lab-title { width: 150px; margin-left: 0; flex: none; }
}
