/**
 * Smart Product Filter - Styles
 *
 * Modern hierarchical tree filter with clean, compact sidebar look.
 * Includes multi-select visual indicators and mobile slide-out panel.
 *
 * @package SmartProductFilter
 * @since 1.2.0
 */

/* ─── Base Styles (Desktop) ─────────────────────────────────────────── */

.spf-title {
  margin: 0 0 10px;
  font-size: 1.05em;
  font-weight: 600;
  color: #1a1a1a;
}

.spf-category-tree {
  list-style: none;
  margin: 0;
  padding: 0;
}

.spf-category-tree ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.spf-category-item {
  position: relative;
  margin: 0;
  padding: 0;
}

.spf-category-label {
  display: flex;
  align-items: center;
  padding: 5px 10px;
  cursor: pointer;
  border-radius: 20px;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
  font-size: 0.9em;
  line-height: 1.4;
  user-select: none;
  margin: 1px 0;
  border: 1px solid transparent;
}

.spf-category-label:hover {
  background-color: #f5f5f5;
  border-color: #e8e8e8;
}

.spf-category-label:focus {
  outline: 2px solid #0073aa;
  outline-offset: -2px;
}

.spf-category-label.spf-active,
.spf-active>.spf-category-label {
  background-color: #0073aa;
  color: #fff;
  font-weight: 500;
  border-color: #0073aa;
}

.spf-category-label.spf-active:hover,
.spf-active>.spf-category-label:hover {
  background-color: #005a87;
  border-color: #005a87;
}

/* ─── Count Badge ───────────────────────────────────────────────────── */

.spf-count {
  color: #aaa;
  font-size: 0.8em;
  margin-left: 4px;
  font-weight: 400;
}

.spf-active .spf-count {
  color: rgba(255, 255, 255, 0.75);
}

/* ─── Children / Nesting (Tree View with Left Border Guide) ─────────── */

.spf-children {
  padding-left: 24px;
  margin-left: 8px;
  border-left: 2px solid #e8e8e8;
  transition: border-color 0.2s ease;
}

.spf-category-item:hover>.spf-children {
  border-left-color: #ccc;
}

.spf-collapsed>.spf-children {
  display: none;
}

/* ─── Toggle Button (Chevron ▸ that rotates 90°) ────────────────────── */

.spf-toggle {
  position: absolute;
  top: 3px;
  right: 4px;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background-color 0.2s ease;
}

.spf-toggle:hover {
  background-color: rgba(0, 0, 0, 0.06);
}

.spf-toggle:focus {
  outline: 2px solid #0073aa;
  outline-offset: -2px;
}

.spf-toggle-icon {
  display: block;
  font-size: 12px;
  line-height: 1;
  color: #666;
  transition: transform 0.25s ease;
  transform: rotate(90deg);
}

.spf-toggle-icon::before {
  content: '▸';
}

.spf-collapsed>.spf-toggle .spf-toggle-icon {
  transform: rotate(0deg);
}

/* ─── Multi-Select Checkbox ──────────────────────────────────────────── */

.spf-multi-select .spf-select-indicator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  min-width: 16px;
  border-radius: 3px;
  border: 2px solid #bbb;
  margin-right: 8px;
  transition: all 0.15s ease;
  position: relative;
  background: #fff;
}

.spf-multi-select .spf-category-label:hover .spf-select-indicator {
  border-color: #0073aa;
}

.spf-multi-select .spf-category-label.spf-active .spf-select-indicator {
  border-color: #0073aa;
  background-color: #0073aa;
}

.spf-multi-select .spf-category-label.spf-active .spf-select-indicator::after {
  content: '';
  display: block;
  width: 4px;
  height: 8px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  margin-top: -2px;
}

/* Hide indicator when multi-select is off */
.spf-filter-widget:not(.spf-multi-select) .spf-select-indicator {
  display: none;
}

/* In multi-select mode, don't use pill highlight — use checkbox only */
.spf-multi-select .spf-category-label.spf-active {
  background-color: transparent;
  color: inherit;
  border-color: transparent;
  font-weight: 600;
}

.spf-multi-select .spf-category-label.spf-active:hover {
  background-color: #f5f5f5;
  border-color: #e8e8e8;
}

.spf-multi-select .spf-active .spf-count {
  color: #aaa;
}

/* ─── Empty / Loading / Error States ────────────────────────────────── */

.spf-no-categories {
  padding: 12px;
  color: #666;
  font-style: italic;
  font-size: 0.9em;
}

.spf-loading {
  position: relative;
  opacity: 0.5;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.spf-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 32px;
  height: 32px;
  margin: -16px 0 0 -16px;
  border: 3px solid rgba(0, 0, 0, 0.1);
  border-top-color: #0073aa;
  border-radius: 50%;
  animation: spf-spin 0.8s linear infinite;
}

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

.spf-error-message {
  padding: 20px;
  text-align: center;
  color: #721c24;
  background-color: #f8d7da;
  border: 1px solid #f5c6cb;
  border-radius: 4px;
  margin: 12px 0;
}

.spf-error-message p {
  margin: 0 0 12px;
}

.spf-retry-btn,
.spf-reload-btn {
  display: inline-block;
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9em;
  font-weight: 500;
  transition: background-color 0.2s ease;
}

.spf-retry-btn {
  background-color: #0073aa;
  color: #fff;
}

.spf-retry-btn:hover {
  background-color: #005a87;
}

.spf-reload-btn {
  background-color: #dc3545;
  color: #fff;
}

.spf-reload-btn:hover {
  background-color: #c82333;
}

/* ─── Product Grid ──────────────────────────────────────────────────── */

.spf-products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
}

.spf-no-results {
  padding: 40px 20px;
  text-align: center;
  color: #666;
}

.spf-no-results p {
  margin: 0;
  font-size: 1em;
}

/* ─── Mobile Toggle Button (Hidden on Desktop) ─────────────────────── */

.spf-mobile-toggle {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 999;
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 50%;
  background-color: #0073aa;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease, transform 0.2s ease;
}

.spf-mobile-toggle:hover {
  background-color: #005a87;
  transform: scale(1.05);
}

.spf-mobile-toggle:focus {
  outline: 2px solid #005a87;
  outline-offset: 3px;
}

.spf-mobile-toggle-icon {
  display: block;
  width: 20px;
  height: 2px;
  background-color: #fff;
  position: relative;
}

.spf-mobile-toggle-icon::before,
.spf-mobile-toggle-icon::after {
  content: '';
  position: absolute;
  left: 0;
  width: 100%;
  height: 2px;
  background-color: #fff;
}

.spf-mobile-toggle-icon::before {
  top: -6px;
}

.spf-mobile-toggle-icon::after {
  top: 6px;
}

/* ─── Mobile Filter Panel (Slide-out Overlay) ───────────────────────── */

.spf-filter-panel {
  display: none;
}

.spf-panel-overlay {
  display: none;
}

/* ─── Mobile Responsive (below 768px) ──────────────────────────────── */

@media screen and (max-width: 768px) {

  /* Show mobile toggle button */
  .spf-mobile-toggle {
    display: flex;
  }

  /* Hide the sidebar tree on mobile by default */
  .spf-filter-widget .spf-category-tree,
  .spf-filter-widget .spf-title {
    display: none;
  }

  /* Panel overlay (dark backdrop) */
  .spf-panel-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 9998;
    opacity: 0;
    transition: opacity 0.3s ease;
  }

  .spf-panel-overlay.spf-panel-open {
    display: block;
    opacity: 1;
  }

  /* Slide-out filter panel */
  .spf-filter-panel {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    width: 85%;
    max-width: 320px;
    height: 100%;
    background-color: #fff;
    z-index: 9999;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    overflow-y: auto;
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.15);
  }

  .spf-filter-panel.spf-panel-open {
    transform: translateX(0);
  }

  /* Panel header */
  .spf-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #eee;
  }

  .spf-panel-title {
    margin: 0;
    font-size: 1.1em;
    font-weight: 600;
  }

  .spf-panel-close {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 24px;
    line-height: 1;
    color: #333;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background-color 0.2s ease;
  }

  .spf-panel-close:hover {
    background-color: rgba(0, 0, 0, 0.08);
  }

  .spf-panel-close:focus {
    outline: 2px solid #0073aa;
    outline-offset: -2px;
  }

  /* Panel body - show tree inside panel */
  .spf-panel-body {
    padding: 16px 12px;
  }

  .spf-panel-body .spf-category-tree,
  .spf-panel-body .spf-title {
    display: block;
  }

  /* Adjust category label padding for touch targets */
  .spf-filter-panel .spf-category-label {
    padding: 10px 14px;
    font-size: 0.95em;
  }

  /* Adjust toggle button size for touch */
  .spf-filter-panel .spf-toggle {
    width: 32px;
    height: 32px;
    top: 8px;
    right: 8px;
  }
}