/* webctl hub — dark theme, mobile-first */
:root {
  --bg: #0b0e14;
  --bg-elev: #121724;
  --bg-elev-2: #1a2132;
  --line: #243049;
  --line-soft: #1b2337;
  --text: #e6ecf5;
  --text-dim: #96a2bb;
  --text-faint: #64708a;
  --accent: #4f8cff;
  --accent-dim: #2b4d8f;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --attn: #c084fc;
  --radius: 10px;
  --pad: 14px;
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas,
    monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a {
  color: var(--accent);
  text-decoration: none;
}
button {
  font-family: inherit;
  font-size: inherit;
}

/* ---- App shell ---- */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.02em;
}
.brand-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}
.spacer {
  flex: 1;
}
.conn {
  display: inline-flex;
  align-items: center;
}
.conn-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: background 0.3s;
}
.conn.online .conn-dot {
  background: var(--good);
  box-shadow: 0 0 8px var(--good);
}
.conn.offline .conn-dot {
  background: var(--bad);
}
.user-chip {
  color: var(--text-dim);
  font-size: 13px;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  font-size: 18px;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.icon-btn:hover {
  background: var(--bg-elev-2);
}
.stop-all {
  background: #3a1218;
  border: 1px solid #7f1d1d;
  color: #fecaca;
  font-weight: 700;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}
.stop-all:hover {
  background: #571a22;
}
.stop-all.armed {
  background: var(--bad);
  color: #1a0505;
  border-color: var(--bad);
  animation: pulse 1.2s infinite;
}
@keyframes pulse {
  50% {
    opacity: 0.7;
  }
}

.body {
  flex: 1;
  display: flex;
  min-height: 0;
}
.sidenav {
  width: 210px;
  flex-shrink: 0;
  background: var(--bg-elev);
  border-right: 1px solid var(--line);
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}
.sidenav a {
  color: var(--text-dim);
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 14px;
  white-space: nowrap;
}
.sidenav a:hover {
  background: var(--bg-elev-2);
  color: var(--text);
}
.sidenav a.active {
  background: var(--accent-dim);
  color: #fff;
}
.nav-scrim {
  display: none;
}
.view {
  flex: 1;
  min-width: 0;
  padding: var(--pad);
  padding-bottom: calc(var(--pad) + env(safe-area-inset-bottom));
  overflow-x: hidden;
}

/* ---- Mobile nav ---- */
@media (max-width: 780px) {
  .sidenav {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    padding-top: max(10px, env(safe-area-inset-top));
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
  }
  .app.nav-open .sidenav {
    transform: translateX(0);
  }
  .app.nav-open .nav-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(0, 0, 0, 0.5);
  }
  .user-chip {
    display: none;
  }
}
@media (min-width: 781px) {
  #navToggle {
    display: none;
  }
}

/* ---- Common blocks ---- */
h1,
h2,
h3 {
  margin: 0 0 12px;
  font-weight: 650;
}
h1 {
  font-size: 21px;
}
h2 {
  font-size: 17px;
}
.page-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.page-head h1 {
  margin: 0;
}
.muted {
  color: var(--text-dim);
}
.faint {
  color: var(--text-faint);
}
.mono {
  font-family: var(--mono);
  font-size: 12.5px;
}
.row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.card + .card {
  margin-top: 12px;
}
.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  margin-bottom: 6px;
}

/* buttons */
.btn {
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 550;
}
.btn:hover {
  border-color: var(--accent-dim);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #06101f;
}
.btn.primary:hover {
  filter: brightness(1.08);
}
.btn.danger {
  background: #3a1218;
  border-color: #7f1d1d;
  color: #fecaca;
}
.btn.good {
  background: #08301f;
  border-color: #12633f;
  color: #a7f3d0;
}
.btn.sm {
  padding: 5px 10px;
  font-size: 13px;
}
.btn.ghost {
  background: transparent;
}

/* form controls */
label.field {
  display: block;
  margin-bottom: 12px;
}
label.field > .lab {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 4px;
}
label.field > .desc {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 3px;
}
input[type="text"],
input[type="password"],
input[type="number"],
input[type="url"],
input[type="datetime-local"],
select,
textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 11px;
  font-family: inherit;
  font-size: 14px;
}
textarea {
  font-family: var(--mono);
  font-size: 13px;
  resize: vertical;
  min-height: 90px;
}
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.check {
  display: flex;
  align-items: center;
  gap: 8px;
}
.check input {
  width: auto;
}

/* tables */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
th,
td {
  text-align: left;
  padding: 9px 11px;
  border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
}
th {
  color: var(--text-dim);
  font-weight: 550;
  background: var(--bg-elev);
  position: sticky;
  top: 0;
}
tbody tr:hover {
  background: var(--bg-elev);
}
tr.clickable {
  cursor: pointer;
}

/* badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  border: 1px solid transparent;
  text-transform: lowercase;
}
.badge.queued {
  background: #1e2740;
  color: var(--text-dim);
}
.badge.running {
  background: #10233f;
  color: #7cc0ff;
  border-color: #23507f;
}
.badge.paused {
  background: #2a2410;
  color: var(--warn);
}
.badge.needs_attention {
  background: #2a1440;
  color: var(--attn);
  border-color: #6b3fa0;
  animation: pulse 1.5s infinite;
}
.badge.succeeded {
  background: #06281b;
  color: var(--good);
}
.badge.failed {
  background: #2a1113;
  color: var(--bad);
}
.badge.canceled {
  background: #22262f;
  color: var(--text-faint);
}
.badge.approved {
  background: #06281b;
  color: var(--good);
}
.badge.draft {
  background: #2a2410;
  color: var(--warn);
}
.badge.disabled {
  background: #22262f;
  color: var(--text-faint);
}
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.dot.on {
  background: var(--good);
  box-shadow: 0 0 6px var(--good);
}
.dot.off {
  background: var(--text-faint);
}

/* code / preview */
pre.code {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  max-height: 340px;
  white-space: pre;
}
.logs {
  background: #05080f;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 12.5px;
  max-height: 320px;
  overflow: auto;
}
.logs .log-line {
  white-space: pre-wrap;
  word-break: break-word;
}
.logs .ts {
  color: var(--text-faint);
  margin-right: 8px;
}

/* login */
.login-root {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 26px;
}
.login-card h1 {
  display: flex;
  align-items: center;
  gap: 10px;
}
.login-err {
  color: var(--bad);
  font-size: 13px;
  min-height: 18px;
  margin-top: 4px;
}

/* toasts */
.toasts {
  position: fixed;
  z-index: 100;
  right: 12px;
  bottom: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, 92vw);
}
.toast {
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 9px;
  padding: 10px 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  animation: slidein 0.2s ease;
}
@keyframes slidein {
  from {
    transform: translateY(8px);
    opacity: 0;
  }
}
.toast .t-title {
  font-weight: 600;
  font-size: 14px;
}
.toast .t-body {
  color: var(--text-dim);
  font-size: 13px;
  margin-top: 2px;
}
.toast.info {
  border-left-color: var(--accent);
}
.toast.success {
  border-left-color: var(--good);
}
.toast.warn {
  border-left-color: var(--warn);
}
.toast.error {
  border-left-color: var(--bad);
}

/* misc */
.empty {
  text-align: center;
  color: var(--text-faint);
  padding: 40px 12px;
}
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
  vertical-align: middle;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.pill {
  display: inline-block;
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 12px;
  color: var(--text-dim);
}
.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 14px;
  font-size: 13.5px;
}
.kv dt {
  color: var(--text-dim);
}
.kv dd {
  margin: 0;
  word-break: break-word;
}
.section-gap {
  margin-top: 18px;
}
.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* live screen */
.screen-stage {
  position: relative;
  background: #000;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  min-height: 200px;
  display: grid;
  place-items: center;
}
.screen-stage img {
  max-width: 100%;
  display: block;
  cursor: crosshair;
}
.screen-stage .overlay-hint {
  position: absolute;
  color: var(--text-faint);
  font-size: 13px;
}
.replay-stage {
  background: #000;
  border: 1px solid var(--line);
  border-radius: 10px;
  display: grid;
  place-items: center;
  min-height: 160px;
}
.replay-stage img {
  max-width: 100%;
  max-height: 60vh;
}
.kill-big {
  width: 100%;
  padding: 18px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.03em;
}
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-soft);
}
.toggle-row:last-child {
  border-bottom: none;
}
.secret-reveal {
  background: #05080f;
  border: 1px solid var(--good);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 13px;
  word-break: break-all;
  display: flex;
  gap: 8px;
  align-items: center;
}
