*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  background: #fff;
  color: #000;
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  overflow: hidden;
}

/* ── Top bar ── */
.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 44px;
  padding: 0 20px;
  background: #111;
  color: #fff;
  flex-shrink: 0;
}

.topbar-label {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 13px;
  letter-spacing: 0.04em;
  opacity: 0.7;
  pointer-events: none;
}

.btn-new-pallet {
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: #fff;
  color: #111;
  border: none;
  padding: 6px 18px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-new-pallet:hover {
  background: #e0e0e0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-attach-label {
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: #fff;
  color: #111;
  border: none;
  padding: 6px 18px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-attach-label:hover {
  background: #e0e0e0;
}

.btn-error-mode {
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: transparent;
  color: #aaa;
  border: 1px solid #444;
  padding: 5px 14px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.btn-error-mode:hover {
  border-color: #e05c00;
  color: #e05c00;
}

.btn-error-mode.active {
  background: #e05c00;
  color: #fff;
  border-color: #e05c00;
}

.error-field {
  color: #1a1a6e;  /* keep handwriting color — error is subtle, not highlighted */
}

.layout {
  display: flex;
  width: 100%;
  height: calc(100% - 44px);
}

.panel {
  flex: 1;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.left-panel {
  border-right: 1px solid #000;
}

/* A4 ratio: 210 x 297 = 1 : 1.4142 */
.a4-wrapper {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.a4-sheet {
  background: #fff;
  border: 1px solid #000;
  box-shadow: 4px 4px 0 #000;
  aspect-ratio: 210 / 297;
  /* Fill as much of the wrapper as possible without overflow */
  max-width: 100%;
  max-height: 100%;
  /* Shrink to fit height */
  width: auto;
  height: 100%;
}

/* ── A4 Document Styles ───────────────────────────────────────────────────── */

.doc {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 1.1em 1.4em 0.8em;
  gap: 0.25em;
  font-size: 1em; /* base — scaled by JS */
}

/* Handwriting font for filled-in fields */
.hw {
  font-family: 'Caveat', cursive;
  font-size: 1em;
  color: #1a1a6e;
}

/* ── Header ── */
.doc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1em;
}

.farm-name {
  font-size: 1.3em;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.farm-sub {
  font-size: 0.78em;
  color: #333;
  margin-top: 0.15em;
}

.header-title {
  text-align: right;
  border: 2px solid #000;
  padding: 0.4em 0.8em;
  background: #f5f5f5;
}

.doc-title {
  font-size: 1.3em;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.doc-subtitle {
  font-size: 1.1em;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.doc-tag {
  font-size: 0.72em;
  color: #555;
  margin-top: 0.2em;
}

.divider {
  border-top: 2.5px solid #000;
  margin: 0.1em 0;
}

/* ── Section label ── */
.section-label {
  font-size: 0.78em;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  background: #000;
  color: #fff;
  padding: 0.15em 0.6em;
  margin-top: 0.15em;
}

/* ── Tables ── */
.tbl {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.tbl td, .tbl th {
  border: 1px solid #555;
  padding: 0.22em 0.5em;
  vertical-align: middle;
  line-height: 1.2;
}

.cell-label {
  font-size: 1em;
  font-weight: 600;
  color: #333;
  background: #f0f0f0;
  width: 20%;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.cell-value {
  font-size: 1em;
  width: 30%;
}

/* Checkbox row inside cell */
.checkbox-row {
  display: flex;
  gap: 1.5em;
  padding: 0.28em 0.5em;
}

.cb-item {
  display: flex;
  align-items: center;
  gap: 0.4em;
  font-size: 1em;
  font-weight: 600;
  text-transform: uppercase;
  cursor: default;
}

.cb {
  display: inline-block;
  width: 1.3em;
  height: 1.3em;
  border: 1.5px solid #000;
  text-align: center;
  line-height: 1.25em;
  font-size: 1em;
  color: transparent; /* hidden by default — checked overrides */
}

.cb.checked {
  color: #1a1a6e;
}

/* ── Lay dates (vertical list — fixed 10 slots) ── */
.lay-dates-cell {
  padding: 0.3em 0.5em !important;
}

.lay-date-entry {
  line-height: 1.3;
  min-height: 1.3em; /* empty slots keep their height */
}

/* ── Signature table ── */
.sig-tbl {
  flex: 1;
}

.sig-head {
  font-size: 0.82em;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: #f0f0f0;
  text-align: center;
  padding: 0.3em;
}

.sig-cell {
  text-align: center;
  padding: 0.5em 0.8em !important;
  vertical-align: bottom;
}

.sig-name {
  min-height: 2em;
  font-size: 1em;
  color: #1a1a6e;
}

.sig-line {
  border-top: 1px solid #000;
  margin: 0.3em 0.5em 0.2em;
}

.sig-date {
  font-size: 1em;
  color: #1a1a6e;
}

/* ── Footer ── */
.doc-footer {
  font-size: 0.72em;
  color: #555;
  text-align: center;
  border-top: 1px solid #aaa;
  padding-top: 0.4em;
  margin-top: auto;
}

/* ── Simple grid layout ── */
.simple-grid {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sg-row {
  display: flex;
  border: 1px solid #555;
  border-top: none;
  min-height: 0;
}

.sg-row:first-child {
  border-top: 1px solid #555;
}

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

.sg-label {
  width: 34%;
  flex-shrink: 0;
  background: #f0f0f0;
  font-size: 1.4em;
  font-weight: 600;
  color: #333;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.2em 0.5em;
  border-right: 1px solid #555;
  display: flex;
  align-items: center;
}

.sg-value + .sg-label {
  border-left: 1px solid #555;
}

.sg-value {
  flex: 1;
  font-size: 2em;
  padding: 0.15em 0.5em;
  display: flex;
  align-items: center;
}

.sg-value.hw {
  font-family: 'Caveat', cursive;
  font-size: 2.4em;
  color: #1a1a6e;
}

.sg-row-grow .sg-value {
  align-items: flex-start;
  flex-direction: column;
  padding: 0.3em 0.5em;
  gap: 0.2em;
}

.sg-row-grow .lay-date-entry {
  font-family: 'Caveat', cursive;
  color: #1a1a6e;
}

.simple-cb-row {
  display: flex;
  flex-direction: column;
  gap: 0.3em;
}

.simple-cb-row .cb-item {
  font-size: 1em;
  display: flex;
  align-items: center;
  gap: 0.4em;
  font-weight: 600;
  text-transform: uppercase;
}

/* Canvas wrapper fills the panel and clips the square canvas */
.canvas-wrapper {
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-canvas {
  display: block;
  width: auto !important;
  height: 100% !important;
  background: transparent !important;
}
