:root {
  --sidebar-width: 420px;
}

[x-cloak] { display: none !important; }

/* ── Backdrop ── */
.cart-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(26, 58, 38, 0.45);
  z-index: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.cart-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

/* ── Drawer ── */
.cart-sidebar {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: var(--sidebar-width);
  max-width: 100vw;
  background: var(--color-bg-surface);
  box-shadow: -4px 0 32px rgba(0, 0, 0, 0.15);
  z-index: 600;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.cart-sidebar.open {
  transform: translateX(0);
}

/* ── Icon sizing within sidebar contexts ── */
.cart-sidebar-title svg { width: 20px; height: 20px; flex-shrink: 0; }
.cart-close-btn svg { width: 16px; height: 16px; }
.shipping-progress-text svg { width: 14px; height: 14px; flex-shrink: 0; }
.cart-empty-icon svg { width: 28px; height: 28px; }
.btn-checkout svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn-go-shop svg { width: 14px; height: 14px; flex-shrink: 0; }

/* ── Sidebar Header ── */
.cart-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.cart-sidebar-title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-text-primary);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.cart-item-count {
  background: var(--color-primary);
  color: #fff;
  font-size: var(--text-xs);
  font-weight: 700;
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  line-height: 1.4;
}
.cart-close-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--color-border);
  background: transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--color-text-secondary);
  transition: background 0.15s, color 0.15s;
}
.cart-close-btn:hover {
  background: var(--color-bg-subtle);
  color: var(--color-text-primary);
}

/* ── Free shipping progress ── */
.shipping-progress {
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.shipping-progress-text {
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-2);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.shipping-progress-text svg { color: var(--color-accent); flex-shrink: 0; }
.shipping-progress-text strong { color: var(--color-text-primary); }
.shipping-progress-text.reached { color: var(--color-primary); font-weight: 600; }
.progress-track {
  width: 100%;
  height: 6px;
  background: var(--color-bg-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--color-accent);
  border-radius: var(--radius-full);
  transition: width 0.4s ease;
}
.progress-fill.reached { background: var(--color-primary); }

/* ── Items list ── */
.cart-items {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4) var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.cart-items::-webkit-scrollbar { width: 4px; }
.cart-items::-webkit-scrollbar-track { background: transparent; }
.cart-items::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 2px; }

.cart-item {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: var(--space-3);
  align-items: start;
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--color-border);
}
.cart-item:last-child { border-bottom: none; padding-bottom: 0; }

.cart-item-img {
  width: 72px; height: 72px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--color-bg-subtle);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.cart-item-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}
.cart-item-category {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-hint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.cart-item-name {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-primary);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cart-item-unit-price {
  font-size: var(--text-xs);
  color: var(--color-text-hint);
}
.cart-item-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: var(--space-2);
}

/* Qty stepper — compact */
.qty-control {
  display: flex;
  align-items: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--color-bg-subtle);
  height: 32px;
}
.qty-btn {
  width: 28px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; cursor: pointer;
  font-size: var(--text-base); color: var(--color-text-secondary);
  transition: background 0.15s, color 0.15s;
  line-height: 1;
}
.qty-btn:hover { background: var(--color-border); color: var(--color-primary); }
.qty-value {
  width: 36px; text-align: center;
  font-family: var(--font-primary); font-size: var(--text-sm); font-weight: 600;
  color: var(--color-text-primary);
  border-left: 1px solid var(--color-border);
  border-right: 1px solid var(--color-border);
  line-height: 32px;
}

.cart-item-price {
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--color-price);
}
.cart-item-remove {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--color-text-hint);
  padding: var(--space-1);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  transition: color 0.15s;
  margin-left: var(--space-2);
}
.cart-item-remove:hover { color: var(--color-error); }

/* ── Cart count badge (header) ── */
.cart-count {
  position: absolute;
  top: -5px; right: -8px;
  background: var(--color-accent); color: #fff;
  font-size: 10px; font-weight: 700;
  border-radius: var(--radius-full);
  width: 16px; height: 16px;
  display: flex; align-items: center; justify-content: center;
}
.cart-count.is-hidden { display: none; }

/* ── Empty state ── */
.cart-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: var(--space-8) var(--space-6);
  text-align: center;
}
.cart-empty-icon {
  width: 64px; height: 64px;
  background: var(--color-bg-subtle);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--color-text-hint);
}
.cart-empty-title {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-text-primary);
}
.cart-empty-desc {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  line-height: 1.6;
}
.btn-go-shop {
  display: inline-flex; align-items: center; gap: var(--space-2);
  background: var(--color-primary); color: #fff;
  border: none; border-radius: var(--radius-md);
  font-family: var(--font-primary); font-size: var(--text-sm); font-weight: 600;
  padding: var(--space-3) var(--space-6);
  cursor: pointer; text-decoration: none;
  transition: background 0.15s;
}
.btn-go-shop:hover { background: var(--color-primary-dark); }

/* ── Footer / Summary ── */
.cart-sidebar-footer {
  border-top: 1px solid var(--color-border);
  padding: var(--space-5) var(--space-6);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  background: var(--color-bg-surface);
}
.cart-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}
.cart-summary-row.total {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-text-primary);
  padding-top: var(--space-2);
  border-top: 1px solid var(--color-border);
}
.cart-summary-row.total .total-price {
  color: var(--color-price);
  font-size: var(--text-xl);
}
.cart-footer-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-1);
}
.btn-checkout {
  display: flex; align-items: center; justify-content: center; gap: var(--space-2);
  background: var(--color-primary); color: #fff;
  border: none; border-radius: var(--radius-md);
  font-family: var(--font-primary); font-size: var(--text-base); font-weight: 600;
  padding: var(--space-4) var(--space-6);
  cursor: pointer; text-decoration: none;
  transition: background 0.15s, transform 0.1s;
}
.btn-checkout:hover { background: var(--color-primary-dark); }
.btn-checkout:active { transform: scale(0.99); }
.btn-view-cart {
  display: flex; align-items: center; justify-content: center;
  background: transparent; color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-primary); font-size: var(--text-sm); font-weight: 500;
  padding: var(--space-3) var(--space-6);
  cursor: pointer; text-decoration: none;
  transition: border-color 0.15s, color 0.15s;
}
.btn-view-cart:hover {
  border-color: var(--color-border-strong);
  color: var(--color-text-primary);
}

/* ── Add-to-cart button flash ── */
.btn.is-added,
.btn-add-to-cart.is-added {
  background: var(--color-primary-light);
  pointer-events: none;
  transition: background 0.15s;
}

/* ── Add-to-cart toast ── */
.cart-toast {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: 800;
  background: var(--color-primary);
  color: #fff;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-family: var(--font-primary);
  font-size: var(--text-sm);
  font-weight: 500;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
}
.cart-toast-body {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.cart-toast-body svg { width: 16px; height: 16px; flex-shrink: 0; }
.cart-toast-action {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius-sm);
  color: #fff;
  font-family: var(--font-primary);
  font-size: var(--text-xs);
  font-weight: 600;
  padding: var(--space-1) var(--space-3);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--space-1);
  transition: background 0.15s;
  align-self: flex-start;
}
.cart-toast-action:hover { background: rgba(255, 255, 255, 0.25); }
.cart-toast-action svg { width: 12px; height: 12px; flex-shrink: 0; }
