:root {
  color-scheme: light;
  --bg: #f7f7f4;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #667085;
  --line: #d8dde5;
  --accent: #0f766e;
  --active: #f59e0b;
  --complete: #16a34a;
  --failed: #dc2626;
}

* {
  box-sizing: border-box;
}

/* The `hidden` attribute must win over component display rules (e.g.
   .auth-gate { display: grid }), which would otherwise keep a "hidden"
   panel visible. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 6px;
  padding: 8px 10px;
  cursor: pointer;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

button.primary:hover:not(:disabled) {
  filter: brightness(1.08);
}

button.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

button.ghost:hover {
  color: var(--ink);
  border-color: var(--line);
}

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  min-width: 0;
  font: inherit;
  color: var(--ink);
  background: #fff;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 1px;
}

/* ---- Toasts ---- */
.toasts {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  min-width: 220px;
  max-width: 360px;
  padding: 11px 14px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  box-shadow: 0 8px 24px rgb(16 24 40 / 20%);
  opacity: 0;
  transform: translateX(12px);
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(0);
}

.toast.error {
  background: var(--failed);
}

.toast.success {
  background: var(--complete);
}

/* ---- Auth gate ---- */
.auth-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 70% -10%, rgb(15 118 110 / 12%), transparent),
    var(--bg);
}

.auth-card {
  width: min(400px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 12px 40px rgb(16 24 40 / 10%);
}

.auth-brand h1 {
  margin: 0;
  font-size: 30px;
}

.auth-brand p {
  margin: 4px 0 20px;
  color: var(--muted);
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px;
  margin-bottom: 18px;
}

.auth-tab {
  border: none;
  background: transparent;
  padding: 8px;
  border-radius: 6px;
  color: var(--muted);
}

.auth-tab.active {
  background: #fff;
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 2px rgb(16 24 40 / 10%);
}

.auth-form {
  display: grid;
  gap: 6px;
}

.auth-form label {
  font-size: 13px;
  color: var(--muted);
  margin-top: 6px;
}

.auth-form .primary {
  margin-top: 16px;
  padding: 11px;
}

.auth-hint {
  margin: 16px 0 0;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

/* ---- Topbar additions ---- */
.topbar-right {
  display: flex;
  align-items: end;
  gap: 24px;
}

.room-control {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  width: auto;
}

.user-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-badge {
  font-weight: 600;
  font-size: 14px;
}

.conn {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.conn.online {
  background: color-mix(in srgb, var(--complete) 16%, transparent);
  color: var(--complete);
}

.conn.offline {
  background: var(--bg);
  color: var(--muted);
}

/* ---- Selects, empty states, editor, hints ---- */
.actions select {
  max-width: 220px;
}

.empty-state {
  max-width: 460px;
  margin: 24px auto;
  padding: 24px;
  text-align: center;
  color: var(--muted);
}

.empty-state h3 {
  margin: 0 0 6px;
  color: var(--ink);
  font-size: 18px;
}

.empty-state ul {
  text-align: left;
  display: inline-block;
  margin: 12px auto;
  line-height: 1.6;
}

.empty-state .primary {
  margin-top: 8px;
}

.editor {
  border-top: 1px solid var(--line);
  background: var(--bg);
}

.editor > summary {
  cursor: pointer;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.editor-body {
  padding: 0 12px 12px;
}

.editor textarea {
  width: 100%;
  min-height: 150px;
  resize: vertical;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
}

.editor-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.hint {
  color: var(--muted);
  font-size: 13px;
  margin: 8px 0 0;
}

.shell {
  min-height: 100vh;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
}

.topbar h1,
.topbar p,
.panel h2,
.panel h3 {
  margin: 0;
}

.topbar h1 {
  font-size: 28px;
  line-height: 1.1;
}

.topbar p {
  color: var(--muted);
  margin-top: 3px;
}

.room-control {
  display: grid;
  gap: 4px;
  width: min(280px, 100%);
}

.room-control label {
  color: var(--muted);
  font-size: 13px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(420px, 1.4fr) minmax(320px, 0.8fr);
  grid-template-rows: minmax(520px, 1fr) 260px;
  gap: 14px;
  min-height: calc(100vh - 112px);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.graph-panel {
  grid-row: 1 / 3;
  display: flex;
  flex-direction: column;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.panel-header h2 {
  font-size: 16px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.graph {
  position: relative;
  flex: 1;
  min-height: 420px;
  overflow: auto;
  padding: 24px;
}

.node {
  position: absolute;
  width: 172px;
  min-height: 58px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 10px;
  box-shadow: 0 1px 2px rgb(16 24 40 / 8%);
}

.node.active {
  border-color: var(--active);
  box-shadow: 0 0 0 3px rgb(245 158 11 / 18%);
}

.node.complete {
  border-color: var(--complete);
}

.node .type {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.node .label {
  margin-top: 4px;
  font-weight: 650;
  line-height: 1.2;
}

.edge {
  position: absolute;
  height: 2px;
  background: var(--line);
  transform-origin: left center;
}

.edge-label {
  position: absolute;
  max-width: 180px;
  color: var(--muted);
  background: var(--panel);
  padding: 2px 4px;
  font-size: 12px;
}

.run-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.run-summary div {
  display: grid;
  gap: 2px;
}

.run-summary span {
  color: var(--muted);
  font-size: 12px;
}

.run-summary strong {
  font-size: 14px;
}

.state-editor {
  padding: 12px;
}

.state-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  margin: 10px 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 7px 4px;
  text-align: left;
  overflow-wrap: anywhere;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.events-panel ol {
  margin: 0;
  padding: 12px 12px 12px 38px;
  height: 205px;
  overflow: auto;
}

.events-panel li {
  margin-bottom: 8px;
  font-size: 13px;
}

#connection-state {
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }

  .graph-panel {
    grid-row: auto;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }
}
