/* Globala box-sizing för att undvika breddproblem */
*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  overflow-x: hidden;
  margin: 0;
  padding: 0;
}

.cart-container {
  max-width: 900px;
  margin: 2rem auto 4rem auto;
  padding: 1rem 2rem;
  background-color: #f9f9f9;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.cart-container h1 {
  font-size: 2rem;
  margin-bottom: 1rem;
  color: #0055aa;
}

/* Kundvagnsknapp - lite förbättring */
.cart-button {
  background: none;
  border: none;
  font-size: 1.8rem;
  cursor: pointer;
  position: relative;
  color: #0055aa;
  transition: color 0.3s ease;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
}

.cart-button:hover,
.cart-button:focus {
  color: #003d7a;
  outline: none;
  background-color: #e6f0ff;
}

/* Kundvagnsräkning */
#cart-count {
  background-color: #ff4444;
  color: white;
  font-size: 0.7rem;
  border-radius: 50%;
  padding: 3px 6px;
  position: absolute;
  top: -8px;
  right: -8px;
  user-select: none;
  font-weight: bold;
  min-width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
  transition: all 0.3s ease;
}

/* Kundvagnspopup */
.cart-popup {
  position: fixed;        /* Positionera popupen relativt viewport */
  top: 3.5rem;            /* Justera så den hamnar under knappen */
  right: 10px;            /* Marginal från högra kanten */
  width: 320px;           /* Standardbredd */
  max-width: 90vw;        /* Max 90% av viewportens bredd */
  max-height: 400px;
  overflow-y: auto;
  background-color: white;
  border: 1px solid #ccc;
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
  padding: 1rem;
  z-index: 10000;
  display: none;          /* Dold som standard */
  font-size: 0.9rem;
  box-sizing: border-box;
  word-wrap: break-word;
  will-change: transform;
  transition: transform 0.3s ease;
}

/* Visa kundvagnspopup när aktiv */
.cart-popup.active {
  display: block;
}

/* Kundvagnspopup rubrik */
.cart-popup h2 {
  font-size: 1.25rem;
  margin-bottom: 0.75rem;
  color: #0055aa;
  border-bottom: 1px solid #eee;
  padding-bottom: 0.25rem;
}

/* Kundvagnslista - enhanced styling */
.cart-items {
  min-height: 150px;
  max-height: 300px;
  overflow-y: auto;
  margin-bottom: 1rem;
}

/* Tom kundvagn */
.cart-empty {
  text-align: center;
  color: #666;
  font-style: italic;
}

/* Checkout-knapp i popup - enhanced styling */
.checkout-button {
  background-color: #0055aa;
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  transition: background-color 0.3s ease;
}

.checkout-button:hover,
.checkout-button:focus {
  background-color: #003d7a;
  outline: none;
}

.hidden {
  display: none;
}

#cart-modal {
  position: fixed;
  top: 3.5rem;
  right: 10px;
  left: auto;
  width: 320px;
  max-width: calc(100vw - 20px); /* max bredd: viewport minus marginal */
  max-height: 400px;
  overflow-y: auto;
  background: linear-gradient(135deg, #ffffff, #f8fbff);
  border: none;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 51, 102, 0.15), 0 4px 15px rgba(0, 0, 0, 0.1);
  padding: 1.5rem;
  z-index: 10000;
  font-size: 0.9rem;
  box-sizing: border-box;
  transform: translateX(0);
  backdrop-filter: blur(10px);
  animation: slideIn 0.3s ease-out;
}

/* For dialog elements, use the natural open state */
#cart-modal[open] {
  display: block;
}

/* Legacy support for div elements with .hidden class */
#cart-modal:not(.hidden) {
  display: block;
}

#close-cart-btn {
  float: right;
  background: linear-gradient(135deg, #ff4757, #ff6b7d);
  border: none;
  font-size: 1rem;
  cursor: pointer;
  color: white;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(255, 71, 87, 0.3);
}

#close-cart-btn:hover {
  background: linear-gradient(135deg, #ff3742, #ff5757);
  transform: scale(1.1);
}

.cart-buttons {
  margin-top: 1rem;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.clear-cart-btn {
  background: linear-gradient(135deg, #6c757d, #868e96);
  color: white;
  border: none;
  padding: 0.6rem 1rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  flex: 1;
  transition: all 0.3s ease;
}

.clear-cart-btn:hover {
  background: linear-gradient(135deg, #5a6268, #6c757d);
  transform: translateY(-1px);
}

.checkout-btn {
  background: linear-gradient(135deg, #003366, #0055aa);
  color: white;
  border: none;
  padding: 0.6rem 1rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  flex: 2;
  transition: all 0.3s ease;
}

.checkout-btn:hover {
  background: linear-gradient(135deg, #0055aa, #0077cc);
  transform: translateY(-1px);
}

#cart-items {
  margin-top: 1rem;
}

.cart-item {
  border-bottom: 1px solid #ccc;
  padding: 0.5rem 0;
}

.cart-item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.remove-item-btn {
  background-color: transparent;
  color: #cc0000;
  border: none;
  padding: 0;
  font-size: 0.9rem;
  text-decoration: underline;
  cursor: pointer;
  margin-left: 10px;
}

.remove-item-btn:hover {
  color: #ff0000;
}

.cart-total {
  margin-top: 10px;
  font-size: 1.1rem;
  font-weight: bold;
  text-align: right;
}

.cart-item-title {
  flex: 2 1 50%;
  font-weight: 600;
}

.cart-item-quantity {
  flex: 1 1 25%;
}

.cart-item-price {
  flex: 1 1 25%;
  text-align: right;
  font-weight: 700;
}

/* --- NYA REGLER FÖR ATT HÅLLA KUNDVAGNSPUPPEN INOM SKÄRMEN --- */
.cart-popup, #cart-modal {
  left: auto !important;
  right: 10px !important;
  max-width: calc(100vw - 20px) !important;
  box-sizing: border-box !important;
  overflow-wrap: break-word !important;
  word-wrap: break-word !important;
  hyphens: auto !important;
  width: auto !important;
}

/* Responsiv justering på små skärmar */
@media (max-width: 400px) {
  .cart-popup, #cart-modal {
    width: calc(100vw - 20px) !important;
    max-width: none !important;
    right: 10px !important;
    left: auto !important;
  }
}

/* Slide-in animation for cart modal */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Improve cart modal title */
#cart-title {
  color: #003366 !important;
  font-weight: 700 !important;
  margin-bottom: 0.5rem !important;
  font-size: 1.2rem !important;
  border-bottom: 2px solid #e6f0ff !important;
  padding-bottom: 0.5rem !important;
}

/* Style the cart description */
#cart-desc {
  color: #666 !important;
  font-size: 0.85rem !important;
  margin-bottom: 1rem !important;
}

/* Custom Alert Dialog */
.custom-alert-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10001;
  animation: fadeIn 0.3s ease;
}

.custom-alert {
  background: linear-gradient(135deg, #ffffff, #f8fbff);
  border-radius: 16px;
  padding: 2rem;
  box-shadow: 0 20px 60px rgba(0, 51, 102, 0.3);
  text-align: center;
  max-width: 400px;
  width: 90%;
  animation: slideInScale 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.custom-alert-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  color: #28a745;
}

.custom-alert-message {
  font-size: 1.1rem;
  color: #003366;
  font-weight: 600;
  margin-bottom: 1.5rem;
  line-height: 1.4;
}

.custom-alert-button {
  background: linear-gradient(135deg, #003366, #0055aa);
  color: white;
  border: none;
  padding: 0.8rem 2rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  min-width: 100px;
}

.custom-alert-button:hover {
  background: linear-gradient(135deg, #0055aa, #0077cc);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 51, 102, 0.3);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideInScale {
  from {
    opacity: 0;
    transform: scale(0.7) translateY(-20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* ===== MODERN CART ITEM LAYOUT ===== */
.cart-item-container {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 8px;
  border-radius: 8px;
  transition: background-color 0.2s ease;
}

.cart-item-container:hover {
  background-color: rgba(0, 51, 102, 0.03);
}

.cart-item-image {
  width: 50px;
  height: 50px;
  border-radius: 6px;
  overflow: hidden;
  background-color: #f8f9fa;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.cart-item-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 6px;
}

.cart-item-icon {
  font-size: 20px;
  color: #6c757d;
}

.cart-item-details {
  flex: 1;
  min-width: 0; /* Allow text to wrap */
}

.cart-item-title {
  font-size: 14px;
  font-weight: 600;
  color: #212529;
  margin-bottom: 4px;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2; /* Standard property for compatibility */
  -webkit-box-orient: vertical;
}

.cart-item-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cart-quantity-badge {
  background: linear-gradient(135deg, #003366, #0055aa);
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 12px;
  min-width: 20px;
  text-align: center;
  line-height: 1;
}

.cart-item-price {
  font-size: 13px;
  font-weight: 700;
  color: #003366;
}

.cart-remove-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background-color: #dc3545;
  color: white;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.cart-remove-btn:hover {
  background-color: #c82333;
  transform: scale(1.1);
}

/* Update the old cart item styles to work with new layout */
.cart-item {
  border-bottom: 1px solid #e9ecef !important;
  padding: 0 !important;
  margin-bottom: 4px;
}

.cart-item:last-child {
  border-bottom: none !important;
}
