/* ==========================================================================
   Customer Photo Gallery – Filters Bar
   Target markup:
   <form id="cpg-gallery-filters" class="cpg-filters">…</form>
   ========================================================================== */

/* Shared tokens + defaults */
:where(#cpg-gallery-filters.cpg-filters,
       .cpg-dimmer) {
  /* Brand / accent colors (fallbacks if global tokens not set) */
  --cpg-brand-1: var(--ctl-c1, #ec8639);
  --cpg-brand-2: var(--ctl-c2, #ffb86c);
  --cpg-brand-3: var(--ctl-c3, #f97316);

  /* Foreground */
  --cpg-fg:      var(--text-high, #f5f5f5);
  --cpg-fg-mid:  var(--text-mid, #d0d0d0);
  --cpg-fg-low:  var(--text-low, #9a9a9a);

  /* Surfaces */
  --cpg-bg-1:    var(--surface-1, #050509);
  --cpg-bg-2:    var(--surface-2, #111827);
  --cpg-bg-3:    var(--surface-3, #020617);

  /* Borders / outlines */
  --cpg-border-subtle: rgba(148, 163, 184, 0.35);
  --cpg-border-strong: rgba(148, 163, 184, 0.7);

  /* Form elements */
  --cpg-input-bg:      rgba(15, 23, 42, 0.9);
  --cpg-input-border:  rgba(148, 163, 184, 0.45);
  --cpg-input-focus:   var(--cpg-brand-1);
  --cpg-placeholder:   rgba(148, 163, 184, 0.8);

  /* Swatches */
  --cpg-swatch-border: rgba(15, 23, 42, 1);
  --cpg-swatch-ring:   rgba(248, 250, 252, 0.9);

  /* Shadows */
  --cpg-elev-1: 0 14px 45px rgba(15, 23, 42, 0.75);
}

/* ==========================================================================
   Layout – Filters bar container
   ========================================================================== */

#cpg-gallery-filters.cpg-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  padding: 0.75rem 1rem;
  margin: 0 0 1rem;
  border-radius: 0.75rem;
  background: radial-gradient(circle at top left,
              rgba(148, 163, 184, 0.14),
              rgba(15, 23, 42, 0.95) 46%,
              rgba(15, 23, 42, 1) 80%);
  border: 1px solid rgba(148, 163, 184, 0.35);
  color: var(--cpg-fg);
  box-shadow: 0 16px 45px rgba(15, 23, 42, 0.8);
  position: relative;
  z-index: 5;
  backdrop-filter: blur(18px);
}

/* Stack more cleanly on very small screens */
@media (max-width: 768px) {
  #cpg-gallery-filters.cpg-filters {
    flex-direction: column;
    align-items: stretch;
    padding: 0.75rem;
  }
}

/* Each field block */
.cpg-filters .cpg-select,
.cpg-filters .cpg-field,
.cpg-filters .cpg-color {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* Make main controls share space nicely on desktop */
.cpg-filters .cpg-select {
  min-width: 180px;
  max-width: 260px;
}

.cpg-filters .cpg-field--product,
.cpg-filters .cpg-field--author {
  flex: 1 1 220px;
  min-width: 0; /* prevent overflow */
}

.cpg-filters .cpg-color {
  position: relative;
  flex: 0 0 auto;
}

/* ==========================================================================
   Inputs + base button styling
   ========================================================================== */

.cpg-filters select,
.cpg-filters input[type="text"],
.cpg-filters input[type="search"] {
  width: 100%;
  padding: 0.4rem 0.55rem;
  border-radius: 0.5rem;
  border: 1px solid var(--cpg-input-border);
  background-color: var(--cpg-input-bg);
  color: var(--cpg-fg);
  font-size: 0.85rem;
  line-height: 1.3;
  outline: none;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.4);
  transition:
    border-color 0.16s ease-out,
    box-shadow 0.16s ease-out,
    background-color 0.16s ease-out;
  appearance: none;
}

.cpg-filters select:focus,
.cpg-filters input[type="text"]:focus,
.cpg-filters input[type="search"]:focus {
  border-color: var(--cpg-input-focus);
  box-shadow:
    0 0 0 1px var(--cpg-input-focus),
    0 0 0 6px rgba(236, 134, 57, 0.18);
  background-color: rgba(15, 23, 42, 0.98);
}

.cpg-filters ::placeholder {
  color: var(--cpg-placeholder);
}

/* Compact vertical spacing for text fields */
.cpg-filters .cpg-field {
  position: relative;
}

/* Buttons */
.cpg-filters .cpg-btn {
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  font-size: 0.78rem;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
  background: linear-gradient(135deg, var(--cpg-brand-1), var(--cpg-brand-3));
  color: #020617;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.7);
  transition:
    transform 0.12s ease-out,
    box-shadow 0.12s ease-out,
    background 0.18s ease-out,
    border-color 0.18s ease-out;
}

.cpg-filters .cpg-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.85);
}

.cpg-filters .cpg-btn:active {
  transform: translateY(0);
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.9) inset;
}

/* Ghost variant */
.cpg-filters .cpg-btn--ghost {
  background: transparent;
  border-color: var(--cpg-border-subtle);
  color: var(--cpg-fg-mid);
  box-shadow: none;
}

.cpg-filters .cpg-btn--ghost:hover {
  background: radial-gradient(circle at top left,
              rgba(148, 163, 184, 0.12),
              rgba(15, 23, 42, 1) 65%);
  border-color: var(--cpg-border-strong);
}

/* Apply + Reset area */
.cpg-filters #cpg-apply,
.cpg-filters #cpg-reset {
  flex: 0 0 auto;
}

/* Result meta */
.cpg-filters .cpg-filter-meta {
  margin-left: auto;
  font-size: 0.78rem;
  color: var(--cpg-fg-low);
  white-space: nowrap;
}

@media (max-width: 768px) {
  .cpg-filters .cpg-filter-meta {
    margin-left: 0;
  }
}

/* ==========================================================================
   Autocomplete / suggestions dropdowns
   ========================================================================== */

.cpg-filters .suggestions {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 2px);
  z-index: 50;
  list-style: none;
  margin: 0;
  padding: 0.15rem 0;
  max-height: 260px;
  overflow-y: auto;
  background:
    radial-gradient(circle at top,
      rgba(15, 23, 42, 0.98),
      rgba(15, 23, 42, 1) 65%);
  border-radius: 0.55rem;
  border: 1px solid rgba(148, 163, 184, 0.5);
  box-shadow: var(--cpg-elev-1);
}

.cpg-filters .suggestions li {
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
  color: var(--cpg-fg-mid);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.cpg-filters .suggestions li:hover,
.cpg-filters .suggestions li[aria-selected="true"] {
  background: linear-gradient(90deg,
              rgba(236, 134, 57, 0.16),
              rgba(15, 23, 42, 1));
  color: var(--cpg-fg);
}

/* ==========================================================================
   Color picker – swatches + popover
   ========================================================================== */

/* Trigger button (Filter by Color) */
.cpg-filters .cpg-color-toggle {
  font-size: 0.78rem;
}

/* Color control wrapper */
.cpg-filters .cpg-color {
  position: relative;
  flex: 0 0 auto;
}

/* Popover: hidden by default */
.cpg-filters .cpg-color-popover {
  position: absolute;
  right: 0;
  top: calc(100% + 0.35rem);
  min-width: 220px;
  max-width: 320px;
  padding: 0.55rem 0.6rem;
  background:
    radial-gradient(circle at top left,
      rgba(15, 23, 42, 1),
      rgba(15, 23, 42, 0.98) 60%);
  border-radius: 0.65rem;
  border: 1px solid rgba(148, 163, 184, 0.55);
  box-shadow: var(--cpg-elev-1);

  /* hidden state */
  display: none;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-4px);
  transition:
    opacity 0.14s ease-out,
    transform 0.14s ease-out,
    visibility 0.14s ease-out;
  z-index: 60;
}

/* Visible when JS opens it */
.cpg-filters .cpg-color.is-open .cpg-color-popover {
  display: block;
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
}

/* Swatch grid */
.cpg-filters .cpg-swatch-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.35rem;
}

@media (max-width: 480px) {
  .cpg-filters .cpg-swatch-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

/* Individual swatch button */
.cpg-filters .cpg-swatch {
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 999px;
  border: 2px solid var(--cpg-swatch-border);
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 1);
  cursor: pointer;
  position: relative;
  outline: none;
  transition:
    transform 0.1s ease-out,
    box-shadow 0.1s ease-out,
    border-color 0.1s ease-out,
    opacity 0.1s ease-out;
}

.cpg-filters .cpg-swatch:hover {
  transform: translateY(-1px);
  box-shadow:
    0 0 0 1px rgba(15, 23, 42, 1),
    0 0 0 3px rgba(148, 163, 184, 0.65);
}

/* Selected state */
.cpg-filters .cpg-swatch.is-selected,
.cpg-filters .cpg-swatch[aria-pressed="true"] {
  border-color: var(--cpg-swatch-ring);
  box-shadow:
    0 0 0 1px rgba(15, 23, 42, 1),
    0 0 0 3px rgba(236, 134, 57, 0.9),
    0 8px 18px rgba(15, 23, 42, 0.9);
  transform: translateY(-1px) scale(1.02);
}


/* ==========================================================================
   Dimmer overlay (used with color popover if JS wants it)
   ========================================================================== */

.cpg-dimmer {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at top,
              rgba(15, 23, 42, 0.8),
              rgba(15, 23, 42, 0.92) 40%,
              rgba(15, 23, 42, 0.98) 80%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s ease-out;
  z-index: 40;
}

.cpg-dimmer.is-active {
  opacity: 1;
  pointer-events: auto;
}

/* ==========================================================================
   Misc
   ========================================================================== */

.cpg-filters * {
  box-sizing: border-box;
}

.cpg-filters label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--cpg-fg-low);
  margin-bottom: 0.2rem;
}

/* Hide the hidden select (but keep accessible) – already inline, just reinforce */
#filter-color-groups {
  position: absolute !important;
  left: -9999px !important;
  top: auto !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
}
