/* ============================================
   PLP Filter System - Complete Styles
   ============================================ */

:root {
  --terra-plp-filter-bg: #FFFFFF;
  --terra-plp-filter-border: #E8E8E8;
  --terra-plp-filter-text: #1A1A1A;
  --terra-plp-filter-text-secondary: #666666;
  --terra-plp-filter-text-muted: #999999;
  --terra-plp-filter-hover-bg: #F9F9F9;
  --terra-plp-filter-active-bg: #F0E8D8;
  --terra-plp-filter-accent: #D4C4A8;
  --terra-plp-filter-backdrop: rgba(0, 0, 0, 0.4);
  --terra-plp-filter-sidebar-width: 354px;
  --terra-plp-filter-tablet-width: 300px;
  --terra-plp-filter-gap: 24px;
  --terra-plp-filter-animation-duration: 300ms;
  --terra-plp-filter-animation-easing: cubic-bezier(0.23, 1, 0.32, 1);
}

/* ============================================
   FILTER BAR - Top Control Section
   ============================================ */

.terra-plp__filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 0;
  margin-bottom: 24px;
  width: 100%;
}

.terra-plp__filter-bar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.terra-plp__filter-bar-right {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-left: auto;
}

/* Filter Button */
.terra-plp__btn-filter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  background-color: var(--terra-plp-filter-active-bg);
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  color: var(--terra-plp-filter-text);
  cursor: pointer;
  transition: all 200ms ease;
  white-space: nowrap;
  height: 50px;
  min-width: 150px;
}

.terra-plp__btn-filter:hover {
  background-color: #E8D8C0;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}

.terra-plp__btn-filter:focus {
  outline: 2px solid var(--terra-plp-filter-accent);
  outline-offset: 2px;
}

.terra-plp__btn-filter-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.terra-plp__btn-filter-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  background-color: var(--terra-black);
  color: var(--terra-white);
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  margin-left: 4px;
}

/* Result Count */
.terra-plp__result-count {
  font-size: 14px;
  color: var(--terra-plp-filter-text-secondary);
  white-space: nowrap;
  height: 50px;
  display: flex;
  align-items: center;
  padding: 0 16px;
}

/* ============================================
   PRODUCTS GRID - Layout Container
   ============================================ */

.terra-plp__products-wrapper {
  display: block;
  width: 100%;
  transition: margin-left var(--terra-plp-filter-animation-duration) var(--terra-plp-filter-animation-easing);
  /* Ensure wrapper itself doesn't hide content */
  min-height: 400px;
}

.terra-plp__products-wrapper--filter-open {
  margin-left: var(--terra-plp-filter-sidebar-width);
}

/* Main Grid - Default 4 columns */
.terra-plp__products-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--terra-plp-filter-gap);
  width: 100%;
  min-height: 200px; /* Ensure grid has minimum height */
  padding: var(--space-6); /* Add padding for visibility */
  box-sizing: border-box;
  /* Debug: Add light bg to see if grid renders */
  background-color: #f5f5f5;
}

/* When filter is open - reduce to 3 columns */
.terra-plp__products-wrapper--filter-open .terra-plp__products-grid {
  grid-template-columns: repeat(3, 1fr);
}

/* Product cards in grid */
.terra-plp__products-grid .product,
.terra-plp__products-grid .terra-product-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 450px; /* Ensure cards have minimum height */
}

/* ============================================
   FILTER PANEL - Desktop Sidebar
   ============================================ */

.terra-plp__filter-panel {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--terra-plp-filter-sidebar-width);
  height: 100vh;
  background-color: var(--terra-plp-filter-bg);
  border-right: 1px solid var(--terra-plp-filter-border);
  padding: 24px 0;
  overflow-y: auto;
  z-index: 210;
  transform: translateX(-100%);
  transition: transform var(--terra-plp-filter-animation-duration) var(--terra-plp-filter-animation-easing);
}

.terra-plp__filter-panel--open {
  transform: translateX(0);
}

.terra-plp__filter-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  margin-bottom: 16px;
}

.terra-plp__filter-panel-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--terra-plp-filter-text);
}

.terra-plp__filter-panel-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--terra-plp-filter-text);
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background-color 200ms ease;
}

.terra-plp__filter-panel-close:hover {
  background-color: var(--terra-plp-filter-hover-bg);
}

.terra-plp__filter-panel-content {
  flex: 1;
  overflow-y: auto;
}

.terra-plp__filter-panel-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-top: 1px solid var(--terra-plp-filter-border);
  gap: 16px;
  position: sticky;
  bottom: 0;
  background-color: var(--terra-plp-filter-bg);
}

.terra-plp__btn-reset {
  background: none;
  border: none;
  color: var(--terra-plp-filter-text);
  font-size: 14px;
  cursor: pointer;
  text-decoration: underline;
  padding: 8px 0;
  transition: color 200ms ease;
}

.terra-plp__btn-reset:hover {
  color: var(--terra-plp-filter-text-secondary);
}

/* ============================================
   FILTER CATEGORIES
   ============================================ */

.terra-plp__filter-category {
  border-bottom:1px solid var(--terra-plp-filter-border);
}

.terra-plp__filter-category:last-child {
  border-bottom: none;
}

.terra-plp__filter-category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 16px;
  cursor: pointer;
  user-select: none;
  background: none;
  border: none;
  width: 100%;
  transition: background-color 100ms ease;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--terra-plp-filter-text);
}

.terra-plp__filter-category-header:hover {
  background-color: var(--terra-plp-filter-hover-bg);
}

.terra-plp__filter-category-title {
  text-transform: uppercase;
  font-size: 14px;
  font-weight: 700;
}

.terra-plp__filter-category-chevron {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  transition: transform var(--terra-plp-filter-animation-duration) ease;
  color: var(--terra-plp-filter-text-secondary);
}

.terra-plp__filter-category--expanded .terra-plp__filter-category-chevron {
  transform: rotate(180deg);
}

.terra-plp__filter-category-options {
  display: none;
  flex-direction: column;
  gap: 12px;
  padding: 0 16px 20px;
}

.terra-plp__filter-category--expanded .terra-plp__filter-category-options {
  display: flex;
}

/* ============================================
   FILTER OPTIONS - Checkboxes & Radios
   ============================================ */

.terra-plp__filter-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
  transition: background-color 100ms ease;
  min-height: 44px;
}

.terra-plp__filter-option:hover {
  background-color: var(--terra-plp-filter-hover-bg);
}

.terra-plp__filter-option--checked {
  background-color: var(--terra-plp-filter-active-bg);
  border-left: 3px solid var(--terra-plp-filter-accent);
  padding-left: 9px;
}

/* Custom Checkbox Input */
.terra-plp__filter-input {
  appearance: none;
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  min-width: 20px;
  border: 2px solid #D0D0D0;
  border-radius: 4px;
  background-color: var(--terra-white);
  cursor: pointer;
  transition: all 200ms ease;
  position: relative;
  flex-shrink: 0;
}

.terra-plp__filter-input:hover {
  border-color: var(--terra-plp-filter-accent);
}

.terra-plp__filter-input:focus {
  outline: 2px solid var(--terra-plp-filter-accent);
  outline-offset: 2px;
}

.terra-plp__filter-input:checked {
  background-color: var(--terra-plp-filter-accent);
  border-color: var(--terra-plp-filter-accent);
}

.terra-plp__filter-input:checked::after {
  content: '✓';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
  font-size: 14px;
  font-weight: bold;
  line-height: 1;
}

/* Radio Button */
.terra-plp__filter-input[type="radio"] {
  border-radius: 50%;
}

.terra-plp__filter-input[type="radio"]:checked::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 8px;
  background-color: white;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.terra-plp__filter-label {
  flex: 1;
  font-size: 14px;
  font-weight: 400;
  color: var(--terra-plp-filter-text);
  cursor: pointer;
  padding: 0;
}

.terra-plp__filter-count {
  margin-left: auto;
  font-size: 12px;
  color: var(--terra-plp-filter-text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ============================================
   MOBILE BOTTOM SHEET MODAL
   ============================================ */

.terra-plp__filter-modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--terra-plp-filter-backdrop);
  z-index: 250;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--terra-plp-filter-animation-duration) ease;
}

.terra-plp__filter-modal-backdrop--visible {
  opacity: 1;
  pointer-events: auto;
}

.terra-plp__filter-modal {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 75vh;
  background-color: var(--terra-plp-filter-bg);
  border-radius: 16px 16px 0 0;
  z-index: 251;
  transform: translateY(100%);
  transition: transform var(--terra-plp-filter-animation-duration) var(--terra-plp-filter-animation-easing);
  display: flex;
  flex-direction: column;
}

.terra-plp__filter-modal--open {
  transform: translateY(0);
}

.terra-plp__filter-modal-drag-handle {
  width: 40px;
  height: 4px;
  background-color: #D0D0D0;
  border-radius: 2px;
  margin: 12px auto;
  flex-shrink: 0;
}

.terra-plp__filter-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px 16px;
  border-bottom: 1px solid var(--terra-plp-filter-border);
}

.terra-plp__filter-modal-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 0;
}

.terra-plp__filter-modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 16px;
  border-top: 1px solid var(--terra-plp-filter-border);
  flex-shrink: 0;
}

.terra-plp__btn-apply {
  flex: 1;
  padding: 12px 24px;
  background-color: #2D5A27;
  color: var(--terra-white);
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 200ms ease;
}

.terra-plp__btn-apply:hover {
  background-color: #1f4517;
}

.terra-plp__btn-apply:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============================================
   LOADING STATES
   ============================================ */

.terra-plp__products-grid--loading {
  opacity: 0.6;
  pointer-events: none;
}

.terra-plp__skeleton-loader {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: plp-loading 1.5s infinite;
  border-radius: 8px;
}

@keyframes plp-loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* ============================================
   RESPONSIVE - TABLET (1024px)
   ============================================ */

@media (max-width: 1024px) {
  .terra-plp__filter-panel {
    width: var(--terra-plp-filter-tablet-width);
  }

  .terra-plp__products-wrapper--filter-open {
    margin-left: var(--terra-plp-filter-tablet-width);
  }

  .terra-plp__products-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .terra-plp__products-wrapper--filter-open .terra-plp__products-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ============================================
   RESPONSIVE - MOBILE (<768px)
   ============================================ */

@media (max-width: 768px) {
  /* Filter bar - keep horizontal on mobile */
  .terra-plp__filter-bar {
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
  }

  .terra-plp__filter-bar-left {
    flex: 1;
    width: 100%;
  }

  .terra-plp__filter-bar-right {
    margin-left: 0;
  }

  /* Full-width filter button on mobile */
  .terra-plp__btn-filter {
    width: 100%;
    border-radius: 24px;
    min-width: auto;
  }

  /* Hide desktop sidebar */
  .terra-plp__filter-panel {
    display: none;
  }

  /* Reset wrapper margins */
  .terra-plp__products-wrapper {
    margin-left: 0 !important;
  }

  /* Mobile grid - 1 column */
  .terra-plp__products-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .terra-plp__products-wrapper--filter-open .terra-plp__products-grid {
    grid-template-columns: 1fr;
  }

  /* Filter modal visible on mobile */
  .terra-plp__filter-modal {
    display: flex;
  }

  .terra-plp__filter-modal-footer {
    padding: 16px;
  }

  /* Touch target sizes */
  .terra-plp__btn-filter,
  .terra-plp__filter-option,
  .terra-plp__filter-input {
    min-height: 44px;
  }
}

/* ============================================
   ACCESSIBILITY - Reduced Motion
   ============================================ */

@media (prefers-reduced-motion: reduce) {
  .terra-plp__filter-panel,
  .terra-plp__filter-modal,
  .terra-plp__filter-category-chevron,
  .terra-plp__products-wrapper,
  .terra-plp__filter-option,
  .terra-plp__filter-input,
  .terra-plp__btn-filter,
  .terra-plp__skeleton-loader {
    transition: none !important;
    animation: none !important;
  }
}

/* Focus visible states */
.terra-plp__filter-option:focus-visible,
.terra-plp__filter-category-header:focus-visible,
.terra-plp__btn-filter:focus-visible {
  outline: 2px solid var(--terra-plp-filter-accent);
  outline-offset: 2px;
}
