:root {
  --ink: #17201d;
  --muted: #66736d;
  --line: #dfe6e2;
  --paper: #ffffff;
  --canvas: #eef1ee;
  --green-950: #102d24;
  --green-900: #173d31;
  --green-800: #205241;
  --green-700: #2d6955;
  --green-100: #e4f0ea;
  --gold: #c69b52;
  --gold-soft: #f4ead8;
  --red: #a73a3a;
  --shadow: 0 18px 50px rgba(28, 44, 37, 0.1);
  --radius: 18px;
  --print-page-width: 210mm;
  --print-page-height: 297mm;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 5% 0%, rgba(198, 155, 82, 0.13), transparent 24rem),
    var(--canvas);
  font-family:
    -apple-system, BlinkMacSystemFont, "Noto Sans Thai", "Thonburi", "Tahoma", sans-serif;
  line-height: 1.45;
}

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

button {
  -webkit-tap-highlight-color: transparent;
}

.topbar {
  height: 92px;
  padding: 0 3.5vw;
  color: white;
  background: var(--green-950);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 3px solid var(--gold);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 50px;
  height: 50px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: var(--gold);
  font-family: "Times New Roman", serif;
  font-size: 28px;
  background: rgba(255, 255, 255, 0.05);
}

.eyebrow,
.step-label,
.preview-kicker {
  margin: 0;
  color: var(--gold);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.brand h1 {
  margin: 1px 0 0;
  font-size: clamp(21px, 2vw, 28px);
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.offline-badge {
  padding: 9px 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 999px;
  color: #d9e5df;
  font-size: 13px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.05);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #72d89f;
  box-shadow: 0 0 0 4px rgba(114, 216, 159, 0.12);
}

.app-shell {
  width: min(1500px, 94vw);
  margin: 28px auto 48px;
  display: grid;
  grid-template-columns: minmax(400px, 0.86fr) minmax(560px, 1.14fr);
  gap: 26px;
  align-items: start;
}

.workspace {
  display: grid;
  gap: 16px;
}

.intro {
  padding: 2px 2px 4px;
}

.intro p:last-child {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.card,
.preview-panel {
  border: 1px solid rgba(23, 61, 49, 0.1);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 24px rgba(33, 55, 46, 0.04);
}

.form-card {
  padding: 21px;
}

.card-heading {
  display: flex;
  align-items: center;
  gap: 13px;
  margin-bottom: 17px;
}

.step-number {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: white;
  background: var(--green-800);
  font-weight: 900;
}

h2,
p {
  margin-top: 0;
}

.card-heading h2,
.items-header h2,
.preview-toolbar h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -0.02em;
}

.card-heading p,
.items-header p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

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

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

.field > span {
  color: #43514b;
  font-size: 13px;
  font-weight: 750;
}

.field-inline-help {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cfd9d4;
  border-radius: 11px;
  color: var(--ink);
  background: #fff;
  outline: none;
  transition:
    border-color 150ms ease,
    box-shadow 150ms ease;
}

input,
select {
  height: 47px;
  padding: 0 13px;
}

select {
  padding-right: 42px;
  cursor: pointer;
  font-weight: 800;
}

textarea {
  padding: 12px 13px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green-700);
  box-shadow: 0 0 0 4px rgba(45, 105, 85, 0.1);
}

input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: var(--red);
  box-shadow: 0 0 0 4px rgba(167, 58, 58, 0.08);
}

.serial-input-wrap,
.unit-input {
  position: relative;
}

.serial-input-wrap input {
  padding-right: 150px;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.auto-pill {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  padding: 6px 9px;
  border-radius: 8px;
  color: var(--green-800);
  background: var(--green-100);
  font-size: 11px;
  font-weight: 800;
  pointer-events: none;
}

.field-help {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.field-error {
  margin: 8px 0 0;
  color: var(--red);
  font-size: 12px;
  font-weight: 700;
}

.weight-entry {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

.unit-input input {
  padding-right: 44px;
  font-size: 18px;
  font-weight: 750;
}

.unit-input > span {
  position: absolute;
  top: 50%;
  right: 13px;
  transform: translateY(-50%);
  color: var(--muted);
  font-weight: 800;
}

.button {
  min-height: 45px;
  padding: 0 17px;
  border: 0;
  border-radius: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 800;
  transition:
    transform 120ms ease,
    filter 120ms ease,
    background 120ms ease;
}

.button:hover {
  filter: brightness(1.03);
}

.button:active {
  transform: translateY(1px);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  filter: none;
}

.button-primary {
  color: white;
  background: var(--green-800);
}

.add-button {
  height: 47px;
}

.bulk-entry {
  margin-top: 13px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}

.bulk-entry summary {
  width: fit-content;
  color: var(--green-700);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
}

.bulk-content {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

.button-soft {
  color: var(--green-900);
  background: var(--green-100);
}

.mixed-workflow-card {
  border-color: rgba(198, 155, 82, 0.38);
  background:
    linear-gradient(180deg, rgba(244, 234, 216, 0.34), transparent 125px),
    rgba(255, 255, 255, 0.97);
}

.mixed-form-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 13px 12px;
}

.mixed-form-grid .field-wide {
  grid-column: 1 / -1;
}

.mixed-form-grid input,
.mixed-form-grid select {
  font-variant-numeric: tabular-nums;
}

.mixed-add-row {
  margin-top: 16px;
  padding-top: 15px;
  border-top: 1px dashed var(--line);
  display: grid;
  grid-template-columns: minmax(140px, 0.65fr) minmax(190px, 1.35fr);
  gap: 12px;
  align-items: end;
}

.quantity-field input {
  text-align: center;
  font-weight: 800;
}

.items-card {
  min-height: 200px;
  padding: 0;
  overflow: hidden;
}

.items-header {
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
}

.small-actions {
  display: flex;
  gap: 12px;
}

.text-button {
  padding: 0;
  border: 0;
  color: var(--green-700);
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.empty-state {
  min-height: 150px;
  padding: 22px;
  display: grid;
  place-items: center;
  align-content: center;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  margin-top: 8px;
  color: #46514c;
}

.empty-state span:last-child {
  margin-top: 2px;
  font-size: 12px;
}

.empty-icon {
  width: 44px;
  height: 44px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  color: var(--green-700);
  background: var(--green-100);
  font-size: 13px;
  font-weight: 900;
}

.items-list {
  max-height: 390px;
  overflow: auto;
}

.item-row {
  min-height: 66px;
  padding: 10px 14px 10px 16px;
  display: grid;
  grid-template-columns: 28px 36px minmax(100px, 0.8fr) minmax(130px, 1.2fr) 36px;
  gap: 10px;
  align-items: center;
  border-bottom: 1px solid #edf1ef;
}

.item-row:last-child {
  border-bottom: 0;
}

.item-row.is-unselected {
  opacity: 0.5;
  background: #f8faf9;
}

.item-check {
  width: 20px;
  height: 20px;
  accent-color: var(--green-700);
}

.item-index {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.item-weight {
  position: relative;
}

.item-weight input {
  height: 40px;
  padding-right: 36px;
  font-weight: 800;
}

.item-weight span {
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  pointer-events: none;
}

.item-serial {
  min-width: 0;
  display: grid;
}

.item-serial span {
  color: var(--muted);
  font-size: 10px;
}

.item-serial strong {
  overflow: hidden;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
}

.item-row.mixed-item-row {
  grid-template-columns: 28px 36px minmax(0, 1fr) auto 36px;
}

.mixed-item-main {
  min-width: 0;
}

.mixed-item-title {
  display: block;
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mixed-item-meta {
  display: block;
  overflow: hidden;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mixed-item-weight {
  min-width: 60px;
  color: var(--green-900);
  text-align: right;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.delete-item {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 9px;
  color: #8d6969;
  background: #faeeee;
  cursor: pointer;
  font-size: 17px;
}

.preview-panel {
  position: sticky;
  top: 18px;
  padding: 21px;
  box-shadow: var(--shadow);
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 15px;
}

.preview-toolbar h2 {
  margin-top: 3px;
}

.template-summary {
  margin: 4px 0 0;
  color: var(--green-700);
  font-size: 12px;
  font-weight: 800;
}

.page-nav {
  min-width: 150px;
  display: grid;
  grid-template-columns: 34px 1fr 34px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.page-nav button {
  height: 34px;
  border: 0;
  color: var(--green-900);
  background: #f5f8f6;
  cursor: pointer;
  font-size: 22px;
}

.page-nav button:disabled {
  color: #aeb8b3;
  cursor: default;
}

.page-nav span {
  color: var(--muted);
  text-align: center;
  font-size: 11px;
  font-weight: 800;
}

.preview-stage {
  min-height: 520px;
  padding: 23px;
  border: 1px solid #d8dfdb;
  border-radius: 14px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    linear-gradient(45deg, #e4e8e5 25%, transparent 25%),
    linear-gradient(-45deg, #e4e8e5 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e4e8e5 75%),
    linear-gradient(-45deg, transparent 75%, #e4e8e5 75%),
    #eef1ef;
  background-position:
    0 0,
    0 8px,
    8px -8px,
    -8px 0;
  background-size: 16px 16px;
}

.preview-page {
  position: relative;
  width: min(100%, 520px);
  aspect-ratio: 210 / 297;
  overflow: hidden;
  background: white;
  box-shadow: 0 8px 24px rgba(22, 34, 29, 0.2);
}

.preview-label {
  position: absolute;
  overflow: hidden;
  container-type: inline-size;
}

.label-svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: hidden;
  text-rendering: geometricPrecision;
}

.summary-strip {
  margin-top: 15px;
  padding: 13px 4px;
  display: grid;
  grid-template-columns: 1fr 1fr 1.3fr;
  gap: 10px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.summary-strip > div {
  min-width: 0;
  padding: 0 12px;
  border-right: 1px solid var(--line);
}

.summary-strip > div:last-child {
  border-right: 0;
}

.summary-strip span {
  display: block;
  color: var(--muted);
  font-size: 10px;
}

.summary-strip strong {
  display: block;
  overflow: hidden;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
}

.primary-actions {
  margin-top: 15px;
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 10px;
}

.button-download {
  min-height: 52px;
  color: white;
  background: var(--green-800);
  box-shadow: 0 8px 18px rgba(32, 82, 65, 0.18);
}

.button-print {
  min-height: 52px;
  color: var(--green-900);
  border: 1px solid #b9c9c1;
  background: white;
}

.print-tip {
  margin: 9px 0 0;
  color: var(--muted);
  text-align: center;
  font-size: 11px;
}

.batch-actions {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.button-quiet,
.button-danger-quiet {
  min-height: 40px;
  font-size: 12px;
}

.button-quiet {
  color: var(--green-800);
  background: var(--green-100);
}

.button-danger-quiet {
  color: var(--red);
  background: #faeeee;
}

.toast {
  position: fixed;
  z-index: 100;
  right: 24px;
  bottom: 24px;
  max-width: min(380px, calc(100vw - 48px));
  padding: 13px 16px;
  border-radius: 12px;
  color: white;
  background: var(--green-950);
  box-shadow: 0 12px 32px rgba(12, 33, 26, 0.28);
  font-size: 13px;
  font-weight: 700;
}

.print-root {
  display: none;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
    width: min(760px, 94vw);
  }

  .preview-panel {
    position: static;
  }
}

@media (max-width: 640px) {
  .topbar {
    height: 80px;
    padding: 0 18px;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
  }

  .brand .eyebrow,
  .offline-badge {
    display: none;
  }

  .app-shell {
    width: calc(100% - 24px);
    margin-top: 16px;
    gap: 16px;
  }

  .date-grid,
  .weight-entry,
  .bulk-content,
  .mixed-form-grid,
  .mixed-add-row,
  .primary-actions,
  .batch-actions {
    grid-template-columns: 1fr;
  }

  .mixed-form-grid .field-wide {
    grid-column: auto;
  }

  .serial-input-wrap input {
    padding-right: 13px;
  }

  .auto-pill {
    display: none;
  }

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

  .item-row {
    grid-template-columns: 26px 25px minmax(85px, 0.8fr) minmax(95px, 1.2fr) 34px;
    gap: 6px;
    padding-inline: 9px;
  }

  .item-row.mixed-item-row {
    grid-template-columns: 26px 25px minmax(0, 1fr) auto 34px;
  }

  .item-serial strong {
    font-size: 11px;
  }

  .preview-panel {
    padding: 14px;
  }

  .preview-stage {
    min-height: 410px;
    padding: 13px;
  }

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

  .page-nav {
    width: 100%;
  }
}

@page {
  margin: 0;
}

@media print {
  html,
  body {
    width: var(--print-page-width);
    min-width: var(--print-page-width);
    margin: 0 !important;
    padding: 0 !important;
    background: white !important;
  }

  body > :not(.print-root) {
    display: none !important;
  }

  .print-root {
    display: block !important;
  }

  .print-sheet {
    position: relative;
    width: var(--print-page-width);
    height: var(--print-page-height);
    margin: 0;
    overflow: hidden;
    break-after: page;
    page-break-after: always;
    background: white;
  }

  .print-sheet:last-child {
    break-after: auto;
    page-break-after: auto;
  }

  .print-label {
    position: absolute;
    overflow: hidden;
  }

  .label-svg {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
}
