/*
 * Clonable Search Widget - expandable field
 *
 * Loaded only when "Expandable search field" is enabled in the Clonable settings.
 *
 * Works on top of the default or custom widget stylesheet, and on its own when the
 * default styling is disabled: every --csw-* colour token has a fallback here.
 *
 * Tokens you can override on .clonable-search-widget-wrapper.clonable-search-expandable:
 *   --csw-toggle-size      size of the button and height of the field
 *   --csw-expand-width     width of the expanded field
 *   --csw-expand-duration  duration of the expand animation
 */

/* --- WIDGET ---------------------------------------------------------------
   Collapsed footprint = the button. The field is taken out of the flow. */

/* Single class: overrides from a stylesheet loaded earlier still win. */
.clonable-search-expandable {
  --csw-toggle-size: 2.75rem;
  --csw-expand-width: 320px;
  --csw-expand-duration: 0.2s;
}

.clonable-search-widget-wrapper.clonable-search-expandable {
  display: inline-block;
  position: relative;
  width: auto;
  max-width: none;
  vertical-align: middle;
}

/* --- TOGGLE BUTTON ------------------------------------***/
.clonable-search-widget-wrapper.clonable-search-expandable
  .clonable-search-toggle {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  z-index: 10000;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: var(--csw-toggle-size);
  height: var(--csw-toggle-size);
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  box-shadow: none;
  color: var(--csw-muted, currentColor);
  font: inherit;
  line-height: 1;
  cursor: pointer;
  transition: color 0.2s ease;
}

.clonable-search-widget-wrapper.clonable-search-expandable
  .clonable-search-toggle:hover,
.clonable-search-widget-wrapper.clonable-search-expandable.is-expanded
  .clonable-search-toggle {
  color: var(--csw-text, currentColor);
}

.clonable-search-widget-wrapper.clonable-search-expandable
  .clonable-search-toggle:focus-visible {
  outline: 2px solid var(--csw-accent, currentColor);
  outline-offset: 2px;
}

.clonable-search-widget-wrapper.clonable-search-expandable
  .clonable-search-toggle-icon {
  display: block;
  width: 1.4em;
  height: 1.4em;
  fill: currentColor;
  pointer-events: none;
}

.clonable-search-widget-wrapper.clonable-search-expandable
  .clonable-search-toggle-label {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

/* --- PANEL ----------------------------------------------------------------
  Absolute, so the open field overlaps its neighbours 
*/

.clonable-search-widget-wrapper.clonable-search-expandable
  .clonable-search-expand-panel {
  position: absolute;
  top: 0;
  left: 0;
  right: auto;
  z-index: 9999;
  visibility: hidden;
  transition: visibility 0s linear var(--csw-expand-duration);
}

.clonable-search-widget-wrapper.clonable-search-expandable.is-expanded
  .clonable-search-expand-panel {
  visibility: visible;
  transition-delay: 0s;
}

.clonable-search-widget-wrapper.clonable-search-expandable[data-clonable-expand="left"]
  .clonable-search-expand-panel {
  left: auto;
  right: 0;
}

/* --- FIELD ----------------------------------------------------------------
   Grows from button size to full width. 
*/

.clonable-search-widget-wrapper.clonable-search-expandable
  .clonable-search-input-wrapper {
  display: block;
  position: relative;
  width: var(--csw-toggle-size);
  min-width: 0;
  max-width: none;
  opacity: 0;
  transition:
    width var(--csw-expand-duration) ease,
    opacity var(--csw-expand-duration) ease;
}

.clonable-search-widget-wrapper.clonable-search-expandable.is-expanded
  .clonable-search-input-wrapper {
  width: var(--csw-expand-width);
  width: min(var(--csw-expand-width), var(--csw-expand-available, 100vw));
  opacity: 1;
}

/* The button is the icon */
.clonable-search-widget-wrapper.clonable-search-expandable
  .clonable-search-input-wrapper::after {
  content: none;
}

.clonable-search-widget-wrapper.clonable-search-expandable
  input[data-clonable-search] {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  max-width: none;
  height: var(--csw-toggle-size);
  min-height: 0;
  margin: 0;
  padding: 0;
  transition:
    padding var(--csw-expand-duration) ease,
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

/* -- OPEN ------------------------------------------- */
.clonable-search-widget-wrapper.clonable-search-expandable.is-expanded
  input[data-clonable-search] {
  padding: 0 1rem 0 var(--csw-toggle-size);
}

.clonable-search-widget-wrapper.clonable-search-expandable.is-expanded[data-clonable-expand="left"]
  input[data-clonable-search] {
  padding: 0 var(--csw-toggle-size) 0 1rem;
}

/* --- RESULTS --------------------------------------------------------------*/

.clonable-search-widget-wrapper.clonable-search-expandable:not(.is-expanded)
  [data-clonable-search-results] {
  display: none;
}

/* --- REDUCED MOTION ------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .clonable-search-widget-wrapper.clonable-search-expandable {
    --csw-expand-duration: 0s;
  }

  .clonable-search-widget-wrapper.clonable-search-expandable
    .clonable-search-toggle {
    transition: none;
  }
}
