:root {
  color-scheme: light;
  --paper: #fbfaf7;
  --paper-deep: #f1efe7;
  --ink: #14231f;
  --muted: #65726d;
  --line: #d8ddd4;
  --field: #ffffff;
  --teal: #0f766e;
  --teal-dark: #0b4f4a;
  --clay: #b45309;
  --clay-soft: #fff1dd;
  --gold: #e2a21a;
  --red: #b42318;
  --green-soft: #e8f4ef;
  --blue-soft: #eaf1fb;
  --shadow: 0 24px 70px rgba(32, 42, 37, 0.14);
  --radius: 8px;
  --font: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  letter-spacing: 0;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.08), transparent 34%),
    linear-gradient(225deg, rgba(226, 162, 26, 0.12), transparent 28%),
    var(--paper);
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.28);
  outline-offset: 2px;
}

.icon-sprite {
  position: absolute;
}

.icon {
  display: inline-block;
  width: 1.05em;
  height: 1.05em;
  flex: 0 0 auto;
  vertical-align: -0.16em;
}

.topbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding: 18px 24px;
  border-bottom: 1px solid rgba(20, 35, 31, 0.1);
  background: rgba(251, 250, 247, 0.88);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(135deg, var(--teal), #263b35);
  box-shadow: 0 12px 24px rgba(15, 118, 110, 0.22);
}

.topbar h1,
.topbar p,
.panel-heading h2,
.preview-heading h2,
.source-panel h2 {
  margin: 0;
}

.topbar h1 {
  font-size: 1.05rem;
  line-height: 1.2;
  font-weight: 800;
}

.topbar p {
  color: var(--muted);
  font-size: 0.88rem;
}

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

.offline-pill,
.preview-meter {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid rgba(15, 118, 110, 0.18);
  border-radius: 999px;
  color: var(--teal-dark);
  background: var(--green-soft);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 430px) minmax(0, 1fr);
  gap: 22px;
  align-items: start;
  max-width: 1480px;
  margin: 0 auto;
  padding: 22px;
}

.control-panel,
.preview-shell {
  min-width: 0;
}

.control-panel {
  border: 1px solid rgba(20, 35, 31, 0.1);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 18px 45px rgba(32, 42, 37, 0.08);
  overflow: hidden;
}

.panel-heading,
.preview-heading,
.source-panel {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
}

.panel-heading {
  padding: 18px 18px 12px;
  border-bottom: 1px solid rgba(20, 35, 31, 0.08);
}

.eyebrow {
  display: block;
  margin-bottom: 3px;
  color: var(--clay);
  font-size: 0.73rem;
  line-height: 1.2;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.panel-heading h2,
.preview-heading h2,
.source-panel h2 {
  font-size: 1rem;
  line-height: 1.25;
}

form {
  display: grid;
  gap: 0;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 18px;
  border: 0;
  border-bottom: 1px solid rgba(20, 35, 31, 0.08);
}

fieldset:last-child {
  border-bottom: 0;
}

legend {
  float: left;
  width: 100%;
  margin: 0 0 12px;
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 800;
}

legend + * {
  clear: both;
}

label {
  display: block;
  margin: 10px 0 6px;
  color: #263b35;
  font-size: 0.82rem;
  font-weight: 750;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px 10px;
  color: var(--ink);
  background: var(--field);
  box-shadow: inset 0 1px 0 rgba(20, 35, 31, 0.03);
}

select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--teal-dark) 50%),
    linear-gradient(135deg, var(--teal-dark) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 18px,
    calc(100% - 12px) 18px;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

.form-grid {
  display: grid;
  gap: 10px;
}

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

.weight-grid {
  grid-template-columns: minmax(82px, 1fr) 90px minmax(132px, 1fr) minmax(96px, 1fr);
  align-items: end;
}

.statement-box {
  margin-top: 12px;
  border: 1px solid rgba(15, 118, 110, 0.16);
  border-radius: 7px;
  padding: 12px;
  background: linear-gradient(180deg, var(--green-soft), #fff);
}

.statement-box strong {
  display: block;
  margin-bottom: 4px;
}

.statement-box p {
  margin: 0;
}

.statement-box .small-note,
.small-note {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.8rem;
}

.statement-box.fallback {
  border-color: rgba(180, 83, 9, 0.28);
  background: linear-gradient(180deg, var(--clay-soft), #fff);
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.82rem;
}

.ingredient-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--field);
}

.ingredient-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.ingredient-table th,
.ingredient-table td {
  padding: 8px;
  border-bottom: 1px solid rgba(20, 35, 31, 0.07);
  text-align: left;
  vertical-align: middle;
}

.ingredient-table tr:last-child td {
  border-bottom: 0;
}

.ingredient-table th {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.ingredient-table th:nth-child(2),
.ingredient-table td:nth-child(2) {
  width: 96px;
}

.ingredient-table th:nth-child(3),
.ingredient-table td:nth-child(3) {
  width: 66px;
  text-align: center;
}

.ingredient-table input {
  min-height: 36px;
  padding: 7px 8px;
}

.primary-button,
.secondary-button,
.ghost-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border-radius: 7px;
  border: 1px solid transparent;
  padding: 9px 13px;
  font-weight: 800;
  white-space: nowrap;
}

.primary-button {
  color: #fff;
  background: var(--teal);
  border-color: var(--teal);
}

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

.secondary-button {
  margin-top: 12px;
  color: var(--teal-dark);
  background: #fff;
  border-color: rgba(15, 118, 110, 0.28);
}

.secondary-button:hover,
.ghost-button:hover,
.icon-button:hover {
  background: var(--green-soft);
}

.ghost-button {
  color: var(--teal-dark);
  background: transparent;
  border-color: rgba(15, 118, 110, 0.16);
}

.ghost-button.compact {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 0.82rem;
}

.icon-button {
  width: 40px;
  min-width: 40px;
  padding: 0;
  color: var(--teal-dark);
  background: #fff;
  border-color: var(--line);
}

.remove-button {
  width: 34px;
  min-width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  color: var(--red);
  background: #fff;
  border: 1px solid rgba(180, 35, 24, 0.22);
}

.remove-button:hover {
  background: #fff0ee;
}

.test-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

#testSummary {
  min-height: 30px;
  padding: 5px 9px;
  border-radius: 999px;
  color: var(--muted);
  background: var(--paper-deep);
  font-weight: 800;
}

#testSummary.pass {
  color: #166534;
  background: #dcfce7;
}

#testSummary.fail {
  color: #991b1b;
  background: #fee2e2;
}

.test-results {
  display: grid;
  gap: 6px;
  margin-top: 12px;
}

.test-result {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding: 8px 10px;
  border-radius: 7px;
  background: var(--paper-deep);
  font-size: 0.82rem;
}

.test-result .status {
  font-family: var(--mono);
  font-weight: 900;
}

.test-result.pass .status {
  color: #166534;
}

.test-result.fail .status {
  color: #991b1b;
}

.preview-panel {
  min-width: 0;
}

.preview-shell {
  display: grid;
  gap: 16px;
}

.preview-heading {
  padding: 8px 4px 0;
}

.label-sheet {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 122px);
  padding: 28px;
  border: 1px solid rgba(20, 35, 31, 0.1);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0.3)),
    repeating-linear-gradient(0deg, rgba(20, 35, 31, 0.035), rgba(20, 35, 31, 0.035) 1px, transparent 1px, transparent 18px),
    var(--paper-deep);
  box-shadow: var(--shadow);
}

.label-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(100%, 5.1in);
  min-height: 6.8in;
  padding: 0.28in;
  overflow: hidden;
  border: 1px solid #27312d;
  color: #131815;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.94), rgba(255,255,255,0.98)),
    radial-gradient(circle at 90% 10%, rgba(226,162,26,0.12), transparent 32%),
    #fff;
  box-shadow: 0 18px 48px rgba(20, 35, 31, 0.24);
}

.label-card.format-3x5 {
  width: min(100%, 4.2in);
  min-height: 5.25in;
  padding: 0.22in;
}

.label-card.format-jar {
  width: min(100%, 7.2in);
  min-height: 3.15in;
  padding: 0.18in 0.24in;
}

.label-card.format-jar h2 {
  font-size: 1.35rem;
}

.label-accent {
  position: absolute;
  inset: 0 auto 0 0;
  width: 8px;
  background: linear-gradient(180deg, var(--teal), var(--gold), var(--clay));
}

.label-topline {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-left: 6px;
  color: #4c5a55;
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.required-statement {
  margin-left: 6px;
  padding: 12px 14px;
  border: 2px solid #17241f;
  background: #f8faf7;
  font-size: 0.96rem;
  line-height: 1.28;
  font-weight: 900;
  text-transform: uppercase;
}

.label-card h2 {
  margin: 4px 0 0 6px;
  font-size: 1.75rem;
  line-height: 1.08;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.net-weight {
  margin-left: 6px;
  font-size: 1rem;
  font-weight: 850;
}

.label-section,
.contains-block,
.producer-block,
.verify-note,
.source-note {
  margin-left: 6px;
}

.label-section {
  padding-top: 8px;
  border-top: 1px solid #d8ddd4;
}

.label-section h3,
.producer-block h3 {
  margin: 0 0 4px;
  font-size: 0.78rem;
  line-height: 1.1;
  font-weight: 900;
  text-transform: uppercase;
}

.label-section p,
.producer-block p,
.batch-block p {
  margin: 0;
}

#labelIngredients {
  overflow-wrap: anywhere;
}

.ingredient-hit {
  display: inline;
  padding: 0 2px;
  border-radius: 3px;
  background: #fff1a8;
  box-shadow: inset 0 -2px 0 rgba(226, 162, 26, 0.38);
  font-weight: 850;
}

.contains-block {
  padding: 10px 12px;
  border-radius: 7px;
  border: 1px solid rgba(180, 83, 9, 0.32);
  background: var(--clay-soft);
  font-weight: 900;
  overflow-wrap: anywhere;
}

.contains-block.clean {
  border-color: rgba(15, 118, 110, 0.2);
  background: var(--green-soft);
  color: var(--teal-dark);
}

.allergen-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.allergen-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 7px;
  border-radius: 999px;
  color: #5f3510;
  background: #ffe8bd;
  font-size: 0.75rem;
  font-weight: 850;
}

.producer-block {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: end;
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid #d8ddd4;
}

.batch-block {
  text-align: right;
  color: #263b35;
  font-size: 0.86rem;
  font-weight: 750;
}

.verify-note {
  padding: 9px 10px;
  border-left: 4px solid var(--clay);
  background: #fff7ed;
  color: #5f3510;
  font-size: 0.82rem;
  font-weight: 750;
}

.source-note {
  color: #5f6763;
  font-size: 0.72rem;
  overflow-wrap: anywhere;
}

.source-panel {
  align-items: start;
  padding: 18px;
  border: 1px solid rgba(20, 35, 31, 0.1);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.78);
}

.source-panel p {
  max-width: 54ch;
  margin: 0;
  color: var(--muted);
}

.source-list {
  display: grid;
  gap: 8px;
  width: 100%;
  max-width: 520px;
}

.source-item {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 10px;
  padding: 9px;
  border: 1px solid rgba(20, 35, 31, 0.08);
  border-radius: 7px;
  background: #fff;
}

.source-code {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 7px;
  color: #fff;
  background: var(--teal-dark);
  font-weight: 900;
}

.source-item strong {
  display: block;
  font-size: 0.84rem;
}

.source-item a,
.source-item span {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  overflow-wrap: anywhere;
}

.source-item a {
  color: var(--teal-dark);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  max-width: min(340px, calc(100vw - 36px));
  padding: 10px 12px;
  border-radius: 7px;
  color: #fff;
  background: #263b35;
  box-shadow: 0 14px 34px rgba(20, 35, 31, 0.22);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

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

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

  .label-sheet {
    min-height: auto;
  }
}

@media (max-width: 720px) {
  .topbar {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .top-actions {
    grid-column: 1 / -1;
    justify-content: stretch;
  }

  .top-actions .primary-button {
    flex: 1;
  }

  .offline-pill {
    display: none;
  }

  .workspace {
    padding: 12px;
  }

  .form-grid.two,
  .weight-grid,
  .producer-block,
  .source-panel {
    grid-template-columns: 1fr;
  }

  .panel-heading,
  .preview-heading {
    align-items: start;
    flex-direction: column;
  }

  .source-panel {
    display: grid;
  }

  .label-sheet {
    padding: 12px;
  }

  .label-card,
  .label-card.format-3x5,
  .label-card.format-jar {
    width: 100%;
    min-height: 0;
    padding: 0.2in;
  }

  .label-card h2 {
    font-size: 1.35rem;
  }

  .batch-block {
    text-align: left;
  }
}

@media (max-width: 460px) {
  .ingredient-table th:nth-child(2),
  .ingredient-table td:nth-child(2) {
    width: 82px;
  }

  .ingredient-table th:nth-child(3),
  .ingredient-table td:nth-child(3) {
    width: 52px;
  }

  .ingredient-table th,
  .ingredient-table td {
    padding: 6px;
  }

  .primary-button,
  .secondary-button,
  .ghost-button {
    white-space: normal;
  }

  .required-statement {
    font-size: 0.86rem;
  }
}
