:root {
  --ink: #17212b;
  --muted: #667085;
  --line: #d8dee6;
  --paper: #ffffff;
  --page: #f3f5f1;
  --green: #187447;
  --green-dark: #0f5a35;
  --amber: #b66b10;
  --red: #b42318;
  --focus: #2f80ed;
  --print-left: 0mm;
  --print-top: 0mm;
  --print-width: 176mm;
  --print-height: 114mm;
  --print-rotation: 0deg;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--page);
}

body {
  margin: 0;
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  background:
    linear-gradient(180deg, #fff 0, #f6f8f4 260px, var(--page) 100%);
}

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

button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 700;
}

button:focus-visible,
input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 70px;
  padding: 12px clamp(14px, 3vw, 34px);
  border-bottom: 1px solid rgba(23, 33, 43, .08);
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}

.brand img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  flex: 0 0 auto;
}

.brand span {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.brand strong {
  font-size: 17px;
  letter-spacing: 0;
  white-space: nowrap;
}

.brand small,
.form-title p,
.preview-header p,
.field small,
.status-pill {
  color: var(--muted);
}

.top-actions,
.data-row,
.action-bar {
  display: flex;
  align-items: end;
  gap: 10px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(340px, 560px) minmax(420px, 1fr);
  gap: 22px;
  width: min(1480px, calc(100% - 32px));
  margin: 22px auto 36px;
  align-items: start;
}

.form-pane,
.preview-pane {
  background: var(--paper);
  border: 1px solid rgba(23, 33, 43, .08);
  border-radius: 8px;
  box-shadow: 0 18px 50px rgba(23, 33, 43, .08);
}

.form-pane {
  padding: 22px;
}

.preview-pane {
  position: sticky;
  top: 92px;
  padding: 18px;
}

.form-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 25px;
  line-height: 1.15;
}

h2 {
  font-size: 19px;
}

fieldset {
  margin: 18px 0 0;
  padding: 0;
  border: 0;
}

legend {
  width: 100%;
  padding: 0 0 8px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--line);
  color: #344054;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}

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

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.wide {
  grid-column: 1 / -1;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field > span {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
  color: #344054;
  font-size: 13px;
}

.field b {
  font-weight: 700;
}

.field em {
  color: #7a8699;
  font-style: normal;
  text-align: right;
  direction: rtl;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid #cfd6df;
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
}

input[readonly],
textarea[readonly],
select:disabled {
  color: #344054;
  border-color: #d8dee6;
  background: #f7f9fb;
  opacity: 1;
}

input,
select {
  height: 42px;
  padding: 0 11px;
}

textarea {
  min-height: 74px;
  padding: 10px 11px;
  resize: vertical;
}

input:invalid,
select:invalid,
textarea:invalid,
.invalid-field {
  border-color: #e67873;
  background: #fff8f7;
}

.data-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  margin: 14px 0 6px;
}

.radio-group {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.radio-group label,
.switch {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border: 1px solid #cfd6df;
  border-radius: 8px;
  background: #fff;
  color: #344054;
  font-weight: 700;
}

.radio-group input,
.switch input {
  width: auto;
  height: auto;
  margin: 0;
  accent-color: var(--green);
}

.calibration {
  align-items: end;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  border: 1px solid rgba(102, 112, 133, .25);
  border-radius: 999px;
  padding: 0 10px;
  background: #fff;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.primary-button {
  min-width: 138px;
  color: #fff;
  background: var(--green);
}

.primary-button:hover {
  background: var(--green-dark);
}

.secondary-button {
  color: #102a1d;
  border: 1px solid rgba(24, 116, 71, .25);
  background: #eaf5ee;
}

.secondary-button:hover {
  background: #dceee4;
}

.ghost-button {
  color: #344054;
  border: 1px solid #cfd6df;
  background: #fff;
}

.danger-button {
  color: var(--red);
  border: 1px solid rgba(180, 35, 24, .25);
  background: #fff3f1;
}

.action-bar {
  justify-content: flex-end;
  margin-top: 18px;
}

.validation-panel {
  display: none;
  margin-top: 14px;
  border-left: 3px solid var(--amber);
  padding: 9px 12px;
  background: #fff8ec;
  color: #694508;
  font-size: 13px;
}

.validation-panel.visible {
  display: block;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

#previewCanvas {
  display: block;
  width: 100%;
  aspect-ratio: 800 / 518;
  border: 1px solid #cfd6df;
  border-radius: 8px;
  background: #eef1f4;
}

#printSheet {
  display: none;
}

#printImage {
  display: block;
}

@media (max-width: 1020px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .preview-pane {
    position: static;
  }
}

@media (max-width: 640px) {
  body {
    font-size: 14px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
    justify-content: space-between;
  }

  .workspace {
    width: calc(100% - 20px);
    margin-top: 10px;
  }

  .form-pane,
  .preview-pane {
    padding: 14px;
  }

  .form-title,
  .preview-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .grid.two,
  .grid.three,
  .grid.four,
  .data-row,
  .radio-group {
    grid-template-columns: 1fr;
  }

  .data-row,
  .top-actions,
  .action-bar {
    align-items: stretch;
  }

  .data-row button,
  .action-bar button,
  .top-actions button {
    width: 100%;
  }
}

@page {
  size: A4 portrait;
  margin: 0;
}

@media print {
  html,
  body {
    width: 210mm;
    height: 297mm;
    background: #fff !important;
  }

  body > *:not(#printSheet) {
    display: none !important;
  }

  #printSheet {
    display: block !important;
    position: relative;
    width: 210mm;
    height: 297mm;
    overflow: hidden;
    background: #fff;
  }

  #printImage {
    position: absolute;
    left: var(--print-left);
    top: var(--print-top);
    width: var(--print-width);
    height: var(--print-height);
    transform: rotate(var(--print-rotation));
    transform-origin: center center;
  }
}
