/* Lernk. Pages sit on light paper; the pipeline sits on the dark slate "board" with chalk-coloured stages. */

:root {
  --board: #1e3330;
  --board-raised: #27423d;
  --board-line: #3e5b55;
  --chalk: #e8efec;
  --chalk-dim: #a7b9b4;
  --paper: #f4f6f5;
  --surface: #ffffff;
  --ink: #16201e;
  --muted: #5b6965;
  --line: #d9e1de;
  --line-strong: #aebbb7;
  --accent: #f2c14e;
  --accent-hover: #e8b23a;
  --accent-ink: #1e3330;
  --danger: #b3412f;
  --focus: #1e3330;
  /* chalk colours, one per pipeline stage */
  --s0: #8fb8de;
  --s1: #b9a2e0;
  --s2: #f2c14e;
  --s3: #f0a07c;
  --s4: #7fc8a9;
  --s5: #c3cbc8;
  --display: Bahnschrift, "DIN Alternate", "DIN Next", "Avenir Next Condensed", "Segoe UI Variable Display", system-ui, sans-serif;
  --body: "Segoe UI Variable Text", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  --radius: 10px;
}

.stage-0 { --stage: var(--s0); }
.stage-1 { --stage: var(--s1); }
.stage-2 { --stage: var(--s2); }
.stage-3 { --stage: var(--s3); }
.stage-4 { --stage: var(--s4); }
.stage-5 { --stage: var(--s5); }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 var(--body); color: var(--ink); background: var(--paper); }
a { color: inherit; }
code, .mono { font-family: var(--mono); font-size: .92em; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }

/* Wordmark */
.wordmark { display: inline-flex; flex-direction: column; font: 700 28px/1 var(--display); letter-spacing: .01em; color: var(--chalk); }
.wordmark b { font-weight: inherit; color: var(--accent); }
.wordmark em { font-style: normal; font-weight: 400; letter-spacing: .06em; color: var(--chalk-dim); }
.wordmark small { margin-top: 6px; font: 500 11px/1.3 var(--body); letter-spacing: .03em; color: var(--chalk-dim); }

/* App shell */
body.app { display: grid; grid-template-columns: 228px minmax(0, 1fr); min-height: 100vh; }
.rail { --focus: var(--accent); position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 28px; padding: 22px 16px; background: var(--board); color: var(--chalk); }
.home { padding: 0 8px; text-decoration: none; }
.ws { display: grid; gap: 6px; margin: 0; padding: 0 8px; font-size: 14px; font-weight: 600; }
.ws label, .ws span { display: block; font-size: 12px; font-weight: 500; color: var(--chalk-dim); }
.ws select { border-color: var(--board-line); background: var(--board-raised); color: var(--chalk); }
.nav { display: grid; gap: 2px; }
.nav a { padding: 9px 10px; border-radius: 8px; color: var(--chalk-dim); font-weight: 600; text-decoration: none; }
.nav a:hover { background: var(--board-raised); color: var(--chalk); }
.nav a[aria-current="page"] { background: var(--accent); color: var(--accent-ink); }
.me { display: grid; gap: 2px; margin-top: auto; padding: 0 8px; font-size: 13px; }
.me form { margin: 0; }
.me .who { overflow: hidden; color: var(--chalk); font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.me .link { color: var(--chalk-dim); }
.main { min-width: 0; padding: 32px 36px 56px; }
.main.on-board { --focus: var(--accent); background: radial-gradient(ellipse at 15% 0%, #25403a, var(--board) 60%); color: var(--chalk); }

/* Headings */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
h1 { margin: 0; font: 700 32px/1.1 var(--display); letter-spacing: .005em; }
h2 { margin: 0 0 12px; font: 650 17px/1.3 var(--display); }
.sub { margin: 6px 0 0; color: var(--muted); }
.on-board .sub { color: var(--chalk-dim); }
.crumb { margin: 0 0 8px; font-size: 14px; }
.crumb a { color: var(--muted); text-decoration: none; }
.crumb a::before { content: "\2190  "; }
.crumb a:hover { color: var(--ink); }

/* Buttons and fields */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 15px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); font: 600 14px/1.1 var(--body); text-decoration: none; white-space: nowrap; cursor: pointer; }
.btn:hover { border-color: var(--line-strong); }
.btn.primary { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { border-color: var(--accent-hover); background: var(--accent-hover); }
.btn.danger { border-color: #e9c6bf; color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.link { padding: 0; border: 0; background: none; color: inherit; font: inherit; text-decoration: underline; cursor: pointer; }

label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; }
input, select, textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); font: 400 15px/1.4 var(--body); }
input:hover, select:hover, textarea:hover { border-color: var(--line-strong); }
textarea { resize: vertical; }
.hint { font-size: 13px; font-weight: 400; color: var(--muted); }
.stack { display: grid; gap: 16px; }
.row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.inline { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0; }
.inline select, .inline input { flex: 1; width: auto; min-width: 180px; }
.search { display: flex; gap: 8px; max-width: 560px; margin-bottom: 16px; }

/* Messages */
.alert, .notice { margin: 0 0 16px; padding: 10px 12px; border-radius: 8px; font-size: 14px; }
.alert { border: 1px solid #efcdc6; background: #fbeeeb; color: #7a2a1e; }
.notice { border: 1px solid #c9e5d6; background: #ebf6f0; color: #1d5a40; }
.empty-state { padding: 40px 20px; border: 1px dashed var(--line-strong); border-radius: var(--radius); color: var(--muted); text-align: center; }

/* Pipeline board */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(190px, 1fr); min-height: calc(100vh - 170px); margin: 0 -8px; padding: 0 8px 12px; overflow-x: auto; scrollbar-color: var(--board-line) transparent; }
.col { display: flex; flex-direction: column; min-width: 0; padding: 0 12px; border-left: 1px dashed var(--board-line); }
.col:first-child { padding-left: 0; border-left: 0; }
.col:last-child { padding-right: 0; }
.col-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 12px; padding-bottom: 10px; border-bottom: 3px solid var(--stage); }
.col-head h2 { margin: 0; color: var(--stage); font-size: 15px; letter-spacing: .02em; }
.count { color: var(--chalk-dim); font: 600 13px var(--mono); }
.cards { display: flex; flex: 1; flex-direction: column; gap: 10px; margin: -4px; padding: 4px; border-radius: var(--radius); transition: background-color .15s ease; }
.col.over .cards { background: rgba(232, 239, 236, .07); }
.card { display: grid; gap: 3px; padding: 12px 14px; border-top: 3px solid var(--stage); border-radius: 8px; background: var(--surface); box-shadow: 0 10px 20px -14px rgba(0, 0, 0, .7); color: var(--ink); text-decoration: none; cursor: grab; transition: transform .15s ease; }
.card:hover { transform: translateY(-2px); }
.card.dragging { opacity: .45; }
.card strong { font-weight: 650; overflow-wrap: anywhere; }
.card .co { color: var(--muted); font-size: 13px; }
.card .meta { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; color: var(--muted); font: 12px var(--mono); }
.empty { margin: 0; padding: 18px 8px; border: 1px dashed var(--board-line); border-radius: 8px; color: var(--chalk-dim); font-size: 13px; text-align: center; }
.cards:has(.card) .empty { display: none; }
.board-empty { margin: -8px 0 20px; color: var(--chalk-dim); }
.board-empty a { color: var(--accent); }

/* Panels */
.panel { padding: 22px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.panel + .panel { margin-top: 16px; }
.panel.narrow { max-width: 640px; }
.panel.readable { max-width: 860px; }
.panel > p.muted { margin: 0 0 14px; }
.split { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); align-items: start; gap: 16px; }
.split > .panel + .panel { margin-top: 0; }
.gap { margin-top: 28px; }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 18px; margin: 0; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.facts { margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--line); }
.danger-zone { margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--line); }

/* Timeline */
.note { display: grid; justify-items: start; gap: 8px; margin: 0 0 24px; }
.timeline { margin: 0; padding: 0; list-style: none; }
.ev { position: relative; padding: 0 0 20px 26px; }
.ev::before { content: ""; position: absolute; top: 5px; left: 0; width: 12px; height: 12px; border-radius: 50%; background: var(--dot, var(--s5)); box-shadow: 0 0 0 3px var(--surface); }
.ev::after { content: ""; position: absolute; top: 21px; bottom: 2px; left: 5px; width: 2px; background: var(--line); }
.ev:last-child { padding-bottom: 0; }
.ev:last-child::after { content: none; }
.ev time { display: block; color: var(--muted); font: 12px/1.6 var(--mono); }
.ev blockquote { margin: 6px 0 0; padding: 8px 12px; border-left: 3px solid var(--s0); border-radius: 0 6px 6px 0; background: var(--paper); white-space: pre-wrap; }
.note-text { margin: 2px 0 0; white-space: pre-wrap; }
.by { font-weight: 600; }
.ev-form_submitted { --dot: var(--s0); }
.ev-note { --dot: var(--s1); }
.ev-stage_changed { --dot: var(--s2); }
.ev-contact_created { --dot: var(--s3); }
.ev-email_sent { --dot: var(--s4); }
.ev-email_failed { --dot: var(--danger); }

/* Contacts table */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { padding: 11px 16px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12px; font-weight: 600; text-align: left; white-space: nowrap; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #f8faf9; }
.table td a { font-weight: 650; text-decoration: none; }
.table td a:hover { text-decoration: underline; }
.table time { color: var(--muted); font: 13px var(--mono); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px 3px 7px; border-radius: 999px; background: #edf1ef; color: var(--ink); font-size: 12px; font-weight: 600; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--stage); }

/* Settings */
.status { display: inline-flex; align-items: center; gap: 8px; margin: 0; font-weight: 600; }
.status::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--s5); }
.status.on::before { background: var(--s4); }
.status time { color: var(--muted); font-weight: 400; }
.steps { display: grid; gap: 6px; margin: 18px 0; padding-left: 20px; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.actions form { margin: 0; }
.secret { margin: 4px 0 0; padding: 16px; border: 1px solid var(--accent); border-radius: var(--radius); background: #fff8e3; }
.secret p { margin: 0 0 12px; }
pre { margin: 0 0 12px; padding: 14px 16px; overflow-x: auto; border-radius: 8px; background: var(--board); color: var(--chalk); font: 13px/1.7 var(--mono); }
.plain { margin: 0 0 16px; padding: 0; list-style: none; }
.plain li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.plain time { color: var(--muted); font: 13px var(--mono); }

/* Sign in and setup */
body.auth { --focus: var(--accent); display: grid; place-items: center; min-height: 100vh; padding: 32px 16px; background: radial-gradient(ellipse at 20% 0%, #29473f, var(--board) 55%); color: var(--chalk); }
.auth-card { width: min(100%, 420px); }
.auth-card .wordmark { margin-bottom: 36px; font-size: 40px; }
.auth h1 { font-size: 26px; }
.lede { margin: 8px 0 0; color: var(--chalk-dim); }
.lede a { color: var(--accent); }
.card-form { --focus: var(--board); margin-top: 20px; padding: 24px; border-radius: 12px; background: var(--surface); box-shadow: 0 24px 48px -24px rgba(0, 0, 0, .6); color: var(--ink); }

/* Small additions */
.aside-link { justify-self: center; color: var(--muted); font-size: 14px; }
.inline .short, .inline input.short { flex: 0 1 240px; min-width: 170px; }
.page-head .actions .inline { flex-wrap: nowrap; }
.panel code { white-space: nowrap; }
.gap-top { margin-top: 20px; }
.num { font-family: var(--mono); }
.bad { color: var(--danger); }
.members li { align-items: center; }
.member-actions { display: flex; align-items: center; gap: 14px; }
.member-actions select { min-width: 150px; }
.pill-role { color: var(--muted); font-size: 14px; }
.secret.readable { max-width: 860px; margin-bottom: 16px; }

/* Run status */
.run { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px 2px 7px; border-radius: 999px; background: #edf1ef; color: var(--ink); font-size: 12px; font-weight: 600; vertical-align: middle; }
.run::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--s5); }
.run-succeeded::before { background: var(--s4); }
.run-failed { background: #fbeeeb; color: #7a2a1e; }
.run-failed::before { background: var(--danger); }
.run-waiting::before, .run-queued::before { background: var(--s2); }
.run-running::before { background: var(--s0); }
.run-off { color: var(--muted); }

/* Workflow editor: steps hang off one line, like a chalk mark down the board */
.wf { grid-template-columns: minmax(0, 8fr) minmax(0, 4fr); }
.flow { position: relative; display: grid; gap: 12px; margin: 12px 0 0; padding: 0 0 0 22px; list-style: none; }
.flow::before { content: ""; position: absolute; top: -12px; bottom: 18px; left: 6px; width: 2px; background: var(--line); }
.step { position: relative; padding: 12px 14px; border: 1px solid var(--line); border-left: 3px solid var(--step, var(--s5)); border-radius: 8px; background: var(--surface); }
.flow > .step::before { content: ""; position: absolute; top: 17px; left: -22px; width: 14px; height: 2px; background: var(--line); }
.trigger-step { --step: var(--accent); background: #fffbef; }
.step-send_email { --step: var(--s4); }
.step-http_request { --step: var(--s0); }
.step-update_contact { --step: var(--s3); }
.step-condition { --step: var(--s1); }
.step-delay { --step: var(--s2); }
.step-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.step-type { font: 650 14px/1.3 var(--display); letter-spacing: .02em; }
.step-summary { flex: 1; min-width: 0; color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.step-tools { display: flex; gap: 12px; font-size: 13px; }
.step-tools form { margin: 0; }
.step-tools .link { color: var(--muted); }
.danger-link:hover { color: var(--danger); }
.step details { margin-top: 10px; }
.step summary { width: fit-content; color: var(--muted); font-size: 13px; font-weight: 600; cursor: pointer; }
.step details[open] > summary { margin-bottom: 12px; }
.step details .stack { padding-top: 12px; border-top: 1px dashed var(--line); }
.row.three { grid-template-columns: minmax(0, 4fr) minmax(0, 3fr) minmax(0, 4fr); }
.row.narrow-first { grid-template-columns: 130px minmax(0, 1fr); }
.branches { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 12px; }
.branch { padding: 10px; border-radius: 8px; background: var(--paper); }
.branch-label { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--surface); font: 650 12px/1.6 var(--display); letter-spacing: .04em; }
.branch-yes .branch-label { color: #1d5a40; }
.branch-no .branch-label { color: #7a2a1e; }
.branch .flow { padding-left: 16px; }
.branch .flow::before { left: 3px; }
.branch .flow > .step::before { left: -16px; width: 10px; }
.add-step { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.add-step select { width: auto; flex: 0 1 200px; }
.runs { margin: 0; padding: 0; list-style: none; }
.runs a { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; text-decoration: none; }
.runs li:last-child a { border-bottom: 0; }
.runs a span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.runs time { color: var(--muted); font: 12px var(--mono); }
.runs a:hover span:nth-child(2) { text-decoration: underline; }
.ev-log-succeeded { --dot: var(--s4); }
.ev-log-failed { --dot: var(--danger); }
.ev details pre { margin: 8px 0 0; }

@media (max-width: 860px) {
  .branches, .row.three, .row.narrow-first { grid-template-columns: minmax(0, 1fr); }
  body.app { grid-template-columns: minmax(0, 1fr); }
  .rail { position: static; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 12px 16px; height: auto; padding: 14px 16px; }
  .home { padding: 0; }
  .rail .wordmark { font-size: 24px; }
  .rail .wordmark small { display: none; }
  .ws { order: 3; width: 100%; padding: 0; }
  .nav { order: 4; display: flex; gap: 4px; width: 100%; overflow-x: auto; }
  .me { margin: 0 0 0 auto; padding: 0; }
  .me .who { display: none; }
  .main { padding: 22px 16px 40px; }
  .split, .row { grid-template-columns: minmax(0, 1fr); }
  .board { grid-auto-columns: minmax(80vw, 1fr); min-height: 60vh; margin: 0 -16px; padding: 0 16px 12px; scroll-snap-type: x mandatory; }
  .col { scroll-snap-align: start; }
  h1 { font-size: 26px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
