:root {
  /* Pure black on pure white for anything you read. The greys that remain are
     for structure — rules, borders, the fill behind a read-only field — and
     never for text. --muted is the one exception, and it is dark enough
     (12.6:1) to be read comfortably at 11.5px rather than merely to pass a
     contrast check. */
  --bg: #ffffff;
  --panel: #ffffff;
  --ink: #000000;
  --muted: #3a3a3a;
  --line: #c4c9d0;
  --sunken: #f1f2f4;
  --accent: #0b3d4a;
  --danger: #8f1428;
  --radius: 6px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
  /* Controls beside an A4 preview needs the room; scroll rather than clip. */
  min-width: 1080px;
}

/* ── Top bar ─────────────────────────────────────────────────────────── */

.bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.bar h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--accent);
}

.bar-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bar-group.right { margin-left: auto; }

.status {
  font-size: 12px;
  color: var(--muted);
  min-width: 80px;
  text-align: right;
}

.status.working { color: var(--accent); }
.status.error { color: var(--danger); font-weight: 600; }

/* ── Controls ────────────────────────────────────────────────────────── */

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

button {
  padding: 6px 12px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

button:hover { filter: brightness(1.12); }
button:disabled { opacity: 0.45; cursor: default; filter: none; }

button.ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
}

button.ghost:hover { color: var(--ink); border-color: var(--muted); filter: none; }

.ghost-link {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  white-space: nowrap;
}

.ghost-link:hover { color: var(--ink); border-color: var(--muted); }

input, select, textarea {
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent);
  outline-offset: -1px;
  border-color: var(--accent);
}

input.name { width: 180px; }
.bar select { width: 190px; }

/* ── Layout ──────────────────────────────────────────────────────────── */

main {
  display: grid;
  grid-template-columns: minmax(380px, 460px) 1fr;
  flex: 1;
  min-height: 0;
}

.panel {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
  box-shadow: 1px 0 0 var(--line);
  min-height: 0;
}

.tabs {
  display: flex;
  gap: 2px;
  padding: 8px 8px 0;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.tabs button {
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: var(--radius) var(--radius) 0 0;
  border-bottom: 2px solid transparent;
  padding: 7px 12px;
}

.tabs button:hover { filter: none; color: var(--ink); }

.tabs button.on {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.scroll {
  overflow-y: auto;
  padding: 16px;
  min-height: 0;
}

.fields { display: flex; flex-direction: column; gap: 12px; }

.fields h2 {
  margin: 10px 0 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink);
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--ink);
}

label.inline { flex-direction: row; align-items: center; gap: 8px; }
label.inline select { width: auto; }

label.check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 13px;
}

label.check input { width: auto; }

.label-key {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.hint {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  font-style: normal;
}

.hint.error { color: var(--danger); }

code {
  font-family: var(--mono);
  font-size: 11px;
  background: var(--sunken);
  padding: 1px 4px;
  border-radius: 3px;
}

/* ── Logo ────────────────────────────────────────────────────────────── */

.logo-row { display: flex; gap: 14px; align-items: flex-start; }

.logo-preview {
  width: 120px;
  height: 68px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  background: #fff;
  flex-shrink: 0;
  overflow: hidden;
}

.logo-preview.empty { border-style: dashed; color: var(--muted); font-size: 11.5px; }
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }

.logo-actions { display: flex; flex-direction: column; gap: 8px; flex: 1; }
.logo-actions input[type=file] { border: none; padding: 0; font-size: 12px; }

/* ── Colours ─────────────────────────────────────────────────────────── */

.colour-row {
  display: grid;
  grid-template-columns: 40px 84px 1fr;
  align-items: center;
  gap: 10px;
}

.colour-row input[type=color] {
  padding: 2px;
  height: 30px;
  cursor: pointer;
}

.colour-row .hex { font-family: var(--mono); font-size: 12px; }
.colour-row span { display: flex; flex-direction: column; line-height: 1.25; }
.colour-row strong { font-size: 12.5px; font-weight: 600; }
.colour-row em { font-size: 11.5px; color: var(--muted); font-style: normal; }

/* ── Sliders ─────────────────────────────────────────────────────────── */

.slider { display: flex; align-items: center; gap: 10px; }
.slider input[type=range] { padding: 0; }

.slider output {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink);
  min-width: 46px;
  text-align: right;
}

/* ── Schema-driven form ──────────────────────────────────────────────── */

.switch { display: flex; gap: 0; }

.switch button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 0;
  padding: 5px 12px;
}

.switch button:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.switch button:last-child { border-radius: 0 var(--radius) var(--radius) 0; border-left: 0; }
.switch button:hover { filter: none; color: var(--ink); }

.switch button.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
}

.field-grid > label { grid-column: span 6; }
.field-grid > label.w-half { grid-column: span 3; }
.field-grid > label.w-third { grid-column: span 2; }

.with-unit { position: relative; display: block; }
.with-unit input { width: 100%; }

.with-unit em {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-style: normal;
  font-size: 11px;
  color: var(--muted);
  pointer-events: none;
}

/* Number fields carry a unit badge; keep the spinners from colliding with it. */
.with-unit input[type=number] { padding-right: 22px; }

input[readonly] { background: var(--sunken); color: var(--muted); }

.rows { display: flex; flex-direction: column; gap: 10px; }

.row-card {
  border: 1px solid var(--line);
  border-left: 3px solid var(--muted);
  border-radius: var(--radius);
  padding: 10px;
  background: #fff;
}

.row-head {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 8px;
}

.row-head .grow { flex: 1; }

.row-head .divider {
  width: 1px;
  align-self: stretch;
  margin: 2px 3px;
  background: var(--line);
}

.row-head button.icon { white-space: nowrap; font-variant-numeric: tabular-nums; }
.row-head select.kind { width: auto; font-size: 12px; padding: 3px 6px; }

button.icon {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  padding: 2px 7px;
  line-height: 1.3;
  font-size: 12px;
}

button.icon:hover { filter: none; color: var(--ink); border-color: var(--muted); }
button.icon.danger:hover { color: var(--danger); border-color: var(--danger); }

.add-row { display: flex; gap: 6px; flex-wrap: wrap; }

.invalid {
  border-left: 3px solid var(--danger);
  background: #fdf3f5;
  border-radius: var(--radius);
  padding: 9px 12px;
  font-size: 12px;
}

.invalid strong { display: block; margin-bottom: 4px; color: var(--danger); }
.invalid ul { margin: 0; padding-left: 16px; color: var(--ink); }

/* ── JSON ────────────────────────────────────────────────────────────── */

textarea.code {
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.5;
  tab-size: 2;
  resize: vertical;
}

/* ── Preview ─────────────────────────────────────────────────────────── */

.preview {
  position: relative;
  background: #52555a;
  min-height: 0;
  display: flex;
}

.pages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  scroll-behavior: auto;
  /* The canvases measure their offsetTop against this box, so it has to be the
     offsetParent — otherwise they report positions relative to .preview. */
  position: relative;
  /* Chrome's scroll anchoring would adjust scrollTop after we have just set it
     ourselves, which is a fight we lose silently. */
  overflow-anchor: none;
}

.pages canvas.page {
  display: block;
  background: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  border-radius: 2px;
}

.viewer-bar {
  position: absolute;
  top: 12px;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px;
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.58);
  color: #f2f4f6;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.viewer-bar > span { padding: 0 4px; }
.viewer-bar .sep { opacity: 0.4; padding: 0; }

.viewer-bar button {
  border: 0;
  background: transparent;
  color: #f2f4f6;
  padding: 2px 7px;
  font-size: 12px;
  line-height: 1.2;
  border-radius: 12px;
}

.viewer-bar button:hover { background: rgba(255, 255, 255, 0.16); filter: none; }
.viewer-bar button.zoom { font-size: 11px; min-width: 44px; }

.empty-preview {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #ffffff;
  font-size: 13px;
  padding: 24px;
  text-align: center;
  pointer-events: none;
  /* The validator joins its sentences with newlines; keep them as lines. */
  white-space: pre-line;
  max-width: 46ch;
  margin: auto;
  line-height: 1.6;
}

.compile-error {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 16px;
  margin: 0;
  padding: 12px 14px;
  max-height: 40%;
  overflow: auto;
  background: #2b1d21;
  color: #ffd7de;
  border-left: 3px solid var(--danger);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 11.5px;
  white-space: pre-wrap;
}

.invalid p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 11.5px;
}

/* ── Stijl tab ───────────────────────────────────────────────────────── */

.presets { display: flex; flex-wrap: wrap; gap: 6px; }

.rule-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.rule-row output {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink);
  white-space: nowrap;
}

.rule-row output.off { color: var(--muted); font-style: italic; }

label.check span strong { display: block; font-size: 13px; font-weight: 600; }
label.check span em { display: block; font-size: 11.5px; color: var(--muted); font-style: normal; }

.rule-controls { display: flex; align-items: center; gap: 8px; }
.rule-controls input[type=range] { flex: 1; }
.rule-controls select { width: auto; flex-shrink: 0; font-size: 12px; padding: 3px 6px; }
.rule-controls select:disabled { opacity: 0.4; }
