/* Ingredient label tool - plain CSS, light + dark via prefers-color-scheme */
:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1d2330;
  --muted: #6b7280;
  --line: #e2e5ea;
  --hover: #f0f2f5;
  --input: #ffffff;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --accent-weak: #e8efff;
  --err: #c62828;
  --err-bg: #fdecec;
  --warn: #a15c00;
  --warn-bg: #fff3dc;
  --ok: #1e7d3a;
  --ok-bg: #e4f4e8;
  --info: #5f6673;
  --info-bg: #eef0f3;
  --box: #1e66f5;      /* ingredient box on the (always white) label */
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #13161b;
    --panel: #1b1f26;
    --text: #e3e6eb;
    --muted: #9aa3af;
    --line: #2c323b;
    --hover: #232831;
    --input: #14171c;
    --accent: #5b8def;
    --accent-text: #0d1117;
    --accent-weak: #1f2a40;
    --err: #f07a7a;
    --err-bg: #3a1f23;
    --warn: #efb45c;
    --warn-bg: #382b16;
    --ok: #5fc27c;
    --ok-bg: #173022;
    --info: #a5adb9;
    --info-bg: #262b33;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: auto;
  overflow-y: hidden;
}
h1 { font-size: 15px; margin: 0; font-weight: 650; }
h2 { font-size: 14px; margin: 0; font-weight: 600; }
h3 { font-size: 13px; margin: 14px 0 6px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 11px; }
.spacer { flex: 1; }
.bad { color: var(--err); }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }

button, input, select, textarea { font: inherit; color: var(--text); }
button {
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  cursor: pointer;
}
button:hover { background: var(--hover); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover { filter: brightness(1.08); }
button.active { background: var(--accent-weak); border-color: var(--accent); }
button.link { border: 0; background: none; padding: 0 2px; color: var(--accent); }
button.link:hover { text-decoration: underline; background: none; }
button.icon { padding: 0 6px; line-height: 20px; }
input[type=text], input[type=search], input[type=number], select, textarea {
  background: var(--input);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 7px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* top bar */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.tpl { display: flex; align-items: center; gap: 6px; color: var(--muted); min-width: 0; }
.tpl select { max-width: min(460px, 100%); min-width: 0; color: var(--text); }
.tpl.toggle { gap: 5px; cursor: pointer; user-select: none; white-space: nowrap; }
.tpl.toggle input { margin: 0; accent-color: var(--accent); }
.tpl.toggle:has(input:checked) { color: var(--warn); font-weight: 600; }
.label-info { color: var(--muted); max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.label-info b { color: var(--text); font-weight: 600; }

.banner {
  position: fixed;
  top: 50px;
  right: 16px;
  z-index: 60;
  max-width: 560px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--err);
  background: var(--err-bg);
  color: var(--err);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .12);
}
.banner.ok { border-color: var(--ok); background: var(--ok-bg); color: var(--ok); }
.banner.info { border-color: var(--line); background: var(--panel); color: var(--text); }
.banner .link { color: inherit; font-size: 16px; line-height: 1; }

/* columns */
.cols {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(200px, 270px) minmax(400px, 1.1fr) minmax(380px, 1fr);
}
.col {
  min-height: 0;
  overflow: auto;
  padding: 12px 14px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}
.col:last-child { border-right: 0; }
.col-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin-bottom: 10px; }
.btn-group { display: inline-flex; }
.btn-group > button { border-radius: 0; }
.btn-group > button:first-child { border-radius: 6px 0 0 6px; }
.btn-group > button:last-child { border-radius: 0 6px 6px 0; margin-left: -1px; }
/* label + rework columns: a plain pass-through normally; "Groot" stacks them in one wide scrolling column */
.work { display: contents; }
.cols.big { grid-template-columns: 270px minmax(0, 1fr); }
.cols.big .work {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  background: var(--panel);
}
.cols.big .work > .col { flex: none; overflow: visible; border-right: 0; }
.cols.big .col-rework { border-top: 1px solid var(--line); }
.cols.big .viewport { height: max(320px, calc(100vh - 175px)); }
/* narrow screens (e.g. 1024 px): a narrower article list and the editor under the label, in one
   scrolling column; the editor's head (Allergeen vet, Inkorten) sticks to the top, its actions
   (Herwerking bewaren, Exporteren) to the bottom */
@media (max-width: 1100px) {
  .cols, .cols.big { grid-template-columns: 210px minmax(0, 1fr); }
  .cols .work {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: auto;
    padding-bottom: 56px; /* room for the fixed actions bar */
    background: var(--panel);
  }
  /* "Herwerking bewaren" / "Exporteren" always in view, also while the label is on screen */
  .col-rework .actions {
    position: fixed;
    left: 210px;
    right: 0;
    bottom: 0;
    z-index: 6;
    margin: 0;
    padding: 8px 14px;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, .08);
  }
  .cols .work > .col { flex: none; overflow: visible; border-right: 0; }
  .cols .col-rework { border-top: 1px solid var(--line); }
  .col-rework > .col-head {
    position: sticky;
    top: 0;
    z-index: 4;
    margin: -12px 0 6px;
    padding: 10px 0 6px;
    background: var(--panel);
  }
  .topbar { gap: 6px 10px; padding: 8px 10px; }
  .label-info { max-width: 300px; }
}

/* 1. article list */
.col-list { display: flex; flex-direction: column; gap: 6px; overflow: hidden; background: var(--bg); }
.col-list input[type=search] { width: 100%; }
.alist { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
.alist li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.alist li:hover { background: var(--hover); }
.alist li.sel { background: var(--accent-weak); }
.alist li.none, .alist li.none:hover { cursor: default; background: none; }
.anr { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 44px; }
.aname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex: none; }

/* badges + tags */
.badges { display: inline-flex; gap: 3px; flex: none; }
.badge {
  display: inline-block;
  min-width: 18px;
  padding: 0 6px;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 600;
  line-height: 17px;
  text-align: center;
  white-space: nowrap;
}
.badge.err { background: var(--err-bg); color: var(--err); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.rw { background: var(--accent-weak); color: var(--accent); font-weight: 500; }
.tag {
  display: inline-block;
  padding: 0 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 11px;
  color: var(--muted);
  line-height: 16px;
}
.tag.mismatch { border-color: var(--warn); color: var(--warn); }
.tag.link { border-color: var(--accent); color: var(--accent); white-space: normal; }

/* 2. label result */
.hint {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  margin-bottom: 8px;
  border-radius: 6px;
  background: var(--accent-weak);
}
.hint { color: var(--accent); font-weight: 500; }
.hint.warn { background: var(--warn-bg); color: var(--warn); }

/* zoom bar + scrollable label viewport (the label is placed in px by app.js layout()) */
.zoombar { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.zoombar .zbtn { min-width: 28px; padding: 2px 6px; font-weight: 600; }
.zoomval { min-width: 52px; text-align: center; font-variant-numeric: tabular-nums; color: var(--muted); cursor: help; }
.viewport {
  position: relative;
  height: max(260px, calc(100vh - 360px));
  overflow: auto;
  scrollbar-gutter: stable;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  cursor: grab;
  overscroll-behavior: contain;
}
.viewport.panning { cursor: grabbing; }
/* "Etiket laden...": over the viewport (not inside it, so it does not scroll) until the new label is drawn */
.vp-wrap { position: relative; }
.label-loading {
  position: absolute; inset: 0; z-index: 5;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--bg) 62%, transparent);
  color: var(--muted); font-weight: 500;
  pointer-events: none;            /* panning / zooming keep working */
  animation: labelLoadingIn .15s ease-out .08s both;   /* a very quick load does not flash */
}
.label-loading[hidden] { display: none; }
.label-loading .spin {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: labelSpin .8s linear infinite;
}
@keyframes labelSpin { to { transform: rotate(360deg); } }
/* "controle bezig..." under the search box while the list badges are computed */
.list-busy { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); }
.spin-sm {
  width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: labelSpin .8s linear infinite;
}
@keyframes labelLoadingIn { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .label-loading .spin { animation-duration: 2.4s; } }
.label-msg { padding: 40px 20px; text-align: center; color: var(--muted); cursor: default; }
.label-msg.bad { color: var(--err); font-weight: 500; }
.stage { position: relative; user-select: none; -webkit-user-select: none; }
.stage img { -webkit-user-drag: none; user-select: none; }
.label-clip {
  position: absolute;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 0 0 1px var(--line), 0 1px 6px rgba(0, 0, 0, .12);
}
.label-clip > #preview { position: absolute; display: block; max-width: none; }
.ibox {
  position: absolute;
  outline: 1.5px dashed var(--box);
  background: rgba(255, 255, 255, .55);
  pointer-events: none;
}
.ibox > #render { position: absolute; left: 0; top: 0; width: 100%; height: auto; display: block; max-width: none; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 6px; }
.tile { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.t-label { color: var(--muted); font-size: 12px; }
.t-value { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.t-sub { color: var(--muted); font-size: 11px; min-height: 15px; }
.tile.bad { border-color: var(--err); background: var(--err-bg); }
.tile.bad .t-value { color: var(--err); }
.tile.good .t-value { color: var(--ok); }

.t-sim { color: var(--warn); font-weight: 600; font-size: 11px; }
/* font slider = simulation only (the label uses the template's size) */
.sim { margin-top: 12px; padding: 6px 10px 8px; border: 1px dashed var(--line); border-radius: 8px; }
.sim.active { border-color: var(--warn); background: var(--warn-bg); }
.sim.active .sim-note { color: var(--warn); }
.sim-note { margin-top: 2px; }
.slider { display: flex; align-items: center; gap: 10px; }
.slider input[type=range] { flex: 1; accent-color: var(--accent); }
.slider output { min-width: 48px; font-weight: 600; font-variant-numeric: tabular-nums; }
.legal { margin-top: 4px; }

/* under the label: what the label picture with the article's data does and does not show */
.label-report { margin-top: 6px; line-height: 1.45; }
.label-report .lr-notes { margin: 2px 0; padding-left: 18px; color: var(--warn); }
.settings { margin-top: 14px; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
.settings summary { cursor: pointer; font-weight: 600; }
.settings[open] summary { margin-bottom: 8px; }
.set-list { display: grid; grid-template-columns: max-content 1fr; gap: 5px 14px; margin: 0 0 8px; }
.set-list dt { color: var(--muted); }
.set-list dd { margin: 0; }
.set-langs { margin: 0; padding-left: 18px; }
.set-langs li + li { margin-top: 2px; }

/* 3. rework */
.col-rework { display: flex; flex-direction: column; padding-bottom: 0; }
.article-head { margin-bottom: 8px; font-size: 13px; }
.article-head b { color: var(--text); }
.slot { margin-bottom: 10px; }
.slot.missing textarea { border-style: dashed; }
.slot-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin-bottom: 3px; }
.slot-name { font-weight: 600; }
.slot-counts { display: inline-flex; gap: 3px; }
.slot.linked textarea { border-left: 3px solid var(--accent); }
/* the languages the label does not print */
.slots-other {
  margin: 16px 0 8px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
  color: var(--muted);
}
.slot textarea:disabled { background: var(--hover); color: var(--muted); }
/* empty languages that the label does not print: folded */
.slots-unused { margin: 16px 0 8px; padding-top: 10px; border-top: 1px dashed var(--line); }
.slots-unused > summary { cursor: pointer; color: var(--muted); font-weight: 600; font-size: 1.05em; padding: 2px 0; }
.slots-unused > summary:hover { color: var(--text); }
.slots-unused[open] > summary { margin-bottom: 6px; }
/* "Vertaal van het Nederlands": target language row under the field */
.tr-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  margin-top: 4px;
  padding: 6px 8px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent-weak);
}
.tr-field { display: inline-flex; align-items: center; gap: 6px; }
.tr-row button.small { padding: 2px 10px; font-size: 12px; }
.tr-why { flex-basis: 100%; }
.slot-len { margin-top: 2px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.slot-len.bad { color: var(--err); font-weight: 600; }
.slot textarea {
  display: block;
  width: 100%;
  min-height: 54px;
  resize: vertical;
  line-height: 1.4;
}
/* recipe tree: collapsed by default, one line per component, no wrapping */
.recipe { margin: 10px 0 4px; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
.recipe summary { cursor: pointer; font-weight: 600; }
.recipe[open] summary { margin-bottom: 6px; }
.recipe-tree {
  margin: 4px 0 0;
  max-height: 360px;
  overflow: auto;
  white-space: pre;
  font: 12px/1.4 ui-monospace, Consolas, monospace;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--input);
}
.find-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.find-hint { font-weight: 400; color: var(--warn); }
.empty { color: var(--muted); padding: 4px 0; }
.empty.bad { color: var(--err); }
.scope-note {
  margin: 3px 0 6px;
  padding: 5px 8px;
  border-radius: 4px;
  background: var(--info-bg);
  color: var(--info);
  font-size: 12px;
}
.fslot { font-size: 11px; font-weight: 600; color: var(--muted); }
.fgroup { margin-bottom: 8px; }
.fgroup-head { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; margin: 6px 0 3px; }
.fgroup.error .fgroup-head { color: var(--err); }
.fgroup.warning .fgroup-head { color: var(--warn); }
.fgroup.info .fgroup-head { color: var(--info); }
.finding {
  display: flex;
  gap: 8px;
  padding: 5px 8px;
  margin: 3px 0;
  border-left: 3px solid var(--info);
  border-radius: 4px;
  background: var(--info-bg);
  cursor: pointer;
}
.finding.error { border-left-color: var(--err); background: var(--err-bg); }
.finding.warning { border-left-color: var(--warn); background: var(--warn-bg); }
.flang { flex: none; width: 28px; font-weight: 600; font-size: 11px; padding-top: 1px; }
.fbody { flex: 1; min-width: 0; }
.fsrc { color: var(--muted); font-size: 11px; }
.fadvice { margin-top: 3px; font-size: 12px; font-weight: 500; }
.fix-btn { flex: none; align-self: flex-start; padding: 1px 8px; font-size: 12px; white-space: nowrap; }
.fix-btn .badge { min-width: 0; padding: 0 4px; font-size: 10px; line-height: 14px; }
.prop-head .badge { font-weight: 600; }
/* rewrite proposal (Inkorten / Herschrijven met AI) */
.proposal {
  margin-bottom: 12px;
  padding: 8px 10px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent-weak);
}
.prop-head { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.prop-line { margin-top: 4px; }
.prop-fit b.bad { color: var(--err); }
.prop-fit b.good { color: var(--ok); }
.prop-problems { margin: 4px 0 0; padding-left: 18px; color: var(--err); }
.prop-problems.ok { color: inherit; }
.prop-changes { margin: 4px 0 0; padding-left: 18px; }
.prop-changes .flang { display: inline-block; width: auto; margin-right: 6px; }
.prop-slot .prop-changes { margin: 0 0 4px; font-size: 12px; }
.prop-changes .tag { margin-right: 2px; }
.prop-slot { margin-top: 8px; }
.prop-slot-head { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; font-weight: 600; }
.prop-diff {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--input);
  line-height: 1.45;
}
.prop-diff del { color: var(--err); background: var(--err-bg); text-decoration: line-through; }
.prop-diff ins { color: var(--ok); background: var(--ok-bg); text-decoration: none; }
.prop-actions { display: flex; align-items: center; gap: 8px; margin-top: 10px; }

.actions {
  position: sticky;
  bottom: 0;
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0 12px;
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.actions input { flex: 1; min-width: 80px; }
.dirty { color: var(--warn); white-space: nowrap; }

/* sheet (batch table + rules) */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .35);
}
.sheet-panel {
  width: min(1100px, 94vw);
  height: 86vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
}
.sheet-head { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.sheet-body { flex: 1; overflow: auto; }
.pad { padding: 14px; }
table.grid { width: 100%; border-collapse: collapse; }
table.grid th {
  position: sticky;
  top: 0;
  background: var(--panel);
  text-align: left;
  font-weight: 600;
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.grid th.sortable { cursor: pointer; user-select: none; }
table.grid th.sortable:hover { color: var(--accent); }
table.grid th.asc::after { content: " \25B2"; font-size: 9px; }
table.grid th.desc::after { content: " \25BC"; font-size: 9px; }
table.grid td { padding: 5px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.grid tbody tr.click { cursor: pointer; }
table.grid tbody tr.click:hover { background: var(--hover); }
table.grid tbody tr.sel { background: var(--accent-weak); }
table.grid .num { text-align: right; font-variant-numeric: tabular-nums; }

/* "Los op" / vertaling: the field the open proposal is about, and a short flash after Toepassen */
.slot.fix-target textarea { outline: 2px dashed var(--accent); outline-offset: 1px; }
.slot.just-fixed textarea { animation: justFixed 2.5s ease-out; }
@keyframes justFixed {
  0%, 40% { box-shadow: 0 0 0 3px var(--accent); }
  100% { box-shadow: 0 0 0 0 transparent; }
}
