:root {
  --bg: #0b0f14;
  --surface: #141a21;
  --surface-2: #1b232c;
  --surface-3: #222c37;
  --border: #2a3440;
  --border-strong: #3a4654;
  --text: #e8eef5;
  --text-dim: #9fb0c3;
  --text-faint: #6b7d91;
  --accent: #4c9aff;
  --accent-soft: rgba(76, 154, 255, 0.14);
  --success: #3fb950;
  --success-soft: rgba(63, 185, 80, 0.14);
  --danger: #f85149;
  --danger-soft: rgba(248, 81, 73, 0.14);
  --warning: #d9a520;
  --warning-soft: rgba(217, 165, 32, 0.14);
  --neutral: #7d8da0;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

.hidden {
  display: none !important;
}

.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 32px 20px 80px;
}

.wrap.narrow {
  max-width: 460px;
}

/* ------------------------------------------------------------- header -- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(20, 26, 33, 0.85);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
  letter-spacing: -0.01em;
  font-size: 16px;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: linear-gradient(140deg, var(--accent), #7c5cff);
  color: #fff;
  font-size: 15px;
  flex-shrink: 0;
}

.topbar .spacer {
  flex: 1;
}

.topbar .who {
  color: var(--text-faint);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
}

/* -------------------------------------------------------------- cards -- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 18px;
}

.card > h2 {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 620;
  letter-spacing: -0.01em;
}

.card > .sub {
  margin: 0 0 18px;
  color: var(--text-dim);
  font-size: 13.5px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

/* -------------------------------------------------------------- forms -- */

label.field {
  display: block;
  margin-bottom: 14px;
}

label.field > span {
  display: block;
  font-size: 13px;
  font-weight: 560;
  margin-bottom: 6px;
  color: var(--text-dim);
}

input[type="email"],
input[type="password"],
input[type="text"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14.5px;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

input::placeholder {
  color: var(--text-faint);
}

textarea {
  font-family: var(--mono);
  font-size: 13px;
  resize: vertical;
  min-height: 92px;
}

.hint {
  font-size: 12.5px;
  color: var(--text-faint);
  margin-top: 6px;
}

.hint code {
  font-family: var(--mono);
  background: var(--surface-3);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}

/* ------------------------------------------------------------ buttons -- */

button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-3);
  color: var(--text);
  font-size: 14px;
  font-weight: 560;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  white-space: nowrap;
}

button:hover:not(:disabled),
.btn:hover {
  background: var(--surface-2);
  border-color: var(--text-faint);
  text-decoration: none;
}

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

button.primary,
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #05121f;
  font-weight: 640;
}
button.primary:hover:not(:disabled) {
  background: #6aabff;
  border-color: #6aabff;
}

button.danger {
  color: var(--danger);
  border-color: rgba(248, 81, 73, 0.4);
  background: var(--danger-soft);
}
button.danger:hover:not(:disabled) {
  background: rgba(248, 81, 73, 0.22);
}

button.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-dim);
}
button.ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

button.small,
.btn.small {
  padding: 5px 10px;
  font-size: 12.5px;
}

/* ------------------------------------------------------------ messages -- */

.msg {
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  margin-bottom: 14px;
  border: 1px solid transparent;
}
.msg.error {
  background: var(--danger-soft);
  border-color: rgba(248, 81, 73, 0.35);
  color: #ffb4af;
}
.msg.ok {
  background: var(--success-soft);
  border-color: rgba(63, 185, 80, 0.35);
  color: #8ee699;
}
.msg.info {
  background: var(--accent-soft);
  border-color: rgba(76, 154, 255, 0.35);
  color: #a8ccff;
}
.msg:empty {
  display: none;
}

/* -------------------------------------------------------------- stats --- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.stat .n {
  font-size: 26px;
  font-weight: 680;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.stat .k {
  font-size: 12px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 4px;
  font-weight: 600;
}

.stat.active .n {
  color: var(--accent);
}
.stat.failed .n {
  color: var(--danger);
}
.stat.ok .n {
  color: var(--success);
}

/* --------------------------------------------------------------- runs --- */

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.toolbar select,
.toolbar input {
  width: auto;
  min-width: 150px;
}

.run {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
}

.run-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  user-select: none;
}

.run-head:hover {
  background: var(--surface-2);
}

.run-main {
  min-width: 0;
  flex: 1;
}

.run-title {
  font-weight: 580;
  font-size: 14.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.run-meta {
  font-size: 12.5px;
  color: var(--text-faint);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 3px;
  font-family: var(--mono);
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--neutral);
}
.dot.success {
  background: var(--success);
  box-shadow: 0 0 8px rgba(63, 185, 80, 0.6);
}
.dot.failure {
  background: var(--danger);
  box-shadow: 0 0 8px rgba(248, 81, 73, 0.5);
}
.dot.in_progress {
  background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}
.dot.queued,
.dot.waiting,
.dot.requested,
.dot.pending {
  background: var(--warning);
}
.dot.cancelled,
.dot.skipped,
.dot.neutral,
.dot.startup_failure {
  background: var(--neutral);
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.45;
    transform: scale(0.8);
  }
}

.badge {
  font-size: 11px;
  font-weight: 640;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 8px;
  border-radius: 20px;
  background: var(--surface-3);
  color: var(--text-dim);
  flex-shrink: 0;
}
.badge.success {
  background: var(--success-soft);
  color: var(--success);
}
.badge.failure {
  background: var(--danger-soft);
  color: var(--danger);
}
.badge.in_progress {
  background: var(--accent-soft);
  color: var(--accent);
}

.chev {
  color: var(--text-faint);
  transition: transform 0.18s;
  flex-shrink: 0;
  font-size: 12px;
}
.run.open .chev {
  transform: rotate(90deg);
}

.run-body {
  border-top: 1px solid var(--border);
  background: var(--bg);
  padding: 6px 16px 14px;
}

.job {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.job:last-child {
  border-bottom: none;
}

.job-head {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  font-weight: 560;
}

.job-sub {
  font-size: 12px;
  color: var(--text-faint);
  font-family: var(--mono);
  margin-top: 2px;
}

.steps {
  margin: 10px 0 0 20px;
  border-left: 2px solid var(--border);
  padding-left: 14px;
}

.step {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  padding: 4px 0;
  color: var(--text-dim);
}
.step .n {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-faint);
  min-width: 18px;
}
.step .nm {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.step.failure .nm {
  color: #ffb4af;
}
.step.success .nm {
  color: var(--text);
}

button.linkish {
  background: none;
  border: none;
  padding: 2px 6px;
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
}
button.linkish:hover {
  background: var(--accent-soft);
  text-decoration: underline;
}

/* ---------------------------------------------------------------- log --- */

.logbox {
  margin-top: 10px;
  background: #06090d;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 420px;
  overflow: auto;
}

.logsec {
  border-bottom: 1px solid var(--border);
}
.logsec:last-child {
  border-bottom: none;
}

.logsec > summary {
  padding: 8px 12px;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--accent);
  cursor: pointer;
  user-select: none;
  background: var(--surface);
  position: sticky;
  top: 0;
}

.logsec pre {
  margin: 0;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.5;
  color: #b9c7d6;
  white-space: pre-wrap;
  word-break: break-word;
}

/* --------------------------------------------------------------- code --- */

.code-display {
  font-family: var(--mono);
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-align: center;
  padding: 20px 12px;
  background: var(--bg);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--accent);
  user-select: all;
}

.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-faint);
}
.empty .big {
  font-size: 34px;
  margin-bottom: 10px;
}

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* -------------------------------------------------------------- table --- */

table.list {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
table.list th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  padding: 0 10px 9px 0;
  font-weight: 640;
  border-bottom: 1px solid var(--border);
}
table.list td {
  padding: 11px 10px 11px 0;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.list tr:last-child td {
  border-bottom: none;
}
table.list td.mono {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text-dim);
}

/* -------------------------------------------------------------- scan ---- */

#scan-video {
  width: 100%;
  border-radius: var(--radius-sm);
  background: #000;
  display: block;
  aspect-ratio: 1 / 1;
  object-fit: cover;
}

.scan-frame {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}

.scan-frame::after {
  content: "";
  position: absolute;
  inset: 14%;
  border: 2px solid rgba(76, 154, 255, 0.85);
  border-radius: 12px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
}
.tabs button {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 8px 12px;
  font-size: 13.5px;
}
.tabs button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

footer.legal {
  text-align: center;
  color: var(--text-faint);
  font-size: 12.5px;
  padding: 26px 20px 40px;
}

/* ---------------------------------------------------------- responsive -- */

@media (max-width: 640px) {
  .wrap {
    padding: 18px 14px 60px;
  }
  .card {
    padding: 17px;
  }
  .stat .n {
    font-size: 22px;
  }
  .run-head {
    padding: 12px 13px;
    gap: 9px;
  }
  .topbar .who {
    max-width: 110px;
  }
  .code-display {
    font-size: 26px;
    letter-spacing: 0.1em;
  }
  .steps {
    margin-left: 8px;
    padding-left: 11px;
  }
  .toolbar select,
  .toolbar input {
    flex: 1;
    min-width: 0;
  }
  .run-meta {
    font-size: 11.5px;
    gap: 7px;
  }
}
