/**
 * Attributes Manager Frontend Styles
 */

/* Product Attributes Container */
.am-product-attributes {
  margin: 30px 0;
  background: #fff;
}

.am-product-attributes h3 {
  margin: 0 0 20px 0;
  color: #23282d;
  font-size: 18px;
  font-weight: 600;
  border-bottom: 2px solid #0073aa;
  padding-bottom: 10px;
}

/* Attribute Groups */
.am-attribute-group {
  margin: 0;
  padding-top: 6px;
  padding-bottom: 6px;
  transition: all 0.3s ease;
  overflow: hidden;
}

/* Conditional attribute transitions */
.am-attribute-group[data-condition-attribute-id] {
  display: none; /* Hide by default */
  transition:
    opacity 0.3s ease,
    max-height 0.3s ease,
    padding 0.3s ease;
}

/* Show conditional attributes when they should be visible */
.am-attribute-group[data-condition-attribute-id].am-visible {
  display: block;
  opacity: 1;
  max-height: none;
  padding-top: 6px;
  padding-bottom: 6px;
  margin: 0;
}

/* Remove bottom border from last attribute group when inside dropdown group */
.am-dropdown-group .am-attribute-group:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

/* Only apply bottom border to the very last attribute group in the entire container */
.am-product-attributes > .am-attribute-group:last-child {
  padding-bottom: 15px;
  /* Removed static separator - now using dynamic separators */
}

.am-attribute-label {
  display: block;
  font-weight: 600;
  color: #23282d;
  font-size: 16px;
  flex-shrink: 1;
}

.am-attribute-label .required {
  color: #dc3232;
  font-weight: bold;
}

/* Single Selection Options */
.am-single-selection {
  display: grid;
  grid-template-columns: repeat(auto-fit, 110px);
  gap: 10px;
  justify-content: start;
}

.am-option-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.am-single-option {
  position: relative;
  cursor: pointer;
  border: 0.5px solid #00000040;
  border-radius: 6px;
  background: #fff;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  width: 100%;
}

.am-single-option:hover {
  border-color: #0073aa;
  box-shadow: 0 4px 8px rgba(0, 115, 170, 0.2);
}

/* Override external WooCommerce styles */
.am-single-option,
.am-multiple-option {
  margin: 0 !important;
}

.am-single-option input[type='checkbox'] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.am-single-option input[type='checkbox']:checked + .am-option-content {
  border-color: #0073aa;
  background: #f0f8ff;
}

.am-single-option input[type='checkbox']:checked + .am-option-content::before {
  content: '✓';
  position: absolute;
  top: 10px;
  right: 10px;
  background: #0073aa;
  color: white;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: bold;
}

/* Multiple Selection Options */
.am-multiple-selection {
  display: grid;
  grid-template-columns: repeat(auto-fit, 110px);
  gap: 10px;
  justify-content: start;
}

.am-multiple-option {
  position: relative;
  cursor: pointer;
  border: 0.5px solid #00000040;
  border-radius: 6px;
  background: #fff;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  width: 100%;
}

.am-multiple-option:hover {
  border-color: #0073aa;
  box-shadow: 0 4px 8px rgba(0, 115, 170, 0.2);
}

.am-multiple-option input[type='checkbox'] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.am-multiple-option input[type='checkbox']:checked + .am-option-content {
  border-color: #0073aa;
  background: #f0f8ff;
}

.am-multiple-option
  input[type='checkbox']:checked
  + .am-option-content::before {
  content: '✓';
  position: absolute;
  top: 10px;
  right: 10px;
  background: #0073aa;
  color: white;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: bold;
}

/* Option Content */
.am-option-content {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 6px;
  border-radius: 4px;
  transition: all 0.3s ease;
}

/* Option Images */
.am-option-image {
  flex-shrink: 0;
  width: 100%;
  height: 90px;
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #f9f9f9;
}

.am-option-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* Option Details */
.am-option-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 4px;
  text-align: center;
  width: 100%;
}

.am-option-name {
  font-weight: 600;
  color: #23282d;
  font-size: 12px;
}

.am-option-price {
  color: #3499f1;
  font-weight: 500;
  font-size: 13px;
}

.am-option-qty {
  color: #666;
  font-size: 12px;
  font-style: italic;
}

/* Color Swatches */
.am-color-swatches {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.am-color-option {
  position: relative;
  cursor: pointer;
  border: 0.5px solid #00000040;
  border-radius: 8px;
  padding: 12px;
  background: #fff;
  transition: all 0.3s ease;
  user-select: none;
}

.am-color-option:hover {
  border-color: #0073aa;
  box-shadow: 0 4px 8px rgba(0, 115, 170, 0.2);
}

/* Visual indicator for deselectable color swatches */
.am-color-option.deselectable {
  position: relative;
}

.am-color-option.deselectable:hover::after {
  content: 'Click to deselect';
  position: absolute;
  top: -30px;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  white-space: nowrap;
  z-index: 1000;
}

.am-color-option.deselectable:hover::before {
  content: '';
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: #333;
  z-index: 1000;
}

.am-color-option input[type='radio'] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.am-color-option input[type='radio']:checked + .am-color-option-content,
.am-color-option.selected .am-color-option-content {
  border-color: #0073aa;
  background: #f0f8ff;
}

.am-color-option input[type='radio']:checked + .am-color-option-content::before,
.am-color-option.selected .am-color-option-content::before {
  content: '✓';
  position: absolute;
  top: 8px;
  right: 8px;
  background: #0073aa;
  color: white;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: bold;
}

.am-color-option-content {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 4px;
  transition: all 0.3s ease;
}

.am-color-swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid #ddd;
  flex-shrink: 0;
}

.am-color-name {
  font-weight: 600;
  color: #23282d;
  font-size: 13px;
}

.am-color-price {
  color: #0073aa;
  font-weight: 600;
  font-size: 12px;
}

.am-color-qty {
  color: #666;
  font-size: 11px;
  font-style: italic;
}

/* Text Input */
.am-text-input {
  width: 100%;
  padding: 12px;
  border: 2px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
  transition: border-color 0.3s ease;
  box-sizing: border-box;
}

.am-text-input:focus {
  outline: none;
  border-color: #0073aa;
  box-shadow: 0 0 0 1px #0073aa;
}

/* Dropdown Group Container */
.am-dropdown-group {
  /* Removed static separator - now using dynamic separators */
  padding: 0 0 14px 0;
  margin: 0;
  background: transparent;
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-bottom: 5px;
}

/* Modern Select Dropdown */
.am-select-input {
  width: 100%;
  padding: 12px 12px 12px 40px;
  border: 0.95px solid #000000;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: #333;
  background: #fff;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
}

.am-select-input:hover {
  border-color: #0073aa;
  box-shadow: 0 2px 4px rgba(0, 115, 170, 0.1);
}

.am-select-input:focus {
  outline: none;
  border-color: #0073aa;
  box-shadow: 0 0 0 2px rgba(0, 115, 170, 0.2);
}

.am-select-input option {
  padding: 12px;
  font-size: 14px;
  background: #fff;
  color: #333;
}

.am-select-input option:disabled {
  color: #999;
  font-style: italic;
  background: #f5f5f5;
}

.am-select-input option:checked {
  background: #0073aa;
  color: #fff;
}

/* Custom select wrapper for better styling */
.am-select-wrapper {
  position: relative;
  width: 100%;
}

.am-select-wrapper::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 12px;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid #666;
  pointer-events: none;
  transition: transform 0.3s ease;
}

.am-select-wrapper:focus-within::after {
  transform: translateY(-50%) rotate(180deg);
}

/* Dynamic Price Display */
.am-dynamic-price {
  display: inline-block;
  animation: fadeIn 0.3s ease;
}

.am-dynamic-price .amount {
  font-weight: bold;
  color: inherit;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Error States */
.am-attribute-group.error {
  border-left: 4px solid #dc3232;
  border-bottom: 1px solid #dc3232;
  background: linear-gradient(135deg, #fff5f5 0%, #ffe6e6 100%);
  box-shadow: 0 2px 8px rgba(220, 50, 50, 0.15);
  border-radius: 8px;
  padding: 15px;
  margin: 10px 0;
  position: relative;
  animation: errorShake 0.5s ease-in-out;
}

.am-error-message {
  color: #dc3232;
  font-size: 13px;
  margin-top: 8px;
  font-weight: 600;
  padding: 8px 12px;
  background: rgba(220, 50, 50, 0.1);
  border-radius: 6px;
  border-left: 3px solid #dc3232;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  position: relative;
  padding-right: 40px; /* Make space for the warning icon */
  min-height: 20px; /* Ensure consistent height for centering */
}

.am-error-message::before {
  content: '⚠';
  font-size: 14px;
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
}

/* Required field indicator */
.am-attribute-label .required {
  color: #dc3232;
  font-weight: bold;
  margin-left: 4px;
}

/* Animations */
@keyframes errorShake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}

@keyframes errorPulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.7;
    transform: scale(1.1);
  }
}

/* Focus states for error fields */
.am-attribute-group.error input:focus,
.am-attribute-group.error select:focus {
  border-color: #dc3232;
  box-shadow: 0 0 0 3px rgba(220, 50, 50, 0.2);
  outline: none;
}

/* Responsive Design */
@media (max-width: 768px) {
  .am-single-selection,
  .am-multiple-selection {
    grid-template-columns: repeat(3, 1fr);
    justify-content: space-evenly;
  }

  .am-color-swatches {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }

  .am-option-content {
    flex-direction: column;
    text-align: center;
  }

  .am-option-image {
    width: 80px;
    height: 80px;
  }

  /* Mobile text input adjustments */
  .am-text-input {
    padding: 8px 10px;
    font-size: 14px;
    border-radius: 6px;
  }

  /* Hide tooltip on mobile for better UX */
  .am-color-option.deselectable:hover::after,
  .am-color-option.deselectable:hover::before {
    display: none;
  }

  /* Mobile error states */
  .am-attribute-group.error {
    padding: 12px;
    margin: 8px 0;
    border-radius: 6px;
  }

  .am-error-message {
    font-size: 12px;
    padding: 6px 10px;
    padding-right: 30px; /* Make space for the warning icon on mobile */
    margin-top: 6px;
  }

  .am-error-message::before {
    font-size: 12px;
  }
}

/* Loading States */
.am-option.loading {
  opacity: 0.6;
  pointer-events: none;
}

.am-option.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid #f3f3f3;
  border-top: 2px solid #0073aa;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Price Updates */
.am-price-update {
  background: #d4edda;
  color: #155724;
  padding: 10px 15px;
  border-radius: 4px;
  margin: 10px 0;
  font-size: 14px;
  font-weight: 600;
}

/* WooCommerce Integration */
.woocommerce .am-product-attributes {
  margin: 20px 0;
}

/* Removed empty ruleset */

/* Accessibility */
.am-option:focus-within,
.am-color-option:focus-within {
  border-color: #0073aa;
  position: relative;
  z-index: 1;
}

/* Ensure focus outlines are visible by overriding parent overflow */
.am-attribute-group:has(.am-option:focus-within),
.am-attribute-group:has(.am-color-option:focus-within) {
  overflow: visible;
}

/* Print Styles */
@media print {
  .am-product-attributes {
    border: 1px solid #000;
    box-shadow: none;
  }

  .am-option-content,
  .am-color-option-content {
    border: 1px solid #000;
  }
}

/* Stock Indicators */
.am-stock-indicator {
  font-size: 12px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 3px;
  display: inline-block;
  margin-top: 4px;
}

.am-stock-indicator.in-stock {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.am-stock-indicator.out-of-stock {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

/* Out of Stock Options */
.am-option.out-of-stock {
  opacity: 0.6;
  pointer-events: none;
}

.am-option.out-of-stock .am-option-content {
  background: #f8f9fa;
}

.am-option.out-of-stock input {
  cursor: not-allowed;
}

/* Stock Error Messages */
.am-stock-error {
  background: #dc3232;
  color: white;
  padding: 10px 15px;
  margin-bottom: 15px;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 600;
}

/* Disabled Options */
.am-option input:disabled + .am-option-content {
  opacity: 0.6;
  cursor: not-allowed;
}

.am-option input:disabled + .am-option-content .am-option-name {
  color: #999;
}

/* Stock Management Hover Effects */
.am-option:not(.out-of-stock):hover .am-stock-indicator.in-stock {
  background: #c3e6cb;
  border-color: #a8d5ae;
}

/* Responsive Stock Indicators */
@media (max-width: 768px) {
  .am-stock-indicator {
    font-size: 11px;
    padding: 1px 4px;
  }
}

/* Cart attributes styling */
.am-cart-attributes {
  margin-top: 8px;
  padding: 8px;
  background: #f8f9fa;
  border: 1px solid #dee2e6;
  border-radius: 4px;
}

.am-cart-attribute {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  font-size: 0.9em;
  line-height: 1.3;
  padding: 4px;
  gap: 5px;
}

.am-cart-attribute:last-child {
  margin-bottom: 0;
}

.am-attribute-label {
  font-weight: 500;
  color: #6c757d;
  min-width: 80px;
  flex-shrink: 1;
  margin-bottom: 0.7em;
}

.am-cart-attribute .am-attribute-label {
  margin-bottom: 0;
}

.am-attribute-value {
  color: #212529;
  flex: 1;
  word-wrap: break-word;
}

.am-attributes-header {
  margin-bottom: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid #dee2e6;
}

.am-attributes-title {
  font-size: 0.85em;
  font-weight: 600;
  color: #495057;
}

/* Frontend Separator Styles */
.am-frontend-separator {
  margin: 0;
  padding: 5px 0;
  text-align: center;
}

.am-frontend-separator .am-separator-line {
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent 0%,
    #00000040 20%,
    #00000040 80%,
    transparent 100%
  );
  border: none;
  margin: 0;
}

/* Product page attributes styling */

/* Elementor WooCommerce product images – fixed height on mobile */
@media (max-width: 768px) {
  .elementor-widget-woocommerce-product-images
    .woocommerce-product-gallery__wrapper,
  .elementor-widget-woocommerce-product-images
    .woocommerce-product-gallery__wrapper
    .woocommerce-product-gallery__image.flex-active-slide
    * {
    height: 402px;
    object-fit: contain;
  }
}
