/* =========================================================================
   Ditable Product Filter — frontend styles
   Structural layout only; theme/design-token colors can be overridden.
   ========================================================================= */

.dpf-widget {
  --dpf-accent: #52B148;
  --dpf-accent-rgb: 82, 177, 72;
  --dpf-radius: 6px;
  --dpf-border: #d9d9d9;
  --dpf-muted: #767676;
  --dpf-panel-width: 300px;
  --dpf-chip-bg: rgba(var(--dpf-accent-rgb), 0.10);
}

/* ---------- Chips (active filters) ---------- */
.dpf-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 16px;
}
.dpf-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--dpf-chip-bg);
  border: 1px solid rgba(var(--dpf-accent-rgb), 0.35);
  color: #1d2327;
  border-radius: var(--dpf-radius);
  padding: 4px 10px;
  font-size: 0.85em;
}
.dpf-chip-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  font-size: 1.1em;
  line-height: 1;
  padding: 0 2px;
}
.dpf-chip-remove:hover { color: #b32d2e; }
.dpf-clear-all {
  background: transparent;
  border: 1px dashed var(--dpf-border);
  border-radius: var(--dpf-radius);
  padding: 4px 10px;
  cursor: pointer;
  font-size: 0.85em;
  margin-left: auto;
}
.dpf-share {
  background: transparent;
  border: 1px solid var(--dpf-border);
  border-radius: var(--dpf-radius);
  padding: 4px 10px;
  cursor: pointer;
  font-size: 0.85em;
  color: var(--dpf-muted);
}
.dpf-share:hover { color: var(--dpf-accent); border-color: var(--dpf-accent); }

/* ---------- Color swatches ---------- */
.dpf-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.15);
  flex: 0 0 auto;
  vertical-align: middle;
}

/* ---------- Sort (orderby) ---------- */
.dpf-results-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  color: var(--dpf-muted);
}
.dpf-orderby-wrap { display: inline-flex; align-items: center; gap: 6px; }
.dpf-orderby-label { font-size: 0.85em; }
.dpf-orderby {
  border: 1px solid var(--dpf-border);
  border-radius: var(--dpf-radius);
  padding: 5px 8px;
  font-size: 0.85em;
  background: #fff;
}

/* ---------- Facets / accordion ---------- */
.dpf-facets { display: block; }
.dpf-facet {
  border: 1px solid var(--dpf-border);
  border-radius: var(--dpf-radius);
  margin-bottom: 12px;
  overflow: hidden;
}
.dpf-facet-title {
  margin: 0;
  padding: 12px 14px;
  font-size: 0.95em;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f7f7f7;
}
.dpf-facet-title[aria-expanded="false"] .dpf-facet-caret::before { content: "+"; }
.dpf-facet-title[aria-expanded="true"] .dpf-facet-caret::before { content: "\2212"; }
.dpf-facet-caret { font-weight: 700; opacity: 0.6; }
.dpf-facet-body { padding: 10px 14px; max-height: 340px; overflow: auto; }

/* ---------- Option lists ---------- */
.dpf-options {
  list-style: none;
  margin: 0;
  padding: 0;
}
.dpf-options li { margin: 2px 0; }
.dpf-option {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9em;
  cursor: pointer;
  padding: 3px 0;
}
.dpf-option input[type="checkbox"],
.dpf-option input[type="radio"] {
  accent-color: var(--dpf-accent);
}
.dpf-option-label { flex: 1; }
.dpf-option-count {
  color: var(--dpf-muted);
  font-size: 0.85em;
}
.dpf-list-search {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 10px;
  margin-bottom: 8px;
  border: 1px solid var(--dpf-border);
  border-radius: var(--dpf-radius);
  font-size: 0.9em;
}
.dpf-show-more {
  background: none;
  border: none;
  color: var(--dpf-accent);
  cursor: pointer;
  padding: 6px 0;
  font-size: 0.85em;
}
.dpf-more-option { display: none; }

/* ---------- Price slider ---------- */
.dpf-price-inputs {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 14px;
}
.dpf-price-inputs input {
  width: 46%;
  box-sizing: border-box;
  padding: 6px;
  border: 1px solid var(--dpf-border);
  border-radius: var(--dpf-radius);
  text-align: center;
}
.dpf-price-track {
  position: relative;
  height: 24px;
  margin: 0 8px;
}
.dpf-price-track::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 50%;
  height: 4px;
  transform: translateY(-50%);
  background: var(--dpf-border);
  border-radius: 2px;
}
.dpf-price-range {
  position: absolute;
  top: 50%;
  height: 4px;
  transform: translateY(-50%);
  background: var(--dpf-accent);
  border-radius: 2px;
}
.dpf-price-handle {
  position: absolute;
  top: 50%;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--dpf-accent);
  transform: translate(-50%, -50%);
  cursor: grab;
  padding: 0;
}
.dpf-price-handle:active { cursor: grabbing; }

/* ---------- Toggles ---------- */
.dpf-toggles { list-style: none; margin: 0; padding: 0; }
.dpf-toggle { margin: 6px 0; }
.dpf-toggle-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 0.9em;
}
.dpf-toggle-label input { display: none; }
.dpf-toggle-switch {
  width: 34px; height: 18px;
  border-radius: 9px;
  background: var(--dpf-border);
  position: relative;
  transition: background 0.15s;
  flex: 0 0 auto;
}
.dpf-toggle-switch::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
}
.dpf-toggle-label input:checked + .dpf-toggle-switch { background: var(--dpf-accent); }
.dpf-toggle-label input:checked + .dpf-toggle-switch::after { transform: translateX(16px); }

/* ---------- Results grid ---------- */
.dpf-results { position: relative; }
.dpf-product-grid {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
  display: grid;
  /* Column count is set by inline CSS from the grid_columns setting
     (see DPF_Plugin::grid_columns_css). This is a safe fallback. */
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}
.dpf-product-grid li.product {
  border: 1px solid var(--dpf-border);
  border-radius: var(--dpf-radius);
  padding: 14px;
  text-align: center;
}
.dpf-product-grid li.product a { text-decoration: none; color: inherit; }
.dpf-product-image img { max-width: 100%; height: auto; }
.dpf-product-grid .price { color: var(--dpf-accent); font-weight: 600; }
.dpf-no-results { grid-column: 1 / -1; text-align: center; padding: 40px; color: var(--dpf-muted); }

/* ---------- Load more button ---------- */
.dpf-load-more {
  display: flex;
  justify-content: center;
  margin: 4px 0 8px;
}
.dpf-load-more-btn {
  border: 1px solid var(--dpf-accent);
  border-radius: var(--dpf-radius);
  background: var(--dpf-accent);
  color: #fff;
  padding: 10px 22px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1.4;
}
.dpf-load-more-btn:hover { opacity: 0.9; }
.dpf-load-more-btn.is-loading { opacity: 0.6; cursor: wait; }
.dpf-load-more-btn:disabled { cursor: wait; }

/* ---------- Loading state ---------- */
.dpf-results.is-loading {
  position: relative;
  min-height: 200px;
}
.dpf-results.is-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.55);
  backdrop-filter: blur(1px);
  z-index: 1;
}
.dpf-results.is-loading::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  border: 4px solid rgba(0,0,0,0.12);
  border-top-color: var(--dpf-accent, #2271b1);
  border-radius: 50%;
  animation: dpf-spin 0.7s linear infinite;
  z-index: 2;
}
@keyframes dpf-spin {
  to { transform: rotate(360deg); }
}

/* ---------- Desktop: two-column layout (products left, filters right) ---------- */
@media (min-width: 768px) {
  .dpf-widget {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 290px;
    grid-template-areas:
      "chips chips"
      "results panel";
    gap: 28px 28px;
    align-items: start;
  }
  .dpf-widget .dpf-chips   { grid-area: chips; }
  .dpf-widget .dpf-panel   { grid-area: panel; }
  .dpf-widget .dpf-results { grid-area: results; min-width: 0; }

  /* Left-positioned filters: mirror the columns so products sit right. */
  .dpf-widget.dpf-sidebar-left {
    grid-template-columns: 290px minmax(0, 1fr);
    grid-template-areas:
      "chips chips"
      "panel results";
  }

  /* Right filter column is sticky so it stays in view while browsing results. */
  .dpf-widget .dpf-panel {
    position: sticky;
    top: 20px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
  }
  /* Panel head + drawer close are mobile-only; hide on desktop. */
  .dpf-widget .dpf-panel-head,
  .dpf-widget .dpf-drawer-close { display: none; }
}

/* ---------- Off-canvas drawer (mobile) ---------- */
@media (max-width: 767px) {
  .dpf-panel {
    position: fixed;
    top: 0;
    right: -100%;
    width: var(--dpf-panel-width);
    max-width: 85vw;
    height: 100vh;
    background: #fff;
    z-index: 100000;
    overflow-y: auto;
    padding: 16px;
    box-sizing: border-box;
    transition: right 0.25s ease;
    box-shadow: 0 0 24px rgba(0,0,0,0.2);
  }
  .dpf-panel.dpf-open { right: 0; }
  .dpf-panel-head { display: flex; justify-content: flex-end; }
  .dpf-drawer-close { font-size: 1.6em; background: none; border: none; cursor: pointer; line-height: 1; }
  .dpf-trigger {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 99999;
    background: var(--dpf-accent);
    color: #fff;
    border: none;
    border-radius: 999px;
    padding: 12px 22px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  }
  .dpf-trigger-count {
    background: #fff;
    color: var(--dpf-accent);
    border-radius: 999px;
    padding: 1px 7px;
    margin-left: 6px;
    font-size: 0.85em;
  }
  .dpf-widget.dpf-open .dpf-trigger { display: none; }
}
