/* ============================================
   forms.css: fields, inputs, selects, checkboxes, the dual price range
   (owner A1, see .claude/md files/redesign-spec.md section 3)

   Field:
     <div class="bl-field">                       (.is-invalid for the error look)
       <label class="bl-field__label" for="email">Email</label>
       <input class="bl-input" id="email" type="email" aria-describedby="email-hint">
       <p class="bl-field__hint" id="email-hint">We never share it.</p>
       <p class="bl-field__error">Enter a valid email.</p>
     </div>
   ASP.NET validation classes (.input-validation-error, .field-validation-error) style the same.

   Prefix:   <span class="bl-affix"><span class="bl-affix__text" aria-hidden="true">$</span>
               <input class="bl-input" …></span>
   Select:   <select class="bl-select">…</select>   (a bare <select> directly inside .bl-field
             gets the same look; .bl-select--bare = text-like, for a heading picker). Always
             the native control: keyboard, phone pickers, posts and validation stay the browser's.
   Checkbox: <label class="bl-checkbox"><input type="checkbox" name="x"><span>Pool</span></label>
             (works for type="radio" too; .bl-checkbox--switch draws an on/off switch)

   Price range (two sliders + two boxes; the boxes carry the names, so without JS the boxes
   alone submit and the sliders stay hidden; a box left empty means "no limit"):
     <div class="bl-range" data-range data-prefix="$">
       <div class="bl-range__track">
         <input type="range" data-range-low  min="0" max="1000" step="10" aria-label="Minimum price">
         <input type="range" data-range-high min="0" max="1000" step="10" aria-label="Maximum price">
       </div>
       <div class="bl-range__boxes">
         <div class="bl-field"> <label class="bl-field__label" for="minPrice">Minimum</label>
           <span class="bl-affix"><span class="bl-affix__text" aria-hidden="true">$</span>
           <input class="bl-input" id="minPrice" name="minPrice" type="number" inputmode="numeric"
                  min="0" max="1000" placeholder="0" data-range-low-box></span></div>
         <span class="bl-range__dash" aria-hidden="true"></span>
         <div class="bl-field"> … name="maxPrice" placeholder="1000+" data-range-high-box … </div>
       </div>
     </div>
   ============================================ */

/* --- Field --- */
.bl-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.bl-field__label {
  color: var(--color-ink);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
}

.bl-field__hint {
  margin: 0;
  color: var(--color-text-muted);
  font-size: 13px;
  line-height: 1.4;
}

.bl-field__error,
.bl-field .field-validation-error {
  margin: 0;
  color: var(--color-danger);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
}

.bl-field__error:empty,
.bl-field .field-validation-valid {
  display: none;
}

/* --- Input / select shared look --- */
.bl-input,
.bl-select,
:where(.bl-field) > select {
  /* Field outline: the ink at low strength reads calmer than grey and stays visible. */
  --bl-field-border: var(--color-border);
  --bl-field-border-hover: var(--color-text-light);

  display: block;
  width: 100%;
  min-height: 48px;
  padding: 0 var(--space-4);
  border: 1px solid var(--bl-field-border);
  border-radius: var(--radius-lg);
  background-color: var(--color-surface);
  color: var(--color-ink);
  font-family: var(--font-family);
  /* 16px keeps iOS from zooming the page on focus. */
  font-size: 16px;
  font-weight: 400;
  line-height: 1.4;
  transition:
    border-color var(--duration-fast) var(--ease-out),
    background-color var(--duration-fast) var(--ease-out);
}

@supports (color: color-mix(in srgb, red 50%, blue)) {
  .bl-input,
  .bl-select,
  :where(.bl-field) > select {
    --bl-field-border: color-mix(in srgb, var(--color-ink) 22%, var(--color-surface));
    --bl-field-border-hover: color-mix(in srgb, var(--color-ink) 48%, var(--color-surface));
  }
}

/* iOS Safari sizes a native date or time input to its own content and ignores width: 100%, so
   the field ran past its card on phones (the wizard's check-in/out and music times). Dropping the
   native look and the content-based minimum keeps it in the column; a tap still opens the phone's
   wheel. */
.bl-input:is([type="date"], [type="time"], [type="datetime-local"], [type="month"]) {
  min-width: 0;
  -webkit-appearance: none;
  appearance: none;
}

/* iOS centres the value once the native look is gone; keep it where every other field's text is. */
.bl-input::-webkit-date-and-time-value {
  text-align: left;
}

/* iPhone and iPad only (the one engine with -webkit-touch-callout): Safari lays these inputs out
   as a flex row that centres the value vertically, and .bl-input's display: block undid it, so
   without the native look the time sat at the top of the box. The flex row (block-level, so the
   field still takes the column's width) puts it back. Not for Chrome or desktop Safari: they
   centre the value on their own, and in Chrome a flex row pulls the clock icon off the edge. */
@supports (-webkit-touch-callout: none) {
  .bl-input:is([type="date"], [type="time"], [type="datetime-local"], [type="month"]) {
    display: flex;
    align-items: center;
  }
}

textarea.bl-input {
  min-height: 112px;
  padding: var(--space-3) var(--space-4);
  resize: vertical;
}

.bl-input::placeholder {
  color: var(--color-text-light);
  opacity: 1;
}

@media (hover: hover) and (pointer: fine) {
  .bl-input:hover,
  .bl-select:hover,
  :where(.bl-field) > select:hover {
    border-color: var(--bl-field-border-hover);
  }
}

.bl-input:focus,
.bl-select:focus,
:where(.bl-field) > select:focus {
  outline: none;
  border-color: var(--green-600);
}

.bl-input:focus-visible,
.bl-select:focus-visible,
:where(.bl-field) > select:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

.bl-input:disabled,
.bl-select:disabled,
:where(.bl-field) > select:disabled {
  background-color: var(--color-surface-muted);
  color: var(--color-text-light);
  cursor: not-allowed;
}

.bl-field.is-invalid .bl-input,
.bl-field.is-invalid .bl-select,
.bl-field.is-invalid > select,
.bl-input.input-validation-error,
.bl-select.input-validation-error,
.bl-field > select.input-validation-error,
.bl-input[aria-invalid="true"],
.bl-select[aria-invalid="true"],
.bl-field > select[aria-invalid="true"] {
  border-color: var(--color-danger);
}

.bl-input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

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

/* --- Select ---
   The browser's own <select> (keyboard, the phone's wheel or sheet, posts, validation) with the
   default arrow switched off and our chevron drawn instead: two crossing 7px gradient strokes
   in --bl-select-arrow (the ink; muted while disabled), so no image asset and no hex. Text and
   padding line up with .bl-input (48px tall, 16px text so iOS doesn't zoom). Light only:
   color-scheme keeps a dark OS from painting the option list dark. */
.bl-select,
:where(.bl-field) > select {
  --bl-select-arrow: var(--color-ink);
  --bl-select-stroke:
    transparent calc(50% - 1.5px),
    var(--bl-select-arrow) calc(50% - 0.75px) calc(50% + 0.75px),
    transparent calc(50% + 1.5px);

  /* Block padding instead of relying on the engine to centre the text (Safari doesn't). */
  padding: 11px var(--space-10) 11px var(--space-4);
  line-height: 24px;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  color-scheme: light;
  background-image:
    linear-gradient(45deg, var(--bl-select-stroke)),
    linear-gradient(-45deg, var(--bl-select-stroke));
  background-position:
    right 23px center,
    right var(--space-4) center;
  background-size: 7px 7px;
  background-repeat: no-repeat;
  cursor: pointer;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Old Edge / IE arrow. */
.bl-select::-ms-expand,
:where(.bl-field) > select::-ms-expand {
  display: none;
}

/* The option list keeps ink on white even while the closed control shows a muted placeholder. */
.bl-select option,
.bl-select optgroup,
:where(.bl-field) > select option,
:where(.bl-field) > select optgroup {
  color: var(--color-ink);
  background-color: var(--color-surface);
}

/* A placeholder choice ("Select a district", value="") reads muted until a real one is picked. */
.bl-select:not(:disabled):has(> option[value=""]:checked),
:where(.bl-field) > select:not(:disabled):has(> option[value=""]:checked) {
  color: var(--color-text-muted);
}

.bl-select:disabled,
:where(.bl-field) > select:disabled {
  --bl-select-arrow: var(--color-text-light);
}

/* Kept apart: a browser that doesn't know :user-invalid drops only this rule. */
.bl-select:user-invalid,
:where(.bl-field) > select:user-invalid {
  border-color: var(--color-danger);
}

/* A list box (multiple, or size > 1) has no arrow. */
.bl-select:is([multiple], [size]:not([size="1"])),
:where(.bl-field) > select:is([multiple], [size]:not([size="1"])) {
  padding: var(--space-2);
  background-image: none;
  white-space: normal;
}

/* Text-like picker for a heading ("October 2026"): no box, the font of its parent, the chevron
   kept. Width follows the text when the parent lets it shrink (inline-block, width auto). */
.bl-select--bare {
  display: inline-block;
  width: auto;
  min-height: 44px;
  padding: 0 26px 0 var(--space-1);
  border-color: transparent;
  border-radius: var(--radius-sm);
  background-color: transparent;
  background-position:
    right 11px center,
    right var(--space-1) center;
  color: inherit;
  font: inherit;
  line-height: 44px;
}

@media (hover: hover) and (pointer: fine) {
  .bl-select--bare:hover {
    border-color: transparent;
    background-color: var(--color-surface-muted);
  }
}

.bl-select--bare:focus {
  border-color: transparent;
}

/* Windows high contrast drops background images: give the native arrow back. */
@media (forced-colors: active) {
  .bl-select,
  :where(.bl-field) > select {
    -webkit-appearance: auto;
    appearance: auto;
    padding-right: var(--space-4);
    background-image: none;
  }
}

/* --- Prefix ($) inside an input --- */
.bl-affix {
  position: relative;
  display: block;
}

.bl-affix__text {
  position: absolute;
  top: 50%;
  left: var(--space-4);
  translate: 0 -50%;
  color: var(--color-text-muted);
  font-size: 16px;
  pointer-events: none;
}

.bl-affix .bl-input {
  padding-left: calc(var(--space-4) + 1.1em);
}

/* --- Checkbox / radio --- */
.bl-checkbox {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 44px;
  color: var(--color-ink);
  font-size: 16px;
  line-height: 1.35;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.bl-checkbox input {
  position: relative;
  flex: none;
  width: 22px;
  height: 22px;
  margin: 0;
  border: 1.5px solid var(--color-text-light);
  border-radius: 6px;
  background-color: var(--color-surface);
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  transition:
    background-color var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out);
}

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

/* Check mark: an L rotated 45°, drawn in the surface colour on the green fill. */
.bl-checkbox input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 6.5px;
  width: 6px;
  height: 11px;
  border: solid var(--color-surface);
  border-width: 0 2px 2px 0;
  rotate: 45deg;
  opacity: 0;
  scale: 0.6;
  transition:
    opacity var(--duration-fast) var(--ease-out),
    scale var(--duration-fast) var(--ease-out);
}

.bl-checkbox input[type="radio"]::after {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  background-color: var(--color-surface);
  opacity: 0;
  scale: 0.4;
  transition:
    opacity var(--duration-fast) var(--ease-out),
    scale var(--duration-fast) var(--ease-out);
}

.bl-checkbox input:checked {
  background-color: var(--green-600);
  border-color: var(--green-600);
}

.bl-checkbox input:checked::after {
  opacity: 1;
  scale: 1;
}

@media (hover: hover) and (pointer: fine) {
  .bl-checkbox:hover input:not(:checked):not(:disabled) {
    border-color: var(--color-ink);
  }
}

.bl-checkbox input:focus {
  outline: none;
}

.bl-checkbox input:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

.bl-checkbox input:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.bl-checkbox input:disabled + * {
  color: var(--color-text-light);
}

/* Switch: <label class="bl-checkbox bl-checkbox--switch"><span>Pets</span>
           <input type="checkbox" role="switch" name="pets" value="true"></label> */
.bl-checkbox--switch {
  justify-content: space-between;
}

.bl-checkbox--switch input[type="checkbox"] {
  width: 44px;
  height: 26px;
  border: 0;
  border-radius: var(--radius-pill);
  background-color: var(--color-border);
}

.bl-checkbox--switch input[type="checkbox"]::after {
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 50%;
  background-color: var(--color-surface);
  box-shadow: var(--shadow-1);
  rotate: none;
  opacity: 1;
  scale: 1;
  transition: translate var(--duration-base) var(--ease-out);
}

.bl-checkbox--switch input[type="checkbox"]:checked {
  background-color: var(--green-600);
}

.bl-checkbox--switch input[type="checkbox"]:checked::after {
  translate: 18px 0;
}

/* --- Dual price range --- */
.bl-range {
  /* 0..1 fractions written by ui.js */
  --bl-range-low: 0;
  --bl-range-high: 1;
  --bl-range-thumb: 44px;

  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* The sliders only make sense with JS: the number boxes work on their own. */
.bl-range__track {
  display: none;
  position: relative;
  height: var(--bl-range-thumb);
}

.bl-range.is-ready .bl-range__track {
  display: block;
}

/* Rail and the green fill between the two thumbs. */
.bl-range__track::before,
.bl-range__track::after {
  content: "";
  position: absolute;
  top: 50%;
  height: 4px;
  margin-top: -2px;
  border-radius: var(--radius-pill);
  pointer-events: none;
}

.bl-range__track::before {
  left: calc(var(--bl-range-thumb) / 2);
  right: calc(var(--bl-range-thumb) / 2);
  background-color: var(--color-border-light);
}

.bl-range__track::after {
  left: calc(var(--bl-range-thumb) / 2 + (100% - var(--bl-range-thumb)) * var(--bl-range-low));
  right: calc(var(--bl-range-thumb) / 2 + (100% - var(--bl-range-thumb)) * (1 - var(--bl-range-high)));
  background-color: var(--green-600);
}

.bl-range__track input[type="range"] {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  pointer-events: none;
}

.bl-range.is-low-top [data-range-low] {
  z-index: 2;
}

.bl-range__track input[type="range"]:focus {
  outline: none;
}

.bl-range__track input[type="range"]::-webkit-slider-runnable-track {
  height: var(--bl-range-thumb);
  background: transparent;
  border: 0;
}

.bl-range__track input[type="range"]::-moz-range-track {
  height: var(--bl-range-thumb);
  background: transparent;
  border: 0;
}

/* Thumb: a 44px hit area drawn as a 26px white disc with a green rim (no shadow box),
   plus a 2px focus ring 2px out when focused from the keyboard. */
.bl-range__track input[type="range"]::-webkit-slider-thumb {
  width: var(--bl-range-thumb);
  height: var(--bl-range-thumb);
  border: 0;
  border-radius: 50%;
  background: radial-gradient(circle closest-side,
    var(--color-surface) 0 10px,
    var(--green-600) 10.5px 13px,
    transparent 13.5px);
  -webkit-appearance: none;
  appearance: none;
  pointer-events: auto;
  cursor: grab;
}

.bl-range__track input[type="range"]::-moz-range-thumb {
  width: var(--bl-range-thumb);
  height: var(--bl-range-thumb);
  border: 0;
  border-radius: 50%;
  background: radial-gradient(circle closest-side,
    var(--color-surface) 0 10px,
    var(--green-600) 10.5px 13px,
    transparent 13.5px);
  pointer-events: auto;
  cursor: grab;
}

.bl-range__track input[type="range"]:active::-webkit-slider-thumb {
  cursor: grabbing;
}

.bl-range__track input[type="range"]:focus-visible::-webkit-slider-thumb {
  background: radial-gradient(circle closest-side,
    var(--color-surface) 0 10px,
    var(--green-600) 10.5px 13px,
    transparent 13.5px 15px,
    var(--color-focus) 15.5px 17.5px,
    transparent 18px);
}

.bl-range__track input[type="range"]:focus-visible::-moz-range-thumb {
  background: radial-gradient(circle closest-side,
    var(--color-surface) 0 10px,
    var(--green-600) 10.5px 13px,
    transparent 13.5px 15px,
    var(--color-focus) 15.5px 17.5px,
    transparent 18px);
}

.bl-range__boxes {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: end;
  gap: var(--space-3);
}

.bl-range__dash {
  width: 12px;
  height: 1.5px;
  margin-bottom: 24px;
  background-color: var(--color-text-light);
}

@media (prefers-reduced-motion: reduce) {
  .bl-checkbox input[type="checkbox"]::after,
  .bl-checkbox input[type="radio"]::after {
    transition: opacity var(--duration-fast) var(--ease-out);
  }

  .bl-checkbox--switch input[type="checkbox"]::after {
    transition: none;
  }
}
