/**
 * FilterBar V2 Styles
 * 
 * Unified styles for category filter bar component system.
 * Uses JCWS Design Pattern Library v1.2.3 variables.
 * 
 * @package JCWS_FilterBar_V2
 * @version 2.1.0
 * @since 2.0.0
 * 
 * CHANGELOG:
 * - v2.1.0: Migrated to project-wide CSS variables from variables.css
 * - v2.0.0: Initial FilterBar V2 implementation
 * 
 * DEPENDENCIES:
 * - css/variables.css (must be loaded first)
 */

/* ==========================================================================
   Container & Layout
   ========================================================================== */

/* ==========================================================================
   RESPONSIVE BREAKPOINTS
   ========================================================================== */

/* === LAPTOP 960px - 1280px === */
@media (min-width: 960px) {
  .jcws-filterbar-v2 {
    margin: var(--space-sm) var(--clamp-padding-value);
    border-radius: var(--radius-lg);
  }
}

/* === TABLET 640px - 960px === */
@media (min-width: 640px) and (max-width: 959px) {

  .jcws-filterbar-v2 {
    margin: 0 var(--clamp-padding-value) var(--space-md);
    border-radius: var(--radius-lg);
  }

}

/* === MOBILE < 640px === */
@media (max-width: 639px) {

  .jcws-filterbar-v2 {
    border-left: none;
    border-radius: 0;
    border-right: none;
    margin: 0 0 var(--space-md);
  }
}

.jcws-filterbar-v2 {
  position: relative;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  margin-bottom: var(--space-md);
  margin-top: var(--space-md);
  transition: box-shadow var(--transition);
}

/* Header / Body / Footer */
.jcws-filterbar-v2__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--clamp-padding-value);
}
.jcws-filterbar-v2__header:hover {
  border-color: var(--jcws-border-strong);
  box-shadow: var(--jcws-shadow-strong);
}

.jcws-filterbar-v2__body {
  display: none; /* Hidden by default */
  background: var(--bg);
  padding: var(--space-sm);
}

.jcws-filterbar-v2__body--open {
  display: block;
}

.jcws-filterbar-v2__footer {
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--border);
  border-bottom-left-radius: var(--radius-lg);
  border-bottom-right-radius: var(--radius-lg);
  background: var(--bg);
}

/* ==========================================================================
   Focus visible (keyboard navigation)
   ========================================================================== */

.jcws-filterbar-v2 a:focus-visible,
.jcws-filterbar-v2 button:focus-visible,
.jcws-filterbar-v2 [role="button"]:focus-visible,
.jcws-filterbar-v2 select:focus-visible,
.jcws-filterbar-v2 input:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ==========================================================================
   Toggle Button Component
   ========================================================================== */

.jcws-filterbar-v2__toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  font-family: var(--font-body);
  font-size: var(--font-base) !important;
  font-weight: 600;
  color: var(--button-text-color);
  background: var(--jcws-accent);
  border: 1px solid var(--main-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
}

.jcws-filterbar-v2__toggle:hover {
  background: var(--jcws-accent-80);
  border-color: var(--button-add-to-cart-color-act);
  transform: translateY(-1px);
  box-shadow: var(--jcws-shadow-strong);
}

.jcws-filterbar-v2__toggle:active {
  transform: translateY(0);
}

.jcws-filterbar-v2__toggle-text {
  flex: 1;
  color: var(--button-text-color);

}

.jcws-filterbar-v2__toggle-icon {
  font-size: var(--font-lg);
  line-height: 1;
  font-weight: 400;
  color: var(--button-text-color);
}

/* Badge zliczająca aktywne filtry */
.jcws-filterbar-v2__toggle-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  height: 1.5rem;
  padding: 0 var(--space-sm);
  font-size: var(--font-sm);
  font-weight: 700;
  color: var(--text);
  background: var(--bg-muted);
  border-radius: var(--radius-full);
}

/* ==========================================================================
   Grid Layout (for widgets in body)
   ========================================================================== */

.jcws-widgets-grid-v2 {
  display: grid;
  gap: var(--space-sm);
}

/* 3 kolumny: 2 obok siebie w górnym rzędzie, 3. na całą szerokość poniżej */
.jcws-widgets-grid-v2--cols-3 {
  grid-template-columns: repeat(2, 1fr);
}

.jcws-widgets-grid-v2--cols-3 > :nth-child(3) {
  grid-column: 1 / -1; /* Full width */
}

/* 2 kolumny: standardowo obok siebie */
.jcws-widgets-grid-v2--cols-2 {
  grid-template-columns: repeat(2, 1fr);
}

@media (max-width: 1280px) {
  .jcws-widgets-grid-v2--cols-3 { 
    grid-template-columns: repeat(2, 1fr); 
  }
  
  .jcws-widgets-grid-v2--cols-3 > :nth-child(3) {
    grid-column: 1 / -1;
  }
}

@media (max-width: 960px) {
  .jcws-widgets-grid-v2--cols-3,
  .jcws-widgets-grid-v2--cols-2 { 
    grid-template-columns: 1fr; 
  }
  
  /* Na mobile wszystkie są full width, więc resetujemy grid-column */
  .jcws-widgets-grid-v2--cols-3 > :nth-child(3) {
    grid-column: auto;
  }
}

/* ==========================================================================
   Widget Area Styling
   ========================================================================== */

.jcws-widget-area-v2 {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  transition: box-shadow var(--transition);
}

.jcws-widget-area-v2:hover {
  box-shadow: var(--shadow-md);
}

.jcws-widget-area-v2 .widget-title {
  margin: 0 0 var(--space-md);
  padding-bottom: var(--space-sm);
  font-family: var(--font-heading);
  font-size: var(--font-lg);
  font-weight: 600;
  color: var(--text);
  border-bottom: 2px solid var(--main-color);
}

/* ==========================================================================
   Active Filters Component
   ========================================================================== */

.jcws-filterbar-v2__active-filters {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-sm);
  padding: var(--space-sm) 0;
}

.jcws-filterbar-v2__active-filters-label {
  margin-right: var(--space-xs);
  font-family: var(--font-body);
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text-light);
}

.jcws-filterbar-v2__active-filter-tag {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  font-family: var(--font-body);
  font-size: var(--font-sm);
  color: var(--text);
  background: linear-gradient(135deg, 
    color-mix(in srgb, var(--main-color) 8%, transparent) 0%, 
    color-mix(in srgb, var(--main-color) 16%, transparent) 100%);
  border: 1px solid var(--main-color);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.jcws-filterbar-v2__active-filter-tag:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.jcws-filterbar-v2__active-filter-label {
  font-weight: 500;
  color: var(--text-light);
  opacity: .9;
}

.jcws-filterbar-v2__active-filter-value {
  font-weight: 700;
  color: var(--text);
}

.jcws-filterbar-v2__active-filter-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  line-height: 1;
  margin-left: var(--space-xs);
  font-size: var(--font-base);
  font-weight: 700;
  text-decoration: none;
  color: var(--white);
  background: var(--button-add-to-cart-color-act);
  border: 1px solid var(--button-add-to-cart-color-act);
  border-radius: 50%;
  transition: var(--transition);
}

.jcws-filterbar-v2__active-filter-remove:hover {
  background: var(--main-color);
  border-color: var(--main-color);
}

.jcws-filterbar-v2__active-filter-remove:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Specyficzne warianty tagów */
.jcws-filterbar-v2__active-filter-tag[data-filter-type="price"] {
  background: linear-gradient(135deg, 
    color-mix(in srgb, var(--warning) 18%, transparent) 0%, 
    color-mix(in srgb, var(--warning) 28%, transparent) 100%);
  border-color: var(--warning);
  color: #664d03;
}

.jcws-filterbar-v2__active-filter-tag[data-filter-type="price"] .jcws-filterbar-v2__active-filter-value { 
  color: #664d03; 
}

.jcws-filterbar-v2__active-filter-tag[data-filter-type="rating"] {
  background: linear-gradient(135deg, 
    color-mix(in srgb, #ff9800 18%, transparent) 0%, 
    color-mix(in srgb, #ff9800 28%, transparent) 100%);
  border-color: #ff9800;
  color: #d84315;
}

.jcws-filterbar-v2__active-filter-tag[data-filter-type="rating"] .jcws-filterbar-v2__active-filter-value { 
  color: #d84315; 
}

/* ==========================================================================
   Clear All Button
   ========================================================================== */

.jcws-filterbar-v2__clear-all {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  font-family: var(--font-body);
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--white);
  background: var(--danger);
  border: 1px solid var(--danger);
  border-radius: var(--radius-md);
  text-decoration: none;
  cursor: pointer;
  transition: var(--transition);
}

.jcws-filterbar-v2__clear-all:hover {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
}

.jcws-filterbar-v2__clear-all:active { 
  transform: translateY(0); 
}

.jcws-filterbar-v2__clear-all:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.jcws-filterbar-v2__clear-all-icon { 
  font-size: var(--font-lg); 
  line-height: 1; 
}

.jcws-filterbar-v2__clear-all-text { 
  font-weight: 600; 
}

/* ==========================================================================
   States: loading, removing, error
   ========================================================================== */

.jcws-filterbar-v2--loading {
  opacity: 0.6;
  pointer-events: none;
}

.jcws-filterbar-v2--loading::after {
  content: '';
  position: absolute;
  top: 50%; 
  left: 50%;
  width: 32px; 
  height: 32px;
  margin: -16px 0 0 -16px;
  border: 3px solid var(--main-color);
  border-top-color: transparent;
  border-radius: 50%;
  animation: jcws-spin .8s linear infinite;
}

.jcws-filterbar-v2__clear-all.jcws-loading {
  opacity: 0.7;
  pointer-events: none;
}

.jcws-filterbar-v2__clear-all.jcws-loading .jcws-filterbar-v2__clear-all-icon {
  animation: jcws-spin .8s linear infinite;
}

.jcws-filterbar-v2__active-filter-tag.jcws-removing {
  animation: jcws-fadeOut .2s ease-out forwards;
}

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

@keyframes jcws-fadeOut {
  from { opacity: 1; transform: scale(1); }
  to   { opacity: 0; transform: scale(0.88); }
}

.jcws-filterbar-v2--error { 
  border-color: var(--danger); 
}

.jcws-filterbar-v2__error-message {
  padding: var(--space-md);
  text-align: center;
  font-family: var(--font-body);
  color: var(--danger);
  background: #fff5f5;
  border: 1px solid var(--danger);
  border-radius: var(--radius-md);
}

/* ==========================================================================
   Responsive Adjustments
   ========================================================================== */

@media (max-width: 768px) {
  .jcws-filterbar-v2__header {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-sm);
  }

  .jcws-filterbar-v2__toggle {
    justify-content: center;
    width: 100%;
  }

  .jcws-filterbar-v2__active-filters {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-sm);
  }

  .jcws-filterbar-v2__active-filter-tag {
    width: 100%;
    justify-content: space-between;
  }

  .jcws-filterbar-v2__clear-all {
    width: 100%;
    justify-content: center;
  }

  .jcws-widget-area-v2 { 
    margin-bottom: var(--space-md); 
  }
}

@media (max-width: 480px) {
  .jcws-filterbar-v2__active-filter-tag {
    font-size: var(--font-xs);
    padding: var(--space-xs) var(--space-sm);
  }
  
  .jcws-filterbar-v2__active-filters-label { 
    font-size: var(--font-xs); 
  }
  
  .jcws-filterbar-v2__clear-all { 
    font-size: var(--font-xs); 
    padding: var(--space-sm) var(--space-md); 
  }
}

/* ==========================================================================
   Accessibility
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  .jcws-filterbar-v2,
  .jcws-filterbar-v2 *,
  .jcws-filterbar-v2__toggle,
  .jcws-filterbar-v2__active-filter-tag,
  .jcws-filterbar-v2__clear-all {
    transition: none !important;
    animation: none !important;
  }
}

@media (prefers-contrast: high) {
  .jcws-filterbar-v2 {
    border-width: 2px !important;
  }
  
  .jcws-filterbar-v2__toggle,
  .jcws-filterbar-v2__active-filter-tag,
  .jcws-filterbar-v2__clear-all {
    border-width: 2px !important;
  }
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
  .jcws-filterbar-v2 { 
    display: none; 
  }
}
