/* ============================================================
   SEARCH WIDGET — homepage smart search
   Markup:  template-parts/sections/search-widget.php
   Logic:   assets/js/search-widget.js
   Loaded:  front page only (see inc/enqueue.php)
   ============================================================ */

/* ============================================================
   SECTION — overlap seam between hero and services
   ============================================================ */
.search-widget {
  position: relative;
  z-index: 10;
  margin-top: -40px;
  padding: 0 var(--container-pad);
  background: transparent;
}

/* ============================================================
   DESKTOP CARD
   ============================================================ */
.search-widget__card {
  display: none; /* shown >=1024px */
  align-items: center;
  gap: 12px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 24px;
  background: var(--pr-white);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
}

.search-widget__fields {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
  gap: 12px;
}

/* Shared field shell — label row above value row */
.sw-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: relative;
}

.sw-field__label {
  font-size: 11px;
  font-weight: 500;
  color: var(--pr-text-muted);
  letter-spacing: 0.02em;
}

/* ============================================================
   SERVICE TYPE SEGMENTED CONTROL
   ============================================================ */
.sw-segment {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  background: var(--pr-cream);
  border-radius: 10px;
  flex-shrink: 0;
}

.sw-segment__btn {
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--pr-text-body);
  white-space: nowrap;
  transition: background 150ms ease-out, color 150ms ease-out;
}

.sw-segment__btn.is-active {
  background: var(--pr-jungle);
  color: var(--pr-white);
}

@media (hover: hover) and (pointer: fine) {
  .sw-segment__btn:not(.is-active):hover {
    background: rgba(13, 31, 20, 0.06);
    color: var(--pr-text-dark);
  }
}

/* ============================================================
   FROM / TO DROPDOWNS
   ============================================================ */
.sw-dropdown {
  flex: 1 1 0;
  min-width: 0;
}

/* Small muted label, sourced from data-placeholder so the
   markup doesn't need a separate label element. Reserves space
   even when hidden so selecting a value doesn't shift layout. */
.sw-dropdown::before {
  content: attr(data-placeholder);
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--pr-text-muted);
  letter-spacing: 0.02em;
  padding-left: 23px;
}

.sw-dropdown:has(.sw-dropdown__value.is-placeholder)::before {
  visibility: hidden;
}

.sw-dropdown__trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 2px 6px 2px 0;
  border-radius: var(--radius-sm);
  text-align: left;
  transition: background var(--transition-fast);
}

@media (hover: hover) and (pointer: fine) {
  .sw-dropdown__trigger:not(:disabled):hover {
    background: var(--pr-cream);
  }
}

.sw-dropdown__trigger .ti-map-pin {
  font-size: 15px;
  color: var(--pr-text-muted);
  flex-shrink: 0;
}

.sw-dropdown__value {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--pr-text-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sw-dropdown__value.is-placeholder {
  color: var(--pr-text-muted);
  font-weight: 400;
}

.sw-dropdown__chevron {
  font-size: 13px;
  color: var(--pr-text-muted);
  flex-shrink: 0;
  transition: transform var(--transition-fast);
}

.sw-dropdown__trigger[aria-expanded="true"] .sw-dropdown__chevron {
  transform: rotate(180deg);
}

/* Vertical divider between From and To on the desktop card */
.search-widget__fields .sw-dropdown[data-sw-dropdown="from"]:not([hidden])::after {
  content: '';
  position: absolute;
  top: 6px;
  bottom: 6px;
  right: -6px;
  width: 1px;
  background: var(--pr-border-light);
}

/* Dropdown panel — position is set inline (fixed) by search-widget.js */
.sw-dropdown__panel {
  z-index: 100;
  background: var(--pr-white);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  max-height: 240px;
  overflow-y: auto;
  padding: 6px;
}

.sw-dropdown__option {
  font-size: 14px;
  padding: 10px 16px;
  border-radius: 8px;
  color: var(--pr-text-dark);
  transition: background var(--transition-fast);
}

.sw-dropdown__option.is-selected {
  background: var(--pr-cream);
  font-weight: 500;
}

@media (hover: hover) and (pointer: fine) {
  .sw-dropdown__option:hover {
    background: var(--pr-cream);
  }
}

.sw-dropdown__option:focus-visible {
  background: var(--pr-cream);
  outline-offset: -2px;
}

/* Inside the mobile sheet, dropdown panels render inline rather than as
   floating fixed-position panels — fixed panels reflow/jump as the sheet
   scrolls or the on-screen keyboard opens. */
@media (max-width: 1023.98px) {
  .sw-sheet .sw-dropdown__panel {
    position: static;
    box-shadow: none;
    border: 1px solid var(--pr-border-light);
    border-radius: 8px;
    margin-top: 4px;
    width: 100%;
  }
}

/* ============================================================
   "DEPARTURE FROM …" NOTE — replaces the To field for tours
   ============================================================ */
.sw-departure-note {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  flex: 1 1 0;
  min-width: 0;
  font-size: 14px;
  color: var(--pr-text-body);
}

.sw-departure-note .ti-flag {
  font-size: 15px;
  color: var(--pr-gold);
  flex-shrink: 0;
}

.sw-departure-note span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* `hidden` must win over the `display: flex` set on .sw-field/.sw-dropdown */
.sw-dropdown[hidden],
.sw-departure-note[hidden] {
  display: none;
}

/* ============================================================
   DATE FIELD
   ============================================================ */
.sw-date-field {
  flex: 0 0 auto;
  min-width: 110px;
  cursor: pointer;
}

.sw-date {
  appearance: none;
  -webkit-appearance: none;
  border: none;
  background: transparent;
  padding: 2px 0;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  color: var(--pr-text-dark);
  cursor: pointer;
  width: 100%;
}

.sw-date:focus {
  outline: none;
}

.sw-date::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 0.5;
  filter: invert(0.3);
  transition: opacity var(--transition-fast);
}

@media (hover: hover) and (pointer: fine) {
  .sw-date::-webkit-calendar-picker-indicator:hover {
    opacity: 1;
  }
}

/* ============================================================
   PASSENGERS STEPPER
   ============================================================ */
.sw-pax {
  flex: 0 0 auto;
}

.sw-pax__control {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sw-pax__btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid var(--pr-border-light);
  color: var(--pr-text-dark);
  font-size: 12px;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}

.sw-pax__btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

@media (hover: hover) and (pointer: fine) {
  .sw-pax__btn:not(:disabled):hover {
    border-color: var(--pr-gold);
    background: var(--pr-cream);
  }
}

.sw-pax__value {
  display: inline-block;
  min-width: 24px;
  font-size: 14px;
  font-weight: 500;
  color: var(--pr-text-dark);
  text-align: center;
}

/* ============================================================
   SUBMIT BUTTON
   ============================================================ */
.sw-submit {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 14px 24px;
  background: var(--pr-gold);
  color: var(--pr-jungle);
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  transition: filter 200ms cubic-bezier(0.23, 1, 0.32, 1);
}

@media (hover: hover) and (pointer: fine) {
  .sw-submit:not(:disabled):hover {
    filter: brightness(1.05);
  }
}

.sw-submit:disabled,
.sw-submit.is-loading {
  opacity: 0.7;
  cursor: not-allowed;
}

.sw-submit--block {
  width: 100%;
  padding: 16px;
  font-size: 16px;
  border-radius: 12px;
}

/* ============================================================
   POPULAR ROUTE CHIPS
   ============================================================ */
.sw-chips {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.sw-chips::-webkit-scrollbar {
  display: none;
}

.sw-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  padding: 6px 14px;
  background: var(--pr-cream);
  border: 1px solid var(--pr-border-light);
  border-radius: 20px;
  color: var(--pr-text-dark);
  font-size: 13px;
  white-space: nowrap;
  transition: background 150ms ease-out;
}

@media (hover: hover) and (pointer: fine) {
  .sw-chip:hover {
    background: var(--pr-cream-dark);
  }
}

.sw-chip__sep {
  opacity: 0.5;
}

.sw-chip__price {
  color: var(--pr-gold);
  font-weight: 600;
}

/* ============================================================
   MOBILE SUMMARY BAR
   ============================================================ */
.sw-summary-bar {
  display: none; /* shown <1024px */
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 52px;
  padding: 0 16px;
  background: var(--pr-white);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
  text-align: left;
  transition: transform 100ms ease-out;
}

.sw-summary-bar:active {
  transform: scale(0.99);
}

.sw-summary-bar__left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.sw-summary-bar__left .ti-search {
  font-size: 20px;
  color: var(--pr-text-muted);
  flex-shrink: 0;
}

.sw-summary-bar__text {
  font-size: 14px;
  color: var(--pr-text-body);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sw-summary-bar > .ti-chevron-right {
  font-size: 16px;
  color: var(--pr-text-muted);
  flex-shrink: 0;
}

/* ============================================================
   MOBILE BOTTOM SHEET
   ============================================================ */
.sw-sheet {
  position: fixed;
  inset: 0;
  top: auto;
  margin: 0;
  width: 100%;
  max-width: none;
  max-height: 90svh;
  border: none;
  padding: 24px 20px 32px;
  background: var(--pr-white);
  color: var(--pr-text-dark);
  border-radius: 20px 20px 0 0;
  overflow-y: auto;

  transform: translateY(100%);
  transition:
    transform 300ms cubic-bezier(0.32, 0.72, 0, 1),
    overlay 300ms allow-discrete,
    display 300ms allow-discrete;
}

.sw-sheet[open],
.sw-sheet.is-open {
  transform: translateY(0);
}

@starting-style {
  .sw-sheet[open] {
    transform: translateY(100%);
  }
}

.sw-sheet::backdrop {
  background: rgba(0, 0, 0, 0);
  transition: background 300ms ease, overlay 300ms allow-discrete, display 300ms allow-discrete;
}

.sw-sheet[open]::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

@starting-style {
  .sw-sheet[open]::backdrop {
    background: rgba(0, 0, 0, 0);
  }
}

.sw-sheet__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.sw-sheet__title {
  font-size: 18px;
}

.sw-sheet__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--pr-cream);
  color: var(--pr-text-dark);
  font-size: 16px;
  flex-shrink: 0;
  transition: background var(--transition-fast);
}

@media (hover: hover) and (pointer: fine) {
  .sw-sheet__close:hover {
    background: var(--pr-border-light);
  }
}

.sw-sheet__body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Service type: full width, 3 equal columns */
.sw-sheet .sw-segment {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: 100%;
}

.sw-sheet .sw-segment__btn {
  text-align: center;
  padding: 10px 4px;
}

/* From / To rows: full width, 56px min height, divider below */
.sw-sheet .sw-dropdown,
.sw-sheet .sw-departure-note {
  width: 100%;
  min-height: 56px;
  justify-content: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--pr-border-light);
}

/* Date + Passengers: 2-column grid */
.sw-sheet__row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.sw-sheet__footer {
  margin-top: 16px;
}

/* ============================================================
   LOADING / DISABLED / EMPTY STATES
   ============================================================ */
.sw-dropdown.is-disabled {
  opacity: 0.4;
}

.sw-dropdown.is-disabled .sw-dropdown__trigger {
  cursor: not-allowed;
}

.sw-dropdown.is-loading .sw-dropdown__value {
  opacity: 0.5;
  animation: sw-pulse 1s ease-in-out infinite;
}

@keyframes sw-pulse {
  0%, 100% { opacity: 0.5; }
  50%      { opacity: 1; }
}

/* ============================================================
   RESPONSIVE BREAKPOINTS
   ============================================================ */
@media (min-width: 1024px) {
  .search-widget__card {
    display: flex;
  }
}

@media (max-width: 1023.98px) {
  .search-widget {
    margin-top: -20px;
  }

  .sw-summary-bar {
    display: flex;
  }
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .sw-sheet,
  .sw-sheet::backdrop {
    transition-duration: 0.01ms;
  }

  .sw-segment__btn,
  .sw-dropdown__trigger,
  .sw-dropdown__chevron,
  .sw-dropdown__option,
  .sw-pax__btn,
  .sw-submit,
  .sw-chip,
  .sw-summary-bar,
  .sw-sheet__close {
    transition: none;
  }

  .sw-dropdown.is-loading .sw-dropdown__value {
    animation: none;
    opacity: 0.6;
  }
}
