/* ============================================
   InfluenceHub – Catalog search clear button
   - Visible "Išvalyti paiešką" (X) button inside
     the #catalog-search wrapper.
   - 44px touch target, focus-visible ring,
     dark mode, prefers-reduced-motion support.
   ============================================ */

/* ---------- Base button ---------- */

#catalog-search-clear {
  position: absolute;
  right: 0.25rem;
  top: 50%;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  /* WCAG 2.5.5 – minimum 44x44px touch target for mobile users */
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 0.6rem;
  border: none;
  background: transparent;
  color: #64748b;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, opacity 0.15s ease, box-shadow 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  z-index: 1;
}

/* ---------- 44px touch target (WCAG 2.5.5) ----------
   Guarantee the clear button stays at least 44x44px on every
   viewport, including small phones where the input shrinks. */

#catalog-search-clear {
  min-width: 44px;
  min-height: 44px;
  width: 44px;
  height: 44px;
}

#catalog-search-clear:hover {
  background: #f1f5f9;
  color: #0f172a;
}

#catalog-search-clear:active {
  background: #e2e8f0;
}

/* High-contrast, always-visible ring for keyboard users. The ring is
   drawn with both an outline and a box-shadow halo so it stays visible
   against the light input background. */
#catalog-search-clear:focus-visible {
  outline: 2px solid #7c3aed;
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.25);
  background: #f1f5f9;
  color: #0f172a;
}

/* Stronger, always-visible ring for keyboard users – the outline is
   paired with a white inner ring so it stays legible even when the
   button sits on a tinted input background. */
#catalog-search-clear:focus-visible {
  outline: 2px solid #7c3aed;
  outline-offset: 2px;
  box-shadow:
    0 0 0 2px #ffffff,
    0 0 0 6px rgba(124, 58, 237, 0.35);
}

/* Fallback for browsers without :focus-visible support */
@supports not selector(:focus-visible) {
  #catalog-search-clear:focus {
    outline: 2px solid #7c3aed;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.25);
    background: #f1f5f9;
    color: #0f172a;
  }
}

#catalog-search-clear.hidden {
  display: none !important;
}

#catalog-search-clear i {
  width: 1rem;
  height: 1rem;
  pointer-events: none;
}

/* ---------- Dark mode ---------- */

.dark #catalog-search-clear {
  color: #94a3b8;
}

.dark #catalog-search-clear:hover {
  background: #1e293b;
  color: #f1f5f9;
}

.dark #catalog-search-clear:active {
  background: #334155;
}

.dark #catalog-search-clear:focus-visible {
  outline-color: #c4b5fd;
  box-shadow: 0 0 0 4px rgba(196, 181, 253, 0.35);
  background: #1e293b;
  color: #f1f5f9;
}

/* Dark mode: add a dark inner ring so the light violet outline stays
   visible against the slate input surface. */
.dark #catalog-search-clear:focus-visible {
  outline-color: #c4b5fd;
  box-shadow:
    0 0 0 2px #0f172a,
    0 0 0 6px rgba(196, 181, 253, 0.45);
}

@supports not selector(:focus-visible) {
  .dark #catalog-search-clear:focus {
    outline-color: #c4b5fd;
    box-shadow: 0 0 0 4px rgba(196, 181, 253, 0.35);
    background: #1e293b;
    color: #f1f5f9;
  }
}

/* ---------- Ensure the input has room for the button ---------- */

#catalog-search {
  padding-right: 3.25rem;
}

/* ---------- Small screens: keep the 44px target, avoid overlap ---------- */

@media (max-width: 480px) {
  #catalog-search-clear {
    right: 0.125rem;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }

  #catalog-search {
    padding-right: 3.25rem;
  }
}

/* ---------- Very small screens: keep the 44px target ---------- */

@media (max-width: 360px) {
  #catalog-search-clear {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  #catalog-search-clear {
    transition: none !important;
    animation: none !important;
    transform: translateY(-50%) !important;
  }

  /* Neutralise any hover/focus/active transform so no motion is perceived */
  #catalog-search-clear:hover,
  #catalog-search-clear:focus,
  #catalog-search-clear:focus-visible,
  #catalog-search-clear:active {
    transform: translateY(-50%) !important;
    transition: none !important;
  }

  /* Keep the focus ring visible but static (no animated halo) */
  #catalog-search-clear:focus-visible,
  #catalog-search-clear:focus {
    box-shadow:
      0 0 0 2px #ffffff,
      0 0 0 6px rgba(124, 58, 237, 0.35) !important;
  }

  .dark #catalog-search-clear:focus-visible,
  .dark #catalog-search-clear:focus {
    box-shadow:
      0 0 0 2px #0f172a,
      0 0 0 6px rgba(196, 181, 253, 0.45) !important;
  }

  /* Icons inside the button must not animate either */
  #catalog-search-clear i {
    animation: none !important;
    transition: none !important;
    transform: none !important;
  }
}

/* ---------- Forced colors (Windows High Contrast) ---------- */

@media (forced-colors: active) {
  #catalog-search-clear {
    border: 1px solid CanvasText;
    color: CanvasText;
    background: Canvas;
  }

  #catalog-search-clear:hover {
    background: Highlight;
    color: HighlightText;
  }

  #catalog-search-clear:focus-visible,
  #catalog-search-clear:focus {
    outline: 2px solid Highlight;
    outline-offset: 2px;
    box-shadow: none;
    background: Highlight;
    color: HighlightText;
  }
}

/* ---------- Fallback for browsers without :focus-visible ---------- */

@supports not selector(:focus-visible) {
  #catalog-search-clear:focus {
    outline: 2px solid #7c3aed;
    outline-offset: 2px;
    box-shadow:
      0 0 0 2px #ffffff,
      0 0 0 6px rgba(124, 58, 237, 0.35);
    background: #f1f5f9;
    color: #0f172a;
  }

  .dark #catalog-search-clear:focus {
    outline-color: #c4b5fd;
    box-shadow:
      0 0 0 2px #0f172a,
      0 0 0 6px rgba(196, 181, 253, 0.45);
    background: #1e293b;
    color: #f1f5f9;
  }
}

/* ============================================
   WCAG AA contrast – search input + clear button
   ============================================ */

/* ---------- Search input (#catalog-search) ----------
   Light mode: #0f172a text on #ffffff = 17.9:1 (passes AA).
   Placeholder: #64748b on #ffffff = 4.8:1 (passes AA for
   normal text). Re-assert with !important so generic
   utilities cannot reduce contrast below AA. */

#catalog-search {
  color: #0f172a !important;
  background-color: #ffffff !important;
  border-color: #cbd5e1 !important;
}

#catalog-search::placeholder {
  color: #64748b !important;
  opacity: 1 !important;
}

/* Dark mode: #f1f5f9 text on #0f172a = 15.9:1 (passes AA).
   Placeholder: #94a3b8 on #0f172a = 7.4:1 (passes AA). */

.dark #catalog-search {
  color: #f1f5f9 !important;
  background-color: #0f172a !important;
  border-color: #334155 !important;
}

.dark #catalog-search::placeholder {
  color: #94a3b8 !important;
  opacity: 1 !important;
}

/* Focus state – visible ring that meets WCAG 2.4.7 (Focus Visible)
   and 1.4.11 (Non-text Contrast). */

#catalog-search:focus-visible {
  outline: 2px solid #7c3aed;
  outline-offset: 2px;
  border-color: #7c3aed !important;
  box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.25);
}

.dark #catalog-search:focus-visible {
  outline-color: #c4b5fd;
  border-color: #c4b5fd !important;
  box-shadow: 0 0 0 4px rgba(196, 181, 253, 0.35);
}

/* ---------- Clear button contrast (WCAG AA) ----------
   Light mode: #475569 icon on #ffffff = 7.5:1 (passes AA).
   Dark mode:  #cbd5e1 icon on #0f172a = 11.6:1 (passes AA). */

#catalog-search-clear {
  color: #475569 !important;
}

#catalog-search-clear:hover {
  color: #0f172a !important;
}

.dark #catalog-search-clear {
  color: #cbd5e1 !important;
}

.dark #catalog-search-clear:hover {
  color: #f1f5f9 !important;
}

/* ============================================
   prefers-reduced-motion guard
   - Disables the clear button's hover/focus
     transitions and any transform animation.
   - Disables the search input's focus ring
     transition so no motion is perceived.
   - Keeps the focus ring visible but static.
   ============================================ */

@media (prefers-reduced-motion: reduce) {
  #catalog-search-clear {
    transition: none !important;
    animation: none !important;
  }

  /* Neutralise any hover/focus/active transform so no motion is perceived */
  #catalog-search-clear:hover,
  #catalog-search-clear:focus,
  #catalog-search-clear:focus-visible,
  #catalog-search-clear:active {
    transform: translateY(-50%) !important;
    transition: none !important;
  }

  /* Icons inside the button must not animate either */
  #catalog-search-clear i {
    animation: none !important;
    transition: none !important;
    transform: none !important;
  }

  /* Keep the focus ring visible but static (no animated halo) */
  #catalog-search-clear:focus-visible,
  #catalog-search-clear:focus {
    box-shadow:
      0 0 0 2px #ffffff,
      0 0 0 6px rgba(124, 58, 237, 0.35) !important;
  }

  .dark #catalog-search-clear:focus-visible,
  .dark #catalog-search-clear:focus {
    box-shadow:
      0 0 0 2px #0f172a,
      0 0 0 6px rgba(196, 181, 253, 0.45) !important;
  }

  /* Search input – no transition on focus ring */
  #catalog-search {
    transition: none !important;
    animation: none !important;
  }

  #catalog-search:focus,
  #catalog-search:focus-visible {
    transition: none !important;
    animation: none !important;
  }
}

/* ============================================
   Forced colors (Windows High Contrast)
   ============================================ */

@media (forced-colors: active) {
  #catalog-search {
    color: CanvasText !important;
    background-color: Canvas !important;
    border-color: CanvasText !important;
  }

  #catalog-search::placeholder {
    color: GrayText !important;
  }

  #catalog-search:focus-visible,
  #catalog-search:focus {
    outline: 2px solid Highlight;
    outline-offset: 2px;
    box-shadow: none;
  }

  #catalog-search-clear {
    color: CanvasText !important;
    background: Canvas !important;
    border: 1px solid CanvasText;
  }

  #catalog-search-clear:hover {
    background: Highlight !important;
    color: HighlightText !important;
  }

  #catalog-search-clear:focus-visible,
  #catalog-search-clear:focus {
    outline: 2px solid Highlight;
    outline-offset: 2px;
    box-shadow: none;
    background: Highlight !important;
    color: HighlightText !important;
  }
}
