﻿/* Search Pills — responsive, mobile-first fixes
   - Desktop: pill-style inline controls with absolute dropdowns
   - Mobile: full-width rows, dropdowns become stacked panels under each pill
   - Colors use Bootstrap 5.3 CSS variables so light/dark theme switching works automatically.
*/

/* -------------------------------------------------------
   Custom variables — each references a Bootstrap variable
   so they update automatically when data-bs-theme changes.
------------------------------------------------------- */
:root {
  --pill-bg:          var(--rq-surface);
  --pill-border:      var(--rq-border);
  --muted:            var(--rq-sub);
  --label-muted:      var(--rq-sub);
  --pill-text:        var(--rq-text);
  --pill-hover-bg:    var(--rq-muted);
  --filter-bg:        var(--rq-page);
  --filter-border:    var(--rq-border);
  --chip-active-bg:   var(--rq-text);
  --chip-active-text: var(--rq-page);
  --accent-gradient:  var(--rq-accent);
}

/* Container */
.search-pills-container {
  display: flex !important;
  align-items: stretch;
  justify-content: center;
  padding: 0.5rem;
  margin: 0 auto;
  width: 100%;
  box-sizing: border-box;
}

/* Wrapper */
.search-pills {
  display: flex;
  align-items: center;
  background: var(--pill-bg);
  border: 1px solid var(--pill-border);
  border-radius: 50px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.05);
  padding: 0.5rem;
  transition: box-shadow .18s ease;
  flex-wrap: nowrap;
  gap: 0;
  width: 100%;
  max-width: 1200px;
  box-sizing: border-box;
}

/* Pills (desktop default) */
.search-pill {
  position: relative;
  flex: 1 1 0%;
  min-width: 0;
  cursor: pointer;
  border-radius: 32px;
  padding: 0.625rem 1.25rem;
  transition: background-color .16s ease;
  border-right: 1px solid var(--pill-border);
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  background: transparent;
}

/* Make sure label/value areas explicitly use the interactive cursor */
.search-pill,
.search-pill .search-pill-label,
.search-pill .search-pill-value {
  cursor: pointer !important;
}

/* Inputs and controls inside the dropdown should keep the default/text cursor */
.search-pill .search-pill-dropdown,
.search-pill .search-pill-dropdown * {
  cursor: auto !important;
}

.search-pill:last-child { border-right: none; }

.search-pill:hover:not(.active) { background-color: var(--pill-hover-bg); }

/* Per-pill header row — label + clear button on same line */
.search-pill-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .125rem;
  min-width: 0;
}
.search-pill-header .search-pill-label {
  margin-bottom: 0;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Per-pill clear button — inline with the label */
.pill-clear-btn {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: none;
  background: var(--rq-surface-sunken);
  color: var(--rq-sub);
  font-size: 8px;
  line-height: 1;
  cursor: pointer !important;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin-left: 4px;
  opacity: 0.75;
  transition: opacity .12s, background .12s, color .12s;
}
.pill-clear-btn:hover {
  opacity: 1;
  background: var(--rq-danger-soft);
  color: var(--rq-danger);
}
.pill-clear-btn i { font-size: 8px; pointer-events: none; }

.search-pill.active {
  background: var(--pill-bg);
  box-shadow: 0 6px 20px rgba(0,0,0,0.12);
  z-index: 1060;
}

.search-pill-label {
  display: block;
  font-size: .75rem;
  font-weight: 800;
  color: var(--pill-text);
  margin-bottom: .125rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: .02em;
}

.search-pill-value {
  display: block;
  font-size: .875rem;
  color: var(--pill-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 400;
  background: transparent;
}

.search-pill-value.placeholder { color: var(--muted); font-weight: 300; }

/* Search button */
.search-button {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-gradient);
  color: var(--rq-on-accent);
  border: none;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  margin-left: .5rem;
  cursor: pointer;
  transition: transform .08s ease, box-shadow .16s ease;
  flex-shrink: 0;
  order: 999;
}
.search-button:hover { transform: scale(1.03); box-shadow: 0 4px 10px rgba(0,0,0,0.12); }
.search-button:active { transform: scale(.98); }

/* -------------------------
   Clear-all button
   Circular on desktop, full-width pill on mobile — shown/hidden via d-none toggle
------------------------- */
.clear-all-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .3rem;
  background: transparent;
  color: var(--muted);
  border: 1.5px solid var(--pill-border);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  padding: 0;
  margin-left: .5rem;
  cursor: pointer;
  flex-shrink: 0;
  order: 998;
  font-size: .85rem;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.clear-all-button:hover {
  background: var(--pill-hover-bg);
  border-color: var(--filter-border);
  color: var(--pill-text);
}
.clear-all-button .clear-all-label {
  display: none;
  font-size: .82rem;
  font-weight: 600;
  white-space: nowrap;
}

/* Desktop dropdown */
.search-pill-dropdown {
  position: absolute;
  top: calc(100% + .75rem);
  left: 50%;
  transform: translateX(-50%);
  background: var(--pill-bg);
  border: 1px solid var(--pill-border);
  border-radius: 16px;
  box-shadow: 0 2px 16px rgba(0,0,0,0.12);
  padding: 2rem;
  min-width: 380px;
  z-index: 1070;
  display: none;
  box-sizing: border-box;
}
.search-pill.active .search-pill-dropdown { display: block; animation: slideUp .18s ease-out; }

/* Dropdown header */
.search-pill-dropdown-header {
  font-size: .875rem;
  font-weight: 700;
  color: var(--pill-text);
  margin-bottom: 1rem;
}

/* Filters */
.filter-section { margin-bottom: 1.25rem; }
.filter-label { display:block; font-weight:600; margin-bottom:.6rem; color: var(--pill-text); }
.filter-input {
  width: 100%;
  padding: .7rem .9rem;
  border: 1px solid var(--filter-border);
  border-radius: 8px;
  background: var(--filter-bg);
  color: var(--pill-text);
  box-sizing: border-box;
}
.filter-chips { display:flex; flex-wrap:wrap; gap:.5rem; }
.filter-chip {
  padding: .45rem .9rem;
  border: 1px solid var(--filter-border);
  border-radius: 24px;
  cursor: pointer;
  background: var(--filter-bg);
  color: var(--pill-text);
  transition: all .12s ease;
}
.filter-chip:hover { background: var(--pill-hover-bg); border-color: var(--pill-text); }
.filter-chip.active { background: var(--chip-active-bg); color: var(--chip-active-text); border-color: var(--chip-active-bg); }

/* Counter / range */
.filter-range { display:grid; grid-template-columns:1fr auto 1fr; gap:.75rem; align-items:center; }
.filter-counter { display:flex; align-items:center; justify-content:space-between; padding:.5rem 0; }
.filter-counter-label { font-size:.95rem; color: var(--pill-text); }
.filter-counter-controls { display:flex; align-items:center; gap:.75rem; }
.filter-counter-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--filter-border);
  background: var(--filter-bg);
  color: var(--pill-text);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .12s ease;
}
.filter-counter-btn:hover:not(:disabled) { border-color: var(--pill-text); }
.filter-counter-btn:disabled { opacity:.35; cursor:default; }
.filter-counter-value { min-width:20px; text-align:center; font-size:.95rem; color: var(--pill-text); }
.filter-range-separator { text-align:center; color: var(--muted); }

/* Keyword inline buttons */
.keyword-search-input-wrapper { position:relative; display:flex; align-items:center; width:100%; }
.keyword-search-input-wrapper .filter-input { padding-right:80px; }
.keyword-btn-clear, .keyword-btn-search {
  position:absolute; right:0; top:50%; transform:translateY(-50%);
  width:32px; height:32px; display:inline-flex; align-items:center; justify-content:center;
  border:none; background:transparent; cursor:pointer; color: var(--muted);
}
.keyword-btn-search { right:4px; color:var(--rq-accent); }
.keyword-btn-clear { right:40px; }

/* Animations */
@keyframes slideUp {
  from { opacity:0; transform: translateX(-50%) translateY(8px); }
  to   { opacity:1; transform: translateX(-50%) translateY(0); }
}

/* -------------------------------------------------------
   DARK MODE — shadow adjustments (shadows must use rgba,
   can't use CSS variables, so we override them explicitly)
   Also override --pill-bg because --bs-card-bg is not
   defined by the Modernize theme in dark mode and falls
   back to the hardcoded #fff default.
------------------------------------------------------- */
[data-bs-theme="dark"] {
  --pill-bg: var(--rq-muted);
}
[data-bs-theme="dark"] .search-pills {
  box-shadow: 0 0 0 1px var(--pill-border);
}
[data-bs-theme="dark"] .search-pill.active {
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
[data-bs-theme="dark"] .search-pill-dropdown {
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
}

/* ----------------------
   MOBILE OVERRIDES
   ---------------------- */
@media (max-width: 767px) {
  .search-pills {
    flex-direction: column;
    gap: .5rem;
    padding: .4rem;
    border-radius: 12px;
    box-shadow: none;
    align-items: stretch;
  }

  .search-pill {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: .6rem .75rem;
    border-radius: 10px;
    border-right: none;
    border: 1px solid var(--pill-border);
    background: var(--pill-bg);
    min-width: 0;
  }

  .search-pill + .search-pill { margin-top: .5rem; }

  .search-pill-label {
    width: 34%;
    margin-bottom: 0;
    font-weight: 700;
    font-size: .72rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .search-pill-value {
    width: 64%;
    text-align: right;
    font-size: .92rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .search-pill-dropdown {
    position: relative;
    left: auto;
    top: auto;
    transform: none;
    width: 100%;
    margin-top: .5rem;
    padding: .9rem;
    border-radius: 10px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.06);
    display: none;
  }
  .search-pill.active .search-pill-dropdown { display: block; animation: slideUpMobile .18s ease-out; }

  @keyframes slideUpMobile {
    from { opacity:0; transform: translateY(6px); }
    to   { opacity:1; transform: translateY(0); }
  }

  .search-button {
    width: 100%;
    height: 44px;
    border-radius: 10px;
    margin-left: 0;
    margin-top: .6rem;
    order: 1000;
    align-self: stretch;
  }

  .clear-all-button {
    width: 100%;
    height: 44px;
    border-radius: 10px;
    margin-left: 0;
    margin-top: .6rem;
    order: 999;
  }
  .clear-all-button .clear-all-label { display: inline; }

  @media (max-width: 420px) {
    .search-pill { padding: .5rem .6rem; }
    .search-pill-label { width: 36%; font-size: .68rem; }
    .search-pill-value { width: 62%; font-size: .82rem; }
    .search-pill-dropdown { padding: .75rem; }
    .search-button { height: 42px; }
    .clear-all-button { height: 42px; }
  }
}

@media (max-width: 360px) {
  .search-pill-dropdown { padding: .6rem; }
  .filter-input { font-size: .95rem; }
}
