:root {
  --bg: #f6f3ef;
  --card: #ffffff;
  --ink: #1f1b18;
  --muted: #6f6760;
  --line: #e7e0d8;
  --brand: #a4241f;
  --brand-dark: #861b17;
  --brand-soft: #fbeceb;
  --warn: #8a5a00;
  --warn-soft: #fff4d6;
  --ok: #1e6b3a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(31, 27, 24, .06), 0 6px 20px rgba(31, 27, 24, .06);
  /* etiketmål – sættes fra indstillingerne */
  --lw: 76mm;
  --lh: 51mm;
  --lm: 2mm;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
h1, h2, p { margin: 0; }
h2 { font-size: 1.2rem; letter-spacing: -.01em; }
small { font-weight: 400; color: var(--muted); }
.muted { color: var(--muted); }
.center { text-align: center; }
.pad { padding: 22px; }
.spacer { flex: 1; }

/* ---------- knapper ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  padding: 10px 16px;
  min-height: 44px;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s, transform .05s;
}
.btn:hover { border-color: #cfc6bc; background: #fbf9f7; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn.big { padding: 12px 24px; font-size: 1.05rem; min-height: 50px; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: rgba(0, 0, 0, .05); }
.btn.danger { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger-ghost { color: var(--brand); border-color: transparent; background: transparent; }
.btn.danger-ghost:hover { background: var(--brand-soft); }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn {
  appearance: none; border: 0; background: transparent; font-size: 1.1rem; color: var(--muted);
  width: 40px; height: 40px; border-radius: 10px; cursor: pointer; flex: none;
}
.icon-btn:hover { background: rgba(0, 0, 0, .06); color: var(--ink); }
:focus-visible { outline: 3px solid rgba(164, 36, 31, .35); outline-offset: 2px; }

/* ---------- formularer ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin: 0 0 14px; min-width: 0; }
.field > span { font-size: .88rem; font-weight: 600; }
input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid #d8d0c7;
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
  width: 100%;
  min-width: 0;
}
textarea { resize: vertical; line-height: 1.4; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(164, 36, 31, .15); }
input.invalid { border-color: var(--brand); background: var(--brand-soft); }
input[type="checkbox"] { width: 20px; height: 20px; min-height: 0; accent-color: var(--brand); flex: none; }
.check { display: flex; align-items: center; gap: 10px; margin: -4px 0 14px; cursor: pointer; }
.hint { font-size: .84rem; color: var(--muted); }
.hint.warn { color: var(--warn); background: var(--warn-soft); border-radius: 10px; padding: 10px 12px; margin-top: 12px; }
.form-error { color: var(--brand); font-weight: 600; margin-bottom: 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.row2.wide-first { grid-template-columns: 2fr 1fr; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 14px; }
.row4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 14px; margin-top: 14px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
fieldset { border: 0; padding: 0; margin: 0 0 20px; min-width: 0; }
legend { padding: 0; margin-bottom: 10px; font-weight: 700; font-size: 1rem; }
.group-label { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 8px; }
.fold { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.fold summary { cursor: pointer; font-weight: 700; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
  width: min(380px, 100%); background: var(--card); border-radius: 20px; box-shadow: var(--shadow);
  padding: 34px 30px; display: flex; flex-direction: column; text-align: center;
}
.login-card h1 { font-size: 1.6rem; letter-spacing: -.02em; }
.login-card .muted { margin-bottom: 24px; }
.login-card .field { text-align: left; }
.brand-mark {
  width: 60px; height: 60px; border-radius: 16px; background: var(--brand); display: grid; place-items: center;
  font-size: 1.8rem; margin: 0 auto 14px;
}
.brand-mark.small { width: 34px; height: 34px; border-radius: 10px; font-size: 1.05rem; margin: 0; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 18px;
  padding: 10px clamp(14px, 3vw, 32px);
  background: rgba(255, 255, 255, .92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.1rem; letter-spacing: -.01em; }
.tabs { display: flex; gap: 4px; margin-right: auto; }
.tab {
  appearance: none; border: 0; background: transparent; font: inherit; font-weight: 600; color: var(--muted);
  padding: 9px 14px; border-radius: 10px; cursor: pointer; min-height: 42px;
}
.tab:hover { background: rgba(0, 0, 0, .05); color: var(--ink); }
.tab.active { background: var(--brand-soft); color: var(--brand); }

main { padding: clamp(14px, 3vw, 32px); max-width: 1280px; margin: 0 auto; }
.view > h2 { margin-bottom: 14px; }

/* ---------- vareliste ---------- */
.toolbar { display: flex; gap: 12px; margin-bottom: 14px; }
.search {
  flex: 1; display: flex; align-items: center; gap: 8px; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; padding: 0 14px;
}
.search:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(164, 36, 31, .15); }
.search input { border: 0; box-shadow: none !important; padding-left: 0; background: transparent; font-size: 1.05rem; min-height: 48px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.chip {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font: inherit; font-size: .92rem; font-weight: 600; padding: 7px 14px; border-radius: 999px; cursor: pointer; min-height: 38px;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip:hover { border-color: #cfc6bc; }
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.allergen-chips { margin-bottom: 14px; }
.allergen-chips .chip.active { background: var(--brand); border-color: var(--brand); }
.allergen-chips.traces .chip.active { background: var(--warn-soft); border-color: #e2b84a; color: var(--warn); }
.allergen-chips .chip:disabled { opacity: .35; cursor: default; }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .75; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.pcard {
  position: relative; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 16px 14px; cursor: pointer; text-align: left; font: inherit; color: inherit;
  display: flex; flex-direction: column; gap: 8px; min-height: 132px;
  transition: box-shadow .15s, transform .15s, border-color .15s;
}
.pcard:hover { box-shadow: var(--shadow); transform: translateY(-2px); border-color: #d9cfc4; }
.pcard-cat { font-size: .76rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--brand); }
.pcard-name { font-size: 1.12rem; font-weight: 700; line-height: 1.25; padding-right: 36px; overflow-wrap: anywhere; }
.pcard-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.tag { font-size: .76rem; font-weight: 600; background: var(--brand-soft); color: var(--brand-dark); border-radius: 6px; padding: 2px 7px; }
.tag.trace { background: var(--warn-soft); color: var(--warn); }
.pcard-meta { margin-top: auto; font-size: .82rem; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.pcard-edit { position: absolute; top: 8px; right: 8px; }
.empty { text-align: center; padding: 70px 20px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty-title { font-size: 1.3rem; font-weight: 700; }

/* ---------- kort / tabel / indstillinger ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.card h2 { margin-bottom: 4px; }
.card h2 + .muted { margin-bottom: 16px; }
.card h2 + .field { margin-top: 14px; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 12px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 16px; align-items: start; }
.logo-preview { background: #fff; border: 1px dashed #d8d0c7; border-radius: 12px; padding: 14px; display: grid; place-items: center; min-height: 110px; margin-bottom: 14px; }
.logo-preview img { max-width: 100%; max-height: 120px; display: block; }
.steps { margin: 0 0 14px; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }

/* ---------- dialoger ---------- */
.dialog {
  border: 0; padding: 0; border-radius: 18px; background: var(--card); color: var(--ink);
  width: min(820px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .3); overflow: hidden;
}
.dialog.wide { width: min(1120px, calc(100vw - 24px)); }
.dialog.small { width: min(420px, calc(100vw - 24px)); }
.dialog::backdrop { background: rgba(31, 27, 24, .5); backdrop-filter: blur(2px); }
.dialog[open] { display: flex; }
.dialog-inner { display: flex; flex-direction: column; min-height: 0; width: 100%; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 22px 12px; }
.dialog-head h2 { font-size: 1.35rem; overflow-wrap: anywhere; }
.dialog-body { padding: 8px 22px 20px; overflow-y: auto; min-height: 0; }
.dialog.small .dialog-body { padding-top: 24px; }
.dialog.small h2 { margin-bottom: 6px; }
.dialog-foot { display: flex; align-items: center; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--line); background: #fbf9f7; flex-wrap: wrap; }
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 26px; align-items: start; }
.dialog.wide .two-col { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); }
.preview-col.sticky { position: sticky; top: 0; }

.stepper { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stepper input { width: 84px; text-align: center; font-size: 1.25rem; font-weight: 700; min-height: 52px; }
.step {
  appearance: none; width: 52px; height: 52px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
  font-size: 1.5rem; font-weight: 600; cursor: pointer; color: var(--ink);
}
.step:hover { background: #fbf9f7; border-color: #cfc6bc; }
.quick { display: flex; gap: 6px; margin-left: 6px; }

/* ---------- forhåndsvisning ---------- */
.preview-stage {
  background: repeating-linear-gradient(45deg, #efeae4, #efeae4 10px, #ebe5de 10px, #ebe5de 20px);
  border-radius: 14px; padding: 18px; display: flex; justify-content: center; overflow: hidden;
}
.preview-scale { flex: none; position: relative; }
.preview-scale .label { transform-origin: top left; position: absolute; top: 0; left: 0; border-radius: 1.5mm; box-shadow: 0 2px 10px rgba(0, 0, 0, .18); }
.fit-note { margin-top: 10px; font-size: .86rem; border-radius: 10px; padding: 8px 12px; background: var(--warn-soft); color: var(--warn); }
.fit-note.bad { background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }

/* ---------- etiketten (samme opbygning på skærm og print) ---------- */
.label {
  width: var(--lw); height: var(--lh); padding: var(--lm);
  background: #fff; color: #000; overflow: hidden;
  font-family: Arial, Helvetica, "Liberation Sans", sans-serif; font-size: 8pt; line-height: 1.14;
  text-align: left;
}
.label p, .label h1 { margin: 0; }
.label .l-inner { min-height: 100%; display: flex; flex-direction: column; }
.label .l-body { flex: none; display: flow-root; }
.label .l-logo { float: right; height: auto; margin: 0 0 1mm 1.5mm; display: block; }
.label .l-foot { margin-top: auto; padding-top: .35em; }
.label .l-name { font-size: 1.55em; line-height: 1.05; font-weight: 700; margin-bottom: .22em; overflow-wrap: anywhere; }
.label .l-key { font-weight: 400; }
.label .l-ingr, .label .l-line, .label .l-note, .label .l-nutr { overflow-wrap: anywhere; }
.label .l-ingr b, .label .l-line b { font-weight: 700; text-transform: uppercase; font-size: .94em; }
.label .l-line, .label .l-note, .label .l-nutr { margin-top: .22em; }
.label .l-note { font-weight: 700; }
.label .l-nutr { font-size: .92em; }
.label .l-storage { font-weight: 700; border-top: .2mm solid #000; padding-top: .3em; }
.label .l-facts { display: flex; flex-wrap: wrap; column-gap: 1em; row-gap: .05em; margin-top: .12em; }
.label .l-fact { white-space: nowrap; }
.label .l-fact.strong { font-weight: 700; }
.label .l-fact.strong .l-key { font-weight: 700; }
.label .l-shop { margin-top: .2em; font-size: .86em; }
.label.test { display: grid; place-items: center; text-align: center; padding: 0; }
.label.test .test-frame { width: calc(100% - 2 * var(--lm)); height: calc(100% - 2 * var(--lm)); border: .4mm solid #000; display: grid; place-items: center; align-content: center; gap: 1mm; font-size: 10pt; }
.label.test b { font-size: 14pt; }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); z-index: 100;
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 12px; font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25); max-width: calc(100vw - 32px);
}
.toast.error { background: var(--brand); }

/* udskriftsområdet ligger uden for skærmen, men er lagt ud, så teksten kan måles */
#print-root { position: absolute; left: -10000px; top: 0; visibility: hidden; }

@media (max-width: 860px) {
  .two-col, .dialog.wide .two-col { grid-template-columns: minmax(0, 1fr); }
  .preview-col.sticky { position: static; order: -1; }
  .row4 { grid-template-columns: 1fr 1fr; }
  .topbar { flex-wrap: wrap; gap: 8px; }
  .tabs { order: 3; width: 100%; margin: 0; }
  .tab { flex: 1; }
  .brand { margin-right: auto; }
}
@media (max-width: 520px) {
  .row2, .row2.wide-first, .row3 { grid-template-columns: minmax(0, 1fr); }
  .toolbar { flex-wrap: wrap; }
  .toolbar .btn { width: 100%; }
  .dialog-foot .btn.big { flex: 1; }
}

@media print {
  html, body { margin: 0 !important; padding: 0 !important; background: #fff !important; }
  body > *:not(#print-root) { display: none !important; }
  #print-root { position: static; visibility: visible; }
  #print-root .label { break-after: page; break-inside: avoid; }
  #print-root .label:last-child { break-after: auto; }
}
