:root {
  color-scheme: light dark;
  --accent: #4f46e5;
  --bg: #0b0d12;
  --panel: #151821;
  --border: #262b38;
  --text: #e7e9ee;
  --muted: #9aa1b2;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  padding: 2rem;
}

header {
  max-width: 720px;
  margin: 0 auto 2rem;
}

header h1 {
  margin-bottom: 0.25rem;
}

header p {
  color: var(--muted);
}

header {
  position: relative;
}

#sign-out-btn {
  position: absolute;
  top: 0;
  right: 0;
}

#login-gate {
  max-width: 720px;
  margin: 0 auto 1.5rem;
  text-align: center;
}

#login-gate h2 {
  margin-top: 0;
}

#google-sign-in-btn {
  margin: 0 auto;
}

main {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Author rules on `display` beat the UA stylesheet's [hidden] rule, so the
   hidden attribute alone won't hide an element that also matches `main`
   above - this reasserts it explicitly for the login-gated app shell. */
main[hidden] {
  display: none;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
}

form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--muted);
}

label.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.row {
  display: flex;
  gap: 1rem;
}

.row label {
  flex: 1;
}

input, select, textarea {
  background: #0f1117;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.55rem 0.7rem;
  font-size: 0.95rem;
  font-family: inherit;
}

textarea {
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, monospace;
}

button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 0.7rem 1rem;
  font-size: 1rem;
  cursor: pointer;
}

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

.steps-field {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.steps-label {
  font-size: 0.9rem;
  color: var(--muted);
}

.steps-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.step-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #0f1117;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.5rem;
}

.step-item.dragging {
  opacity: 0.4;
}

.step-item.drag-over {
  border-color: var(--accent);
}

.step-handle {
  cursor: grab;
  color: var(--muted);
  letter-spacing: -3px;
  user-select: none;
  padding: 0 0.1rem;
}

.step-number {
  color: var(--muted);
  min-width: 1.6rem;
  text-align: right;
  font-size: 0.9rem;
}

.step-input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 0.3rem 0.2rem;
}

.step-input:focus {
  outline: none;
  background: rgba(79, 70, 229, 0.1);
  border-radius: 6px;
}

.step-remove {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
}

.step-remove:hover {
  color: #f87171;
}

.secondary-btn {
  align-self: flex-start;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
}

.step-badge {
  background: rgba(79, 70, 229, 0.25);
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

.step-badge-guided {
  background: rgba(234, 179, 8, 0.25);
  color: #eab308;
}

.step-marker {
  width: 14px;
  height: 14px;
  min-width: 14px;
  border-radius: 50%;
  border: 2px solid var(--muted);
  background: transparent;
  padding: 0;
  flex-shrink: 0;
  cursor: pointer;
}

.step-marker:hover:not(:disabled) {
  border-color: var(--text);
}

.step-marker.selected {
  background: #ef4444;
  border-color: #ef4444;
}

.step-marker:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

#vnc-viewer-wrap {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  height: 500px;
}

#vnc-frame {
  width: 100%;
  height: 100%;
  border: none;
  background: #000;
}

.step-ghost {
  opacity: 0.45;
  pointer-events: none;
  border-style: dashed;
}

.step-marker-ghost {
  width: 14px;
  height: 14px;
  min-width: 14px;
  border-radius: 50%;
  border: 2px dashed var(--muted);
  flex-shrink: 0;
}

.step-ghost-text {
  flex: 1;
  font-style: italic;
  color: var(--muted);
  font-size: 0.9rem;
}

.scenario-list {
  list-style: none;
  padding: 0;
  margin: 0 0 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.scenario-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: #0f1117;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
}

.scenario-name {
  font-weight: 600;
}

.scenario-url {
  color: var(--muted);
  font-size: 0.85rem;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#group-manage-row {
  margin-bottom: 1rem;
}

#group-manage-row input {
  flex: 1;
}

.group-section {
  margin-bottom: 1.25rem;
}

.group-section:last-child {
  margin-bottom: 0.75rem;
}

.group-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}

.group-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.group-action {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  padding: 0.15rem 0.5rem;
  font-size: 0.75rem;
  cursor: pointer;
}

.group-action:hover {
  color: var(--text);
  border-color: var(--text);
}

.screenplay-scenes {
  white-space: normal;
}

.scene-name {
  font-weight: 600;
}

.matrix-segment-row td {
  background: rgba(79, 70, 229, 0.12);
  color: var(--accent);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--border);
}

.run-error {
  color: #f87171;
  font-size: 0.85rem;
  margin-top: -0.5rem;
}

.matrix-wrap {
  margin-bottom: 1.5rem;
}

.run-matrix {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.run-matrix th,
.run-matrix td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.7rem;
}

.run-matrix th {
  color: var(--muted);
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
}

.run-matrix th:first-child {
  text-align: left;
}

.matrix-step-label {
  color: var(--text);
  white-space: nowrap;
}

.matrix-cell {
  position: relative;
  text-align: center;
  cursor: default;
}

.matrix-box {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  background: #3f4658;
}

.matrix-cell.status-success .matrix-box { background: #22c55e; }
.matrix-cell.status-failed .matrix-box { background: #ef4444; }
.matrix-cell.status-running .matrix-box { background: #eab308; }
.matrix-cell.status-pending .matrix-box { background: #3f4658; }

.matrix-tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: #1c2030;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  font-size: 0.8rem;
  line-height: 1.35;
  text-align: left;
  white-space: normal;
  width: max-content;
  max-width: 260px;
  z-index: 20;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.matrix-tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #1c2030;
}

.matrix-cell:hover .matrix-tooltip {
  display: block;
}

.run-status {
  margin-bottom: 1rem;
  font-weight: 600;
}

.run-cards {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.run-card-title {
  margin-top: 0;
}

video {
  width: 100%;
  border-radius: 8px;
  background: black;
}

.actions {
  margin-top: 1rem;
}

.actions a {
  color: var(--accent);
}
