:root {
  color-scheme: light;
  --bg: #f3f4f1;
  --panel: #ffffff;
  --text: #17201b;
  --muted: #5d665f;
  --line: #c9d0c9;
  --line-strong: #919b93;
  --accent: #1f7a55;
  --accent-strong: #155c40;
  --accent-soft: #e7f4ec;
  --warn: #a86200;
  --warn-soft: #fff3d8;
  --error: #b42318;
  --error-soft: #ffe5e2;
  --field: #ffffff;
  --shadow: 0 14px 34px rgba(34, 43, 37, 0.08);
}

body.dark {
  color-scheme: dark;
  --bg: #181a17;
  --panel: #242722;
  --text: #f4f6f0;
  --muted: #c1c8bd;
  --line: #41483f;
  --line-strong: #687164;
  --accent: #74c69d;
  --accent-strong: #9bddb9;
  --accent-soft: #26392d;
  --warn: #f8c46b;
  --warn-soft: #3a2e18;
  --error: #ff9a91;
  --error-soft: #3c2220;
  --field: #171916;
  --shadow: 0 14px 34px rgba(0, 0, 0, 0.2);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 16px;
  line-height: 1.35;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  padding: 0.68rem 0.95rem;
  font-weight: 700;
}

button:hover,
button:focus-visible {
  border-color: var(--accent);
  outline: 2px solid color-mix(in srgb, var(--accent) 28%, transparent);
  outline-offset: 1px;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

button.primary:hover,
button.primary:focus-visible {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

button:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input,
select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--text);
  padding: 0.58rem 0.68rem;
}

input:focus,
select:focus {
  border-color: var(--accent);
  outline: 3px solid color-mix(in srgb, var(--accent) 22%, transparent);
}

label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
}

label input,
label select {
  color: var(--text);
  text-transform: none;
  font-weight: 500;
}

code {
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 0.1rem 0.28rem;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem clamp(1rem, 3vw, 2rem);
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header h1 {
  margin: 0.1rem 0 0;
  font-size: clamp(1.2rem, 2vw, 1.75rem);
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.header-actions,
.quick-actions,
.calibration-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
}

.quick-actions select {
  width: min(360px, 100%);
}

.layout {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: clamp(1rem, 2.4vw, 2rem);
  display: grid;
  gap: 1rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: clamp(1rem, 2vw, 1.35rem);
}

body:not(.advanced-visible) .advanced-section {
  display: none;
}

.quick-start {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.quick-start h2,
.section-head h2 {
  margin: 0;
  font-size: 1.02rem;
  letter-spacing: 0;
}

.quick-start p {
  max-width: 720px;
  margin: 0.35rem 0 0;
  color: var(--muted);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.section-head span,
.save-state {
  color: var(--muted);
  font-size: 0.9rem;
}

.wizard-panel {
  display: grid;
  gap: 1rem;
}

.wizard-head,
.wizard-actions,
.product-toolbar,
.product-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.wizard-head h2 {
  margin: 0.1rem 0 0;
  font-size: clamp(1.45rem, 2.4vw, 2rem);
}

.wizard-progress {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--line);
}

.wizard-progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 160ms ease;
}

.wizard-grid,
.review-grid,
.product-card-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 0.9rem;
}

.wizard-body {
  display: grid;
  gap: 1rem;
}

.wizard-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
  border-top: 1px solid var(--line);
  padding-top: 1rem;
}

.wizard-status {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.wizard-status span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.35rem 0.6rem;
  font-size: 0.86rem;
  font-weight: 700;
}

.wizard-status .ok {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--line));
}

.wizard-status .todo {
  background: var(--warn-soft);
  border-color: color-mix(in srgb, var(--warn) 35%, var(--line));
}

.wizard-confirm {
  margin-top: 0;
}

.wizard-finish {
  margin-top: 0;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(125px, 1fr));
  gap: 0.55rem;
}

.product-toggle {
  min-height: 58px;
  display: grid;
  align-content: center;
  gap: 0.12rem;
  text-align: left;
}

.product-toggle small {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.product-toggle.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.product-separator {
  min-height: 1px;
}

.product-cards {
  display: grid;
  gap: 0.75rem;
}

.product-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.9rem;
  display: grid;
  gap: 0.75rem;
}

.product-card-head strong {
  font-size: 1.05rem;
}

.empty-state {
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  padding: 1rem;
  text-align: center;
}

.review-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem;
  display: grid;
  gap: 0.25rem;
}

.review-item span,
.review-products span {
  color: var(--muted);
}

.review-products {
  display: grid;
  gap: 0.55rem;
}

.review-products > div {
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.55rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 0.9rem;
}

.form-grid label:first-child {
  grid-column: span 2;
}

.required-field input {
  border-color: var(--warn);
  background: color-mix(in srgb, var(--warn-soft) 50%, var(--field));
}

.finish-field {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 1rem 0 0;
  padding: 0.9rem;
}

.finish-field legend {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  padding: 0 0.35rem;
  text-transform: uppercase;
}

.finish-options,
.confirmation-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
}

.choice,
.confirm-check {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--text);
  padding: 0.65rem 0.85rem;
  text-transform: none;
}

.choice {
  flex: 1 1 120px;
}

.confirm-check {
  flex: 1 1 250px;
  margin-top: 0.85rem;
}

.choice input,
.confirm-check input {
  width: auto;
  min-height: 0;
  accent-color: var(--accent);
}

.confirm-warning {
  border-color: var(--warn) !important;
  background: color-mix(in srgb, var(--warn-soft) 58%, var(--field)) !important;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  background: var(--panel);
}

th,
td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 0.45rem;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: color-mix(in srgb, var(--panel) 86%, var(--accent-soft));
  color: var(--text);
  font-size: 0.76rem;
  text-align: left;
  text-transform: uppercase;
}

td:last-child,
th:last-child {
  border-right: 0;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody input {
  min-height: 42px;
  border-radius: 7px;
  padding: 0.45rem 0.5rem;
}

.part-cell {
  min-width: 150px;
  font-weight: 800;
  background: color-mix(in srgb, var(--panel) 92%, var(--accent-soft));
}

.part-cell .part-no {
  display: block;
  margin-bottom: 0.35rem;
}

.copy-identical {
  min-height: 34px;
  padding: 0.3rem 0.5rem;
  font-size: 0.74rem;
  font-weight: 700;
}

.separator-row td {
  height: 32px;
  background: repeating-linear-gradient(
    -45deg,
    color-mix(in srgb, var(--line) 38%, transparent),
    color-mix(in srgb, var(--line) 38%, transparent) 4px,
    transparent 4px,
    transparent 10px
  );
}

.field-warning {
  border-color: var(--warn) !important;
  background: color-mix(in srgb, var(--warn-soft) 58%, var(--field)) !important;
}

.field-error {
  border-color: var(--error) !important;
  background: color-mix(in srgb, var(--error-soft) 62%, var(--field)) !important;
}

.validation-summary {
  margin-top: 1rem;
  display: grid;
  gap: 0.45rem;
}

.notice {
  border-radius: 8px;
  padding: 0.7rem 0.85rem;
  background: var(--accent-soft);
  color: var(--text);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line));
}

.notice.warn {
  background: var(--warn-soft);
  border-color: color-mix(in srgb, var(--warn) 35%, var(--line));
}

.notice.error {
  background: var(--error-soft);
  border-color: color-mix(in srgb, var(--error) 35%, var(--line));
}

.preview-panel iframe {
  width: 100%;
  height: min(72vh, 680px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.print-frame {
  position: fixed;
  right: 0;
  bottom: 0;
  width: 1px;
  height: 1px;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

.pdf-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-bottom: 0.75rem;
}

.button-link {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 0.68rem 0.95rem;
  font-weight: 700;
  text-decoration: none;
}

.button-link:hover,
.button-link:focus-visible {
  border-color: var(--accent);
  outline: 2px solid color-mix(in srgb, var(--accent) 28%, transparent);
  outline-offset: 1px;
}

.calibration-grid {
  align-items: end;
}

.calibration-grid label {
  min-width: 90px;
  flex: 1 1 120px;
}

.calibration-grid label:first-child {
  flex-basis: 300px;
}

.file-import {
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  color: var(--text);
  cursor: pointer;
}

.file-import input {
  display: none;
}

.hidden {
  display: none !important;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  max-width: min(420px, calc(100vw - 2rem));
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  background: #17201b;
  color: white;
  border-radius: 8px;
  padding: 0.8rem 1rem;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.24);
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 20;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 900px) {
  .app-header,
  .quick-start,
  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .header-actions button,
  .quick-actions button {
    flex: 1 1 180px;
  }

  .form-grid {
    grid-template-columns: repeat(2, minmax(130px, 1fr));
  }

  .wizard-grid,
  .review-grid,
  .product-card-grid {
    grid-template-columns: repeat(2, minmax(130px, 1fr));
  }

  .form-grid label:first-child {
    grid-column: span 2;
  }
}

@page {
  size: letter landscape;
  margin: 0;
}

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

  .wizard-grid,
  .review-grid,
  .product-card-grid {
    grid-template-columns: 1fr;
  }

  .form-grid label:first-child {
    grid-column: auto;
  }

  .wizard-head,
  .wizard-actions,
  .product-toolbar,
  .product-card-head,
  .review-products > div {
    align-items: stretch;
    flex-direction: column;
  }

  .header-actions,
  .quick-actions,
  .pdf-actions,
  .finish-options,
  .confirmation-grid,
  .calibration-grid {
    display: grid;
    grid-template-columns: 1fr;
  }
}
