/* ============================================
   UNIFIED CART STYLES
   Single source of truth for all cart functionality
   ============================================ */

/* ============================================
   1. CART PAGE (main cart page at /cart/)
   ============================================ */

.cart-page {
  min-height: 100vh;
  background-color: #f8f9fa;
  padding: 20px 0;
}

.cart-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.cart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 1px solid #e9ecef;
}

.cart-header h1 {
  font-size: 2rem;
  font-weight: 600;
  color: #212529;
  margin: 0;
}

.cart-items-count {
  color: #6c757d;
  font-size: 1rem;
}

.cart-content {
  display: grid;
  grid-template-columns: 1fr 350px;
  gap: 30px;
  align-items: start;
  align-content: start;
}

.cart-items {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 20px;
}

.cart-item {
  display: grid;
  grid-template-columns: auto 120px 1fr auto;
  gap: 20px;
  background: white;
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: box-shadow 0.2s;
  border: 1px solid #e5e5e5;
}

.cart-item-checkbox {
  display: flex;
  align-items: center;
  justify-content: center;
}

.item-checkbox {
  width: 20px;
  height: 20px;
  cursor: pointer;
  accent-color: #008fa1;
}

.cart-item:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.cart-item-image {
  position: relative;
  width: 120px;
  height: 90px;
  border-radius: 8px;
  overflow: hidden;
  background-color: #f8f9fa;
  flex-shrink: 0;
}

.cart-item-image img,
.cart-item-image video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cart-item-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.file-type-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  background-color: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
}

.cart-item-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 8px;
  font-weight: 600;
  padding: 2px 4px;
  border-radius: 2px;
  line-height: 1;
}

.cart-item-details {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
}

.cart-item-info {
  flex: 1;
  min-width: 0;
}

.cart-item-title {
  font-size: 1.1rem;
  font-weight: 500;
  color: #212529;
  margin: 0 0 8px 0;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.cart-item-id {
  font-weight: 600;
  color: #222;
  font-size: 14px;
  margin-bottom: 4px;
}

.cart-item-meta {
  color: #6c757d;
  font-size: 0.875rem;
  margin-bottom: 8px;
}

.cart-item-description {
  color: #666;
  font-size: 13px;
  line-height: 1.4;
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.cart-item-added {
  color: #888;
  font-size: 12px;
}

.cart-item-price {
  font-size: 1rem;
  font-weight: 600;
  color: var(--link-color);
}

.cart-item-controls {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

.buy-credits-btn,
.buy-money-btn {
  background: #28a745;
  border: none;
  color: white;
  cursor: pointer;
  padding: 10px 16px;
  border-radius: 6px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}

.buy-money-btn {
  background: var(--button-primary-bg);
}

.buy-credits-btn:hover {
  background: #218838;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(40, 167, 69, 0.3);
}

.buy-money-btn:hover {
  background: var(--button-primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 143, 161, 0.3);
}

.buy-credits-btn:active,
.buy-money-btn:active {
  transform: translateY(0);
}

.remove-btn,
.cart-item-remove {
  background: none;
  border: none;
  color: #666;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 4px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  width: auto;
  height: auto;
  flex-shrink: 0;
  gap: 4px;
}

.remove-btn svg {
  flex-shrink: 0;
}

.remove-btn:hover,
.cart-item-remove:hover {
  background-color: #f5f5f5;
  color: #e74c3c;
}

/* Cart Summary */
.cart-summary {
  position: sticky;
  height: fit-content;
  align-self: start;
}

.summary-card {
  background: white;
  border-radius: 12px;
  padding: 25px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.summary-card h3 {
  font-size: 1.3rem;
  font-weight: 600;
  margin: 0 0 20px 0;
  color: #212529;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 1rem;
}

.summary-row span:first-child {
  color: #6c757d;
}

.summary-row span:last-child {
  font-weight: 500;
  color: #212529;
}

.summary-total {
  font-size: 1.1rem;
  font-weight: 600;
  color: #212529;
  padding-top: 15px;
  border-top: 1px solid #e9ecef;
  margin-bottom: 25px;
}

.summary-total span {
  color: #212529;
}

/* Payment method toggle */
.payment-method-toggle {
  margin: 16px 0;
}

.payment-method-toggle label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
  color: #333;
}

.toggle-buttons {
  background-color: #f5f5f5;
  display: flex;
  padding: 4px;
  border-radius: 8px;
  position: relative;
  gap: 0;
}

/* Sliding background indicator */
.toggle-buttons::before {
  content: '';
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: var(--indicator-left, 4px);
  width: calc(50% - 8px);
  background: #008FA1;
  border-radius: 6px;
  transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
  z-index: 0;
  box-shadow: 0 2px 8px rgba(0, 143, 161, 0.2);
}

/* Position the sliding background based on active button using CSS variables */
.toggle-buttons:has(.payment-toggle-btn[data-method="credits"].active)::before {
  --indicator-left: 4px;
}

.toggle-buttons:has(.payment-toggle-btn[data-method="money"].active)::before {
  --indicator-left: calc(50% + 4px);
}

.payment-toggle-btn {
  background: none;
  border: none;
  border-radius: 6px;
  padding: 7px 18px;
  font-size: 15px;
  font-weight: 500;
  color: #666;
  cursor: pointer;
  transition: color 0.2s;
  position: relative;
  z-index: 1;
  flex: 1;
  text-align: center;
}

.payment-toggle-btn.active {
  color: #fff;
  font-weight: 600;
}

.payment-toggle-btn:hover {
  color: #008FA1;
}

.payment-toggle-btn.active:hover {
  color: #fff;
}

.checkout-btn {
  width: 100%;
  background-color: #28a745;
  color: white;
  border: none;
  padding: 15px;
  border-radius: 8px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 15px;
}

.checkout-btn:hover:not(:disabled) {
  background-color: #218838;
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(40, 167, 69, 0.3);
}

.checkout-btn:disabled {
  background-color: #6c757d;
  cursor: not-allowed;
}

.continue-shopping {
  display: block;
  text-align: center;
  color: var(--link-color);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s;
}

.continue-shopping:hover {
  color: var(--link-hover);
  text-decoration: none;
}

/* Cart Actions */
.cart-actions {
  padding-top: 20px;
  border-top: 1px solid #e5e5e5;
  margin-top: 20px;
}

.cart-clear {
  width: 100%;
  background: #fff;
  border: 2px solid #e5e5e5;
  color: #666;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.cart-clear:hover {
  border-color: #e74c3c;
  color: #e74c3c;
  background: #fef5f5;
}

/* Empty Cart State */
.cart-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  text-align: center;
  background: white;
  border-radius: 12px;
  padding: 60px 30px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  color: #666;
}

.cart-empty-icon {
  font-size: 64px;
  margin-bottom: 30px;
  opacity: 0.5;
}

.cart-empty h2 {
  font-size: 1.5rem;
  color: #495057;
  margin-bottom: 15px;
}

.cart-empty p {
  color: #6c757d;
  margin: 0 0 30px 0;
  font-size: 18px;
}

/* Loading State */
.cart-loading,
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  text-align: center;
  padding: 40px 20px;
  color: #666;
  font-size: 16px;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #f3f3f3;
  border-top: 3px solid var(--button-primary-bg);
  border-radius: 50%;
  animation: cartSpin 1s linear infinite;
  margin-bottom: 15px;
}

.cart-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top: 2px solid #fff;
  border-radius: 50%;
  animation: cartSpin 1s linear infinite;
}

/* Error State */
.cart-error {
  text-align: center;
  padding: 40px 20px;
  color: #e74c3c;
  font-size: 16px;
}

/* ============================================
   2. CART SIDE PANEL (overlay cart)
   ============================================ */

.cart-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  display: flex;
  justify-content: flex-end;
}

.cart-panel {
  background: #fff;
  width: 400px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 16px rgba(0, 0, 0, 0.2);
}

.cart-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #666;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.2s;
}

.cart-close:hover {
  background: #f5f5f5;
}

.cart-content {
  flex: 1;
  overflow-y: auto;
}

/* ============================================
   3. CART BUTTONS (add to cart buttons)
   ============================================ */

/* Button variant */
.cart-button {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #008fa1;
  border: none;
  border-radius: 8px;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}

.cart-button:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

.cart-button:not(:disabled):hover {
  background: #007281;
  transform: translateY(-1px);
}

.cart-button--in-cart {
  background: #28a745;
}

.cart-button--in-cart:not(:disabled):hover {
  background: #218838;
}

/* Button sizes */
.cart-button--small {
  padding: 6px 12px;
  font-size: 13px;
}

.cart-button--small .cart-button__icon {
  width: 14px;
  height: 14px;
}

.cart-button--medium {
  padding: 12px 20px;
  font-size: 15px;
}

.cart-button--medium .cart-button__icon {
  width: 16px;
  height: 16px;
}

.cart-button--large {
  padding: 16px 24px;
  font-size: 18px;
}

.cart-button--large .cart-button__icon {
  width: 20px;
  height: 20px;
}

.cart-button__icon {
  flex-shrink: 0;
  transition: transform 0.2s;
}

.cart-button__text {
  white-space: nowrap;
}

/* Icon button variant */
.cart-icon-button {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 50%;
  color: #666;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}

.cart-icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

.cart-icon-button:not(:disabled):hover {
  background: #f8f9fa;
  border-color: #008fa1;
  color: #008fa1;
  transform: scale(1.05);
}

.cart-icon-button--in-cart {
  background: #28a745;
  border-color: #28a745;
  color: #fff;
}

.cart-icon-button--in-cart:not(:disabled):hover {
  background: #218838;
  border-color: #218838;
}

/* Icon button sizes */
.cart-icon-button--small {
  width: 32px;
  height: 32px;
}

.cart-icon-button--small .cart-icon-button__icon {
  width: 16px;
  height: 16px;
}

.cart-icon-button--medium {
  width: 40px;
  height: 40px;
}

.cart-icon-button--medium .cart-icon-button__icon {
  width: 20px;
  height: 20px;
}

.cart-icon-button--large {
  width: 48px;
  height: 48px;
}

.cart-icon-button--large .cart-icon-button__icon {
  width: 24px;
  height: 24px;
}

.cart-icon-button__icon {
  transition: transform 0.2s;
}

/* Button spinners */
.cart-button__spinner,
.cart-icon-button__spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top: 2px solid #fff;
  border-radius: 50%;
  animation: cartSpin 1s linear infinite;
}

.cart-icon-button__spinner {
  border: 2px solid rgba(0, 0, 0, 0.1);
  border-top: 2px solid currentColor;
}

.cart-icon-button--in-cart .cart-icon-button__spinner {
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top: 2px solid #fff;
}

.cart-button--loading,
.cart-icon-button--loading {
  pointer-events: none;
}

.cart-button--loading .cart-button__icon,
.cart-icon-button--loading .cart-icon-button__icon {
  opacity: 0;
}

/* ============================================
   4. CART HEADER BUTTON (header icon)
   ============================================ */

.cart-header-button {
  position: relative;
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: 8px;
  border-radius: 4px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cart-header-button:hover {
  background: rgba(255, 255, 255, 0.1);
}

.cart-header-button__icon {
  width: 24px;
  height: 24px;
  transition: transform 0.2s;
}

.cart-header-button:hover .cart-header-button__icon {
  transform: scale(1.1);
}

.cart-header-button__badge {
  position: absolute;
  top: 0;
  right: 0;
  background: #e74c3c;
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transform: translate(25%, -25%);
  animation: cartBadgePulse 0.3s ease-out;
}

/* Header integration */
.header__nav-item-icon-cart .cart-header-button {
  width: 100%;
  height: 100%;
  color: #fff;
  padding: 0;
}

.header__nav-item-icon-cart .cart-header-button__icon {
  width: 20px;
  height: 20px;
}

/* ============================================
   5. NOTIFICATIONS
   ============================================ */

.cart-notification,
.notification {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 12px 20px;
  border-radius: 8px;
  z-index: 1001;
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  background: #28a745;
  opacity: 0;
  transform: translateX(100%);
  transition: all 0.3s ease-out;
}

.notification.show {
  opacity: 1;
  transform: translateX(0);
}

.notification.success,
.cart-notification--success {
  background: #28a745;
}

.notification.error,
.cart-notification--error {
  background: #e74c3c;
}

/* ============================================
   6. CATALOG INTEGRATION
   ============================================ */

.catalog-page__action--cart {
  position: relative;
}

.catalog-page__action--cart .cart-icon-button {
  border: none;
  background: transparent;
  color: inherit;
  width: 100%;
  height: 100%;
  border-radius: 4px;
}

.catalog-page__action--cart .cart-icon-button:hover {
  background: rgba(0, 143, 161, 0.1);
  transform: none;
}

.catalog-page__action--cart .cart-icon-button--in-cart {
  background: rgba(40, 167, 69, 0.1);
  color: #28a745;
}

/* ============================================
   7. ANIMATIONS
   ============================================ */

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

@keyframes cartBadgePulse {
  0% {
    transform: translate(25%, -25%) scale(0);
  }
  50% {
    transform: translate(25%, -25%) scale(1.2);
  }
  100% {
    transform: translate(25%, -25%) scale(1);
  }
}

@keyframes cartNotificationSlide {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* ============================================
   8. RESPONSIVE DESIGN
   ============================================ */

@media (max-width: 968px) {
  .cart-content {
    grid-template-columns: 1fr;
  }

  .summary-card {
    order: -1;
  }
}

@media (max-width: 768px) {
  .cart-container {
    padding: 0 15px;
  }

  .cart-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .cart-item {
    grid-template-columns: 100px 1fr;
    gap: 15px;
  }

  .cart-item-controls {
    grid-column: 1 / -1;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #e9ecef;
  }

  .cart-item-image {
    width: 100px !important;
    height: 75px !important;
  }

  .summary-card {
    padding: 20px;
  }

  .cart-button--large {
    padding: 12px 20px;
    font-size: 16px;
  }

  .cart-icon-button--large {
    width: 44px;
    height: 44px;
  }

  .cart-button__text {
    display: none;
  }

  .cart-button {
    gap: 0;
  }
}

@media (max-width: 480px) {
  .cart-panel {
    width: 100vw !important;
  }

  .cart-item {
    grid-template-columns: 80px 1fr;
    gap: 12px;
    padding: 15px;
  }

  .cart-item-image {
    width: 80px !important;
    height: 60px !important;
  }

  .cart-item-title {
    font-size: 1rem;
  }

  .cart-item-description {
    font-size: 12px;
  }

  .cart-notification,
  .notification {
    left: 10px;
    right: 10px;
    top: 10px;
  }
}
