/* ============================================================================
   Search emphasis — canonical search-input pattern
   ----------------------------------------------------------------------------
   Used wherever the user types text to scope a list:
   - Services Availed dashboard
   - Client Records page
   - Pending obligations
   - Reports (inline card filter — uses --sm)
   - Program category recipients (inline card filter — uses --sm)

   Markup contract (rendered by views/partials/search_box.php):

     <div class="app-search [app-search--sm] [app-search--has-value]">
       <span class="app-search__icon" aria-hidden="true">…magnifier svg…</span>
       <input type="search" class="form-input app-search__input" …>
       <button type="button" class="app-search__clear" aria-label="Clear search">…×…</button>
     </div>

   The wrapper is positioned and sized; the input keeps .form-input for inheritance
   so other surfaces don't disagree about colour, font, height baseline.
   ============================================================================ */

:root {
  /* Canonical search halo — derived from --rose-500 (#f54a7d).
     Defining as a CSS var lets us tune one value and have every search field
     and the .search-hero__field on programs/service.php agree. */
  --search-halo:        rgba(245, 74, 125, 0.16);
  --search-halo-strong: rgba(245, 74, 125, 0.45);
}

/* When .app-search lives in a .filter-bar, center the row so the taller
   search input doesn't drag the smaller filters to its top edge. */
.filter-bar:has(.app-search) { align-items: center; }
/* :has() fallback for older browsers — no harm if it doesn't match. */
.filter-bar.filter-bar--has-search { align-items: center; }

.app-search {
  position: relative;
  flex: 2 1 320px;
  min-width: 240px;
  display: flex;
  align-items: center;
}

/* When the search box sits inside a .reports-card__inline-filter (compact
   header context), don't try to dominate the row — keep proportional. */
.app-search--sm {
  flex: 1 1 220px;
  min-width: 180px;
}

.app-search__icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  color: var(--rose-500);
  pointer-events: none;
  transition:
    color var(--motion-fast) var(--ease-standard),
    transform var(--motion-fast) var(--ease-standard);
}

.app-search--sm .app-search__icon {
  left: 11px;
}

.app-search__input.form-input {
  /* Emphasis without breaking native input layout ------------------------
     Earlier revision used height: 52px + padding: 0 — that combo can
     interact badly with native input shape on some browsers. Back to
     standard padding-driven sizing (matches every other .form-input on
     the page), but keep the larger font-size, 2px rose border, and the
     icon padding. Visual emphasis comes from the border + halo + icon,
     not from forcing a fixed height. */
  width: 100%;
  padding: 0.7rem 2.6rem 0.7rem 2.7rem;
  font-size: var(--fs-15);
  font-weight: 500;
  color: var(--text-primary);
  background: var(--surface-raised);
  border: 2px solid var(--rose-300);
  border-radius: var(--r-lg);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.7) inset,
    0 1px 2px rgba(60, 28, 38, 0.04);
  transition:
    border-color var(--motion-fast) var(--ease-standard),
    box-shadow var(--motion-ui) var(--ease-standard),
    background var(--motion-fast) var(--ease-standard);
}

.app-search--sm .app-search__input.form-input {
  height: 38px;
  padding: 0 2.1rem 0 2.25rem;
  font-size: var(--fs-14);
  border-radius: var(--r-md);
  border-width: 1px;
  background: var(--surface-raised);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.6) inset,
    0 1px 2px rgba(60, 28, 38, 0.04);
}

.app-search__input.form-input::placeholder {
  color: var(--text-muted);
  font-weight: 400;
}

.app-search__input.form-input:hover {
  border-color: var(--rose-500);
}

.app-search__input.form-input:focus {
  outline: 0;
  border-color: var(--rose-500);
  background: #fff;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.85) inset,
    0 0 0 4px var(--search-halo),
    0 6px 14px -8px var(--search-halo-strong);
}

.app-search--sm .app-search__input.form-input:focus {
  transform: none;
  box-shadow:
    0 0 0 3px var(--search-halo),
    0 1px 0 rgba(255,255,255,0.6) inset;
}

.app-search:focus-within .app-search__icon {
  transform: translateY(-50%) scale(1.08);
}

/* Strip native [type=search] clear so we don't render two affordances */
.app-search__input[type="search"]::-webkit-search-decoration,
.app-search__input[type="search"]::-webkit-search-cancel-button,
.app-search__input[type="search"]::-webkit-search-results-button,
.app-search__input[type="search"]::-webkit-search-results-decoration {
  -webkit-appearance: none;
  appearance: none;
}

/* Clear (×) — visible only when input has a value */
.app-search__clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  display: none;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  transition:
    background var(--motion-fast) var(--ease-standard),
    color var(--motion-fast) var(--ease-standard);
}

.app-search--sm .app-search__clear {
  width: 22px;
  height: 22px;
  right: 6px;
}

.app-search--has-value .app-search__clear {
  display: inline-flex;
}

.app-search__clear:hover {
  background: var(--rose-50);
  color: var(--rose-500);
}

.app-search__clear:focus-visible {
  outline: 2px solid var(--rose-500);
  outline-offset: 2px;
}

/* Submit-icon button (rendered when partial is called with submit=true).
   Sits inside the input, like a Stripe/Linear search submit. */
.app-search__submit {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  display: none;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: var(--r-md);
  background: var(--rose-500);
  color: #fff;
  cursor: pointer;
  padding: 0;
  transition:
    background var(--motion-fast) var(--ease-standard),
    transform var(--motion-fast) var(--ease-standard);
}

.app-search--has-submit .app-search__submit {
  display: inline-flex;
}

.app-search--has-submit.app-search--has-value .app-search__submit {
  /* When clear is also showing, push submit further left of clear */
  right: 38px;
}

.app-search__submit:hover {
  background: var(--rose-600, #e23270);
}

.app-search__submit:focus-visible {
  outline: 2px solid var(--rose-500);
  outline-offset: 2px;
}

/* The icon nudges colour when the field is focused, signalling target lock */
@media (prefers-reduced-motion: reduce) {
  .app-search__input.form-input,
  .app-search__icon,
  .app-search__clear,
  .app-search__submit {
    transition: none;
  }
  .app-search:focus-within .app-search__icon { transform: translateY(-50%); }
}

@media (max-width: 720px) {
  .app-search {
    flex-basis: 100%;
  }
}

/* When auto-submit-filter.js is alive, the redundant "Apply filters" button
   visually fades but stays in the tab order for screen readers + a no-script
   fallback. Reset stays clickable, the search box is the actual UI. */
.btn--auto-submit-hidden {
  opacity: 0.45;
  font-size: var(--fs-12);
  padding: 4px 10px;
  cursor: default;
}
.btn--auto-submit-hidden::before {
  content: 'auto · ';
  color: var(--rose-500);
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-size: var(--fs-11);
}

/* ----- Hero variant on programs/service.php ---------------------------------
   Already styled by .search-hero__* in pages/programs.css. We just
   harmonize the focus halo so it agrees with this canonical token. */
.search-hero__field:focus-within {
  box-shadow: 0 0 0 4px var(--search-halo);
}

/* ============================================================================
   Typeahead dropdown — used when the search box has data-typeahead="clients".
   ============================================================================ */
.filter-typeahead {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 50;
  max-height: 360px;
  overflow-y: auto;
  background: var(--surface-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--r-lg);
  box-shadow:
    0 12px 28px -10px rgba(60, 28, 38, 0.18),
    0 2px 6px rgba(60, 28, 38, 0.06);
  padding: 4px;
}

.filter-typeahead__row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 8px 10px;
  border: 0;
  background: transparent;
  border-radius: var(--r-md);
  text-align: left;
  cursor: pointer;
  transition:
    background var(--motion-fast) var(--ease-standard),
    color var(--motion-fast) var(--ease-standard);
  font: inherit;
  color: var(--text-primary);
}

.filter-typeahead__row.is-highlighted,
.filter-typeahead__row:hover {
  background: var(--rose-50);
}

.filter-typeahead__avatar {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--mauve-200), var(--rose-200));
  color: var(--mauve-800);
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: var(--fs-12);
  font-family: var(--font-display);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.filter-typeahead__body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.filter-typeahead__name {
  font-weight: 600;
  font-size: var(--fs-14);
  color: var(--mauve-900);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filter-typeahead__meta {
  font-size: var(--fs-12);
  color: var(--text-muted);
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filter-typeahead__chevron {
  flex-shrink: 0;
  color: var(--text-muted);
  display: inline-flex;
  opacity: 0;
  transform: translateX(-4px);
  transition:
    opacity var(--motion-fast) var(--ease-standard),
    transform var(--motion-fast) var(--ease-standard),
    color var(--motion-fast) var(--ease-standard);
}

.filter-typeahead__row.is-highlighted .filter-typeahead__chevron,
.filter-typeahead__row:hover .filter-typeahead__chevron {
  opacity: 1;
  transform: translateX(0);
  color: var(--rose-500);
}

.filter-typeahead__empty {
  padding: var(--sp-3);
  font-size: var(--fs-13);
  color: var(--text-muted);
  text-align: center;
}

.filter-typeahead__more {
  padding: 6px 10px;
  border-top: 1px dashed var(--border-subtle);
  margin-top: 2px;
  font-size: var(--fs-12);
  color: var(--text-muted);
  text-align: center;
  font-style: italic;
}

@media (prefers-reduced-motion: reduce) {
  .filter-typeahead__row,
  .filter-typeahead__chevron {
    transition: none;
  }
}
