/**
 * WPE Query Builder - Facet Styles
 * Frontend styling for facet filters
 * Version: 2.0.0
 */

/* ========================================
   Variables & Base
   ======================================== */
:root {
  --wpe-primary: #2563eb;
  --wpe-primary-dark: #1e40af;
  --wpe-primary-light: #dbeafe;
  --wpe-text: #0f172a;
  --wpe-text-light: #64748b;
  --wpe-text-muted: #94a3b8;
  --wpe-bg: #ffffff;
  --wpe-bg-light: #f8fafc;
  --wpe-bg-gray: #f1f5f9;
  --wpe-border: #e2e8f0;
  --wpe-border-light: #f1f5f9;
  --wpe-radius: 6px;
  --wpe-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --wpe-shadow-lg: 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* ========================================
   Main Container
   ======================================== */
.wpe-facet-filters-wrapper {
  margin-bottom: 30px;
  position: relative;
}

/* Layout: Top */
.wpe-facet-filters-wrapper[data-layout="top"] .wpe-facets-top {
  background: var(--wpe-bg);
  border: 1px solid var(--wpe-border);
  border-radius: var(--wpe-radius);
  padding: 24px;
  box-shadow: var(--wpe-shadow);
}

.wpe-facets-top h3 {
  margin: 0 0 20px 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--wpe-text);
}

.wpe-facets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
}

/* Layout: Sidebar */
.wpe-facet-sidebar-wrapper {
  display: flex;
  gap: 30px;
}

.wpe-facet-sidebar-wrapper[style*="row-reverse"] {
  flex-direction: row-reverse;
}

.wpe-facets-sidebar {
  flex-shrink: 0;
}

.wpe-facets-sidebar > div {
  background: var(--wpe-bg);
  border: 1px solid var(--wpe-border);
  border-radius: var(--wpe-radius);
  padding: 24px;
  box-shadow: var(--wpe-shadow);
  position: sticky;
  top: 20px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}

.wpe-facets-sidebar h3 {
  margin: 0 0 24px 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--wpe-text);
  padding-bottom: 16px;
  border-bottom: 2px solid var(--wpe-border-light);
}

.wpe-query-content-area {
  flex-grow: 1;
  min-width: 0;
}

/* ========================================
   Facet Control
   ======================================== */
.wpe-facet-control {
  background: var(--wpe-bg);
  border: 1px solid var(--wpe-border);
  border-radius: var(--wpe-radius);
  margin-bottom: 16px;
  transition: all 0.3s ease;
}

.wpe-facet-control:hover {
  border-color: var(--wpe-primary);
  box-shadow: var(--wpe-shadow);
}

/* Facet Header */
.wpe-facet-header {
  padding: 14px 16px;
  background: var(--wpe-bg-light);
  border-bottom: 1px solid var(--wpe-border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
  border-radius: var(--wpe-radius) var(--wpe-radius) 0 0;
}

.wpe-facet-header h4 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--wpe-text);
}

.wpe-facet-toggle {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: var(--wpe-text-light);
  font-size: 14px;
  transition: transform 0.3s ease;
}

.wpe-facet-toggle[data-collapsed="true"] {
  transform: rotate(180deg);
}

/* Facet Body */
.wpe-facet-body {
  padding: 16px;
  background: var(--wpe-bg);
  border-radius: 0 0 var(--wpe-radius) var(--wpe-radius);
}

.wpe-facet-control[data-collapsed="true"] .wpe-facet-body {
  display: none;
}

/* ========================================
   Checkbox Controls
   ======================================== */
.wpe-checkbox-list,
.wpe-radio-list {
  max-height: 250px;
  overflow-y: auto;
  padding-right: 8px;
}

.wpe-checkbox-list::-webkit-scrollbar,
.wpe-radio-list::-webkit-scrollbar {
  width: 6px;
}

.wpe-checkbox-list::-webkit-scrollbar-track,
.wpe-radio-list::-webkit-scrollbar-track {
  background: var(--wpe-bg-light);
  border-radius: 3px;
}

.wpe-checkbox-list::-webkit-scrollbar-thumb,
.wpe-radio-list::-webkit-scrollbar-thumb {
  background: var(--wpe-border);
  border-radius: 3px;
}

.wpe-checkbox-list::-webkit-scrollbar-thumb:hover,
.wpe-radio-list::-webkit-scrollbar-thumb:hover {
  background: var(--wpe-text-light);
}

.wpe-checkbox-list label,
.wpe-radio-list label {
  display: flex;
  align-items: center;
  padding: 8px 10px;
  margin: 0 -10px 2px;
  cursor: pointer;
  font-size: 14px;
  color: var(--wpe-text);
  border-radius: 4px;
  transition: background-color 0.2s ease;
}

.wpe-checkbox-list label:hover,
.wpe-radio-list label:hover {
  background: var(--wpe-bg-light);
}

.wpe-checkbox-list input[type="checkbox"],
.wpe-radio-list input[type="radio"] {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin: 0 10px 0 0;
  cursor: pointer;
  accent-color: var(--wpe-primary);
}

.wpe-checkbox-list span:first-of-type,
.wpe-radio-list span:first-of-type {
  flex-grow: 1;
  line-height: 1.4;
}

/* Count badges */
.wpe-checkbox-list span:last-child,
.wpe-radio-list span:last-child {
  margin-left: 8px;
  padding: 2px 6px;
  background: var(--wpe-bg-gray);
  color: var(--wpe-text-muted);
  font-size: 11px;
  font-weight: 500;
  border-radius: 10px;
}

/* Hierarchical checkboxes */
.wpe-checkbox-tree > div {
  margin-left: 20px;
  padding-left: 20px;
  border-left: 1px solid var(--wpe-border-light);
}

/* ========================================
   Select/Dropdown Controls
   ======================================== */
.wpe-facet-select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--wpe-border);
  border-radius: var(--wpe-radius);
  font-size: 14px;
  color: var(--wpe-text);
  background: var(--wpe-bg);
  cursor: pointer;
  transition: all 0.2s ease;
}

.wpe-facet-select:hover {
  border-color: var(--wpe-primary);
}

.wpe-facet-select:focus {
  outline: none;
  border-color: var(--wpe-primary);
  box-shadow: 0 0 0 3px var(--wpe-primary-light);
}

/* ========================================
   Text Input Controls
   ======================================== */
.wpe-facet-text {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--wpe-border);
  border-radius: var(--wpe-radius);
  font-size: 14px;
  color: var(--wpe-text);
  background: var(--wpe-bg);
  transition: all 0.2s ease;
}

.wpe-facet-text:hover {
  border-color: var(--wpe-primary);
}

.wpe-facet-text:focus {
  outline: none;
  border-color: var(--wpe-primary);
  box-shadow: 0 0 0 3px var(--wpe-primary-light);
}

.wpe-facet-text::placeholder {
  color: var(--wpe-text-muted);
}

/* ========================================
   Range Controls
   ======================================== */
.wpe-range-facet {
  padding: 8px 0;
}

.wpe-range-facet > div {
  display: flex;
  gap: 12px;
  align-items: center;
}

.wpe-range-facet input[type="number"] {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--wpe-border);
  border-radius: var(--wpe-radius);
  font-size: 13px;
  color: var(--wpe-text);
  background: var(--wpe-bg);
  transition: all 0.2s ease;
}

.wpe-range-facet input[type="number"]:hover {
  border-color: var(--wpe-primary);
}

.wpe-range-facet input[type="number"]:focus {
  outline: none;
  border-color: var(--wpe-primary);
  box-shadow: 0 0 0 3px var(--wpe-primary-light);
}

.wpe-range-facet span {
  color: var(--wpe-text-light);
  font-size: 13px;
  font-weight: 500;
}

/* ========================================
   Apply & Clear Buttons
   ======================================== */
.wpe-apply-filters-btn,
.wpe-facet-apply-btn {
  width: 100%;
  margin-top: 20px;
  padding: 12px 20px;
  background: var(--wpe-primary);
  color: white;
  border: none;
  border-radius: var(--wpe-radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.wpe-apply-filters-btn:hover,
.wpe-facet-apply-btn:hover {
  background: var(--wpe-primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--wpe-shadow-lg);
}

.wpe-clear-all-filters,
.wpe-clear-all-btn {
  padding: 8px 16px;
  background: white;
  color: var(--wpe-text);
  border: 1px solid var(--wpe-border);
  border-radius: var(--wpe-radius);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.wpe-clear-all-filters:hover,
.wpe-clear-all-btn:hover {
  background: var(--wpe-bg-light);
  border-color: var(--wpe-text-light);
}

/* ========================================
   Active Filters Bar
   ======================================== */
.wpe-active-filters,
.wpe-active-filters-bar {
  margin-bottom: 24px;
  padding: 16px;
  background: var(--wpe-primary-light);
  border: 1px solid var(--wpe-primary);
  border-radius: var(--wpe-radius);
  display: none;
}

.wpe-active-filters-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.wpe-active-filters-header strong {
  color: var(--wpe-primary-dark);
  font-size: 14px;
}

.wpe-active-filters-list,
.wpe-active-filter-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.wpe-filter-tag {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  background: white;
  border: 1px solid var(--wpe-border);
  border-radius: 20px;
  font-size: 13px;
  color: var(--wpe-text);
}

.wpe-filter-tag button {
  margin-left: 6px;
  padding: 0;
  background: none;
  border: none;
  color: var(--wpe-text-light);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}

.wpe-filter-tag button:hover {
  color: var(--wpe-primary);
}

/* ========================================
   Loading States
   ======================================== */
.wpe-query-posts.loading {
  opacity: 0.5;
  pointer-events: none;
  position: relative;
}

.wpe-query-posts.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 32px;
  height: 32px;
  margin: -16px 0 0 -16px;
  border: 3px solid var(--wpe-border);
  border-top-color: var(--wpe-primary);
  border-radius: 50%;
  animation: wpe-spin 0.8s linear infinite;
}

@keyframes wpe-spin {
  to { transform: rotate(360deg); }
}


/* Toggle Button Styles */
.wpe-facet-toggle {
  background: none;
  border: none;
  padding: 4px 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  border-radius: 4px;
}

.wpe-facet-toggle:hover {
  background: var(--wpe-border-light);
  color: var(--wpe-primary);
}

/* Rotate animation when collapsed */
.wpe-facet-toggle[data-collapsed="true"] {
  transform: rotate(180deg);
}

/* Facet Body Transitions */
.wpe-facet-body {
  overflow: hidden;
  transition: opacity 0.3s ease, max-height 0.3s ease;
}

.wpe-facet-control[data-collapsed="true"] .wpe-facet-body {
  display: none;
  opacity: 0;
  max-height: 0;
}

/* ========================================
   Responsive Design
   ======================================== */
@media (max-width: 768px) {
  .wpe-facet-sidebar-wrapper {
    flex-direction: column !important;
  }
  
  .wpe-facets-sidebar {
    width: 100% !important;
    position: static;
  }
  
  .wpe-facets-sidebar > div {
    max-height: none;
    position: static;
  }
  
  .wpe-facets-grid {
    grid-template-columns: 1fr;
  }
  
  .wpe-active-filters-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  
  .wpe-clear-all-btn {
    width: 100%;
    text-align: center;
  }
}

@media (max-width: 480px) {
  .wpe-facets-sidebar > div,
  .wpe-facets-top {
    padding: 16px;
  }
  
  .wpe-facet-control {
    margin-bottom: 12px;
  }
  
  .wpe-facet-header {
    padding: 12px;
  }
  
  .wpe-facet-body {
    padding: 12px;
  }
}