:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1c232c;
  --border: #232a33;
  --border-strong: #303a46;
  --text: #e6edf3;
  --muted: #aaaaaa;
  --dim: #888888;
  --accent: #58a6ff;
  --ok: #3fb950;
  --warn: #d29922;
  --err: #f85149;
  --run: #a371f7;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  /* The page itself must never scroll sideways; wide children scroll internally. */
  overflow-x: hidden;
}

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

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

.hidden { display: none !important; }

/* ---------- layout ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 40;
}
.topbar .brand {
  font-weight: 700;
  letter-spacing: -0.2px;
  flex-shrink: 0;
  white-space: nowrap;
}
.topbar .brand span { color: var(--accent); }
.topbar .ver {
  color: var(--dim);
  font-size: 12px;
  flex-shrink: 0;
  white-space: nowrap;
}
.topbar .spacer { flex: 1 1 auto; min-width: 0; }

.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: thin;
  white-space: nowrap;
  min-width: 0;
}
.tabs button {
  flex-shrink: 0;
  white-space: nowrap;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 6px 12px;
  color: var(--muted);
  cursor: pointer;
}
.tabs button:hover { color: var(--text); background: var(--panel-2); }
.tabs button.active {
  color: var(--text);
  background: var(--panel-2);
  border-color: var(--border-strong);
}

main { padding: 18px; max-width: 1500px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 18px;
  overflow: hidden;
}
.card > header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
  white-space: nowrap;
}
.card > header h2 {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.card > header .spacer { flex: 1 1 auto; min-width: 0; }
.card .body { padding: 14px; }

/* ---------- stat row ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
@media (max-width: 1100px) { .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 600px)  { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  min-width: 0;
}
.stat .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat .value {
  font-size: 20px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- tables ---------- */

.table-wrap { overflow-x: auto; }

table.tbl {
  width: 100%;
  min-width: 940px;
  border-collapse: collapse;
  /* Fixed layout is the fix that makes per-cell truncation actually hold.
     Column widths come from the colgroup, so one long cell can never squeeze
     its neighbours below their declared width. */
  table-layout: fixed;
}
table.tbl th,
table.tbl td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
table.tbl th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--dim);
  font-weight: 600;
  background: var(--panel-2);
  position: sticky;
  top: 0;
  z-index: 2;
}
table.tbl tbody tr:hover { background: #1a212a; }
table.tbl tbody tr.selected { background: #1e2733; }
table.tbl td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.tbl td.mono, .mono { font-family: var(--mono); font-size: 12px; }
table.tbl .empty { color: var(--dim); text-align: center; padding: 26px; }

/* ---------- badges & bars ---------- */

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  border: 1px solid transparent;
}
.badge.queued    { color: var(--muted); border-color: var(--border-strong); }
.badge.preparing,
.badge.installing,
.badge.bundling  { color: var(--warn); border-color: #4a3a12; background: #241d0c; }
.badge.rendering,
.badge.encoding  { color: var(--run); border-color: #3b2a5c; background: #1f1730; }
.badge.done      { color: var(--ok); border-color: #1b4620; background: #0f2413; }
.badge.failed    { color: var(--err); border-color: #5c2020; background: #2a1113; }
.badge.cancelled { color: var(--dim); border-color: var(--border-strong); }

.bar {
  position: relative;
  height: 6px;
  background: #0b0f14;
  border-radius: 999px;
  overflow: hidden;
  min-width: 60px;
}
.bar > i {
  display: block;
  height: 100%;
  background: var(--accent);
  transition: width 0.25s ease;
}
.bar.done > i { background: var(--ok); }
.bar.failed > i { background: var(--err); }

.progress-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  min-width: 0;
}
.progress-cell .bar { flex: 1 1 auto; min-width: 0; }
.progress-cell .pct {
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 12px;
  width: 38px;
  text-align: right;
}

.ts { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* ---------- controls ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  white-space: nowrap;
  background: var(--panel-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: var(--radius);
  padding: 6px 12px;
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: #46525f; background: #222b35; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: #1f6feb; border-color: #1f6feb; }
.btn.primary:hover:not(:disabled) { background: #2b7bf3; }
.btn.danger { color: var(--err); border-color: #5c2020; }
.btn.danger:hover:not(:disabled) { background: #2a1113; }
.btn.sm { padding: 3px 9px; font-size: 12px; }

.field { margin-bottom: 12px; min-width: 0; }
.field label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
  white-space: nowrap;
}
.field input[type="text"],
.field input[type="number"],
.field input[type="password"],
.field input[type="file"],
.field select,
.field textarea {
  width: 100%;
  background: #0b0f14;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 7px 10px;
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { font-family: var(--mono); font-size: 12px; resize: vertical; min-height: 110px; }
.field .hint { font-size: 11px; color: var(--dim); margin-top: 4px; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 14px; }
@media (max-width: 760px) { .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); } }

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  min-width: 0;
}
.row > .grow { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

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

.log {
  background: #080b0f;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  padding: 10px 12px;
  height: 320px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.log .l { color: #c9d1d9; }
.log .l.rrbox { color: var(--accent); }
.log .l.err { color: var(--err); }
.log .t { color: var(--dim); margin-right: 8px; }

/* ---------- login ---------- */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.login {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 26px;
}
.login h1 { margin: 0 0 4px; font-size: 20px; }
.login h1 span { color: var(--accent); }
.login p.sub { margin: 0 0 18px; color: var(--muted); font-size: 13px; }
.login .err {
  color: var(--err);
  font-size: 13px;
  margin-bottom: 10px;
  min-height: 18px;
}

/* ---------- modal (never a native dialog) ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  width: 100%;
  max-width: 560px;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  overflow: hidden;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.modal .body { padding: 16px; overflow: auto; }
.modal footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  white-space: nowrap;
}
.modal .msg { color: var(--muted); margin: 0 0 8px; }

/* ---------- toasts ---------- */

.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
  max-width: min(420px, calc(100vw - 32px));
}
.toast {
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-left-width: 3px;
  border-radius: var(--radius);
  padding: 10px 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  animation: slide-in 0.18s ease;
  overflow-wrap: anywhere;
}
.toast.ok   { border-left-color: var(--ok); }
.toast.err  { border-left-color: var(--err); }
.toast.info { border-left-color: var(--accent); }
.toast .title { font-weight: 600; margin-bottom: 2px; }
.toast .detail { color: var(--muted); font-size: 12px; }

@keyframes slide-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- misc ---------- */

video.preview {
  width: 100%;
  max-width: 100%;
  border-radius: var(--radius);
  background: #000;
  display: block;
}

.kv { display: grid; grid-template-columns: minmax(0, 140px) minmax(0, 1fr); gap: 6px 12px; }
.kv dt { color: var(--dim); white-space: nowrap; }
.kv dd {
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meter {
  height: 10px;
  border-radius: 999px;
  background: #0b0f14;
  overflow: hidden;
  display: flex;
}
.meter i { display: block; height: 100%; }
.meter i.out  { background: var(--accent); }
.meter i.jobs { background: var(--run); }
.meter i.deps { background: var(--warn); }
.meter i.tmp  { background: var(--dim); }

.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.legend i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; flex-shrink: 0; }

code.key {
  display: block;
  background: #0b0f14;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 10px;
  font-family: var(--mono);
  font-size: 12px;
  overflow-wrap: anywhere;
  margin: 8px 0;
}
