/**
 * Peak Form.
 *
 * The fields sit on one flex row-wrap rather than a grid, because a field's
 * width is per-field (100 / 50 / 33) and a grid would need a column count the
 * widget cannot know. Each field carries its own flex-basis and they wrap
 * naturally; below 600px every field goes full width, since a 33%-wide phone
 * input helps nobody.
 *
 * Every knob is a `--peak-form-*` custom property on the root, patched live by
 * the panel. See [[peak-widgets-module]].
 *
 * @package Peak
 */

.peak-form {
  --peak-form-gap-x: 16px;
  --peak-form-gap-y: 16px;
  --peak-form-field-bg: transparent;
  --peak-form-field-color: inherit;
  --peak-form-field-border: rgba(0, 0, 0, 0.18);
  --peak-form-field-radius: 6px;
  --peak-form-field-pad: 12px;
  /* The four sides of a field, resolved ONCE. Each falls back to the single
	   value every form saved before the four-sided control existed, so nothing
	   moves; everything below reads the alias rather than repeating the chain. */
  --_fp-t: var(--peak-form-field-pt, var(--peak-form-field-pad));
  --_fp-r: var(--peak-form-field-pr, var(--peak-form-field-pad));
  --_fp-b: var(--peak-form-field-pb, var(--peak-form-field-pad));
  --_fp-l: var(--peak-form-field-pl, var(--peak-form-field-pad));
  --peak-form-accent: currentColor;
  /* The space between a label and the box under it. */
  --peak-form-label-gap: 6px;
  --peak-form-label-color: inherit;
  /* A soft ring around a field. Empty by default — the Inputs section's
	   "Glow" writes it, most usefully on the Focus tab. */
  --peak-form-field-glow: transparent;
  /* The tick/dot drawn inside a checked control. It has to contrast with the
	   accent it sits on, so it is its own token rather than the field colour. */
  --peak-form-mark: #ffffff;
  --peak-form-control: 18px;
  /* A floating panel cannot inherit a transparent field background — it has to
	   be opaque or the page shows through the options. */
  --peak-form-popover-bg: #ffffff;
  --peak-form-popover-fg: #111111;
  --peak-form-popover-border: rgba(0, 0, 0, 0.1);
  --peak-form-popover-hover: rgba(0, 0, 0, 0.055);
  --peak-form-popover-radius: 10px;
  --peak-form-popover-shadow:
    0 10px 30px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.08);
  --peak-form-error: #d9464f;
  --peak-form-ok: #2f9e63;
  --peak-form-submit-align: flex-start;
  --peak-form-submit-bg: currentColor;
  --peak-form-submit-color: #fff;
  --peak-form-submit-radius: 6px;
  --peak-form-dur: 0.18s;
}

/* ---- layout ---- */

.peak-form__fields {
  display: flex;
  flex-wrap: wrap;
  gap: var(--peak-form-gap-y) var(--peak-form-gap-x);
}

.peak-form__field {
  display: flex;
  flex-direction: column;
  gap: var(--peak-form-label-gap);
  box-sizing: border-box;
  min-width: 0;
  /* basis minus its share of the gap, so two 50%s really fit on one row */
  flex: 1 1 100%;
}

/* A field's width comes from its own Object Styles box (`--pob-w`).
 *
 * The basis subtracts a whole gap and flex-grow gives the slack back, which is
 * what makes percentages actually fit: two 50% fields would otherwise be
 * 50% + gap + 50% and wrap onto separate lines. `max-width` then stops a field
 * that ends up alone on the last row from stretching to fill it. */
.peak-form__field.pob-w {
  flex: 1 1 calc(var(--pob-w) - var(--peak-form-gap-x));
  max-width: var(--pob-w);
  width: auto;
}

/* ---- labels ---- */

.peak-form__label {
  display: block;
  color: var(--peak-form-label-color);
  font-family: var(--peak-form-label-ff, inherit);
  font-size: var(--peak-form-label-fs, 0.875em);
  font-weight: var(--peak-form-label-fw, 500);
  line-height: var(--peak-form-label-lh, 1.3);
  letter-spacing: var(--peak-form-label-ls, normal);
  text-transform: var(--peak-form-label-tt, none);
}

.peak-form__req {
  margin-inline-start: 2px;
  color: var(--peak-form-error);
}

/* A hidden label is hidden from EYES only — it stays in the accessibility tree,
   so the field is still announced. */
.peak-form .screen-reader-text {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---- inputs ---- */

/* One rule for every text-ish control AND the select, so a form never shows a
   mix of Peak fields and browser chrome. `appearance:none` is what removes the
   OS look from selects, date inputs and iOS's rounded text fields. */
.peak-form__input,
.peak-form select {
  appearance: none;
  -webkit-appearance: none;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  padding: var(--_fp-t) var(--_fp-r) var(--_fp-b) var(--_fp-l);
  color: var(--peak-form-field-color);
  background: var(--peak-form-field-bg);
  /* The Inputs section's four-sided Border, falling back to the single
	   colour every form saved before it existed (`field_border`). A width of
	   zero on a side with no style is what makes "None" mean none. */
  border-style: var(--peak-form-field-bds, none);
  border-color: var(--peak-form-field-bdc, var(--peak-form-field-border));
  border-top-width: var(
    --peak-form-field-bdwt,
    var(--peak-form-field-bdw, 1px)
  );
  border-right-width: var(
    --peak-form-field-bdwr,
    var(--peak-form-field-bdw, 1px)
  );
  border-bottom-width: var(
    --peak-form-field-bdwb,
    var(--peak-form-field-bdw, 1px)
  );
  border-left-width: var(
    --peak-form-field-bdwl,
    var(--peak-form-field-bdw, 1px)
  );
  border-radius: var(--peak-form-field-radius);
  box-shadow: 0 0 0 3px var(--peak-form-field-glow);
  font-family: var(--peak-form-input-ff, inherit);
  font-size: var(--peak-form-input-fs, 1em);
  font-weight: var(--peak-form-input-fw, 400);
  line-height: var(--peak-form-input-lh, 1.4);
  letter-spacing: var(--peak-form-input-ls, normal);
  text-transform: var(--peak-form-input-tt, none);
  transition:
    border-color var(--peak-form-dur) ease,
    box-shadow var(--peak-form-dur) ease;
  outline: none !important;
}

.peak-form textarea.peak-form__input {
  resize: vertical;
}

/* Focus draws NOTHING of its own.
 *
 * A clicked field used to grow a heavy border and a glow: `--peak-form-accent`
 * is `currentColor` until somebody picks a Focus Colour, so "the accent" was
 * simply the text colour, and a field went from a hairline to a near-black
 * frame the moment the cursor entered it. What a focused field looks like is
 * the Focus tab's decision now, and its default is "the same as idle".
 *
 * The two declarations stay, at the specificity a THEME uses for its own focus
 * ring, because they are what NEUTRALISES it: Peak Starter styles
 * `input:where(…):focus` (0,2,0), which beats the plain `.peak-form__input`
 * (0,1,0) the base rule declares at. Deleting them would not have removed a
 * border, it would have handed the border back to the theme. They resolve to
 * the idle values unless a Focus state redefines the variables.
 *
 * The keyboard still gets a ring, below. `:focus-visible` is the indicator a
 * visitor who is not using a mouse depends on, and it never fires on a click —
 * so it costs the complaint nothing and keeps the form operable. */
.peak-form__input:focus,
.peak-form select:focus {
  outline: none;
  border-color: var(--peak-form-field-bdc, var(--peak-form-field-border));
  box-shadow: 0 0 0 3px var(--peak-form-field-glow);
}

.peak-form__input:focus-visible,
.peak-form select:focus-visible {
  outline: 2px solid var(--peak-form-accent);
  outline-offset: 1px;
}

/* Autofill repaints the field with the browser's own yellow. Chrome only lets
   it be overridden through an inset shadow, which is why this looks odd. */
.peak-form__input:-webkit-autofill,
.peak-form__input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--peak-form-field-color);
  box-shadow: 0 0 0 1000px var(--peak-form-field-bg) inset;
  transition: background-color 100000s ease 0s;
}

.peak-form__input:disabled,
.peak-form select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.peak-form__input::placeholder {
  opacity: 0.6;
}

/* ---- select ---- */

.peak-form__select {
  position: relative;
  display: block;
}

/* A CSS chevron rather than an SVG: it inherits colour, needs no asset, and
   matches the one the panel draws. */
.peak-form__select::after {
  content: "";
  position: absolute;
  top: 50%;
  right: calc(var(--_fp-r) + 2px);
  width: 7px;
  height: 7px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateY(-70%) rotate(45deg);
  opacity: 0.5;
  pointer-events: none;
}

.peak-form__select select {
  padding-right: calc(var(--_fp-r) * 2 + 12px);
  cursor: pointer;
}

/* A multiple select is a list, not a dropdown — no chevron, and it keeps its
   own scroll. */
.peak-form__select:has(select[multiple])::after {
  display: none;
}

.peak-form__select select[multiple] {
  min-height: 8em;
  padding-right: var(--_fp-r);
  cursor: default;
}

.peak-form__select select[multiple] option {
  padding: 4px 2px;
}

/* ---- number ---- */

/* The spinners are tiny, unstyleable and inconsistent between browsers; the
   field reads better without them. */
.peak-form__input[type="number"] {
  -moz-appearance: textfield;
}

.peak-form__input[type="number"]::-webkit-outer-spin-button,
.peak-form__input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* ---- date ---- */

/* Safari refuses to size a date input from its content, so it collapses unless
   it is told to fill the field like every other input. */
.peak-form__input[type="date"] {
  min-height: calc(1.4em + var(--_fp-t) + var(--_fp-b));
  cursor: text;
}

.peak-form__input[type="date"]::-webkit-date-and-time-value {
  text-align: left;
}

/* Browsers paint an empty date's dd.mm.yyyy hint in the text colour, so it
   looks filled next to a real placeholder. The runtime marks it empty. */
.peak-form__input[type="date"].is-empty::-webkit-datetime-edit,
.peak-form__input[type="time"].is-empty::-webkit-datetime-edit {
  opacity: 0.6;
}

.peak-form__input[type="date"].is-empty {
  color: color-mix(in srgb, var(--peak-form-field-color) 60%, transparent);
}

/* Chrome's calendar button is a black glyph on any background; recolour it to
   the field's own text and give it a real hit area. */
.peak-form__input[type="date"]::-webkit-calendar-picker-indicator {
  padding: 4px;
  margin-inline-start: 4px;
  border-radius: var(--peak-form-field-radius);
  opacity: 0.55;
  cursor: pointer;
  filter: invert(var(--peak-form-invert, 0));
  transition:
    opacity var(--peak-form-dur) ease,
    background-color var(--peak-form-dur) ease;
}

.peak-form__input[type="date"]::-webkit-calendar-picker-indicator:hover {
  opacity: 1;
  background: color-mix(in srgb, currentColor 12%, transparent);
}

/* ---- field groups ----
 *
 * A `fieldset` with the browser's own chrome taken off: the box, the padding
 * and the legend's notch in the border are all decisions the Group Box popover
 * gets to make instead. `min-width: 0` is the fieldset's own quirk — without
 * it a fieldset refuses to shrink below its content and a grid inside one
 * overflows the form.
 */

.peak-form__group {
  display: flex;
  flex-direction: column;
  gap: var(--peak-form-label-gap);
  flex: 1 1 100%;
  box-sizing: border-box;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

/* Same width rule as a field: its own Object Styles box decides. */
.peak-form__group.pob-w {
  flex: 1 1 calc(var(--pob-w) - var(--peak-form-gap-x));
  max-width: var(--pob-w);
  width: auto;
}

/* The group's heading has a look of its own, falling back to the field labels'
   so a group nobody styles still matches the form. It is the name of a SECTION
   and the labels under it are the names of boxes, which is exactly why it
   needed to be able to differ. Every `--peak-form-gl-*` is written by the
   group's own Label popover (Peak_Form_Widget::group_layout_vars). */
.peak-form__group-label {
  display: block;
  float: none;
  width: 100%;
  padding: 0;
  margin-block-end: var(--peak-form-gl-gap, 0);
  color: var(--peak-form-gl-color, var(--peak-form-label-color));
  font-family: var(--peak-form-gl-ff, var(--peak-form-label-ff, inherit));
  font-size: var(--peak-form-gl-fs, var(--peak-form-label-fs, 0.875em));
  font-weight: var(--peak-form-gl-fw, var(--peak-form-label-fw, 500));
  line-height: var(--peak-form-gl-lh, var(--peak-form-label-lh, 1.3));
  letter-spacing: var(--peak-form-gl-ls, var(--peak-form-label-ls, normal));
  text-transform: var(--peak-form-gl-tt, var(--peak-form-label-tt, none));
  text-align: var(--peak-form-gl-align, inherit);
}

/* The group's Layout popover, read in one place. A group defaults to the same
   wrapping row the form itself is, so a group nobody styles still lays its
   fields out the way they were laid out before it existed. */
.peak-form__group-fields {
  display: var(--peak-form-g-display, flex);
  flex-direction: var(--peak-form-g-dir, row);
  flex-wrap: var(--peak-form-g-wrap, wrap);
  justify-content: var(--peak-form-g-justify, flex-start);
  align-items: var(--peak-form-g-align, stretch);
  grid-template-columns: var(--peak-form-g-cols, none);
  gap: var(--peak-form-g-gap, var(--peak-form-gap-y) var(--peak-form-gap-x));
  min-width: 0;
}

/* ---- choices ---- */

.peak-form__choices {
  display: flex;
  flex-wrap: wrap;
  gap: var(--peak-form-choice-gap, 8px) var(--peak-form-choice-gap, 18px);
}

/* One choice — and the whole thing is the control, box or no box.
 *
 * Every property here is a variable with the old hard-coded value as its
 * fallback, which is what lets the Choices section's three tabs (idle, hover,
 * selected) paint it without a second set of rules: a state's CSS redefines
 * the variables on `.peak-form__choice:hover` / `:has(input:checked)`, and the
 * declarations below read whichever definition is closest. */
.peak-form__choice {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  cursor: pointer;
  line-height: 1.4;
  color: var(--peak-form-choice-color, inherit);
  background-color: var(--peak-form-choice-bg, transparent);
  background-image: var(--peak-form-choice-bg-i, none);
  border-style: var(--peak-form-choice-bds, none);
  border-color: var(--peak-form-choice-bdc, currentColor);
  border-width: var(--peak-form-choice-bdwt, 1px)
    var(--peak-form-choice-bdwr, 1px) var(--peak-form-choice-bdwb, 1px)
    var(--peak-form-choice-bdwl, 1px);
  border-radius: var(--peak-form-choice-radius, 0);
  padding: var(--peak-form-choice-pt, 0) var(--peak-form-choice-pr, 0)
    var(--peak-form-choice-pb, 0) var(--peak-form-choice-pl, 0);
  font-family: var(--peak-form-choice-ff, inherit);
  font-size: var(--peak-form-choice-fs, inherit);
  font-weight: var(--peak-form-choice-fw, inherit);
  line-height: var(--peak-form-choice-lh, 1.4);
  letter-spacing: var(--peak-form-choice-ls, normal);
  text-transform: var(--peak-form-choice-tt, none);
  transition:
    background-color var(--peak-form-dur) ease,
    color var(--peak-form-dur) ease,
    border-color var(--peak-form-dur) ease;
}

/* ---- label-only choices ----
 *
 * The box goes, the words stay, and the words become the button. The input is
 * still in the DOM and still focusable — it is the thing a screen reader and
 * the keyboard operate, and it is what `:has(input:checked)` reads — it simply
 * draws nothing. `clip` rather than `display:none`, because a hidden input
 * cannot be focused and the keyboard would lose the control entirely.
 *
 * The idle look is deliberately quiet and the SELECTED look is the site's own
 * accent, so a form that never opens the Choices section still reads correctly.
 */
.peak-form__choice.is-label input[type="radio"],
.peak-form__choice.is-label input[type="checkbox"],
.peak-form__choices.is-label input[type="radio"],
.peak-form__choices.is-label input[type="checkbox"] {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  appearance: none;
}

.peak-form__choices.is-label .peak-form__choice,
.peak-form__choice.is-label {
  gap: 0;
  align-items: center;
  background-color: var(
    --peak-form-choice-bg,
    color-mix(in srgb, currentColor 6%, transparent)
  );
  background-image: var(--peak-form-choice-bg-i, none);
  border-radius: var(--peak-form-choice-radius, var(--peak-form-field-radius));
  padding: var(--peak-form-choice-pt, 0.5em) var(--peak-form-choice-pr, 0.9em)
    var(--peak-form-choice-pb, 0.5em) var(--peak-form-choice-pl, 0.9em);
  user-select: none;
}
/* NO default border, and that is the fix rather than an omission: it used to
   fall back to `solid`, so picking None in the Border control changed nothing —
   None emits no value, the fallback painted the border straight back, and there
   was no way to take an edge off a chip. The base `.peak-form__choice` rule
   already defaults `border-style` to `none`; a chip is bare until somebody asks
   for an edge, and the tint alone is what makes it read as one. */

/* Picked. Named by the input's own state, so nothing has to keep a class in
   sync — and the Selected tab in the panel overrules both of these.
   `[data-peak-pstate]` is the same look shown on the CANVAS while that tab is
   open (peak-form.js): the builder swallows the click that would have ticked
   the box, so without it the one state you most need to see was the one you
   could not.
 *
 * The fill is on the CHIP and the text colour on the SPAN inside it, and the
 * split is the whole trick: `currentColor` in a background resolves against the
 * element's OWN colour, so a rule that filled with currentColor and then set
 * the text to white painted white on white. The span is a different element,
 * so the chip's currentColor is still the inherited text colour.
 *
 * No font-weight change. Bolding the picked one widened the chip and nudged
 * every chip after it along the row, which reads as the layout twitching
 * rather than as an answer being chosen. */
.peak-form__choices.is-label .peak-form__choice:has(input:checked),
.peak-form__choice.is-label:has(input:checked),
.peak-form__choices.is-label
  .peak-form__choice[data-peak-pstate="choice_selected"],
.peak-form__choice.is-label[data-peak-pstate="choice_selected"] {
  background-color: var(--peak-form-choice-bg, currentColor);
  background-image: var(--peak-form-choice-bg-i, none);
}
.peak-form__choices.is-label .peak-form__choice:has(input:checked) > span,
.peak-form__choice.is-label:has(input:checked) > span,
.peak-form__choices.is-label
  .peak-form__choice[data-peak-pstate="choice_selected"]
  > span,
.peak-form__choice.is-label[data-peak-pstate="choice_selected"] > span {
  color: var(--peak-form-choice-color, var(--peak-form-mark));
}

/* The keyboard has to be able to see where it is, with no box to ring. */
.peak-form__choices.is-label .peak-form__choice:has(input:focus-visible),
.peak-form__choice.is-label:has(input:focus-visible) {
  outline: 2px solid var(--peak-form-accent);
  outline-offset: 2px;
}

/* The native control is replaced rather than tinted: `accent-color` alone still
   leaves the OS shape, size and focus ring, which is exactly the mismatch that
   makes a styled form look unfinished. The input keeps its place in the DOM (so
   labels, focus and validation all still work) and is drawn over. */
.peak-form__choice input[type="radio"],
.peak-form__choice input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 auto;
  position: relative;
  width: var(--peak-form-control);
  height: var(--peak-form-control);
  margin: 0;
  /* nudge the box onto the first line's optical centre */
  margin-top: calc((1.4em - var(--peak-form-control)) / 2);
  background: var(--peak-form-control-bg, var(--peak-form-field-bg));
  border: 1px solid var(--peak-form-field-border);
  border-radius: var(--peak-form-field-radius);
  cursor: pointer;
  transition:
    background-color var(--peak-form-dur) ease,
    border-color var(--peak-form-dur) ease;
}

.peak-form__choice input[type="radio"] {
  border-radius: 50%;
}

.peak-form__choice input:hover {
  border-color: var(--peak-form-accent);
}

.peak-form__choice input:checked {
  background: var(--peak-form-accent);
  border-color: var(--peak-form-accent);
}

/* The tick: two borders rotated into a check, so it scales with the control and
   needs no image. */
.peak-form__choice input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 46%;
  left: 50%;
  width: 0.3em;
  height: 0.55em;
  border-right: 2px solid var(--peak-form-mark);
  border-bottom: 2px solid var(--peak-form-mark);
  transform: translate(-50%, -55%) rotate(45deg) scale(0);
  transition: transform var(--peak-form-dur) ease;
}

.peak-form__choice input[type="checkbox"]:checked::after {
  transform: translate(-50%, -55%) rotate(45deg) scale(1);
}

.peak-form__choice input[type="radio"]::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 38%;
  height: 38%;
  background: var(--peak-form-mark);
  border-radius: 50%;
  transform: scale(0);
  transition: transform var(--peak-form-dur) ease;
}

.peak-form__choice input[type="radio"]:checked::after {
  transform: scale(1);
}

/* Keyboard focus must stay visible now that the OS ring is gone. */
.peak-form__choice input:focus-visible {
  outline: none;
  border-color: var(--peak-form-accent);
  box-shadow: 0 0 0 3px
    color-mix(in srgb, var(--peak-form-accent) 30%, transparent);
}

@media (prefers-reduced-motion: reduce) {
  .peak-form__choice input::after {
    transition: none;
  }
}

/* An errored choice group marks its controls, not just the message. */
.peak-form__field.has-error .peak-form__choice input:not(:checked) {
  border-color: var(--peak-form-error);
}

/* ---- file upload ---- */

.peak-form__file {
  position: relative;
}

/* The real input stays in the layout (so focus and validation work) but is
   invisible; the label is the control. */
.peak-form__file-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.peak-form__file-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: calc(1.4em + var(--_fp-t) + var(--_fp-b));
  padding: var(--_fp-t) var(--_fp-r) var(--_fp-b) var(--_fp-l);
  background: var(--peak-form-field-bg);
  border: 1px dashed var(--peak-form-field-border);
  border-radius: var(--peak-form-field-radius);
  color: var(--peak-form-field-color);
  cursor: pointer;
  transition:
    border-color var(--peak-form-dur) ease,
    background-color var(--peak-form-dur) ease;
}

.peak-form__file-input:focus-visible + .peak-form__file-label,
.peak-form__file-label:hover {
  border-color: var(--peak-form-accent);
  background: color-mix(in srgb, var(--peak-form-accent) 5%, transparent);
}

/* Dragging a file over the field should say so. */
.peak-form__file-input:focus-visible + .peak-form__file-label {
  box-shadow: 0 0 0 3px
    color-mix(in srgb, var(--peak-form-accent) 22%, transparent);
}

/* Once files are chosen the dashes stop being a drop hint. */
.peak-form__file.has-files .peak-form__file-label {
  border-style: solid;
}

.peak-form__file-hint {
  opacity: 0.6;
  font-size: 0.8125em;
}

.peak-form__file-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.875em;
}

.peak-form__file-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  background: color-mix(in srgb, currentColor 6%, transparent);
  border-radius: var(--peak-form-field-radius);
  /* A long filename must not push the field wider than its column. */
  overflow-wrap: anywhere;
}

.peak-form__file-remove {
  flex: 0 0 auto;
  padding: 0 6px;
  background: none;
  border: 0;
  color: inherit;
  font-size: 1.1em;
  line-height: 1;
  cursor: pointer;
  opacity: 0.6;
}

.peak-form__file-remove:hover {
  opacity: 1;
}

/* ---- errors ---- */

.peak-form__error {
  margin: 0;
  font-size: 0.8125em;
  line-height: 1.35;
  color: var(--peak-form-error);
}

.peak-form__error:empty {
  display: none;
}

.peak-form__field.has-error .peak-form__input,
.peak-form__field.has-error select,
.peak-form__field.has-error .peak-form__file-label {
  border-color: var(--peak-form-error);
}

/* ---- captcha + submit ---- */

.peak-form__captcha:not(:empty) {
  margin-top: var(--peak-form-gap-y);
}

/* Column direction, so ONE property covers both questions the alignment
   setting asks: flex-start / center / flex-end place the button, and `stretch`
   — which does nothing to a child on a row — makes it full width here. */
.peak-form__actions {
  display: flex;
  flex-direction: column;
  align-items: var(--peak-form-submit-align);
  margin-top: var(--peak-form-gap-y);
}

/* Position (Submit Style → Position): the ROW moves, measured from the form.
   Relative nudges it in place; Absolute takes it out of the flow — and its
   top margin with it, or an empty gap would stay where it was. */
.peak-form__form { position: relative; }
.peak-form--submit-relative .peak-form__actions,
.peak-form--submit-absolute .peak-form__actions {
  top: var(--peak-form-submit-ot, auto);
  right: var(--peak-form-submit-or, auto);
  bottom: var(--peak-form-submit-ob, auto);
  left: var(--peak-form-submit-ol, auto);
  z-index: var(--peak-form-submit-z, auto);
}
.peak-form--submit-relative .peak-form__actions { position: relative; }
.peak-form--submit-absolute .peak-form__actions { position: absolute; margin-top: 0; }

/* Everything a state can change is a variable with the old value as its
   fallback — see the note on `.peak-form__choice` above. The three tabs in
   Submit Style write `:hover` and `:active` rules that redefine them. */
.peak-form__submit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-sizing: border-box;
  padding: var(--peak-form-submit-pt, var(--_fp-t))
    var(--peak-form-submit-pr, calc(var(--_fp-r) * 2))
    var(--peak-form-submit-pb, var(--_fp-b))
    var(--peak-form-submit-pl, calc(var(--_fp-l) * 2));
  color: var(--peak-form-submit-color);
  background-color: var(--peak-form-submit-bg);
  background-image: var(--peak-form-submit-bg-i, none);
  border-style: var(--peak-form-submit-bds, none);
  border-color: var(--peak-form-submit-bdc, currentColor);
  border-width: var(--peak-form-submit-bdwt, 1px)
    var(--peak-form-submit-bdwr, 1px) var(--peak-form-submit-bdwb, 1px)
    var(--peak-form-submit-bdwl, 1px);
  border-radius: var(--peak-form-submit-radius);
  box-shadow: 0 0 0 3px var(--peak-form-submit-glow, transparent);
  font-family: var(--peak-form-submit-ff, inherit);
  font-size: var(--peak-form-submit-fs, inherit);
  font-weight: var(--peak-form-submit-fw, inherit);
  line-height: var(--peak-form-submit-lh, inherit);
  letter-spacing: var(--peak-form-submit-ls, normal);
  text-transform: var(--peak-form-submit-tt, none);
  cursor: pointer;
  transition:
    background-color var(--peak-form-dur) ease,
    color var(--peak-form-dur) ease,
    border-color var(--peak-form-dur) ease,
    box-shadow var(--peak-form-dur) ease,
    opacity var(--peak-form-dur) ease;
}

/* Focus is the keyboard's version of hover, and a Hover tab that left it out
   would be a button that changes for the mouse and not for the keyboard. */
.peak-form__submit:focus-visible {
  outline: 2px solid var(--peak-form-accent);
  outline-offset: 2px;
}

.peak-form__submit:disabled {
  cursor: wait;
  opacity: 0.65;
}

.peak-form__submit-icon {
  --peak-icon-size: 1em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.peak-form__spinner {
  display: none;
  width: 1em;
  height: 1em;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: peak-form-spin 0.7s linear infinite;
}

.peak-form.is-sending .peak-form__spinner {
  display: block;
}

.peak-form.is-sending .peak-form__submit-icon {
  display: none;
}

@keyframes peak-form-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .peak-form__spinner {
    animation-duration: 2s;
  }
}

/* ---- result ---- */

.peak-form__result {
  margin-top: var(--peak-form-gap-y);
  line-height: 1.5;
}

.peak-form__result:empty {
  display: none;
}

.peak-form__result.is-error {
  color: var(--peak-form-error);
}

.peak-form__result.is-success {
  color: var(--peak-form-ok);
}

.peak-form__result:focus {
  outline: none;
}

/* ---- editor placeholder ---- */

.peak-form--empty {
  padding: 20px;
  border: 1px dashed currentColor;
  border-radius: var(--peak-form-field-radius);
  opacity: 0.6;
  text-align: center;
}

/* ---- another plugin's form, wearing ours ---- */

.peak-form--external
  input:not([type="submit"]):not([type="checkbox"]):not([type="radio"]),
.peak-form--external textarea,
.peak-form--external select {
  box-sizing: border-box;
  width: 100%;
  padding: var(--_fp-t) var(--_fp-r) var(--_fp-b) var(--_fp-l);
  color: var(--peak-form-field-color);
  background: var(--peak-form-field-bg);
  border: 1px solid var(--peak-form-field-border);
  border-radius: var(--peak-form-field-radius);
  font: inherit;
}

.peak-form--external input[type="submit"],
.peak-form--external button[type="submit"] {
  padding: var(--_fp-t) calc(var(--_fp-r) * 2) var(--_fp-b)
    calc(var(--_fp-l) * 2);
  color: var(--peak-form-submit-color);
  background-color: var(--peak-form-submit-bg);
  background-image: var(--peak-form-submit-bg-i, none);
  border: 0;
  border-radius: var(--peak-form-submit-radius);
  font: inherit;
  cursor: pointer;
}

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

@media (max-width: 600px) {
  /* A 33%-wide input on a phone helps nobody. */
  .peak-form__field.pob-w {
    flex-basis: 100%;
    max-width: 100%;
  }
}

/* ==== custom select =====================================================
 * A native <select> paints its option list in the OS, where no stylesheet can
 * reach it — which is why a "styled" select still drops a grey system menu. The
 * list below is ours; the real <select> stays in the DOM holding the value and
 * the name, so submission, server validation and a no-JS visitor are untouched.
 */

.peak-form__select.is-enhanced select {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.peak-form__select.is-enhanced::after {
  display: none;
}

.peak-select__trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  box-sizing: border-box;
  width: 100%;
  min-height: calc(1.4em + var(--_fp-t) + var(--_fp-b));
  padding: var(--_fp-t) var(--_fp-r) var(--_fp-b) var(--_fp-l);
  background: var(--peak-form-field-bg);
  border: 1px solid var(--peak-form-field-border);
  border-radius: var(--peak-form-field-radius);
  color: var(--peak-form-field-color);
  font-family: var(--peak-form-input-ff, inherit);
  font-size: var(--peak-form-input-fs, 1em);
  font-weight: var(--peak-form-input-fw, 400);
  line-height: var(--peak-form-input-lh, 1.4);
  text-align: left;
  cursor: pointer;
  transition:
    border-color var(--peak-form-dur) ease,
    box-shadow var(--peak-form-dur) ease;
}

.peak-select__trigger:hover {
  border-color: var(--peak-form-accent);
}

.peak-select__trigger:focus-visible,
.peak-form__select.is-open .peak-select__trigger {
  outline: none;
  border-color: var(--peak-form-accent);
  box-shadow: 0 0 0 3px
    color-mix(in srgb, var(--peak-form-accent) 22%, transparent);
}

/* An unset value reads like a placeholder, not like an answer. */
.peak-select__trigger.is-placeholder .peak-select__value {
  opacity: 0.55;
}

.peak-select__value {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.peak-select__chevron {
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  margin-inline-end: 2px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
  opacity: 0.5;
  transition: transform var(--peak-form-dur) ease;
}

.peak-form__select.is-open .peak-select__chevron {
  transform: translateY(1px) rotate(-135deg);
}

/* ---- the floating list ---- */

.peak-select__panel,
.peak-date__panel {
  position: absolute;
  z-index: 40;
  top: calc(100% + 6px);
  left: 0;
  box-sizing: border-box;
  background: var(--peak-form-popover-bg);
  color: var(--peak-form-popover-fg);
  border: 1px solid var(--peak-form-popover-border);
  border-radius: var(--peak-form-popover-radius);
  box-shadow: var(--peak-form-popover-shadow);
  animation: peak-form-pop 0.12s ease;
}

/* Flipped by the runtime when there is no room below. */
.peak-select__panel.is-up,
.peak-date__panel.is-up {
  top: auto;
  bottom: calc(100% + 6px);
}

@keyframes peak-form-pop {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .peak-select__panel,
  .peak-date__panel {
    animation: none;
  }
}

.peak-select__panel {
  min-width: 100%;
  max-height: 280px;
  padding: 4px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.peak-select__option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: calc(var(--peak-form-popover-radius) - 5px);
  font-size: 0.9375em;
  line-height: 1.3;
  cursor: pointer;
  user-select: none;
}

/* Hover and keyboard land on the SAME state, so the two ways of choosing look
   identical rather than fighting each other. */
.peak-select__option.is-active {
  background: var(--peak-form-popover-hover);
}

.peak-select__option.is-placeholder {
  opacity: 0.6;
}

/* The tick marks the current choice without shifting the row's text. */
.peak-select__option::after {
  content: "";
  width: 0.32em;
  height: 0.6em;
  margin-inline-start: auto;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) scale(0);
  transition: transform var(--peak-form-dur) ease;
}

.peak-select__option.is-selected::after {
  transform: rotate(45deg) scale(1);
}

/* ==== custom date picker ================================================
 * Same contract as the select: the <input type="date"> stays, carrying the
 * Y-m-d value and its own min/max; only the OS calendar is replaced.
 */

.peak-date {
  position: relative;
}

.peak-date.is-enhanced input[type="date"] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.peak-date__trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  box-sizing: border-box;
  width: 100%;
  min-height: calc(1.4em + var(--_fp-t) + var(--_fp-b));
  padding: var(--_fp-t) var(--_fp-r) var(--_fp-b) var(--_fp-l);
  background: var(--peak-form-field-bg);
  border: 1px solid var(--peak-form-field-border);
  border-radius: var(--peak-form-field-radius);
  color: var(--peak-form-field-color);
  font: inherit;
  font-size: var(--peak-form-input-fs, 1em);
  line-height: var(--peak-form-input-lh, 1.4);
  text-align: left;
  cursor: pointer;
  transition:
    border-color var(--peak-form-dur) ease,
    box-shadow var(--peak-form-dur) ease;
}

.peak-date__trigger:hover {
  border-color: var(--peak-form-accent);
}

.peak-date__trigger:focus-visible {
  outline: none;
  border-color: var(--peak-form-accent);
  box-shadow: 0 0 0 3px
    color-mix(in srgb, var(--peak-form-accent) 22%, transparent);
}

.peak-date__trigger.is-placeholder .peak-date__value {
  opacity: 0.55;
}

/* A calendar drawn from two boxes: a page with a bound across the top. */
.peak-date__icon {
  position: relative;
  flex: 0 0 auto;
  width: 0.95em;
  height: 0.95em;
  border: 1.5px solid currentColor;
  border-radius: 3px;
  opacity: 0.5;
}

.peak-date__icon::before {
  content: "";
  position: absolute;
  top: 2px;
  left: -1.5px;
  right: -1.5px;
  height: 2px;
  background: currentColor;
}

.peak-date__panel {
  width: 268px;
  padding: 10px;
}

.peak-date__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.peak-date__title {
  font-size: 0.875em;
  font-weight: 600;
}

.peak-date__nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  color: inherit;
  cursor: pointer;
}

.peak-date__nav:hover {
  background: var(--peak-form-popover-hover);
  border-color: var(--peak-form-popover-border);
}

.peak-date__arrow {
  width: 6px;
  height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg) translate(-1px, -1px);
  opacity: 0.7;
}

.peak-date__nav.is-prev .peak-date__arrow {
  transform: rotate(135deg) translate(-1px, -1px);
}

.peak-date__week,
.peak-date__grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.peak-date__week {
  margin-bottom: 4px;
}

.peak-date__week span {
  padding: 4px 0;
  font-size: 0.75em;
  font-weight: 500;
  text-align: center;
  opacity: 0.55;
}

.peak-date__day {
  aspect-ratio: 1;
  padding: 0;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  color: inherit;
  font: inherit;
  font-size: 0.8125em;
  cursor: pointer;
  transition: background-color var(--peak-form-dur) ease;
}

.peak-date__day:hover:not(:disabled) {
  background: var(--peak-form-popover-hover);
}

.peak-date__day:focus-visible {
  outline: none;
  border-color: var(--peak-form-accent);
}

/* Today is outlined, the chosen day is filled — two different facts, so two
   different treatments rather than one fighting the other. */
.peak-date__day.is-today {
  border-color: color-mix(in srgb, currentColor 30%, transparent);
  font-weight: 600;
}

.peak-date__day.is-selected {
  background: var(--peak-form-accent);
  border-color: var(--peak-form-accent);
  color: var(--peak-form-mark);
  font-weight: 600;
}

.peak-date__day:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.peak-date__foot {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--peak-form-popover-border);
}

.peak-date__action {
  flex: 1 1 auto;
  padding: 7px 10px;
  background: none;
  border: 1px solid var(--peak-form-popover-border);
  border-radius: 6px;
  color: inherit;
  font: inherit;
  font-size: 0.8125em;
  cursor: pointer;
}

.peak-date__action:hover {
  background: var(--peak-form-popover-hover);
}

/* Errors mark the control the visitor can see. */
.peak-form__field.has-error .peak-select__trigger,
.peak-form__field.has-error .peak-date__trigger {
  border-color: var(--peak-form-error);
}

@media (max-width: 420px) {
  .peak-date__panel {
    width: min(268px, calc(100vw - 40px));
  }
}
