:root {
  color-scheme: light;
  --ink: #20394c;
  --muted: #647783;
  --line: #dce5e8;
  --surface: #ffffff;
  --canvas: #f3f6f7;
  --green: #398e68;
  --green-dark: #287452;
  --green-soft: #e8f4ec;
  --gold: #a56d18;
  --gold-soft: #fff4dc;
  --shadow: 0 8px 26px rgba(27, 55, 68, 0.06);
  font-family: "Segoe UI", Aptos, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.topbar {
  height: 78px;
  padding: 0 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand, .toolbar, .sidebar-heading, .card-heading, .formula-heading, .label-preview-heading {
  display: flex;
  align-items: center;
}

.brand { gap: 10px; }
.brand-logo { display: block; width: 60px; height: 38px; object-fit: contain; }
.brand-logo-secondary { display: block; width: 55px; height: 68px; object-fit: contain; }
.brand-title { margin: 0 0 0 20px; color: var(--green); font-size: 14px; font-weight: 800; line-height: 1.1; letter-spacing: .2px; }

.eyebrow {
  margin: 0 0 4px;
  color: var(--green);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1.15px;
}

h1, h2, h3, h4, p { margin-top: 0; }
h1 { margin: 0; font-size: 17px; letter-spacing: -0.3px; }
h2 { margin: 0; font-size: 17px; }
h3 { margin: 0; font-size: 16px; }
h4 { margin: 0; font-size: 13px; }

.toolbar { gap: 8px; }
.save-state { color: var(--muted); font-size: 11px; margin-right: 3px; }
.save-state.dirty { color: var(--gold); }
.save-state.saved { color: var(--green-dark); }

.button {
  min-height: 34px;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 0 11px;
  font-size: 11px;
  font-weight: 700;
  transition: background .15s ease, transform .15s ease;
}
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .6; cursor: wait; transform: none; }
.button-primary { background: var(--green); color: white; }
.button-primary:hover { background: var(--green-dark); }
.button-muted { background: #edf2f3; color: var(--ink); }
.button-muted:hover, .button-outline:hover { background: var(--green-soft); }
.button-outline { border-color: #b7d6c3; background: white; color: var(--green-dark); }
.button-quiet { padding: 0 8px; background: transparent; color: var(--green-dark); }
.button-icon { min-width: 34px; padding: 0; background: #edf2f3; color: var(--ink); font-size: 20px; line-height: 1; }
.button-icon:disabled { opacity: .4; cursor: default; }
.list-controls { display: grid; gap: 8px; }
.sort-wrap { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 10px; }
.sort-wrap select { height: 32px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--ink); padding: 0 8px; font-size: 11px; }
.product-legend { display: grid; gap: 6px; margin-top: 9px; color: var(--ink); font-size: 10px; font-weight: 700; }
.product-legend-title { margin-bottom: 3px; font-size: 11px; }
.product-legend span { display: flex; align-items: center; gap: 6px; }
.legend-swatch { width: 16px; height: 16px; flex: 0 0 auto; border: 1px solid; border-radius: 4px; }
.legend-swatch-ok { background: #b9e5c7; border-color: #398e68; }
.legend-swatch-difference { background: #ffd1a3; border-color: #c66b16; }
.legend-swatch-pending { background: #fff; border-color: #cbd6da; }

.app-shell {
  min-height: calc(100vh - 78px);
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
}

.sidebar {
  background: #f8fafb;
  border-right: 1px solid var(--line);
  padding: 18px 12px 14px;
  height: calc(100vh - 78px);
  position: sticky;
  top: 78px;
  display: flex;
  flex-direction: column;
}

.sidebar-heading { justify-content: space-between; padding: 0 7px 10px; }
.sidebar-heading h2 span { color: #81919a; font-weight: 500; font-size: 12px; margin-left: 4px; }
.generate-product { width: 100%; margin-bottom: 10px; }

.search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 11px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: white;
  color: #84939a;
}
.search-wrap span { font-size: 17px; }
.search-wrap input { border: 0; outline: 0; width: 100%; font-size: 11px; color: var(--ink); }
.search-wrap input::placeholder { color: #8b9aa1; }

.product-list {
  margin-top: 18px;
  overflow: auto;
  padding-right: 2px;
}

.product-item {
  margin-bottom: 3px;
  border-radius: 8px;
  background: #ffedc2;
  color: var(--ink);
  overflow: hidden;
  box-shadow: inset 3px 0 #c88717;
}
.product-item:hover { filter: brightness(.97); }
.product-item.active { box-shadow: inset 4px 0 #a96d0a; }
.product-item.section-color-ok { background: #d0ecd8; box-shadow: inset 3px 0 #287452; }
.product-item.section-color-ok.active { background: #b9e2c5; box-shadow: inset 4px 0 #1e6545; }
.product-item.section-color-difference { background: #ffe2c4; box-shadow: inset 3px 0 #c66b16; }
.product-item.section-color-difference.active { background: #ffd1a3; box-shadow: inset 4px 0 #a6530b; }
.product-item.section-color-pending { background: #fff; box-shadow: none; }
.product-item.section-color-pending.active,
.product-item.section-color-pending:hover { background: #fff; box-shadow: inset 4px 0 #cbd6da; }
.product-open {
  display: block;
  width: 100%;
  min-height: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 5px 8px 2px;
}
.product-open strong { display: block; font-size: 11px; line-height: 1.3; }
.product-open small { color: var(--muted); font-size: 9px; display: block; margin-top: 2px; }
.product-status { display: block; box-sizing: border-box; width: 100%; margin-top: 4px; padding: 3px 6px; border-radius: 6px; font-size: 9px; line-height: 1.3; font-weight: 800; white-space: normal; }
.product-status.product-note { background: rgba(32, 57, 76, .08); color: var(--ink); font-weight: 600; white-space: pre-line; }
.product-status.status-ok { background: #a9daba; color: #174f36; }
.product-status.status-difference { background: #ffd879; color: #684000; }
.product-status.status-pending { background: #d1dbe0; color: #43535d; }
.product-status-line { display: block; }
.product-status-line.status-line-ok { color: #174f36; }
.product-status-line.status-line-difference { color: #684000; }
.product-status-line.status-line-pending { color: #43535d; }
.product-status-coincidence { display: inline-block; padding: 1px 4px; border-radius: 4px; background: #91cda3; color: #174f36; }
.product-actions { display: flex; justify-content: flex-end; gap: 3px; padding: 0 5px 2px; }
.product-actions button { width: 24px; height: 20px; padding: 0; border: 0; border-radius: 5px; background: transparent; font-size: 14px; line-height: 1; font-weight: 700; }
.product-edit { color: var(--green-dark); }
.product-delete { color: #a34a44; font-size: 20px !important; }
.product-actions button:hover { background: rgba(32, 57, 76, .08); }

.workspace { padding: 20px clamp(16px, 3.2vw, 44px) 38px; min-width: 0; }
.editor {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: start;
  gap: 8px;
  width: min(100%, 980px);
  margin: 0 auto;
}
.page-heading { grid-column: 1 / -1; }
.hidden { display: none !important; }
.empty-state {
  min-height: 55vh;
  display: grid;
  align-content: center;
  justify-items: center;
  text-align: center;
  color: var(--muted);
}
.empty-state h2 { color: var(--ink); margin: 12px 0 7px; }
.empty-state p { font-size: 13px; }
.empty-icon { width: 54px; height: 54px; display: grid; place-items: center; border-radius: 17px; background: var(--green-soft); color: var(--green); font-size: 24px; }

.page-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin: 0 0 19px;
}
.page-heading > div:first-child { flex: 1; min-width: 0; }
.page-actions { display: flex; align-items: center; justify-content: flex-end; gap: 9px; }
.button-danger { border-color: #efc3bf; background: #fff6f5; color: #a33e36; }
.button-danger:hover { background: #fdeceb; }
.page-heading h2 { font-size: 21px; letter-spacing: -.5px; }
.muted { color: var(--muted); font-size: 11px; margin: 5px 0 0; }
.status-badge { border-radius: 999px; padding: 6px 9px; font-size: 9px; font-weight: 800; white-space: nowrap; }
.status-badge.exact { background: var(--green-soft); color: var(--green-dark); }
.status-badge.review { background: var(--gold-soft); color: var(--gold); }
.status-badge.missing { background: #eef1f3; color: #667780; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 13px;
  box-shadow: var(--shadow);
  margin-bottom: 11px;
  padding: 15px 16px;
}
.card-heading { justify-content: space-between; gap: 12px; margin-bottom: 13px; }
.card-heading .eyebrow { margin-bottom: 4px; }
.accordion > summary { cursor: pointer; list-style: none; user-select: none; }
.accordion > summary::-webkit-details-marker { display: none; }
.accordion > summary {
  margin: -15px -16px 13px;
  padding: 15px 16px;
  border-radius: 12px 12px 0 0;
  background: #fff;
}
.accordion.comparison-ok { border-color: #b6d9c2; }
.accordion.comparison-ok > summary { background: #e7f4eb; }
.accordion.comparison-difference { border-color: #f0b77e; }
.accordion.comparison-difference > summary { background: #ffe2c4; }
.accordion.comparison-pending > summary { background: #fff; }
.section-color-control { display: flex; justify-content: flex-end; margin: -2px 0 10px; }
.section-color-control label { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 9px; font-weight: 700; }
.section-color-control select { height: 28px; padding: 0 7px; border: 1px solid var(--line); border-radius: 7px; background: white; color: var(--ink); font-size: 10px; }
.accordion > summary::after {
  content: "+";
  width: 26px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--green-dark);
  font-size: 18px;
  font-weight: 500;
  flex: 0 0 auto;
}
.accordion[open] > summary::after { content: "−"; }
.accordion:not([open]) > summary { margin-bottom: -15px; border-radius: 12px; }
.accordion > summary:focus-visible { outline: 2px solid #6bb38d; outline-offset: 3px; }
.section-divider {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 16px 0 8px;
}
.section-divider .eyebrow { margin-bottom: 4px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.single-field { margin-top: 11px; }
.field { min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.field > span { color: #536873; font-size: 10px; font-weight: 700; }
.field input, .field select, .ingredient-row input {
  width: 100%;
  min-width: 0;
  height: 34px;
  border: 1px solid #d5e0e3;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 9px;
  outline: 0;
  font-size: 11px;
}
.field textarea {
  width: 100%;
  min-width: 0;
  height: 58px;
  min-height: 58px;
  resize: vertical;
  border: 1px solid #d5e0e3;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 8px 9px;
  outline: 0;
  font: inherit;
  font-size: 11px;
}
.field textarea:focus { border-color: #6bb38d; box-shadow: 0 0 0 3px rgba(57, 142, 104, .12); }
.notes-field { margin-top: 9px; width: 100%; max-width: none; }
#association-badge { display: none; }
.field input:focus, .field select:focus, .ingredient-row input:focus { border-color: #6bb38d; box-shadow: 0 0 0 3px rgba(57, 142, 104, .12); }
.field-wide { grid-column: 1 / -1; }

.ingredient-grid { display: grid; grid-template-columns: minmax(0, 3.2fr) 78px 32px; gap: 7px; align-items: center; }
.table-head {
  padding: 7px 9px;
  background: var(--ink);
  color: white;
  border-radius: 7px 7px 0 0;
  font-size: 9px;
  font-weight: 800;
}
.item-list { border: 1px solid var(--line); border-top: 0; border-radius: 0 0 8px 8px; overflow: hidden; }
.ingredient-row { display: grid; grid-template-columns: minmax(0, 3.2fr) 78px 32px; gap: 7px; padding: 5px 8px; border-bottom: 1px solid #e8edef; align-items: center; }
.ingredient-row:last-child { border-bottom: 0; }
.ingredient-row:nth-child(even) { background: #f7faf8; }
.ingredient-row input { height: 30px; }
.remove-item { width: 30px; height: 30px; border: 0; border-radius: 7px; background: transparent; color: #839199; font-size: 17px; }
.remove-item:hover { background: #fdeceb; color: #b3463e; }
.empty-items { color: var(--muted); padding: 10px; font-size: 10px; }

.formula-heading { justify-content: space-between; gap: 7px; margin: 16px 0 8px; }
.formula-heading h4 { color: #415864; }
.formula-heading .button { min-height: 34px; font-size: 11px; }
.formula-heading h4 { margin-right: auto; }
.source-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.source-fields { margin-top: 10px; }
.rnpa-source { margin-top: 11px; }
.source-row { min-width: 0; padding: 9px; border: 1px solid var(--line); border-radius: 8px; display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; gap: 8px; align-items: center; }
.source-icon { width: 28px; height: 30px; border-radius: 7px; display: grid; place-items: center; background: #eaf3ed; color: var(--green-dark); font-size: 8px; font-weight: 900; }
.source-icon-spec { background: #eef0fa; color: #6269a7; }
.source-row strong, .source-row small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-row strong { font-size: 10px; }
.source-row small { color: var(--muted); font-size: 8px; margin-top: 2px; }
.text-link { color: var(--green-dark); font-weight: 800; font-size: 9px; text-decoration: none; }
.text-link:hover { text-decoration: underline; }
.attachment-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin-top: 9px; }
.attachment-tools .button { min-height: 31px; font-size: 10px; }
.attachment-status { flex-basis: 100%; margin: 0; color: var(--muted); font-size: 9px; line-height: 1.45; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.label-preview { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.label-preview-heading { justify-content: space-between; margin-bottom: 8px; }
.label-preview-heading span { color: var(--muted); font-size: 9px; }
.label-image-frame { position: relative; width: 100%; max-width: 500px; aspect-ratio: 0.71; overflow: hidden; border: 1px solid var(--line); border-radius: 7px; background: #f7f8f8; }
.label-image-frame img { display: block; width: 100%; height: 100%; object-fit: contain; object-position: center; }
.image-zoom-trigger { position: absolute; inset: 0; width: 100%; height: 100%; padding: 0; border: 0; border-radius: inherit; background: transparent; cursor: zoom-in; }
.magnifier-icon { position: absolute; top: 9px; right: 47px; width: 30px; height: 30px; padding: 5px; border-radius: 50%; background: rgba(32, 57, 76, .9); fill: none; stroke: white; stroke-linecap: round; stroke-width: 2; opacity: 0; transition: opacity .15s ease; }
.label-image-frame:hover .magnifier-icon, .image-zoom-trigger:focus-visible .magnifier-icon { opacity: 1; }
.image-delete-trigger { position: absolute; top: 9px; right: 9px; z-index: 2; width: 30px; height: 30px; padding: 0; border: 0; border-radius: 50%; background: #b3463e; color: #fff; font-size: 22px; line-height: 1; cursor: pointer; }
.image-delete-trigger:hover { background: #8f302a; }
.image-zoom-dialog { position: relative; max-width: 96vw; max-height: 96vh; padding: 48px 16px 16px; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: white; }
.image-zoom-dialog::backdrop { background: rgba(15, 29, 39, .78); }
.image-zoom-view { width: min(92vw, 1200px); height: min(82vh, 900px); overflow: auto; }
.image-zoom-view img { display: block; max-width: none; max-height: none; object-fit: contain; }
.image-zoom-controls { position: absolute; top: 8px; right: 52px; z-index: 1; display: flex; align-items: center; gap: 5px; }
.image-zoom-controls button { min-width: 32px; height: 32px; padding: 0 8px; border: 0; border-radius: 7px; background: var(--ink); color: white; font-size: 18px; line-height: 1; cursor: pointer; }
.image-zoom-controls button:nth-child(2) { min-width: 52px; font-size: 11px; }
.image-zoom-controls button:hover, .image-zoom-controls button:focus-visible { background: var(--green-dark); }
.image-zoom-controls #image-lens-toggle { display: grid; width: 32px; min-width: 32px; place-items: center; padding: 5px; }
.lens-icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-width: 2; }
.image-zoom-controls #image-lens-toggle[aria-pressed="true"] { background: var(--green-dark); }
.image-lens { position: absolute; z-index: 2; pointer-events: none; border: 3px solid white; border-radius: 50%; box-shadow: 0 2px 12px rgba(0,0,0,.45); background-repeat: no-repeat; cursor: none; }
.image-zoom-view { position: relative; }
.image-zoom-close { position: absolute; top: 8px; right: 8px; z-index: 1; width: 32px; height: 32px; border: 0; border-radius: 50%; background: var(--ink); color: white; font-size: 22px; cursor: pointer; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 10;
  transform: translate(-50%, 20px);
  opacity: 0;
  padding: 9px 14px;
  background: var(--ink);
  color: white;
  border-radius: 10px;
  font-size: 11px;
  pointer-events: none;
  transition: all .2s ease;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 230px minmax(0, 1fr); }
  .workspace { padding: 18px 14px 32px; }
  .ingredient-grid, .ingredient-row { grid-template-columns: minmax(0, 1fr) 130px 30px; }
  .toolbar { gap: 6px; }
  .save-state { display: none; }
  .editor { grid-template-columns: 1fr; gap: 0; }
  .page-heading { grid-column: 1; }
}
@media (max-width: 680px) {
  .topbar { height: auto; min-height: 72px; padding: 11px 14px; align-items: flex-start; }
  .brand-logo { width: 54px; height: 36px; }
  .brand-logo-secondary { width: 42px; height: 52px; }
  .brand-title { margin-left: 8px; font-size: 10px; }
  h1 { font-size: 16px; }
  .toolbar { flex-direction: row; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
  .toolbar .button { min-height: 34px; }
  .button { min-height: 34px; }
  .app-shell { display: block; }
  .sidebar { height: auto; max-height: 38vh; position: relative; top: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .product-list { max-height: 22vh; }
  .workspace { padding: 18px 11px 30px; }
  .card { padding: 14px 12px; }
  .accordion > summary { margin: -14px -12px 12px; padding: 14px 12px; }
  .accordion:not([open]) > summary { margin-bottom: -14px; }
  .field-grid, .source-grid { grid-template-columns: 1fr; }
  .ingredient-grid, .ingredient-row { grid-template-columns: minmax(0, 1fr) 105px 30px; gap: 5px; }
  .page-heading h2 { font-size: 18px; }
  .status-badge { font-size: 8px; }
}
