/* ==========================================================================
   ProzPart Cart Modal - Clean Professional Design
   Design System: Minimal, Notion-like, light theme
   ========================================================================== */

/* CSS Variables (Design Tokens) - Dark Theme */
:root {
  /* Colors - Dark Theme */
  --cart-bg: #1a1d2e;
  --cart-panel: #252939;
  --cart-card: #2a2f42;
  --cart-text: #e2e8f0;
  --cart-muted: #94a3b8;
  --cart-border: rgba(255, 255, 255, 0.1);
  --cart-accent: #c2410c;
  --cart-danger: #ef4444;
  --cart-success: #10b981;

  /* Spacing (8px grid) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;

  /* Border radius */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 12px;
  --radius-pill: 999px;

  /* Typography */
  --font-base: 14px;
  --font-md: 16px;
  --font-lg: 18px;
  --font-sm: 12px;

  /* Shadows - Subtle for dark theme */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-modal: 0 4px 16px rgba(0, 0, 0, 0.4);
}

/* ==========================================================================
   Modal Container & Overlay
   ========================================================================== */

#cart-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  animation: fadeIn 0.15s ease;
}

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

.modal-content {
  background: var(--cart-bg);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-modal);
  max-width: 1400px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.15s ease;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ==========================================================================
   Modal Header
   ========================================================================== */

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

.modal-header h2 {
  font-size: var(--font-lg);
  font-weight: 700;
  color: var(--cart-text);
  margin: 0;
  letter-spacing: -0.01em;
}

.modal-close {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--cart-muted);
  font-size: 24px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all 0.15s ease;
}

.modal-close:hover {
  background: var(--cart-panel);
  color: var(--cart-text);
}

.modal-close:focus-visible {
  outline: 2px solid var(--cart-accent);
  outline-offset: 2px;
}

/* Modal Header Actions */
.modal-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.cart-modal-header-left {
  flex: 1;
}

/* Icon buttons */
.btn-icon-inline {
  width: 28px;
  height: 28px;
  padding: 0;
  margin-left: var(--space-2);
  border: none;
  background: transparent;
  color: var(--cart-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  vertical-align: middle;
}

.btn-icon-inline:hover {
  background: rgba(194, 65, 12, 0.1);
  color: var(--cart-accent);
}

.btn-icon-inline svg {
  width: 14px;
  height: 14px;
}

.btn-icon-danger {
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--cart-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.btn-icon-danger:hover {
  background: rgba(239, 68, 68, 0.1);
  color: var(--cart-danger);
}

.btn-icon-danger svg {
  width: 16px;
  height: 16px;
}

/* ==========================================================================
   Modal Body (Vendor Grid)
   ========================================================================== */

.modal-body {
  padding: var(--space-4);
  overflow-y: auto;
  flex: 1;
}

/* Custom scrollbar (webkit) */
.modal-body::-webkit-scrollbar {
  width: 8px;
}

.modal-body::-webkit-scrollbar-track {
  background: transparent;
}

.modal-body::-webkit-scrollbar-thumb {
  background: var(--cart-border);
  border-radius: var(--radius-pill);
}

.modal-body::-webkit-scrollbar-thumb:hover {
  background: var(--cart-muted);
}

#cart-items-grid {
  display: flex;
  flex-wrap: nowrap;
  gap: var(--space-4);
  overflow-x: auto;
  align-items: start;
  justify-content: center;
}

/* Auto-sizing for 3+ vendors */
#cart-items-grid > * {
  flex: 1 1 400px;
  min-width: 400px;
}

/* Fixed width when 1 or 2 vendors */
#cart-items-grid > *:first-child:nth-last-child(1),
#cart-items-grid > *:first-child:nth-last-child(2),
#cart-items-grid > *:first-child:nth-last-child(2) ~ * {
  flex: 0 0 400px;
  max-width: 400px;
}

/* ==========================================================================
   Vendor Card
   ========================================================================== */

.vendor-cart-column {
  background: var(--cart-card);
  border: 1px solid var(--cart-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  transition: border-color 0.15s ease;
  min-width: 400px;
  align-self: stretch;
}

.vendor-cart-column:hover {
  border-color: rgba(255, 255, 255, 0.2);
}

/* Vendor Header */
.vendor-cart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--cart-border);
}

.vendor-cart-header > span:first-child {
  font-size: var(--font-md);
  font-weight: 600;
  color: var(--cart-text);
  letter-spacing: -0.01em;
}

.vendor-cart-count {
  background: rgba(255, 255, 255, 0.1);
  color: var(--cart-muted);
  padding: var(--space-1) 10px;
  border-radius: var(--radius-pill);
  font-size: var(--font-sm);
  font-weight: 600;
}

/* ==========================================================================
   Cart Items List
   ========================================================================== */

.vendor-cart-items {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  flex: 1;
}

/* Cart Item Card - Professional compact style */
.cart-item {
  display: grid;
  grid-template-columns: 80px 1fr;
  grid-template-rows: auto auto;
  gap: 12px;
  background: var(--cart-panel);
  border: 1px solid var(--cart-border);
  border-radius: 8px;
  padding: 12px;
  align-items: start;
  transition: border-color 0.15s ease;
  position: relative;
}

.cart-item:hover {
  border-color: rgba(255, 255, 255, 0.2);
}

.cart-item-image {
  width: 80px;
  height: 80px;
  border-radius: 6px;
  object-fit: cover;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--cart-border);
  image-rendering: auto;
  display: block;
  transition: opacity 0.15s ease;
  grid-row: 1 / 2;
  grid-column: 1 / 2;
}

.cart-item-image:hover {
  opacity: 0.85;
}

.cart-item-clickable {
  grid-row: 1 / 2;
  grid-column: 2 / 3;
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-decoration: none;
  color: inherit;
  min-width: 0;
}

.cart-item-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.cart-item-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--cart-text);
  margin-bottom: 4px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.cart-item-sku {
  font-size: 11px;
  color: var(--cart-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cart-item-price {
  font-size: 14px;
  line-height: 1.3;
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 4px;
  text-align: right;
  position: absolute;
  right: 12px;
  bottom: 60px;
}

.cart-item-price .price-unit {
  font-size: 12px;
  font-weight: 500;
  color: var(--cart-muted);
}

.cart-item-price .price-total {
  font-size: 16px;
  font-weight: 700;
  color: var(--cart-text);
}

.cart-item-bottom-row {
  grid-row: 2 / 3;
  grid-column: 1 / 3;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--cart-border);
}

.cart-item-availability {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: fit-content;
  justify-self: start;
}

/* Availability badges - Minimal professional style */
.cart-item-availability.availability-in-stock {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
}

.cart-item-availability.availability-supplier {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
}

.cart-item-availability.availability-low-stock {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
}

/* ==========================================================================
   Actions Column (Quantity + Delete) - Professional Compact Style
   ========================================================================== */

.cart-item-qty-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-self: center;
}

/* Quantity stepper - outlined square buttons */
.cart-qty-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--cart-border);
  background: transparent;
  color: var(--cart-text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  user-select: none;
}

.cart-qty-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.2);
}

.cart-qty-btn:active {
  transform: scale(0.98);
}

.cart-qty-btn:focus-visible {
  outline: 2px solid var(--cart-accent);
  outline-offset: 1px;
}

/* Quantity display - compact neutral pill */
.cart-item-qty {
  min-width: 36px;
  padding: 4px 8px;
  text-align: center;
  font-weight: 600;
  font-size: 13px;
  color: var(--cart-text);
  background: rgba(255, 255, 255, 0.08);
  border-radius: 6px;
}

/* Delete button - icon only, no background, aligned to right */
.cart-item-remove {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  background: transparent;
  border: none;
  color: var(--cart-muted);
  font-size: 16px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: color 0.15s, background 0.15s;
  padding: 0;
  flex-shrink: 0;
  justify-self: end;
}

.cart-item-remove:hover {
  background: rgba(239, 68, 68, 0.1);
  color: var(--cart-danger);
}

.cart-item-remove:active {
  transform: scale(0.95);
}

.cart-item-remove:focus-visible {
  outline: 2px solid var(--cart-danger);
  outline-offset: 2px;
}

/* ==========================================================================
   Vendor Footer (Subtotal & Checkout)
   ========================================================================== */

.vendor-cart-footer {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--cart-border);
  margin-top: auto;
}

.vendor-subtotal {
  font-size: var(--font-md);
  font-weight: 700;
  color: var(--cart-text);
  text-align: right;
}

.btn-vendor-checkout {
  width: 100%;
  padding: 10px var(--space-4);
  border-radius: 10px;
  border: 1px solid rgba(194, 65, 12, 0.5);
  background: #c2410c;
  color: #ffffff;
  font-size: var(--font-base);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-vendor-checkout:hover {
  background: #ea580c;
  border-color: #ea580c;
}

.btn-vendor-checkout:active {
  transform: scale(0.98);
}

.btn-vendor-checkout:focus-visible {
  outline: 2px solid var(--cart-accent);
  outline-offset: 2px;
}

/* ==========================================================================
   Modal Footer (Global Actions)
   ========================================================================== */

.modal-footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--cart-border);
  background: var(--cart-bg);
  flex-shrink: 0;
}

.cart-summary {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-3);
}

.cart-total-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-2);
}

.cart-total-items {
  font-size: var(--font-md);
  color: var(--cart-text);
}

.cart-total-items strong {
  font-weight: 500;
  color: var(--cart-muted);
  margin-right: var(--space-2);
}

.cart-total-global {
  font-size: 20px;
  font-weight: 700;
  color: #10b981;
}

.cart-total-global strong {
  font-weight: 500;
  color: var(--cart-muted);
  margin-right: var(--space-2);
}

.cart-actions-bottom {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  justify-content: flex-start;
}

/* ==========================================================================
   Buttons (Primary & Secondary)
   ========================================================================== */

.btn-export,
.btn-checkout,
.btn-refresh-prices {
  padding: 10px var(--space-4);
  border-radius: 10px;
  font-size: var(--font-base);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid transparent;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-refresh-prices {
  background: rgba(194, 65, 12, 0.15);
  color: #ea580c;
  border-color: rgba(194, 65, 12, 0.3);
}

.btn-refresh-prices:hover {
  background: rgba(194, 65, 12, 0.25);
  border-color: rgba(194, 65, 12, 0.5);
}

.btn-refresh-prices:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-refresh-prices.loading svg {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.btn-export {
  background: rgba(194, 65, 12, 0.15);
  color: #ea580c;
  border-color: rgba(194, 65, 12, 0.3);
}

.btn-export:hover {
  background: rgba(194, 65, 12, 0.25);
  border-color: rgba(194, 65, 12, 0.5);
}

.btn-checkout {
  background: var(--cart-accent);
  color: white;
  border-color: var(--cart-accent);
}

.btn-checkout:hover {
  background: #9a3412;
}

.btn-export:active,
.btn-checkout:active {
  transform: scale(0.98);
}

.btn-export:focus-visible,
.btn-checkout:focus-visible {
  outline: 2px solid var(--cart-accent);
  outline-offset: 2px;
}

/* ==========================================================================
   Empty State
   ========================================================================== */

#cart-empty {
  text-align: center;
  padding: 60px var(--space-5);
  color: var(--cart-muted);
  font-size: var(--font-md);
}

#cart-empty p {
  margin: 0;
}

/* ==========================================================================
   Responsive Adjustments
   ========================================================================== */

@media (max-width: 720px) {
  .modal-content {
    max-height: 95vh;
    border-radius: var(--radius-lg);
  }

  .modal-header {
    padding: var(--space-3) var(--space-4);
  }

  .modal-header h2 {
    font-size: var(--font-md);
  }

  .modal-body {
    padding: var(--space-3);
  }

  .modal-footer {
    padding: var(--space-3) var(--space-4);
  }

  .cart-summary {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-3);
  }

  .cart-total-info {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
  }

  .cart-actions-bottom {
    flex-direction: column-reverse;
    width: 100%;
  }

  .btn-export,
  .btn-checkout,
  .btn-refresh-prices {
    width: 100%;
  }

  /* Cart items responsive */
  .cart-item {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .cart-item-clickable {
    grid-template-columns: 56px 1fr;
    gap: 10px;
  }

  .cart-item-image {
    width: 56px;
    height: 56px;
  }

  .cart-item-qty-controls {
    justify-content: flex-start;
  }
}

/* ==========================================================================
   Accessibility
   ========================================================================== */

/* Focus states for keyboard navigation */
*:focus-visible {
  outline: 2px solid var(--cart-accent);
  outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
