:root {
  --bg: #0b1016;
  --bg-soft: #111823;
  --card: #141d29;
  --line: #22303f;
  --line-soft: #1a2634;
  --ink: #e8eef5;
  --ink-dim: #9aabbd;
  --ink-faint: #6b7d90;
  --accent: #f4c95d;
  --accent-ink: #241d05;
  --ok: #5fd08a;
  --warn: #e8b45a;
  --bad: #ea6f6f;
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  background-image:
    radial-gradient(900px 500px at 130% -10%, rgba(244, 201, 93, 0.07), transparent 60%),
    radial-gradient(700px 400px at -10% 110%, rgba(95, 208, 138, 0.05), transparent 60%);
  background-attachment: fixed;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 16px; }
p { margin: 0; }
code { font-family: var(--mono); font-size: 0.88em; color: var(--ink); background: #0d141c; padding: 1px 5px; border-radius: 5px; border: 1px solid var(--line-soft); }
.muted { color: var(--ink-dim); }
.tiny { font-size: 12.5px; line-height: 1.55; }
.spacer { flex: 1; }
em { font-style: normal; color: var(--ink-faint); }
[hidden] { display: none !important; }

/* ── login ──────────────────────────────────────────────────────────────── */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 26px;
  display: grid;
  gap: 18px;
  box-shadow: 0 24px 60px -30px #000;
}
.brand { display: flex; gap: 12px; align-items: center; }
.brand h1 { font-size: 19px; }
.brand small, .brand p { font-size: 12.5px; }
.brand-mark { color: var(--accent); display: grid; place-items: center; }
.brand.small { gap: 9px; }
.brand.small strong { font-size: 14.5px; letter-spacing: 0.01em; }

/* ── shell ──────────────────────────────────────────────────────────────── */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(11, 16, 22, 0.85);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab {
  background: none;
  border: 0;
  color: var(--ink-dim);
  font: inherit;
  font-size: 13.5px;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}
.tab:hover { color: var(--ink); background: #16202c; }
.tab.active { color: var(--accent-ink); background: var(--accent); font-weight: 600; }
.tab .count { font-size: 11px; background: #0d141c; color: var(--ink-dim); border-radius: 20px; padding: 1px 6px; }
.tab.active .count { background: rgba(0, 0, 0, 0.22); color: var(--accent-ink); }

main { padding: 20px; max-width: 1400px; width: 100%; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }
.grid.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.jobs-grid { grid-template-columns: minmax(340px, 0.85fr) 1.15fr; }
@media (max-width: 980px) {
  .grid.two, .jobs-grid { grid-template-columns: 1fr; }
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  display: grid;
  gap: 14px;
  align-content: start;
}
.card-head { display: flex; align-items: center; gap: 10px; }

/* ── forms ──────────────────────────────────────────────────────────────── */
.stack { display: grid; gap: 13px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row .grow { flex: 1 1 160px; }
.field { display: grid; gap: 6px; font-size: 13px; color: var(--ink-dim); }
.field > span { display: flex; gap: 6px; align-items: baseline; }
input, select, textarea {
  width: 100%;
  background: #0d141c;
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 9px;
  padding: 9px 11px;
  font: inherit;
  font-size: 14px;
  appearance: none;
}
textarea { font-family: var(--mono); font-size: 12.5px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #35506b; outline-offset: -1px; border-color: #3d5c7a; }
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-faint) 50%), linear-gradient(135deg, var(--ink-faint) 50%, transparent 50%);
  background-position: calc(100% - 16px) 18px, calc(100% - 11px) 18px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
}
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; font-size: 13px; color: var(--ink-dim); }
.checks label { display: flex; gap: 8px; align-items: center; }
.checks input { width: auto; }
/* the global input rule above is for text fields — keep native control sizing */
input[type="checkbox"],
input[type="radio"] {
  /* the global rule above sets appearance:none for text fields — put the native
     control back, otherwise checkboxes render as empty invisible boxes */
  appearance: auto;
  -webkit-appearance: auto;
  width: 15px;
  height: 15px;
  padding: 0;
  margin: 0;
  accent-color: var(--accent);
  background: none;
  flex: none;
  cursor: pointer;
}
label:has(> input[type="checkbox"]) { cursor: pointer; }
.advanced { border-top: 1px dashed var(--line-soft); padding-top: 12px; display: grid; gap: 12px; }
.advanced summary { cursor: pointer; color: var(--ink-dim); font-size: 13px; }
.actions { align-items: center; }

.btn {
  background: #1b2735;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 14px;
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.05s ease;
  white-space: nowrap;
}
.btn:hover { background: #22303f; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 650; }
.btn.primary:hover { background: #ffd977; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 12.5px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.error { color: var(--bad); font-size: 13px; }
.pill {
  font-size: 11px;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 2px 8px;
  color: var(--ink-dim);
  background: #0d141c;
  font-weight: 500;
}
.pill.ok { color: var(--ok); border-color: #244a35; background: #10231a; }
.pill.bad { color: var(--bad); border-color: #4a2424; background: #231012; }

/* ── lessons ────────────────────────────────────────────────────────────── */
.lessons { display: grid; gap: 2px; max-height: 420px; overflow: auto; }
.lesson {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 7px 8px;
  border-radius: 7px;
  font-size: 13.5px;
}
.lesson:hover { background: #16202c; }
.lesson input { width: auto; margin-right: 2px; }
.lesson .n { color: var(--ink-faint); font-family: var(--mono); font-size: 12px; min-width: 26px; }
.lesson .t { flex: 1; }
.lesson a { color: var(--ink-faint); font-size: 11.5px; text-decoration: none; }
.lesson a:hover { color: var(--accent); }

/* ── jobs ───────────────────────────────────────────────────────────────── */
.jobs { display: grid; gap: 8px; max-height: 70vh; overflow: auto; }
.job {
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 11px 12px;
  display: grid;
  gap: 7px;
  cursor: pointer;
  background: #121a24;
}
.job:hover { border-color: var(--line); }
.job.active { border-color: #3d5c7a; background: #16202c; }
.job-top { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.job-url { font-family: var(--mono); font-size: 11.5px; color: var(--ink-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job-sub { font-size: 12.5px; color: var(--ink-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; border-radius: 5px; padding: 2px 6px; }
.status.running { background: #12283a; color: #6fc0f0; }
.status.queued { background: #1e2333; color: var(--ink-dim); }
.status.done { background: #10231a; color: var(--ok); }
.status.done-with-errors { background: #2a2310; color: var(--warn); }
.status.failed, .status.interrupted { background: #231012; color: var(--bad); }
.status.cancelled, .status.cancelling { background: #1e1e26; color: var(--ink-faint); }
.bar { height: 5px; background: #0d141c; border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width 0.4s ease; }
.bar.indeterminate > i { width: 35% !important; animation: slide 1.4s ease-in-out infinite; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(300%); } }
.job-stats { display: flex; gap: 10px; font-size: 11.5px; color: var(--ink-faint); font-family: var(--mono); }
.job-warn { font-size: 12px; color: var(--warn); }

.log-card { position: sticky; top: 70px; }
.log {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  background: #080d12;
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  padding: 12px;
  height: min(70vh, 620px);
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: #c6d4e2;
}
.log .l-err { color: var(--bad); }
.log .l-ok { color: var(--ok); }
.log .l-warn { color: var(--warn); }
.log .l-dim { color: var(--ink-faint); }
.log .l-cmd { color: #7fb2e5; }

/* ── library ────────────────────────────────────────────────────────────── */
.library { display: grid; gap: 10px; }
.course {
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  overflow: hidden;
  background: #121a24;
}
.course > summary {
  cursor: pointer;
  padding: 11px 13px;
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 14px;
  list-style: none;
}
.course > summary::-webkit-details-marker { display: none; }
.course > summary::before { content: "▸"; color: var(--ink-faint); font-size: 11px; }
.course[open] > summary::before { content: "▾"; }
.course-files { border-top: 1px solid var(--line-soft); }
.file {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 6px 13px;
  font-size: 13px;
  border-bottom: 1px solid #0f1720;
}
.file:last-child { border-bottom: 0; }
.file .name { flex: 1; font-family: var(--mono); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file .size { color: var(--ink-faint); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.file a { color: var(--accent); text-decoration: none; font-size: 12px; }
.file a:hover { text-decoration: underline; }

/* destructive actions: present, but never the loudest thing on screen */
.linkish {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-size: 12px;
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
}
.linkish:hover { text-decoration: underline; }
.linkish.danger { color: #e0796b; }
.course > summary .delete-course { margin-left: auto; font-size: 11.5px; opacity: .75; }
.course > summary:hover .delete-course { opacity: 1; }
.linkish.armed { color: #ff8f7a; font-weight: 600; }

/* inline player — the way to watch a capture inside a sandboxed preview */
.player-dialog {
  width: min(900px, 94vw);
  padding: 0;
  border: 1px solid var(--line, #1e2a37);
  border-radius: 12px;
  background: #0b1219;
  color: inherit;
}
.player-dialog::backdrop { background: rgba(3, 7, 12, .78); }
.player-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; font-size: 13px; }
.player-head strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-dialog video { display: block; width: 100%; max-height: 70vh; background: #000; }
.player-foot { padding: 8px 14px 12px; }
.player-foot code { word-break: break-all; }

/* copied-link box: a row of its own under the file, selected, ready for ctrl+c.
   It must stay in normal flow — floating it over the row swallowed clicks on
   the buttons underneath. */
.link-box {
  flex: 1 0 100%;
  order: 9;
  margin: 2px 0 4px;
  padding: 4px 7px;
  font-family: var(--mono);
  font-size: 11.5px;
  background: #0f1720;
  color: var(--ink, #dfe7ef);
  border: 1px solid var(--accent, #f4c95d);
  border-radius: 6px;
}
.file { position: relative; flex-wrap: wrap; }

/* ── session / sites ────────────────────────────────────────────────────── */
.session-status { display: grid; gap: 6px; font-size: 13px; color: var(--ink-dim); }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 7px; font-size: 13px; color: var(--ink-dim); }
.steps li::marker { color: var(--accent); }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left;
  font-weight: 550;
  color: var(--ink-faint);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
}
.table td { padding: 8px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.table td:first-child { font-family: var(--mono); font-size: 12px; white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  background: #1b2735;
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13.5px;
  box-shadow: 0 18px 40px -20px #000;
  z-index: 100;
  max-width: min(560px, 90vw);
}
.toast.bad { border-color: #4a2424; color: #f3b9b9; }
