/* ============================================
   COMPARE.CSS - Product Comparison System
   Premium UI for compare feature
   ============================================ */

/* ============================================
   1) COMPARE TOGGLE (Checkbox/Button on Cards)
   ============================================ */

.product-card {
  position: relative; /* Ensure absolute positioning of toggle works */
}

.compare-toggle-wrapper {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 10;
}

.compare-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}

.compare-toggle input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.compare-toggle-box {
  width: 24px;
  height: 24px;
  border: 2px solid var(--primary);
  border-radius: 6px;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
  overflow: hidden;
}

.compare-toggle input:checked + .compare-toggle-box {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-color: var(--primary);
  transform: scale(1.1);
}

.compare-toggle-box::after {
  content: '✓';
  color: white;
  font-size: 14px;
  font-weight: bold;
  opacity: 0;
  transform: scale(0) rotate(45deg);
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.compare-toggle input:checked + .compare-toggle-box::after {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

.compare-toggle-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary);
  background: white;
  padding: 4px 8px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.compare-toggle input:checked ~ .compare-toggle-label {
  background: var(--primary);
  color: white;
}

.compare-toggle:hover .compare-toggle-box {
  border-color: var(--accent);
  transform: scale(1.05);
}

.compare-toggle:focus-within .compare-toggle-box {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ============================================
   2) FLOATING COMPARE BAR (Bottom Sticky)
   ============================================ */

.compare-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98) 0%, rgba(255, 255, 255, 1) 100%);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(45, 134, 89, 0.2);
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.1);
  z-index: 9996;
  transform: translateY(100%);
  opacity: 0;
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}

.compare-bar.visible {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.compare-bar-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px clamp(1rem, 3vw, 3rem);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.compare-bar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex: 1;
  min-width: 0;
}

.compare-count {
  font-weight: 700;
  color: var(--primary);
  font-size: clamp(0.9rem, 2vw, 1rem);
  white-space: nowrap;
}

.compare-chips {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  overflow-x: auto;
  scroll-behavior: smooth;
  scrollbar-width: none;
  -ms-overflow-style: none;
  flex: 1;
  min-width: 0;
}

.compare-chips::-webkit-scrollbar {
  display: none;
}

.compare-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  padding: 8px 12px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(45, 134, 89, 0.3);
  animation: chipSlideIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  flex-shrink: 0;
}

@keyframes chipSlideIn {
  from {
    opacity: 0;
    transform: scale(0.5) translateY(20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.compare-chip-remove {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 14px;
  font-weight: bold;
  transition: all 0.2s ease;
  padding: 0;
  line-height: 1;
}

.compare-chip-remove:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
}

.compare-chip-remove:focus {
  outline: 2px solid white;
  outline-offset: 2px;
}

.compare-bar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.compare-bar-btn {
  padding: 10px 20px;
  border-radius: 25px;
  font-weight: 600;
  font-size: 0.9rem;
  border: none;
  cursor: pointer;
  transition: all 0.3s ease;
  white-space: nowrap;
}

.compare-bar-btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  box-shadow: 0 4px 12px rgba(45, 134, 89, 0.3);
}

.compare-bar-btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(45, 134, 89, 0.4);
}

.compare-bar-btn-secondary {
  background: transparent;
  color: var(--primary);
  border: 2px solid var(--primary);
}

.compare-bar-btn-secondary:hover {
  background: var(--primary);
  color: white;
}

/* ============================================
   3) COMPARE MODAL
   ============================================ */

.compare-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.compare-modal.active {
  opacity: 1;
  pointer-events: auto;
}

.compare-modal-content {
  background: white;
  border-radius: var(--radius-lg);
  max-width: 1200px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  transform: scale(0.9) translateY(40px);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.compare-modal.active .compare-modal-content {
  transform: scale(1) translateY(0);
}

.compare-modal-header {
  padding: 24px 32px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.compare-modal-title {
  font-size: clamp(1.25rem, 3vw, 1.75rem);
  font-weight: 700;
  color: var(--primary);
  margin: 0;
}

.compare-modal-close {
  background: transparent;
  border: none;
  font-size: 2rem;
  color: var(--text-light);
  cursor: pointer;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.compare-modal-close:hover {
  background: var(--light);
  color: var(--dark);
  transform: scale(1.1);
}

.compare-modal-close:focus {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.compare-modal-body {
  padding: 24px 32px;
  overflow-x: auto;
  overflow-y: auto;
  flex: 1;
}

/* ============================================
   4) COMPARISON TABLE
   ============================================ */

.comparison-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 600px;
}

.comparison-table thead {
  position: sticky;
  top: 0;
  z-index: 10;
  background: white;
}

.comparison-table th {
  padding: 16px 12px;
  text-align: center;
  font-weight: 600;
  color: var(--dark);
  border-bottom: 2px solid var(--primary);
  background: linear-gradient(180deg, rgba(45, 134, 89, 0.05) 0%, white 100%);
}

.comparison-table th:first-child {
  text-align: left;
  font-weight: 700;
  color: var(--primary);
  border-bottom-color: var(--border);
}

.comparison-table td {
  padding: 16px 12px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.comparison-table td:first-child {
  text-align: left;
  font-weight: 600;
  color: var(--text-dark);
  background: rgba(45, 134, 89, 0.03);
  position: sticky;
  left: 0;
  z-index: 5;
}

.comparison-table tbody tr:hover td {
  background: rgba(45, 134, 89, 0.05);
}

.comparison-table tbody tr:hover td:first-child {
  background: rgba(45, 134, 89, 0.1);
}

/* Product header cell */
.product-header-cell {
  text-align: center;
  padding: 20px 12px !important;
  background: white !important;
}

.product-icon {
  font-size: 3rem;
  margin-bottom: 8px;
  display: block;
}

.product-name {
  font-weight: 700;
  color: var(--primary);
  font-size: 1rem;
  margin: 0;
}

.product-category {
  font-size: 0.75rem;
  color: var(--text-light);
  text-transform: uppercase;
  margin-top: 4px;
}

/* Value cells with highlighting */
.value-cell {
  font-size: 0.95rem;
  color: var(--text-dark);
}

.value-best {
  background: linear-gradient(135deg, rgba(45, 134, 89, 0.15), rgba(79, 169, 119, 0.15));
  font-weight: 700;
  color: var(--primary);
  position: relative;
}

.value-best::before {
  content: '⭐';
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 0.8rem;
}

/* Price badge */
.price-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 600;
}

.price-badge.budget {
  background: #10b981;
  color: white;
}

.price-badge.standard {
  background: #3b82f6;
  color: white;
}

.price-badge.premium {
  background: #8b5cf6;
  color: white;
}

/* Action buttons in table */
.compare-action-cell {
  padding: 12px !important;
}

.compare-order-btn {
  padding: 8px 16px;
  background: linear-gradient(135deg, #25d366, #128c7e);
  color: white;
  border: none;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(37, 211, 102, 0.3);
}

.compare-order-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(37, 211, 102, 0.4);
}

/* ============================================
   5) EMPTY STATE
   ============================================ */

.compare-empty {
  text-align: center;
  padding: 4rem 2rem;
}

.compare-empty-icon {
  font-size: 5rem;
  margin-bottom: 1rem;
  opacity: 0.3;
}

.compare-empty-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-dark);
  margin-bottom: 0.5rem;
}

.compare-empty-text {
  color: var(--text-light);
  margin-bottom: 2rem;
}

/* ============================================
   6) RESPONSIVE DESIGN
   ============================================ */

/* Tablets and below */
@media (max-width: 968px) {
  .compare-bar-content {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 12px 16px;
  }
  
  .compare-bar-left {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  
  .compare-chips {
    width: 100%;
  }
  
  .compare-bar-actions {
    width: 100%;
    justify-content: space-between;
  }
  
  .compare-bar-btn {
    flex: 1;
    padding: 10px 16px;
    font-size: 0.85rem;
  }
  
  .compare-modal-content {
    max-height: 85vh;
    margin: 10px;
  }
  
  .compare-modal-header {
    padding: 20px;
  }
  
  .compare-modal-body {
    padding: 20px;
  }
  
  .comparison-table {
    font-size: 0.9rem;
  }
  
  .comparison-table th,
  .comparison-table td {
    padding: 12px 8px;
  }
  
  .product-icon {
    font-size: 2.5rem;
  }
  
  .product-name {
    font-size: 0.9rem;
  }
}

/* Mobile phones */
@media (max-width: 640px) {
  .compare-toggle-label {
    display: none;
  }
  
  .compare-bar {
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  
  .compare-count {
    font-size: 0.85rem;
  }
  
  .compare-chip {
    font-size: 0.75rem;
    padding: 6px 10px;
  }
  
  .compare-modal {
    padding: 10px;
  }
  
  .compare-modal-header {
    padding: 16px;
  }
  
  .compare-modal-body {
    padding: 16px;
  }
  
  .comparison-table {
    font-size: 0.85rem;
    min-width: 500px;
  }
  
  .comparison-table th,
  .comparison-table td {
    padding: 10px 6px;
  }
  
  .product-icon {
    font-size: 2rem;
  }
  
  .product-name {
    font-size: 0.85rem;
  }
  
  .compare-order-btn {
    font-size: 0.75rem;
    padding: 6px 12px;
  }
}

/* Very small screens */
@media (max-width: 360px) {
  .compare-bar-btn {
    font-size: 0.8rem;
    padding: 8px 12px;
  }
  
  .comparison-table {
    min-width: 450px;
  }
}

/* ============================================
   7) ACCESSIBILITY
   ============================================ */

@media (prefers-reduced-motion: reduce) {
  .compare-bar,
  .compare-chip,
  .compare-modal,
  .compare-modal-content {
    transition: none !important;
    animation: none !important;
  }
}

/* Focus trap styles */
.compare-modal:focus {
  outline: none;
}

/* Keyboard navigation */
.compare-toggle:focus-within,
.compare-chip-remove:focus,
.compare-bar-btn:focus,
.compare-modal-close:focus,
.compare-order-btn:focus {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

/* ============================================
   8) SCROLL HINTS
   ============================================ */

.scroll-hint {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 60px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.95));
  pointer-events: none;
  display: none;
}

.comparison-table-wrapper {
  position: relative;
}

.comparison-table-wrapper.has-scroll .scroll-hint {
  display: block;
}

/* ============================================
   9) PRINT STYLES
   ============================================ */

@media print {
  .compare-bar,
  .compare-modal-close,
  .compare-order-btn {
    display: none !important;
  }
  
  .compare-modal {
    position: static;
    background: transparent;
  }
  
  .compare-modal-content {
    box-shadow: none;
    max-height: none;
  }
}
