/* Data Curation – workflow tree (top-down hierarchy)
   Level 1: Data Curation (with the totals table)
   Level 2: Curator 1 and Curator 2
   Level 3: each curator's workflows, spread side by side
   Level 4: each workflow's screens, running straight down under it
   "Split" pulls the two curator branches apart into separate panels. */

/* Colours are plain CSS colour names (no hex codes). Change a name here and it changes everywhere. */
:root {
  --bg: whitesmoke;
  --surface: white;
  --soft: gainsboro;
  --ink: black;
  --muted: slategray;
  --line: lightsteelblue;
  --shadow: lightgray;
  --root: black;
  --root-text: aliceblue;
  --root-muted: darkgray;
  --root-line: dimgray;
  --stage1: teal;
  /* Curator 1 */
  --stage1-tint: lightcyan;
  --stage2: blueviolet;
  /* Curator 2 */
  --stage2-tint: lavender;
  --notice: chocolate;
  /* notifications */
  --notice-tint: linen;
  --on-color: white;

  --sans: "Plus Jakarta Sans", system-ui, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;

  --col-w: 250px;
  /* width of a workflow column (keep in sync with COL_W in script.js) */
  --shot-h: 142px;
  /* screenshot height (keep in sync with SHOT_H in script.js) */
  --drop: 34px;
  /* height of the connector between tree levels */
  --edge: var(--line);
  /* connector colour, set per branch */
}

/* ---------- page ---------- */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  overflow: hidden;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ---------- toolbar ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 10px 18px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.toolbar h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
}

.spacer {
  flex: 1;
}

.zoom {
  display: flex;
  align-items: center;
  gap: 6px;
}

button {
  font: 600 13px var(--sans);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
}

button:hover {
  background: var(--soft);
}

button.primary {
  background: var(--ink);
  color: var(--surface);
  border-color: var(--ink);
}

button.toggle {
  min-width: 84px;
  border-color: var(--stage1);
  color: var(--stage1);
}

button.toggle[aria-pressed="true"] {
  background: var(--stage1);
  color: var(--on-color);
}

button:disabled {
  opacity: .6;
  cursor: progress;
}

button:focus-visible,
.card:focus-visible {
  outline: 2px solid var(--stage1);
  outline-offset: 2px;
}

#zoomLabel {
  font: 500 12px var(--mono);
  color: var(--muted);
  min-width: 44px;
  text-align: center;
}

/* ---------- canvas ---------- */
.viewport {
  flex: 1;
  overflow: auto;
  cursor: grab;
  background: var(--bg);
}

.viewport.dragging {
  cursor: grabbing;
  user-select: none;
}

.canvas {
  display: inline-block;
  padding: 48px;
  background: var(--bg);
}

/* =========================================================
   Tree connectors (classic top-down org-chart lines)
   ========================================================= */
.tree ul {
  position: relative;
  display: flex;
  justify-content: center;
  margin: 0;
  padding: var(--drop) 0 0;
  list-style: none;
}

.tree li {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--drop) 10px 0;
}

/* horizontal bar above the siblings + short drop into each child */
.tree li::before,
.tree li::after {
  content: "";
  position: absolute;
  top: 0;
  width: 50%;
  height: var(--drop);
  border-top: 2px solid var(--edge);
}

.tree li::before {
  right: 50%;
}

.tree li::after {
  left: 50%;
  border-left: 2px solid var(--edge);
}

.tree li:first-child::before,
.tree li:last-child::after {
  border: 0;
}

.tree li:last-child::before {
  border-right: 2px solid var(--edge);
  border-top-right-radius: 8px;
}

.tree li:first-child::after {
  border-top-left-radius: 8px;
}

.tree li:only-child {
  padding-top: 0;
}

.tree li:only-child::before,
.tree li:only-child::after {
  display: none;
}

/* line from a parent down to its children's bar */
.tree ul ul::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  height: var(--drop);
  border-left: 2px solid var(--edge);
}

.tree>ul {
  padding-top: 0;
}

.tree>ul>li {
  padding-top: 0;
}

.tree>ul>li::before,
.tree>ul>li::after {
  display: none;
}

/* =========================================================
   Level 1 – Data Curation (root) with totals
   ========================================================= */
.root {
  display: flex;
  gap: 36px;
  align-items: center;
  padding: 26px 30px;
  border-radius: 18px;
  background: var(--root);
  color: var(--root-text);
}

.root .eyebrow {
  font: 500 11px var(--mono);
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--root-muted);
}

.root h2 {
  margin: 6px 0 0;
  font-size: 32px;
  font-weight: 800;
  line-height: 1.1;
}

.totals {
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  color: var(--root-text);
}

.totals th,
.totals td {
  padding: 7px 14px;
  text-align: right;
  border-bottom: 1px solid var(--root-line);
}

.totals th {
  font: 500 10.5px var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--root-muted);
}

.totals th:first-child,
.totals td:first-child {
  text-align: left;
}

.totals td {
  font: 700 15px var(--sans);
  color: var(--root-text);
}

.totals tr:last-child td {
  border-bottom: 0;
  font-size: 17px;
}

.totals .tag {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 3px;
  margin-right: 8px;
}

/* =========================================================
   Level 2 – curators (+ Split / Attach)
   ========================================================= */
.branch {
  --accent: var(--stage1);
  --tint: var(--stage1-tint);
  transition: padding .5s ease;
}

.branch.s2 {
  --accent: var(--stage2);
  --tint: var(--stage2-tint);
}

.branch .panel ul {
  --edge: var(--accent);
}

/* lines inside a curator branch take its colour */
.branch>.panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 24px;
  transition: padding .5s ease, background .5s ease, border-color .5s ease, box-shadow .5s ease;
}

.curator {
  display: inline-flex;
  align-items: center;
  gap: 18px;
  padding: 16px 22px;
  border-radius: 16px;
  background: var(--accent);
  color: var(--on-color);
}

.curator .badge {
  font: 700 12px var(--mono);
  letter-spacing: .1em;
  text-transform: uppercase;
  opacity: .85;
}

.curator b {
  display: block;
  font-size: 26px;
  font-weight: 800;
}

.curator .mini {
  display: flex;
  gap: 18px;
  padding-left: 18px;
  border-left: 1px solid lightgray;
}

.curator .mini span {
  font: 500 11px var(--mono);
  letter-spacing: .06em;
  text-transform: uppercase;
  opacity: .9;
}

.curator .mini strong {
  display: block;
  font: 800 22px var(--sans);
}

/* split: the two branches move apart and become separate panels */
.tree.split>ul>li>ul::before,
.tree.split>ul>li>ul>li::before,
.tree.split>ul>li>ul>li::after {
  opacity: 0;
}

.tree>ul>li>ul::before,
.tree>ul>li>ul>li::before,
.tree>ul>li>ul>li::after {
  transition: opacity .3s;
}

.tree.split .branch {
  padding-inline: 140px;
}

.tree.split .branch>.panel {
  padding: 30px;
  background: var(--surface);
  border-color: var(--line);
  box-shadow: 0 18px 40px var(--shadow);
}

/* =========================================================
   Level 3 – workflows
   ========================================================= */
.wf-node {
  width: var(--col-w);
  box-sizing: border-box;
  height: 116px;
  padding: 12px 14px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--surface);
  border: 1.5px solid var(--accent);
}

.wf-node .code {
  align-self: flex-start;
  font: 700 11.5px var(--mono);
  color: var(--on-color);
  background: var(--accent);
  padding: 4px 8px;
  border-radius: 6px;
}

.wf-node b {
  font-size: 14px;
  line-height: 1.3;
  font-weight: 700;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.wf-node .count {
  margin-top: auto;
  font-size: 11.5px;
  color: var(--muted);
}

/* =========================================================
   Level 4 – screens, straight down under their workflow
   ========================================================= */
.screens {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.screens>.card {
  margin-top: var(--drop);
}

.card {
  position: relative;
  width: var(--col-w);
  display: flex;
  flex-direction: column;
  gap: 7px;
  cursor: zoom-in;
}

.card::before {
  /* line from the item above */
  content: "";
  position: absolute;
  left: 50%;
  top: calc(-1 * var(--drop));
  height: calc(var(--drop) - 6px);
  border-left: 2px solid var(--accent);
}

.card::after {
  /* small arrow head */
  content: "";
  position: absolute;
  left: calc(50% - 5px);
  top: -9px;
  border: 5px solid transparent;
  border-top: 7px solid var(--accent);
  border-bottom: 0;
}

.shot {
  height: var(--shot-h);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.shot img {
  display: block;
  border-radius: 4px;
}

.card:hover .shot {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--tint);
}

.shot .empty {
  text-align: center;
  padding: 0 16px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  line-height: 1.45;
}

.shot .empty small {
  display: block;
  font-weight: 500;
  font-size: 11px;
}

.card.missing .shot,
.card.email:not(:has(img)) .shot,
.card.ref .shot {
  border: 1.5px dashed var(--line);
  background: transparent;
}

.card.missing,
.card.ref,
.card.email:not(:has(img)) {
  cursor: default;
}

.caption {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.num {
  flex: none;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  box-sizing: border-box;
  border-radius: 6px;
  display: grid;
  place-items: center;
  font: 700 11px var(--mono);
  color: var(--on-color);
  background: var(--accent);
}

.caption-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.caption-text small {
  font: 500 10px var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

.caption-text b {
  font-size: 12.5px;
  line-height: 1.35;
  font-weight: 700;
}

.card.notice,
.card.email {
  --accent: var(--notice);
  --tint: var(--notice-tint);
}

/* ---------- viewer ---------- */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 10;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: black;
}

.viewer img {
  max-width: min(1500px, 96vw);
  max-height: 70vh;
  border-radius: 8px;
  background: white;
}

.viewer .info {
  width: min(1100px, 96vw);
  background: var(--surface);
  color: var(--ink);
  border-radius: 12px;
  padding: 14px 18px;
}

.viewer .crumb {
  font: 500 12px var(--mono);
  color: var(--muted);
}

.viewer h2 {
  margin: 6px 0;
  font-size: 18px;
}

.viewer p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
  font-size: 14px;
}

.viewer-buttons {
  display: flex;
  gap: 8px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  z-index: 20;
  background: var(--ink);
  color: var(--surface);
  font-size: 13px;
  padding: 10px 14px;
  border-radius: 10px;
}

/* ---------- split mode: panels are selectable and react to hover ---------- */
.tree.split .branch>.panel {
  cursor: pointer;
  transition: padding .5s ease, background .5s ease, border-color .25s ease, box-shadow .25s ease, transform .25s ease, opacity .25s ease;
}

.tree.split .branch>.panel:hover {
  border-color: var(--accent);
  box-shadow: 0 22px 48px var(--shadow), 0 0 0 4px var(--tint);
  transform: translateY(-3px);
}

.tree.split .branch.selected>.panel {
  border-color: var(--accent);
  border-width: 2px;
  box-shadow: 0 24px 56px var(--shadow), 0 0 0 6px var(--tint);
}

.tree.split.has-selection .branch:not(.selected)>.panel {
  opacity: .4;
}

.tree.split.has-selection .branch:not(.selected)>.panel:hover {
  opacity: .75;
}

.tree.split .wf-node {
  transition: box-shadow .2s, transform .2s;
}

.tree.split .wf:hover>.wf-node {
  box-shadow: 0 0 0 4px var(--tint), 0 8px 18px var(--shadow);
  transform: translateY(-2px);
}

.tree.split .wf:hover .card::before {
  border-left-width: 3px;
}

@media (prefers-reduced-motion: reduce) {

  .branch,
  .branch>.panel {
    transition: none;
  }
}

@media (max-width: 760px) {
  #fitAll {
    display: none;
  }
}