/**
 * Shipley Farms piece-or-pound purchase module.
 *
 * Colour: --sf-red is #A82024, the red the live site actually renders, which clears WCAG
 * AAA against white. The brighter #E03C31 from older brand material fails AA on white at
 * body sizes and is deliberately not used for text or for anything a shopper must read.
 *
 * Accessibility rules this file has to hold to, because low-vision shoppers are a primary
 * audience on this store:
 *   - selected state is never colour alone (WCAG 1.4.1). Presets and mode buttons carry a
 *     border weight change and a check glyph as well as fill.
 *   - every interactive control has a visible :focus-visible ring that is not the same
 *     treatment as hover.
 *   - touch targets are at least 44px on the short edge (WCAG 2.5.8).
 */

.sf-purchase {
  --sf-red: #A82024;
  --sf-red-dark: #8C191D;
  --sf-ink: #1F1B18;
  --sf-muted: #5C5550;
  --sf-line: #DDD5C9;
  --sf-cream: #FDFAF3;
  --sf-radius: 8px;

  color: var(--sf-ink);
  margin-top: 0.5rem;
}

/* ---------- price header ---------- */

.sf-cost-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--sf-line);
}

.sf-cost-main {
  font-size: 2.5rem;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.sf-cost-uom {
  font-size: 1.5rem;
  font-weight: 600;
}

.sf-cost-aside {
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--sf-muted);
}

.sf-cost-aside strong {
  color: var(--sf-ink);
  font-weight: 600;
  /* Keep a money range intact. Without this the line broke mid-value on mobile, giving
     "Estimated per filet: $29.75 -" on one line and "$44.62" on the next. The label may
     wrap above it; the range itself may not be split. */
  white-space: nowrap;
}

.sf-avail {
  margin: 0.75rem 0 0;
  font-size: 0.9375rem;
}

.sf-avail-in { color: #1B6E3C; font-weight: 600; }
.sf-avail-out,
.sf-avail-back { color: var(--sf-red); font-weight: 600; }

/* ---------- purchase box ---------- */

.sf-purchase-box {
  margin-top: 1.25rem;
  padding: 1.25rem;
  background: var(--sf-cream);
  border: 1px solid var(--sf-line);
  border-radius: var(--sf-radius);
}

.sf-field {
  border: 0;
  padding: 0;
  margin: 0 0 1.25rem;
}

.sf-legend {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.625rem;
  padding: 0;
  float: none;
  width: auto;
}

.sf-hidden { display: none !important; }

/* Scoped under .sf-purchase deliberately, to WIN a specificity fight.
 *
 * Frappe's website.bundle.css carries:
 *     input[type="radio"] { position: relative; height: var(--checkbox-size); ... }
 *
 * That selector is (0,1,1) and a bare `.sf-visually-hidden` is (0,1,0), so the framework
 * won: the radios kept position:relative at 14x14, stayed in the grid flow, took up two
 * of the four cells in .sf-mode-group, and pushed both mode buttons into a single column.
 * `clip` was inert throughout because clip only applies to absolutely positioned boxes.
 *
 * `.sf-purchase .sf-visually-hidden` is (0,2,0), which beats (0,1,1) on class count. The
 * extra `input` qualifier on the second rule makes the radio case explicit rather than
 * relying on the reader to work the arithmetic out.
 */
.sf-purchase .sf-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
  /* -webkit- prefix first: Safari below 15.4 ignores unprefixed `appearance`, and an
     unstyled native radio leaking through is exactly the bug this class exists to stop. */
  -webkit-appearance: none;
  appearance: none;
}

.sf-purchase input.sf-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
}

/* ---------- focus rings ----------
 *
 * Three-rule pattern, in this order, because it is the only one that degrades safely:
 *
 *   1. :focus                     always draws a ring
 *   2. :focus:not(:focus-visible) removes it again for mouse users
 *   3. :focus-visible             restores it for keyboard users
 *
 * A browser that does not understand :focus-visible (Safari below 15.4, released March
 * 2022) treats rules 2 and 3 as invalid selectors and DROPS THE WHOLE RULE, so it keeps
 * rule 1 and every focus shows a ring. Slightly noisier for old-Safari mouse users, and
 * correct for old-Safari keyboard users, who would otherwise get no focus indicator at
 * all. That is the right way round to fail.
 *
 * Rules 2 and 3 must stay in their own blocks. Grouping them with rule 1 would make old
 * browsers discard the fallback too.
 */
.sf-purchase .sf-mode-input:focus + .sf-mode,
.sf-purchase .sf-sub-input:focus + .sf-sub-card,
.sf-purchase .sf-sub-input:focus + .sf-sub-row,
.sf-purchase .sf-preset:focus,
.sf-purchase .sf-step:focus,
.sf-purchase .sf-qty:focus,
.sf-purchase .sf-sub-select:focus,
.sf-purchase .sf-buy:focus {
  outline: 3px solid var(--sf-ink);
  outline-offset: 2px;
}

.sf-purchase .sf-mode-input:focus:not(:focus-visible) + .sf-mode,
.sf-purchase .sf-sub-input:focus:not(:focus-visible) + .sf-sub-card,
.sf-purchase .sf-sub-input:focus:not(:focus-visible) + .sf-sub-row,
.sf-purchase .sf-preset:focus:not(:focus-visible),
.sf-purchase .sf-step:focus:not(:focus-visible),
.sf-purchase .sf-qty:focus:not(:focus-visible),
.sf-purchase .sf-sub-select:focus:not(:focus-visible),
.sf-purchase .sf-buy:focus:not(:focus-visible) {
  outline: none;
}

.sf-purchase .sf-mode-input:focus-visible + .sf-mode,
.sf-purchase .sf-sub-input:focus-visible + .sf-sub-card,
.sf-purchase .sf-sub-input:focus-visible + .sf-sub-row,
.sf-purchase .sf-preset:focus-visible,
.sf-purchase .sf-step:focus-visible,
.sf-purchase .sf-qty:focus-visible,
.sf-purchase .sf-sub-select:focus-visible,
.sf-purchase .sf-buy:focus-visible {
  outline: 3px solid var(--sf-ink);
  outline-offset: 2px;
}

/* ---------- order mode ---------- */

.sf-mode-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.sf-mode {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.125rem;
  min-height: 56px;
  padding: 0.625rem 0.75rem;
  background: #FFFFFF;
  border: 2px solid var(--sf-line);
  border-radius: var(--sf-radius);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.12s ease, background-color 0.12s ease;
}

.sf-mode-title { font-weight: 700; font-size: 1rem; }
.sf-mode-sub { font-size: 0.8125rem; color: var(--sf-muted); }

.sf-mode:hover { border-color: var(--sf-muted); }

/* Selected mode. Fill plus a heavier border plus a check glyph: three signals, so the
   state survives greyscale, high-contrast mode and colour blindness. */
.sf-mode-input:checked + .sf-mode {
  background: var(--sf-red);
  border-color: var(--sf-red-dark);
  color: #FFFFFF;
}

.sf-mode-input:checked + .sf-mode .sf-mode-sub { color: rgba(255, 255, 255, 0.85); }

.sf-mode-input:checked + .sf-mode .sf-mode-title::before {
  content: "\2713\00a0";
  font-weight: 700;
}

.sf-mode-input:focus-visible + .sf-mode {
  outline: 3px solid var(--sf-ink);
  outline-offset: 2px;
}

/* ---------- occasion presets ---------- */

.sf-presets {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 0.625rem;
  margin-bottom: 0.875rem;
}

.sf-preset {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.125rem;
  min-height: 64px;
  padding: 0.625rem 0.5rem;
  background: #FFFFFF;
  border: 2px solid var(--sf-line);
  border-radius: var(--sf-radius);
  cursor: pointer;
  text-align: center;
  font: inherit;
  color: inherit;
}

.sf-preset-qty { font-size: 1.375rem; font-weight: 700; line-height: 1.1; }
.sf-preset-label { font-size: 0.875rem; font-weight: 600; }
.sf-preset-sub { font-size: 0.75rem; color: var(--sf-muted); line-height: 1.3; }

.sf-preset:hover { border-color: var(--sf-muted); }

.sf-preset-active {
  background: var(--sf-red);
  border-color: var(--sf-red-dark);
  color: #FFFFFF;
}

.sf-preset-active .sf-preset-sub { color: rgba(255, 255, 255, 0.85); }

.sf-preset-active .sf-preset-qty::after {
  content: "\00a0\2713";
  font-size: 0.875rem;
}

.sf-preset:focus-visible,
.sf-step:focus-visible,
.sf-qty:focus-visible,
.sf-buy:focus-visible {
  outline: 3px solid var(--sf-ink);
  outline-offset: 2px;
}

/* ---------- stepper ---------- */

.sf-stepper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sf-step {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  font-size: 1.375rem;
  line-height: 1;
  background: #FFFFFF;
  border: 2px solid var(--sf-line);
  border-radius: var(--sf-radius);
  cursor: pointer;
  color: inherit;
}

.sf-step:hover { border-color: var(--sf-muted); }

.sf-qty {
  width: 88px;
  height: 44px;
  padding: 0 0.5rem;
  text-align: center;
  font-size: 1.125rem;
  font-weight: 700;
  border: 2px solid var(--sf-line);
  border-radius: var(--sf-radius);
  background: #FFFFFF;
  color: inherit;
}

.sf-qty-uom { font-size: 0.875rem; color: var(--sf-muted); }

/* ---------- subscribe and save ----------
 *
 * The subscribe option is visually primary because it is the better value, but it is NOT
 * pre-selected. A pre-ticked recurring charge raises the disclosure bar sharply under the
 * FTC Negative Option Rule, and here it would also break: set_cart_subscription rejects
 * Guest, so a defaulted guest would hit an error on Add to Cart.
 */

.sf-sub-stack { display: block; }

/* The featured subscription card and the plain one-time row below it. */
.sf-sub-card,
.sf-sub-row {
  position: relative;
  display: block;
  background: #FFFFFF;
  border: 2px solid var(--sf-line);
  border-radius: var(--sf-radius);
  cursor: pointer;
}

.sf-sub-card { padding: 0.875rem 1rem 1rem; }

.sf-sub-row {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-height: 56px;
  padding: 0.75rem 1rem;
  margin-top: 0.625rem;
}

.sf-sub-card-head {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding-bottom: 0.625rem;
  border-bottom: 1px solid var(--sf-line);
}

.sf-sub-title { font-weight: 700; font-size: 1.0625rem; }

/* nowrap belongs on the two figures, NOT on their container.
 *
 * With it on the container, "$238.00-$357.00 $226.10-$339.15" was one unbreakable line
 * and ran 1px past a 375px viewport at 8 filets. Each range must stay intact, but the
 * struck-through price and the member price are allowed to fall onto separate lines. */
.sf-sub-cost { margin-left: auto; font-weight: 700; white-space: normal; text-align: right; }
.sf-sub-was, .sf-sub-now { white-space: nowrap; display: inline-block; }

/* A drawn radio, because the real input is visually hidden for styling. It is
   aria-hidden and purely decorative: the input still owns focus and semantics. */
.sf-sub-radio {
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  border: 2px solid var(--sf-muted);
  border-radius: 50%;
}

.sf-sub-input:checked + .sf-sub-card,
.sf-sub-input:checked + .sf-sub-row {
  border-color: var(--sf-red);
  background: var(--sf-cream);
}

.sf-sub-input:checked + .sf-sub-card .sf-sub-radio,
.sf-sub-input:checked + .sf-sub-row .sf-sub-radio {
  border-color: var(--sf-red);
  /* Filled centre as well as the colour change, so selection survives greyscale and
     forced-colors mode (WCAG 1.4.1). */
  box-shadow: inset 0 0 0 4px var(--sf-red);
}

.sf-sub-input:focus-visible + .sf-sub-card,
.sf-sub-input:focus-visible + .sf-sub-row {
  outline: 3px solid var(--sf-ink);
  outline-offset: 2px;
}

.sf-sub-badge {
  position: absolute;
  top: -0.6rem;
  right: 0.75rem;
  padding: 0.15rem 0.45rem;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #FFFFFF;
  background: var(--sf-red);
  border-radius: 4px;
}

.sf-sub-was { color: var(--sf-muted); font-weight: 400; margin-right: 0.3rem; }
.sf-sub-now { color: var(--sf-ink); }

/* Sits inside the card visually but outside the <label>, so the select owns its own
   clicks. A <select> nested in a label toggles the radio in Safari. */
.sf-sub-detail {
  margin: -2px 0 0;
  padding: 0.75rem 1rem 0.875rem;
  background: var(--sf-cream);
  border: 2px solid var(--sf-red);
  border-top: 0;
  border-radius: 0 0 var(--sf-radius) var(--sf-radius);
}

.sf-sub-cadence { display: block; margin-bottom: 0.35rem; font-weight: 600; }

.sf-sub-select {
  width: 100%;
  min-height: 44px;
  padding: 0 0.5rem;
  font: inherit;
  border: 2px solid var(--sf-line);
  border-radius: var(--sf-radius);
  background: #FFFFFF;
  color: inherit;
}

.sf-sub-perks {
  margin: 0.625rem 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.875rem;
  color: var(--sf-ink);
}

.sf-sub-perks li { display: flex; gap: 0.4rem; line-height: 1.5; }
.sf-sub-perks li::before { content: "\2713"; color: var(--sf-red); font-weight: 700; }

.sf-sub-login { margin: 0.75rem 0 0; font-size: 0.875rem; }
.sf-sub-login a { color: var(--sf-red); font-weight: 600; }

/* ---------- summary ---------- */

.sf-summary {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem 1rem;
  padding: 0.875rem 1rem;
  margin-bottom: 1rem;
  background: #FFFFFF;
  border: 1px solid var(--sf-line);
  border-radius: var(--sf-radius);
}

.sf-summary-label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--sf-muted);
}

.sf-summary-headline { font-size: 1.375rem; font-weight: 700; }

.sf-summary-right { margin: 0; text-align: right; }

.sf-summary-row {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  font-size: 0.9375rem;
}

.sf-summary-row dt { color: var(--sf-muted); font-weight: 400; }
.sf-summary-row dd { margin: 0; font-weight: 600; }
.sf-summary-total { font-weight: 700; }

/* ---------- call to action ---------- */

.sf-buy {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.25rem 0.75rem;
  width: 100%;
  min-height: 56px;
  padding: 0.875rem 1rem;
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: #FFFFFF;
  background: var(--sf-red);
  border: 2px solid var(--sf-red-dark);
  border-radius: var(--sf-radius);
  cursor: pointer;
}

.sf-buy:hover { background: var(--sf-red-dark); }

.sf-buy[disabled] { opacity: 0.6; cursor: progress; }

.sf-cta-cost { font-weight: 600; opacity: 0.92; }

.sf-cta-cost::before { content: "\00b7\00a0"; }

.sf-view-cart {
  display: block;
  margin-top: 0.75rem;
  text-align: center;
  font-weight: 600;
  color: var(--sf-red);
}

.sf-note {
  margin: 0.875rem 0 0;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--sf-muted);
}

/* ---------- trust strip ---------- */

.sf-trust {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  margin: 1rem 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.8125rem;
  color: var(--sf-muted);
}

.sf-trust li { display: flex; align-items: center; gap: 0.375rem; }

.sf-trust li::before {
  content: "\2713";
  font-weight: 700;
  color: var(--sf-red);
}

/* ---------- reviews ----------
 *
 * The farm block is styled DIFFERENTLY from the product block on purpose. The two say
 * different things (one is about this cut, one is about the farm) and a reader skimming
 * should be able to tell them apart without reading the headings. Same reason the farm
 * block carries no stars in its summary: nothing there feeds a product rating.
 */

.sf-reviews {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--sf-line);
}

.sf-reviews-heading {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0 0 0.75rem;
}

.sf-reviews-note {
  margin: -0.25rem 0 1rem;
  font-size: 0.875rem;
  color: var(--sf-muted);
}

.sf-reviews-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  font-size: 0.9375rem;
}

.sf-stars { color: var(--sf-red); letter-spacing: 0.08em; }
.sf-reviews-score { font-weight: 700; }
.sf-reviews-count { color: var(--sf-muted); }

.sf-review {
  padding: 0.875rem 0;
  border-bottom: 1px solid var(--sf-line);
}

.sf-review:last-child { border-bottom: 0; }

.sf-review-rating {
  color: var(--sf-red);
  letter-spacing: 0.08em;
  margin-bottom: 0.25rem;
}

.sf-review-body {
  margin: 0 0 0.5rem;
  padding: 0;
  border: 0;
  font-size: 1rem;
  line-height: 1.6;
  /* Reviews are quoted VERBATIM. Never trim one to fit a layout: editing a testimonial
     changes what the customer said, which is its own problem under the same FTC rule. */
  white-space: pre-line;
}

.sf-review-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.8125rem;
  color: var(--sf-muted);
}

.sf-review-meta > span:first-child { font-weight: 600; color: var(--sf-ink); }

.sf-reviews-farm { background: var(--sf-cream); padding: 1.25rem; border-radius: var(--sf-radius); }
.sf-reviews-farm .sf-review { border-bottom-color: #E6DDD0; }

/* ---------- narrow screens ---------- */

@media (max-width: 480px) {
  .sf-cost-main { font-size: 2rem; }
  .sf-cost-header { flex-direction: column; align-items: flex-start; }
  .sf-summary { flex-direction: column; align-items: stretch; }
  .sf-summary-right { text-align: left; }
  .sf-summary-row { justify-content: space-between; }
  .sf-presets { grid-template-columns: repeat(2, 1fr); }

  /* The CTA had ~178px of usable text at 375px: 264px box, less 40px of box padding,
     less 44px of button padding. The label plus a price range does not fit in that at
     the ~20px this font-size resolves to, because rem inherits the site's larger mobile
     root, so "ADD 99 FILETS - EST. $2,797.99-$4,196.99" wrapped into a 159px-tall block.
     Reclaim the padding, stack the two lines deliberately rather than by accident, and
     drop the size. */
  .sf-purchase-box { padding: 0.875rem; }

  .sf-buy {
    flex-direction: column;
    gap: 0.1rem;
    padding: 0.7rem 0.6rem;
    font-size: 0.9375rem;
    min-height: 52px;
    line-height: 1.25;
  }

  /* The middot separator only makes sense when the two sit on one line. */
  .sf-cta-cost::before { content: none; }
  .sf-cta-cost { font-size: 0.8125rem; }

  .sf-sub-card, .sf-sub-row { padding-left: 0.75rem; padding-right: 0.75rem; }
  .sf-sub-card-head { flex-wrap: wrap; }
  .sf-sub-cost { margin-left: 0; width: 100%; }
}

/* A money range must never break mid-number: "$2,797.99-$4,196" on one line and ".99" on
   the next is worse than a taller button. Breaking BETWEEN the two figures is fine, so
   each is wrapped in its own nowrap span by the JS and the template. */
.sf-cta-cost,
.sf-summary-total,
.sf-sub-cost { overflow-wrap: normal; word-break: keep-all; }

/* Respect a reduced-motion preference: the only transitions here are decorative. */
@media (prefers-reduced-motion: reduce) {
  .sf-mode { transition: none; }
}

/* Windows high-contrast mode drops background colours entirely, so the selected state
   has to survive on border and glyph alone. */
@media (forced-colors: active) {
  .sf-mode-input:checked + .sf-mode,
  .sf-preset-active {
    border-width: 3px;
    border-style: solid;
  }
}
