/**
 * MG Filter Tool Frontend Styles
 *
 * @package MG_Filter_Tool
 */

/* ==================== FILTER BAR ==================== */

.mgf-filter-bar-widget {
  position: relative;
  z-index: 100;
}

.mgf-filter-bar {
  position: relative;
}

.mgf-filter-bar-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding: 10px 0;
}

.mgf-filter-bar-inner::-webkit-scrollbar {
  display: none;
}

/* Filter Buttons - 使用 !important 覆蓋主題樣式 */
.mgf-filter-btn {
  display: inline-flex !important;
  align-items: center !important;
  gap: 8px !important;
  padding: 10px 20px !important;
  background: #fff !important;
  border: 1px solid #e0e0e0 !important;
  border-radius: 25px !important;
  font-size: 14px !important;
  font-weight: 400 !important;
  cursor: pointer !important;
  white-space: nowrap !important;
  transition: all 0.2s ease !important;
  text-transform: none !important;
  min-height: auto !important;
  line-height: 1.4 !important;
  box-shadow: none !important;
  color: #333 !important;
}

.mgf-filter-btn:hover {
  border-color: #333 !important;
  font-weight: 600 !important;
  background: #fff !important;
}

.mgf-filter-btn i {
  font-size: 12px;
}

/* Scroll Buttons */
.mgf-scroll-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.mgf-scroll-btn:hover {
  background: #f5f5f5;
}

.mgf-scroll-left {
  left: 0;
}

.mgf-scroll-right {
  right: 0;
}

/* ==================== DROPDOWNS ==================== */

.mgf-dropdown {
  position: relative;
}

.mgf-dropdown.open {
  z-index: 100;
}

.mgf-dropdown-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.mgf-dropdown-toggle i {
  transition: transform 0.2s ease;
}

.mgf-dropdown.open .mgf-dropdown-toggle i {
  transform: rotate(180deg);
}

.mgf-dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 180px;
  max-height: 300px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  display: none;
  margin-top: 5px;
}

.mgf-dropdown.open .mgf-dropdown-menu {
  display: none !important; /* 隱藏原本的選單，使用 fixed menu 代替 */
}

/* Fixed dropdown menu (appended to body) */
.mgf-dropdown-menu-fixed {
  position: fixed;
  min-width: 180px;
  max-height: 300px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 120;
  display: block;
}

/* ==================== FULLWIDTH DROPDOWN ==================== */

/* Only apply flex to the FIXED menu clone, not the original */
.mgf-dropdown-menu-fixed.mgf-dropdown-menu-fullwidth {
  min-width: 100%;
  max-height: none;
  display: flex;
  flex-wrap: wrap;
  padding: 15px;
  gap: 5px;
}

.mgf-dropdown-menu-fixed.mgf-dropdown-menu-fullwidth {
  left: 0 !important;
  right: 0 !important;
  width: 100vw !important;
  max-width: 100vw !important;
  border-radius: 0 0 8px 8px;
}

/* ==================== CONTAINER WIDTH DROPDOWN ==================== */

.mgf-dropdown-menu-fixed.mgf-dropdown-menu-container {
  max-height: none;
  display: flex;
  flex-wrap: wrap;
  padding: 15px;
  gap: 5px;
  border-radius: 8px;
}

.mgf-dropdown-menu-fixed.mgf-dropdown-menu-container .mgf-filter-option {
  display: inline-block !important;
  width: auto !important;
  margin: 0;
  border-radius: 20px;
  flex: 0 0 auto;
}

/* Fullwidth menu items (only apply to fixed menu) */
.mgf-dropdown-menu-fullwidth .mgf-dropdown-item,
.mgf-dropdown-menu-fullwidth .mgf-filter-option {
  flex: 0 0 auto;
  padding: 8px 15px;
  border-radius: 20px;
  background: #f5f5f5;
  margin: 2px;
}

.mgf-dropdown-menu-fullwidth .mgf-dropdown-item:hover,
.mgf-dropdown-menu-fullwidth .mgf-filter-option:hover {
  background: #e0e0e0;
}

.mgf-dropdown-menu-fullwidth .mgf-filter-option.selected {
  background: #fff;
  border-color: #333;
}

.mgf-dropdown-item {
  display: block;
  padding: 10px 15px;
  color: #333;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.2s ease;
}

.mgf-dropdown-item:hover {
  background: #f5f5f5;
}

.mgf-dropdown-item.active {
  background: #e7f5ff;
  color: #1971c2;
}

/* Checkbox Items (legacy) */
.mgf-checkbox-item {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mgf-checkbox-item input[type='checkbox'] {
  width: 18px;
  height: 18px;
  margin: 0;
}

/* ==================== FILTER OPTION BUTTONS ==================== */

.mgf-filter-option {
  padding: 8px 16px;
  background: #f5f5f5;
  border: 2px solid transparent;
  border-radius: 20px;
  color: #333;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.mgf-filter-option:hover {
  background: #e8e8e8;
}

.mgf-filter-option.selected {
  background: #fff;
  border-color: #333;
  font-weight: 500;
}

/* Normal dropdown - vertical layout */
.mgf-dropdown-menu-fixed .mgf-filter-option {
  display: block;
  width: 100%;
  margin: 2px 0;
  border-radius: 4px;
}

/* Fullwidth dropdown - horizontal layout (override) */
.mgf-dropdown-menu-fixed.mgf-dropdown-menu-fullwidth .mgf-filter-option {
  display: inline-block;
  width: auto;
  border-radius: 20px;
}

/* Sidebar filter options */
.mgf-sidebar-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mgf-sidebar-options .mgf-filter-option {
  padding: 6px 12px;
  font-size: 13px;
}

/* ==================== COLOR SWATCH ==================== */

.mgf-color-swatch {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.15);
    vertical-align: middle;
    margin-right: 8px;
    flex-shrink: 0;
}

/* White needs darker border */
.mgf-color-swatch--white {
    border: 1px solid #ccc;
}

/* Multicolor gradient */
.mgf-color-swatch--multicolor {
    background: linear-gradient(135deg,
        #e74c3c 0%,
        #f1c40f 25%,
        #27ae60 50%,
        #3498db 75%,
        #9b59b6 100%
    ) !important;
    border: none;
}

/* Color option items in dropdown and sidebar */
.mgf-dropdown-item.mgf-color-option,
.mgf-checkbox-item.mgf-color-option {
    display: flex;
    align-items: center;
}

.mgf-checkbox-item.mgf-color-option input[type="checkbox"] {
    margin-right: 8px;
}

/* ==================== ACTIVE FILTERS ====================

/* 隱藏已選過濾器標籤 */
.mgf-active-filters {
  display: none !important;
}

.mgf-active-filter-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: #e7f5ff;
  border-radius: 15px;
  font-size: 13px;
  color: #1971c2;
}

.mgf-active-filter-tag .remove {
  cursor: pointer;
  font-weight: bold;
}

.mgf-active-filter-tag .remove:hover {
  color: #d63638;
}

/* ==================== SIDEBAR ==================== */

.mgf-sidebar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 9998;
}

.mgf-sidebar {
  position: fixed;
  top: 0;
  left: -100%;
  width: 320px;
  max-width: 90vw;
  height: 100vh;
  background: #fff;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  transition: left 0.3s ease;
  box-shadow: 4px 0 12px rgba(0, 0, 0, 0.15);
}

.mgf-sidebar.open {
  left: 0;
}

.mgf-sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  border-bottom: 1px solid #e0e0e0;
}

.mgf-sidebar-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.mgf-sidebar-close {
  background: none;
  border: none;
  font-size: 28px;
  cursor: pointer;
  color: #666;
  line-height: 1;
  padding: 0;
}

.mgf-sidebar-close:hover {
  color: #d63638;
}

.mgf-sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.mgf-sidebar-section {
  margin-bottom: 25px;
}

.mgf-sidebar-section:last-child {
  margin-bottom: 0;
}

.mgf-sidebar-section-title {
  margin: 0 0 12px 0;
  font-size: 15px;
  font-weight: 600;
  color: #333;
}

.mgf-sidebar-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mgf-sidebar-footer {
  display: flex;
  gap: 10px;
  padding: 15px 20px;
  border-top: 1px solid #e0e0e0;
}

.mgf-clear-all {
  flex: 1;
  padding: 12px;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s ease;
}

.mgf-clear-all:hover {
  background: #f5f5f5;
}

.mgf-apply-filters {
  flex: 2;
  padding: 12px;
  background: #333;
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.2s ease;
}

.mgf-apply-filters:hover {
  background: #555;
}

/* ==================== PRODUCT GRID ==================== */

.mgf-product-grid-widget {
  position: relative;
  z-index: 1;
}

.mgf-product-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
}

.mgf-product-card {
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  transition: box-shadow 0.2s ease;
}

.mgf-product-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.mgf-product-image {
  position: relative;
  overflow: hidden;
  z-index: auto;
}

.mgf-product-image img {
  width: 100%;
  height: auto;
  display: block;
  transition: transform 0.3s ease;
}

.mgf-product-card:hover .mgf-product-image img {
  transform: scale(1.05);
}

.mgf-product-info {
  padding: 15px;
}

.mgf-product-title {
  margin: 0 0 8px 0;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
}

.mgf-product-title a {
  color: inherit;
  text-decoration: none;
}

.mgf-product-title a:hover {
  color: #1971c2;
}

.mgf-product-sku {
  font-size: 12px;
  color: #666;
  margin-bottom: 8px;
  font-family: monospace;
}

.mgf-product-price {
  font-size: 16px;
  font-weight: 600;
  color: #333;
  margin-bottom: 10px;
}

.mgf-product-price del {
  color: #999;
  font-weight: normal;
  margin-right: 5px;
}

.mgf-product-price ins {
  text-decoration: none;
  color: #d63638;
}

.mgf-product-actions {
  margin-top: 10px;
}

.mgf-product-actions .button {
  width: 100%;
  text-align: center;
}

.mgf-no-products {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px;
  color: #666;
  font-size: 16px;
}

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

.mgf-loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.mgf-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #e0e0e0;
  border-top-color: #333;
  border-radius: 50%;
  animation: mgf-spin 0.8s linear infinite;
}

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

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

@media (max-width: 1024px) {
  .mgf-product-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 768px) {
  .mgf-product-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
  }

  .mgf-filter-btn {
    padding: 6px 12px;
    font-size: 13px;
  }

  .mgf-sidebar {
    width: 100%;
    max-width: 100%;
  }

  .mgf-product-info {
    padding: 10px;
  }

  .mgf-product-title {
    font-size: 13px;
  }

  .mgf-product-price {
    font-size: 14px;
  }
}

@media (max-width: 480px) {
  .mgf-filter-bar-inner {
    gap: 6px;
  }

  .mgf-filter-btn {
    padding: 5px 10px;
    font-size: 12px;
  }
}
