/**
 * Filter Bar — Chips bar, XW popover, Edit modal, Corner tab toggle
 */

/* === Filter Chips Bar === */
.filter-chips-bar {
  flex-shrink: 0;
  height: 46px;
  background: #131F2E;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  display: flex;
  align-items: center;
  padding: 0 var(--space-4);
  gap: var(--space-2);
  overflow: visible;
  position: relative;
  z-index: 100;
}

/* Mobile: horizontal scroll; Edit chip is sticky at right */
@media (max-width: 639px) {
  .filter-chips-bar {
    overflow-x: auto;
    overflow-y: visible;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    /* z-index:auto removes the stacking context. A z-index value here traps
       position:fixed children in WebKit (overflow:auto parent clips them to
       its own bounds). Popovers carry their own z-index:700 (see mobile
       .chip-popover rule) so they paint above the backdrop (699) in the root
       stacking context without needing the bar to have a context. */
    z-index: auto;
  }
  .filter-chips-bar::-webkit-scrollbar { display: none; }
}

/* === Filter Chips === */
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-pill);
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.05);
  font-family: var(--font-primary);
  font-size: 0.8125rem;
  font-weight: 500;
  color: rgba(255,255,255,0.45);
  cursor: pointer;
  white-space: nowrap;
  transition: background 150ms, border-color 150ms, color 150ms, box-shadow 150ms;
  line-height: 1;
}

.filter-chip:hover {
  border-color: rgba(255,255,255,0.22);
  background: rgba(255,255,255,0.09);
}

.filter-chip:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Active chip — has a non-default / active value set */
.filter-chip--active {
  border-color: rgba(150,199,232,0.45);
  color: #96C7E8;
  background: rgba(150,199,232,0.18);
}
.filter-chip--active:hover {
  background: rgba(150,199,232,0.22);
  border-color: rgba(150,199,232,0.6);
}

/* Dimmed chip — optional filter not set */
.filter-chip--dim {
  color: rgba(255,255,255,0.2);
  border-color: rgba(255,255,255,0.07);
  background: rgba(255,255,255,0.02);
}
.filter-chip--dim:hover {
  color: rgba(255,255,255,0.35);
  border-color: rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.05);
}

/* Home chip — same font as other chips */
.filter-chip--home {
  font-weight: 600;
}

/* Edit button — styled as active chip */
.filter-chip--edit {
  background: rgba(150,199,232,0.18);
  border-color: rgba(150,199,232,0.45);
  color: #96C7E8;
  margin-left: auto;
  flex-shrink: 0;
  font-weight: 600;
}
.filter-chip--edit:hover {
  background: rgba(150,199,232,0.22);
  border-color: rgba(150,199,232,0.6);
  color: #96C7E8;
}

/* Mobile: Edit chip sticks to the right of the scroll container */
@media (max-width: 639px) {
  .filter-chip--edit {
    position: sticky;
    right: 0;
    margin-left: 0;
    box-shadow: -10px 0 12px #131F2E, 0 0 0 1px #131F2E;
  }

  /* Hide dim (default/no-limit) chips on mobile — they clutter the chips bar
     and overlap the sticky Edit button. Accessible via Edit search instead. */
  .chip-wrapper:has(.filter-chip--dim) {
    display: none;
  }
}

/* === Chip Wrapper (anchor for each chip's popover) === */
.chip-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

/* === Chip Popover (shared by all chips) === */
.chip-popover {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  background: var(--surface-bg);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-4) var(--space-5);
  width: 280px;
  z-index: 300;
}
.chip-popover[hidden] { display: none; }

/* XW-style header: label left, value right */
.chip-popover__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}

/* Section label — uppercase, used both in XW header and as standalone title */
.chip-popover__label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0;
}
p.chip-popover__label {
  margin-bottom: var(--space-2);
}

/* XW value display */
.chip-popover__value {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--horizon-teal);
}

/* XW slider */
.chip-popover__slider {
  width: 100%;
  cursor: pointer;
  margin-bottom: var(--space-2);
}

/* Hint text */
.chip-popover__hint {
  font-size: 0.6875rem;
  color: var(--gray-400);
  text-align: center;
  margin-top: var(--space-2);
  margin-bottom: 0;
}

/* Footer with Search button */
.chip-popover__footer {
  display: flex;
  justify-content: flex-end;
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--gray-100);
}
.chip-popover__footer .btn {
  padding: var(--space-1) var(--space-3);
  font-size: 0.8125rem;
  min-height: auto;
}

/* Mobile backdrop */
#chip-popover-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 699;
}
#chip-popover-backdrop.visible { display: block; }

/* Mobile: popovers become bottom sheets */
@media (max-width: 639px) {
  .chip-popover {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    width: 100%;
    max-height: 60dvh;
    overflow-y: auto;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    z-index: 700;
    padding: var(--space-5) var(--space-5) calc(var(--space-5) + env(safe-area-inset-bottom, 0px));
  }

  /* Home popover: allow autocomplete dropdown to overflow the sheet upward.
     The dropdown flips to open above the input, floating over the map, so it
     isn't clipped by the sheet's overflow-y or hidden behind the keyboard. */
  #home-popover {
    overflow: visible;
  }
  #home-popover .autocomplete-dropdown {
    top: auto;
    bottom: calc(100% + 4px);
    border-top: 1px solid var(--gray-200);
    border-bottom: none;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    max-height: 40dvh;
  }
}

/* === Edit Modal Overlay === */
.filter-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.42);
  z-index: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}
.filter-modal-overlay[hidden] { display: none !important; }

/* === Edit Modal === */
.filter-modal {
  background: var(--surface-bg);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 400px;
  max-width: 94vw;
  max-height: calc(100dvh - 100px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.filter-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--gray-200);
  flex-shrink: 0;
}

.filter-modal__title {
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--gray-900);
  margin: 0;
}

.filter-modal__close {
  background: none;
  border: none;
  font-size: 1.375rem;
  line-height: 1;
  color: var(--gray-500);
  cursor: pointer;
  min-width: 32px;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  padding: 0;
}
.filter-modal__close:hover { background: var(--gray-100); color: var(--gray-700); }

.filter-modal__body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-3) var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.filter-modal__footer {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--gray-200);
  flex-shrink: 0;
  background: var(--surface-bg);
}

.filter-modal__footer-btns {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
}

#modal-filter-error {
  margin: 0;
}

/* Cancel button override — btn--ghost uses white text designed for dark hero bg */
.filter-modal__footer .btn--ghost {
  color: var(--gray-600);
  border-color: var(--gray-300);
  background: transparent;
  min-height: auto;
  padding: var(--space-2) var(--space-4);
  font-size: 0.875rem;
}
.filter-modal__footer .btn--ghost:hover {
  background: var(--gray-100);
  color: var(--gray-700);
  border-color: var(--gray-400);
}

/* Match search button size to cancel button */
.filter-modal__footer .btn--primary {
  min-height: auto;
  padding: var(--space-2) var(--space-4);
  font-size: 0.875rem;
}

/* === Modal: bottom sheet on mobile === */
@media (max-width: 639px) {
  .filter-modal-overlay {
    align-items: flex-end;
  }
  .filter-modal {
    width: 100%;
    max-width: 100%;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    max-height: 90dvh;
  }
  /* Tighter spacing to fit content on smaller phones (e.g. iPhone SE, 667px) */
  .filter-modal__body {
    padding: var(--space-2) var(--space-4);
    gap: var(--space-2);
  }
  .filter-modal__footer {
    padding: var(--space-2) var(--space-4);
  }
}

/* === Modal form sections === */
.modal-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.modal-section__label {
  font-size: 0.625rem;
  font-weight: 600;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0;
}

/* Crosswind row in modal */
.modal-xw-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.modal-xw-row input[type="range"] {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

/* Search mode toggle in modal */
.modal-mode-toggle {
  display: flex;
  gap: 2px;
  background: var(--gray-100);
  border-radius: var(--radius-md);
  padding: 2px;
}

.modal-mode-btn {
  flex: 1;
  padding: var(--space-1) var(--space-3);
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-primary);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--gray-500);
  background: transparent;
  cursor: pointer;
  transition: all 100ms;
}
.modal-mode-btn--active {
  background: #fff;
  color: var(--gray-900);
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

