/* Finished-goods production: touch-first, deliberately scoped to the two forms. */
.fg-touch-form {
  width: min(100%, 1180px);
  margin-inline: auto;
  min-width: 0;
}

.fg-touch-form *,
.fg-touch-picker-modal * { box-sizing: border-box; }

.fg-touch-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.8fr) minmax(260px, 1fr);
  align-items: start;
  gap: 1rem;
}

.fg-touch-selection,
.fg-touch-details { min-width: 0; }

.fg-touch-section {
  min-width: 0;
  margin-block: .55rem;
}

.fg-touch-quick {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  min-width: 0;
}

.fg-touch-quick > button,
.fg-touch-option-grid > button,
#sp-cat-chips > button,
#sp-ser-chips > button,
#sp-flavor-grid > button {
  min-height: 48px;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  touch-action: manipulation;
  border-radius: 10px;
  border: 1px solid var(--border-input, #CBD5E1);
  background: #fff;
  color: var(--ink2, #334155);
}

.fg-touch-category,
.fg-touch-product {
  width: 100%;
  min-width: 0;
  border-radius: 10px !important;
  border: 1px solid var(--border-input, #CBD5E1) !important;
  background: #fff !important;
  padding: .65rem .75rem !important;
  text-align: left;
}

.fg-touch-product .fg-touch-name,
.fg-touch-product .fg-touch-spec,
.fg-touch-product .fg-touch-code { display: block; }

.fg-touch-product .fg-touch-name { font-weight: 700; }
.fg-touch-product .fg-touch-spec { color: var(--ink2, #334155); }
.fg-touch-product .fg-touch-code { color: var(--muted, #64748B); }
.fg-touch-product:active,
.fg-touch-category:active { border-color: var(--p, #4F46E5) !important; background: #EEF2FF !important; }

#sp-cat-chips > button,
#pp-chips > button {
  min-height: 42px;
  padding: .4rem .7rem !important;
  font-size: .84rem !important;
}

.fg-touch-option-grid,
#sp-flavor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr));
  gap: .55rem;
  min-width: 0;
}

.fg-touch-option-grid > button,
#sp-flavor-grid > button {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  min-height: 76px;
  padding: .7rem .8rem;
  text-align: left;
  line-height: 1.3;
  overflow-wrap: anywhere;
  white-space: normal;
}

.fg-touch-search,
.fg-touch-numeric {
  width: 100%;
  min-height: 48px;
  font-size: 16px;
}

.fg-touch-actionbar {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
}

.fg-touch-actionbar { min-height: 48px; justify-content: center; }

#sp-cat-chips,
#sp-ser-chips {
  display: flex !important;
  flex-wrap: wrap !important;
  max-width: 100%;
  min-width: 0;
  overflow-x: clip !important;
  overflow-y: visible !important;
  white-space: normal !important;
}

#sp-cat-chips > button,
#sp-ser-chips > button,
#pp-chips > button {
  flex: 0 1 auto !important;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  white-space: normal !important;
  overflow-wrap: anywhere;
}

#sp-flavor-grid .spf span {
  max-width: 100%;
  overflow-wrap: anywhere;
  white-space: normal;
}

@media (min-width: 600px) {
  .fg-touch-option-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (min-width: 900px) {
  .fg-touch-option-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* Picker modal uses the full desktop canvas, but remains a compact sheet on phones. */
.modal:has(.fg-touch-picker-modal) {
  width: min(96vw, 980px);
  max-width: 980px;
}

.fg-touch-picker-modal .fg-touch-option-grid.cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.fg-touch-picker-modal #pp-list > div:not(.fg-touch-product) {
  grid-column: 1 / -1;
}

.fg-touch-name,
#sp-flavor-grid .spf span:first-child {
  font-size: 1rem !important;
  line-height: 1.3;
  overflow-wrap: anywhere;
  white-space: normal;
}

.fg-touch-spec,
#sp-flavor-grid .spf span:nth-child(2) {
  font-size: .875rem !important;
  line-height: 1.3;
  overflow-wrap: anywhere;
  white-space: normal;
}

.fg-touch-code { font-size: .75rem; font-style: normal; }

@media (min-width: 700px) {
  .fg-touch-picker-modal .fg-touch-option-grid.cols-2 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 1100px) {
  .fg-touch-picker-modal .fg-touch-option-grid.cols-2 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 480px) {
  .fg-touch-option-grid,
  #sp-flavor-grid { gap: .45rem; }
  .fg-touch-option-grid > button,
  #sp-flavor-grid > button { min-height: 80px; padding: .65rem; }
}

@media (max-width: 900px) {
  .fg-touch-layout { grid-template-columns: minmax(0, 1fr); }
}

/* SJA production: choose a product, then enter quantity directly below its summary. */
.fg-sja-entry { width: 100%; max-width: none; }
.fg-sja-entry .fg-touch-layout { grid-template-columns: minmax(0, 1fr); }
.fg-selected-heading { display: flex; align-items: center; gap: .7rem; margin-bottom: .6rem; }
.fg-sja-entry [hidden] { display: none !important; }
.fg-entry-heading { display: flex; align-items: center; gap: .6rem; margin-bottom: .85rem; }
.fg-entry-heading h3 { margin: 0; font-size: 1.05rem; }
.fg-step { display: grid; place-items: center; width: 28px; height: 28px; flex: 0 0 28px; border-radius: 50%; background: #EEF2FF; color: var(--p); font-weight: 800; }
.fg-entry-search { margin-left: auto; min-height: 44px; border: 1px solid var(--border-input); border-radius: 8px; padding: .4rem .65rem; background: white; color: var(--ink2); font: inherit; cursor: pointer; }
.fg-entry-modes { display: flex; gap: .4rem; padding: .3rem; margin-bottom: .8rem; border-radius: 10px; background: #F1F5F9; }
.fg-entry-modes button { flex: 1; min-width: 0; min-height: 44px; padding: .5rem; border: none; border-radius: 7px; background: transparent; color: var(--ink2); font: inherit; font-weight: 700; cursor: pointer; }
.fg-entry-modes button[aria-pressed=true] { background: white; color: var(--p); box-shadow: 0 1px 4px #0001; }
.fg-entry-help { display: block; margin: 0 0 .65rem; color: var(--muted); font-size: .85rem; line-height: 1.45; }
.fg-entry-subheading { margin: 1rem 0 .5rem; font-size: .85rem; font-weight: 800; color: var(--ink2); }
.fg-sja-entry #sp-cat-chips, .fg-sja-entry #sp-ser-chips { gap: .45rem; }
.fg-sja-entry #sp-cat-chips button, .fg-sja-entry #sp-ser-chips button { border-radius: 8px; min-height: 44px; }
.fg-sja-entry .fg-touch-option-grid, .fg-sja-entry #sp-flavor-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.fg-sja-entry .spf { padding: .7rem .8rem; min-height: 92px; border-radius: 10px; }
.fg-sja-entry .spf-act { border: 2px solid var(--p) !important; background: #EEF2FF !important; }
.fg-sja-entry .fg-touch-details { width: 100%; max-width: 900px; padding: 1rem; border: 1px solid #DCE2EB; border-radius: 12px; background: #FAFBFD; }
.fg-entry-selected { margin-bottom: 1rem; min-height: 64px; font-size: .9rem; color: var(--ink2); }
.fg-sja-entry #sp-pinfo > div { margin-top: 0 !important; }
.fg-sja-entry .fg-touch-details .fr { flex-wrap: wrap; }
.fg-sja-entry .fg-touch-details .fr .ig { min-width: 110px; }
.fg-sja-entry .fg-entry-additional { margin-top: 1rem; padding-top: .15rem; border-top: 1px solid #E2E8F0; }
.fg-sja-entry .fg-touch-actionbar { margin-top: .75rem; }
@media (min-width: 1024px) {
  .fg-sja-entry .fg-touch-selection { padding-right: .25rem; }
  .fg-sja-entry .fg-touch-option-grid, .fg-sja-entry #sp-flavor-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 185px), 1fr)); }
}
@media (max-width: 1023px) {
  .fg-sja-entry .fg-touch-layout { grid-template-columns: minmax(0, 1fr); }
}

/* Align choices into lists so staff can scan down instead of searching a cloud of pills. */
.fg-catalog-layout, .fg-product-column, .fg-category-column { min-width: 0; }
.fg-sja-entry #sp-cat-chips, .fg-sja-entry #sp-ser-chips {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
  overflow: visible !important;
  border: 1px solid #DCE2EB;
  border-radius: 4px;
}
.fg-sja-entry #sp-cat-chips > button, .fg-sja-entry #sp-ser-chips > button {
  display: flex; justify-content: space-between; align-items: center; gap: .6rem;
  width: 100%; min-height: 46px; margin: 0; border: 0; border-bottom: 1px solid #E2E8F0;
  border-radius: 0; padding: .6rem .7rem !important; text-align: left;
  font: inherit; font-size: .9rem !important; font-weight: 600; background: white; cursor: pointer;
}
.fg-sja-entry .fg-list-choice[aria-pressed=true] { background: #EEF2FF !important; color: #3730A3; box-shadow: inset 3px 0 #4F46E5; }
.fg-choice-mark { flex-shrink: 0; font-weight: 800; }
.fg-sja-entry .fg-list-choice:focus-visible { outline: 2px solid #4F46E5; outline-offset: -3px; }
.fg-sja-entry .fg-step { border-radius: 4px; }
.fg-touch-picker-modal #pp-chips > button { border-radius: 4px !important; text-align: left; }
@media (min-width: 1200px) {
  .fg-catalog-layout { display: grid; grid-template-columns: 155px minmax(0, 1fr); gap: 1rem; align-items: start; }
  .fg-sja-entry #sp-cat-chips { grid-template-columns: minmax(0, 1fr); }
  .fg-sja-entry #sp-ser-chips { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }
  .fg-sja-entry #sp-flavor-grid, .fg-sja-entry #sp-quick-grid { grid-template-columns: minmax(0, 1fr); gap: .4rem; }
  .fg-sja-entry #sp-flavor-grid > button, .fg-sja-entry #sp-quick-grid > button {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .2rem .75rem;
    min-height: 64px; border-radius: 4px; padding: .6rem .75rem; align-content: center;
  }
  .fg-sja-entry .spf .fg-touch-name { grid-column: 1; grid-row: 1 / span 2; }
  .fg-sja-entry .spf .fg-touch-spec { grid-column: 2; grid-row: 1; text-align: right; }
  .fg-sja-entry .spf .fg-touch-code { grid-column: 2; grid-row: 2; text-align: right; }
}

/* Compact product tiles (owner: fit the most products on one phone screen).
   3 columns at 393px, more on wider screens; content top-aligned, tight line-height; name 14px (3 lines max), packaging and code
   on small grey lines; tap target stays >= 44px. Desktop list mode (>=1200px) is untouched. */
@media (max-width: 1199px) {
  .fg-touch-form .fg-touch-option-grid,
  .fg-touch-form #sp-flavor-grid,
  .fg-touch-picker-modal .fg-touch-option-grid,
  .fg-touch-picker-modal .fg-touch-option-grid.cols-2,
  .fg-sja-entry .fg-touch-option-grid,
  .fg-sja-entry #sp-flavor-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)) !important;
    gap: 5px !important;
  }
  .fg-touch-picker-modal #pp-list { margin: 0 !important; }
  :is(#sp-flavor-grid, .fg-touch-form .fg-touch-option-grid, .fg-touch-picker-modal .fg-touch-option-grid) > button:is(.spf, .fg-touch-product) {
    display: grid !important;
    grid-template-columns: 1fr !important;
    align-content: start !important;
    gap: 0 !important;
    min-height: 44px !important;
    padding: 4px 6px !important;
    border-radius: 8px !important;
    line-height: 1.15 !important;
    text-align: left;
  }
  :is(#sp-flavor-grid, .fg-touch-form .fg-touch-option-grid, .fg-touch-picker-modal .fg-touch-option-grid) > button:is(.spf, .fg-touch-product) .fg-touch-name {
    display: -webkit-box !important;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
    grid-column: 1 !important; grid-row: auto !important;
    font-size: .875rem !important;
    line-height: 1.15 !important;
    font-weight: 700 !important;
    margin: 0 !important;
  }
  :is(#sp-flavor-grid, .fg-touch-form .fg-touch-option-grid, .fg-touch-picker-modal .fg-touch-option-grid) > button:is(.spf, .fg-touch-product) .fg-touch-spec,
  :is(#sp-flavor-grid, .fg-touch-form .fg-touch-option-grid, .fg-touch-picker-modal .fg-touch-option-grid) > button:is(.spf, .fg-touch-product) .fg-touch-code {
    display: block !important;
    grid-column: 1 !important; grid-row: auto !important;
    text-align: left !important;
    margin: 0 !important;
    font-size: .6875rem !important;
    line-height: 1.15 !important;
    color: var(--muted, #64748B) !important;
  }
  :is(#sp-flavor-grid, .fg-touch-form .fg-touch-option-grid, .fg-touch-picker-modal .fg-touch-option-grid) > button:is(.spf, .fg-touch-product) .fg-touch-code { white-space: nowrap !important; }
  .fg-sja-entry #sp-flavor-grid > button.spf.spf-act {
    border: 1px solid var(--p, #4F46E5) !important;
    box-shadow: inset 0 0 0 1.5px var(--p, #4F46E5);
    background: #EEF2FF !important;
  }
  /* tighter chrome above the grid so more rows land on the first screen */
  .fg-sja-entry .fg-entry-heading { margin-bottom: .4rem; }
  .fg-sja-entry .fg-entry-modes { margin-bottom: .45rem; padding: .2rem; }
  .fg-sja-entry .fg-entry-modes button { min-height: 40px; padding: .3rem; }
  .fg-sja-entry .fg-entry-subheading { margin: .55rem 0 .3rem; }
  .fg-sja-entry .fg-entry-help { margin-bottom: .4rem; }
  .fg-sja-entry #sp-cat-chips > button, .fg-sja-entry #sp-ser-chips > button { min-height: 44px; padding: .3rem .6rem !important; }
}
