/**
 * Mercado Mayor / Bazarial — "Aplica para vender" / "Aplica para comprar"
 * ---------------------------------------------------------------------------
 * The category question added to both Fluent Forms by
 * inc/application-categories.php. Fluent Forms renders a checkbox group as one
 * stacked row per option, which is fine for three options and unusable for ten
 * — the applicant scrolls a wall of ticks between the social links and the
 * description.
 *
 * These are the same toggle chips the registration form already uses (see
 * css/custom/regcat.css); the markup underneath is Fluent Forms' own, so the
 * selectors differ, but the resulting component is deliberately identical —
 * someone who applies and later registers meets the same control twice.
 *
 * As there, the native checkbox stays in the DOM and does the work. It is
 * visually hidden rather than replaced, so keyboard focus, the tab order and
 * screen-reader semantics remain the browser's.
 */

/* These forms are laid out as a two-column grid by css/custom/recursos.css,
   which opts individual rows out into full width with `grid-column: 1 / -1`
   (the heading, any textarea, the submit row). A row of ten chips belongs in
   that group too: confined to one column it had barely 40% of the form to
   flow in, so the chips wrapped one or two per line into a tall ragged
   block. Same scoping as the rules it joins, since that grid only exists
   under `body.mm-recursos`. */
body.mm-recursos .ff-el-group.mm-ff-categories {
  grid-column: 1 / -1;
}

.mm-ff-categories .ff-el-input--content {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* -- Link to the published fee schedule ---------------------------------
 * Sits between the last field and the submit button, so the applicant meets
 * the commercial terms before committing rather than after approval. Full
 * width for the same reason the chips are: confined to one grid column the
 * sentence broke across three ragged lines. */
body.mm-recursos .ff-el-group.mm-ff-feeslink-wrap {
  grid-column: 1 / -1;
}

.mm-ff-feeslink {
  margin: 4px 0 0;
  padding: 12px 16px;
  background: var(--mm-surface-sunken, #F5F4F2);
  border-radius: var(--mm-radius, 8px);
  font-family: var(--mm-font-ui, inherit);
  font-size: .8125rem;
  line-height: 1.6;
  color: var(--mm-ink-muted, #5A5A5A);
  text-align: center;
}

.mm-ff-feeslink a {
  color: var(--mm-accent, #D23D2D);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.mm-ff-feeslink a:hover {
  color: var(--mm-accent-hover, #AA2418);
}

/* Fluent Forms wraps each option in its own div and sizes that div by
   percentage — `width: 100%` in one of its stylesheets, `width: 33.3%` in
   another. As flex items those percentages make each chip claim a fraction of
   the row rather than its own width, so the chips wrapped at arbitrary points
   (one on a line, then three, then one). `!important` because the plugin ships
   `width: auto !important` on the same element, so nothing weaker survives.
   Sized by its content instead, which is what a chip row needs. */
.mm-ff-categories .ff-el-form-check {
  flex: 0 0 auto;
  width: auto !important;
  min-height: 0;
  margin: 0;
  padding: 0;
}

.mm-ff-categories .ff-el-form-check-label {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: auto;
  max-width: 100%;
  margin: 0;
  padding: 7px 14px;
  font-family: var(--mm-font-ui, inherit);
  font-size: .8125rem;
  font-weight: 500;
  line-height: 1.3;
  color: var(--mm-ink-muted, #5A5A5A);
  background: var(--mm-surface, #fff);
  border: 1px solid var(--mm-border-strong, #D4D3CF);
  border-radius: 999px;
  cursor: pointer;
  user-select: none;
  transition: background-color .18s ease, border-color .18s ease, color .18s ease;
}

.mm-ff-categories .ff-el-form-check-label:hover {
  border-color: var(--mm-accent-pastel, #EFA79F);
  color: var(--mm-ink, #1E1E1E);
}

/* Clipped rather than `display: none`, which would drop it out of the tab
   order and take the label's own click target with it. */
.mm-ff-categories .ff-el-form-check-input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.mm-ff-categories .ff-el-form-check-label:has(input:checked) {
  color: var(--mm-ink, #1E1E1E);
  background: var(--mm-accent-pastel, #EFA79F);
  border-color: var(--mm-accent-pastel, #EFA79F);
}

/* The hidden input can still take focus; the ring has to be drawn on the chip
   instead, or keyboard users get no indication of where they are. */
.mm-ff-categories .ff-el-form-check-label:has(input:focus-visible) {
  outline: 2px solid var(--mm-accent, #D23D2D);
  outline-offset: 2px;
}

/* A tick appears on the selected chips, so the state does not rest on colour
   alone — it stays legible to anyone who cannot separate the two fills. */
.mm-ff-categories .ff-el-form-check-label > span::before {
  content: '';
  display: inline-block;
  width: 0;
  height: 6px;
  margin-right: 0;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg) scale(0);
  transform-origin: center;
  transition: width .18s ease, margin .18s ease, transform .18s ease;
  vertical-align: 1px;
}

.mm-ff-categories .ff-el-form-check-label:has(input:checked) > span::before {
  width: 9px;
  margin-right: 8px;
  transform: rotate(-45deg) scale(1);
}

/* Fallback for engines without :has() — the tick simply never appears, and the
   chips read as a plain (still usable) checkbox list. */
@supports not selector(:has(*)) {
  .mm-ff-categories .ff-el-form-check-input {
    position: static;
    width: auto;
    height: auto;
    margin-right: 7px;
    overflow: visible;
    clip: auto;
    clip-path: none;
  }
  .mm-ff-categories .ff-el-form-check-label > span::before {
    display: none;
  }
}

@media (max-width: 575px) {
  .mm-ff-categories .ff-el-input--content {
    gap: 6px;
  }
  .mm-ff-categories .ff-el-form-check-label {
    padding: 6px 12px;
  }
}
