:root {
  --bg: #eef0f3;
  --card: #ffffff;
  --border: #d9dde3;
  --border-strong: #b9bfc8;
  --text: #1c2230;
  --muted: #677084;
  --link: #2f3fb6;
  --accent: #cd1c22;
  --accent-hover: #b0161b;
  --error: #b3261e;
  --error-bg: #fdecea;
  --warn: #8a5a00;
  --warn-bg: #fff4de;
  --focus: #2f6fed;
  --radius: 10px;
  --mono: "Cascadia Mono", Consolas, "SFMono-Regular", Menlo, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding-inline: 16px;
  padding-block: 20px 40px;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

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

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.app-header, .layout { max-width: 1120px; margin-inline: auto; }

.app-header { margin-bottom: 14px; display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 14px; }
.app-header h1 { margin: 0; font-size: 1.35rem; font-weight: 650; letter-spacing: -0.01em; }
.app-sub { margin: 0; color: var(--muted); font-size: 0.9rem; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
@media (max-width: 820px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px 20px;
  min-width: 0;
}

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: -4px 0 16px; }
.tab {
  border: 0;
  background: none;
  padding: 6px 10px 9px;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-weight: 550;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--text); border-bottom-color: var(--accent); }

.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0 0 12px; font-size: 1.6rem; font-weight: 500; letter-spacing: -0.01em; }
.info {
  display: inline-grid;
  place-items: center;
  width: 17px;
  height: 17px;
  border: 1.5px solid var(--link);
  color: var(--link);
  border-radius: 50%;
  font: 700 11px/1 Georgia, serif;
  vertical-align: super;
  cursor: help;
}
.links { display: flex; gap: 14px; }
.link { border: 0; background: none; padding: 0; color: var(--link); cursor: pointer; }
.link:hover { text-decoration: underline; }

.field-label { display: block; color: var(--muted); font-size: 0.9rem; margin-bottom: 4px; }
textarea {
  display: block;
  width: 100%;
  min-height: 230px;
  resize: vertical;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.95rem;
  line-height: 1.5;
  tab-size: 12;
  white-space: pre;
  overflow-wrap: normal;
}
.hint { margin: 6px 0 0; color: var(--muted); font-size: 0.85rem; }

.row { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px 16px; margin-top: 14px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--text); }
.inline-field { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.inline-field input { width: 76px; }

input[type="number"], input:not([type]), select {
  padding: 6px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: #fff;
  min-width: 0;
}

input.is-invalid { border-color: var(--error); background: var(--error-bg); }
input:disabled { opacity: 0.5; }

/* Issues */
.issues { margin-top: 14px; display: grid; gap: 8px; }
.issue { border-radius: 6px; padding: 8px 10px; font-size: 0.88rem; }
.issue.error { background: var(--error-bg); color: var(--error); }
.issue.warn { background: var(--warn-bg); color: var(--warn); }
.issue strong { font-weight: 650; }
.issue ul { margin: 4px 0 0; padding-left: 18px; }
.issue button {
  border: 0;
  background: none;
  padding: 0;
  color: inherit;
  text-decoration: underline;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.85rem;
}

/* Settings */
.settings { display: grid; gap: 14px; }
.settings fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px 14px; margin: 0; display: grid; gap: 10px; }
.settings legend { padding: 0 6px; font-weight: 600; }
.settings label:not(.check) { display: grid; gap: 3px; color: var(--muted); font-size: 0.88rem; }
.settings label:not(.check) > input, .settings label:not(.check) > select { color: var(--text); font-size: 0.95rem; }
.settings .check { font-size: 0.92rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }

/* Preview */
.preview-card { display: flex; flex-direction: column; }
.preview-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.summary { color: var(--muted); font-size: 0.92rem; }
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: #6b7280;
  cursor: pointer;
}
.icon-btn:hover:not(:disabled) { background: #f0f1f4; color: var(--text); }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
.icon-btn svg { width: 24px; height: 24px; }
#gear svg { width: 26px; height: 26px; }

.stage {
  margin: 8px 0 4px;
  padding: 14px 12px 18px;
  background: #f6f7f9;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.stage-fit {
  align-self: stretch;
  display: grid;
  place-items: center;
  container-type: inline-size;
}
/* The empty ::before balances the height label so the label stays centred. */
.stage-row { display: flex; align-items: center; gap: 8px; }
.stage-row::before { content: ""; width: 16px; }
.label-frame {
  /* --ratio (width / height) is set from the label size in app.js. */
  width: min(440px, calc(100cqw - 48px), calc(100cqh * var(--ratio, 1.333)), calc(60svh * var(--ratio, 1.333)));
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 0 0 1px #c9ced6, 0 6px 18px rgba(20, 30, 50, 0.10);
  overflow: hidden;
  position: relative;
}
.label-svg-wrap, .label-svg-wrap svg { display: block; width: 100%; height: auto; }
.label-frame.has-error { box-shadow: 0 0 0 2px var(--error), 0 6px 18px rgba(20, 30, 50, 0.10); }
.dim { color: var(--muted); font-size: 0.78rem; font-variant-numeric: tabular-nums; }
.dim-w { margin-bottom: 6px; }
.dim-h { writing-mode: vertical-rl; width: 16px; }
.label-message { margin: 10px 0 0; color: var(--error); font-size: 0.9rem; text-align: center; max-width: 420px; }

.pager { display: flex; align-items: center; justify-content: center; gap: 8px; font-variant-numeric: tabular-nums; }
.details { margin: 0 0 10px; text-align: center; color: var(--muted); font-size: 0.82rem; min-height: 1.2em; }

.actions { display: grid; gap: 6px; }
.action-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.action-buttons .btn-primary { flex: 1 1 200px; }
.action-buttons .btn-secondary { flex: 1 1 150px; font-weight: 550; }
.action-buttons .btn-secondary svg { width: 22px; height: 22px; }
.action-foot { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 4px 12px; }
.action-foot .link { font-size: 0.85rem; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-radius: 4px;
  padding: 8px 16px;
  border: 1px solid transparent;
  cursor: pointer;
}
.btn svg { width: 26px; height: 26px; }
.btn:disabled { cursor: not-allowed; opacity: 0.45; }
.btn-primary { background: var(--accent); color: #fff; font-size: 1.35rem; padding-block: 9px; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: #fff; border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: #f4f5f7; }
.btn-ghost { background: none; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: #f0f1f4; }
.settings .btn-ghost { justify-self: start; }
.action-note { margin: 0; min-height: 1.2em; color: var(--muted); font-size: 0.85rem; }

.tips-list { margin: 0; padding-left: 20px; display: grid; gap: 6px; }

/* Dialog */
.dialog {
  border: 0;
  border-radius: var(--radius);
  padding: 20px 22px;
  width: min(460px, calc(100vw - 32px));
  box-shadow: 0 20px 50px rgba(15, 20, 35, 0.3);
}
.dialog::backdrop { background: rgba(20, 25, 35, 0.45); }
.dialog h2 { margin: 0 0 14px; font-size: 1.2rem; }
.dialog label { display: grid; gap: 3px; color: var(--muted); font-size: 0.88rem; }
.dialog label input { color: var(--text); font-size: 0.95rem; }
.seq-preview { margin: 14px 0 0; padding: 8px 10px; background: #f6f7f9; border-radius: 6px; font-family: var(--mono); font-size: 0.88rem; overflow-wrap: anywhere; }
.seq-preview.error { color: var(--error); background: var(--error-bg); font-family: inherit; }
.dialog-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.dialog-actions .btn-primary { font-size: 1rem; padding-block: 8px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 0.9rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  max-width: calc(100vw - 32px);
}

/*
 * On desktop-sized windows the page fills exactly one screen: the data box,
 * settings and issue list scroll inside their cards, the label preview shrinks
 * to fit, and the PDF buttons are always visible. Smaller screens scroll normally.
 */
@media (min-width: 821px) and (min-height: 480px) {
  html, body { height: 100%; }
  body { display: flex; flex-direction: column; padding-block: 14px; }
  .app-header { flex: none; width: 100%; }
  .layout { flex: 1 1 auto; min-height: 0; width: 100%; align-items: stretch; }
  .card { display: flex; flex-direction: column; min-height: 0; }
  .panel { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
  #panelSettings { overflow-y: auto; margin-inline: -8px; padding-inline: 8px; padding-bottom: 4px; }
  textarea { flex: 1 1 auto; min-height: 96px; resize: none; }
  .issues { flex: 0 1 auto; min-height: 0; max-height: 32vh; overflow-y: auto; }
  .stage { flex: 1 1 auto; min-height: 0; }
  .stage-fit { flex: 1 1 auto; min-height: 0; container-type: size; }
}

[hidden] { display: none !important; }
