/*
  PLAT-013 — the generic form-renderer stylesheet. Device-agnostic, RTL-safe, WCAG-aligned, and entirely
  domain-free (no pack/vertical selectors; everything keys off the structural kf-* classes the renderer emits).

  Mobile/Responsive First (PRD §PLAT-013A):
   - columnCount drives an N-column CSS grid on desktop via the --kf-columns custom property; at the 600px
     mobile breakpoint the grid REFLOWS to a single column (WCAG 1.4.10 reflow — usable at 320px with no
     horizontal scrolling). Logical reading order is preserved because DOM order == declared order and we
     never CSS-reorder.
   - RTL/bidi: ALL inset/spacing uses LOGICAL properties (margin-inline / padding-inline / inset-inline-start)
     — there is no hardcoded left/right anywhere — so the layout mirrors under dir="rtl". LTR data embedded in
     RTL UI (IDs, coordinates, case numbers, timestamps) is bidi-isolated.
   - WCAG 2.5.8 target size: interactive controls are >= 44x44 CSS px on every platform.
*/

.kf-form {
  inline-size: 100%;
  max-inline-size: 100%;
  box-sizing: border-box;
}

.kf-section {
  margin-block-end: 1.5rem;
  padding-inline: 0.5rem;
  border-inline-start: 2px solid transparent; /* logical accent, mirrors under RTL */
}

.kf-section-header {
  margin-block: 0 0.5rem;
  text-align: start; /* logical alignment (mirrors under RTL) */
}

/* Desktop: an N-column grid (N = section columnCount). */
.kf-grid {
  display: grid;
  grid-template-columns: repeat(var(--kf-columns, 1), 1fr);
  gap: 0.75rem;
}

.kf-cell {
  grid-column: span min(var(--kf-colspan, 1), var(--kf-columns, 1));
  min-inline-size: 0; /* allow content to shrink, never force horizontal scroll */
}

.kf-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.kf-label {
  text-align: start; /* logical */
}

/* WCAG 2.5.8: interactive targets are at least 44x44 CSS px. */
.kf-input,
.kf-select,
.kf-typeahead,
.kf-textarea,
.kf-native-fallback {
  min-block-size: 44px;
  inline-size: 100%;
  box-sizing: border-box;
  padding-inline: 0.5rem;
}

.kf-textarea {
  min-block-size: 88px;
}

/* Bidi isolation for LTR data embedded in RTL UI (IDs, coordinates, case numbers, timestamps). */
.kf-ltr-data {
  unicode-bidi: isolate;
  direction: ltr;
}

/* Mobile breakpoint: reflow EVERY grid to a single column (WCAG 1.4.10). */
@media (max-width: 600px) {
  .kf-grid {
    grid-template-columns: 1fr;
  }

  .kf-cell {
    grid-column: span 1;
  }

  /* mobilePriority=secondary sections are deferred (collapsed) on phones. */
  .kf-mobile-secondary {
    order: 1;
    opacity: 0.96;
  }
}

/* =============================================================================
   Lookup COMBOBOX — the generic pick-or-write control that replaces the native
   <select> Dropdown (LookupComboBox.razor). STRUCTURE ONLY here (device-agnostic,
   RTL-safe, token-free for MAUI parity); the brand SKIN (colours, surfaces, the
   chevron colour, dark/outdoor flips) lives in the web design-system stylesheet.
   The hidden native <select> mirror is never painted.
   ========================================================================== */
.kf-combobox {
  position: relative;
  inline-size: 100%;
  box-sizing: border-box;
}

.kf-combobox-native {
  display: none;
}

/* FIX (Task-30): NATIVE MOBILE picker. A combobox opted in with NativeOnMobile (root .kf-combobox--native-mobile)
   swaps its custom pick-or-write popup — which drops UNDER the field and will not track scroll on a touch device —
   for the hidden native <select> mirror on phones (≤640px), so it uses the OS's native picker like the sibling
   native selects. CSS-only: the committed value + the data-testid/anchor already ride the native <select>. The
   author display + the box styling below outrank both `.kf-combobox-native{display:none}` and the `hidden` attribute
   (author > UA). Desktop (>640px) is untouched — the combobox control stays the interactive surface. */
@media (max-width: 640px) {
  .kf-combobox--native-mobile .kf-combobox-control { display: none; }
  .kf-combobox--native-mobile .kf-combobox-listbox,
  .kf-combobox--native-mobile .kf-combobox-addpopup { display: none; }
  .kf-combobox--native-mobile .kf-combobox-native {
    display: block;
    position: static;
    inline-size: 100%;
    box-sizing: border-box;
    min-block-size: var(--k-touch, 48px);
    padding: 0 var(--k-space-3, 0.75rem);
    font: inherit;
    font-size: 16px; /* ≥16px so mobile Safari never zooms on focus */
    color: var(--k-text);
    background: var(--k-surface);
    border: 1px solid var(--k-outline, var(--k-border));
    border-radius: var(--k-radius-sm);
  }
}

/* The visible box: a flex row holding chips (multi) + the borderless text input, with the chevron pinned to the
   trailing (logical) edge. WCAG 2.5.8: at least 44px tall. */
.kf-combobox-control {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  min-block-size: 44px;
  inline-size: 100%;
  box-sizing: border-box;
  padding-inline: 0.5rem;
  padding-inline-end: 2rem; /* reserve room for the trailing chevron */
}

/* The inner input is borderless/transparent — the wrapper IS the box (so chips sit inside one field, and the focus
   ring is one ring on the whole control). A reset is needed because the generic input rule would otherwise box it. */
.kf-combobox-input {
  flex: 1 1 6ch;
  min-inline-size: 4ch;
  min-block-size: 42px;
  border: 0;
  background: transparent;
  outline: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
}

/* The chevron's container is HALF the control height, vertically centered (the owner wanted the DIV around the
   chevron half-height, not the glyph). The flex box then centers the chevron within it. */
/* The chevron is drawn BARE on the box (no button wrapper — a <button> attracts UA + global touch-target min-height
   that overflowed the control top/bottom). It is a small, absolutely-positioned, vertically-centered FontAwesome icon
   (.ki ki-chevron-down / ki-chevron-up); the open/closed glyph swaps in the markup. A bare span is exactly the glyph's
   size, so it can never exceed the control height. The control reserves trailing padding so text never runs under it. */
.kf-combobox-chevron {
  position: absolute;
  inset-inline-end: 0.6rem;
  inset-block-start: 50%;
  transform: translateY(-50%);
  font-size: 0.72rem;
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;
}
.kf-combobox--disabled .kf-combobox-chevron { cursor: not-allowed; }

/* Selected-value chips (multi). */
.kf-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  max-inline-size: 100%;
  padding-inline: 0.4rem;
  padding-block: 0.1rem;
  border-radius: 999px;
  font-size: 0.85em;
  line-height: 1.4;
}
.kf-chip-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kf-chip-remove {
  border: 0;
  background: transparent;
  cursor: pointer;
  line-height: 1;
  font-size: 1.1em;
  padding: 0 0.15rem;
  min-block-size: auto;
}

/* The popover listbox (positioned fixed by the interop module so no clip ancestor cuts it off; these are fallbacks
   for the no-JS / pre-position frame). */
.kf-combobox-listbox {
  list-style: none;
  margin: 0;
  padding: 0.25rem;
  position: absolute;
  inset-inline-start: 0;
  inset-block-start: calc(100% + 0.25rem);
  inline-size: 100%;
  box-sizing: border-box;
  max-block-size: 280px;
  overflow-y: auto;
  border-radius: 0.5rem;
  z-index: 1200;
}
.kf-combobox-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-block-size: 36px;
  padding: 0.35rem 0.5rem;
  border-radius: 0.35rem;
  cursor: pointer;
}
.kf-combobox-option-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kf-combobox-option-hint { flex: none; font-size: 0.78em; opacity: 0.75; white-space: nowrap; }
.kf-combobox-empty { padding: 0.5rem; opacity: 0.75; }

/* The blur add-confirm popup (the owner's "ask to add on losing focus"). */
.kf-combobox-addpopup {
  position: absolute;
  inset-inline-start: 0;
  inset-block-start: calc(100% + 0.25rem);
  inline-size: min(24rem, 92vw);
  box-sizing: border-box;
  padding: 0.75rem;
  border-radius: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 1300;
}
.kf-combobox-addpopup-q { margin: 0; }
.kf-combobox-addpopup-term { font-weight: 700; }
.kf-combobox-addpopup-suggest { display: flex; flex-direction: column; gap: 0.25rem; }
.kf-combobox-addpopup-suggest-head { font-size: 0.8em; opacity: 0.8; }
.kf-combobox-addpopup-suggest-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.2rem; }
.kf-combobox-useexisting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  inline-size: 100%;
  min-block-size: 36px;
  padding: 0.3rem 0.5rem;
  border: 0;
  border-radius: 0.35rem;
  cursor: pointer;
  text-align: start;
}
.kf-combobox-useexisting-action { flex: none; font-size: 0.8em; }
.kf-combobox-addpopup-field { display: flex; flex-direction: column; gap: 0.2rem; }
.kf-combobox-addpopup-advanced { display: flex; flex-direction: column; gap: 0.25rem; }
.kf-combobox-addpopup-advtoggle {
  align-self: flex-start;
  border: 0; background: transparent; cursor: pointer;
  font-size: 0.82em; padding: 0; text-decoration: underline; min-block-size: auto;
}
.kf-combobox-addpopup-actions { display: flex; justify-content: flex-end; gap: 0.5rem; }
.kf-combobox-addpopup-warn { margin: 0; font-size: 0.88em; }
.kf-combobox-proposed-note { display: block; margin-block-start: 0.2rem; font-size: 0.82em; }
