/**
 * Shadcn / Vaul Cart Drawer Styles
 * Matches components/ui/drawer.tsx & demo.tsx exactly
 */

:root {
  --drawer-bg: #ffffff;
  --drawer-fg: #0f172a;
  --drawer-muted: #f1f5f9;
  --drawer-muted-fg: #64748b;
  --drawer-border: #e2e8f0;
  --drawer-radius: 1.5rem;
  --drawer-primary: #0f172a;
  --drawer-primary-fg: #ffffff;
}

[data-theme="dark"],
.dark {
  --drawer-bg: #090d16;
  --drawer-fg: #f8fafc;
  --drawer-muted: #1e293b;
  --drawer-muted-fg: #94a3b8;
  --drawer-border: #1e293b;
  --drawer-primary: #f8fafc;
  --drawer-primary-fg: #0f172a;
}

/* 1. Backdrop Overlay */
.shadcn-drawer {
  position: fixed;
  inset: 0;
  z-index: 999999;
  pointer-events: none;
  visibility: hidden;
  transition: visibility 0.3s ease;
}

.shadcn-drawer[data-state="open"] {
  pointer-events: auto;
  visibility: visible;
}

.shadcn-drawer-overlay {
  position: fixed;
  inset: 0;
  z-index: 999999;
  background-color: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
}

.shadcn-drawer[data-state="open"] .shadcn-drawer-overlay {
  opacity: 1;
  pointer-events: auto;
}

/* 2. Content Container */
.shadcn-drawer-content {
  position: fixed;
  z-index: 1000000;
  background-color: var(--drawer-bg);
  color: var(--drawer-fg);
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  box-sizing: border-box;
}

/* Mobile: Bottom Sheet */
@media (max-width: 639.98px) {
  .shadcn-drawer-content {
    inset-inline: 0;
    bottom: 0;
    height: 85vh;
    max-height: 85vh;
    border-top-left-radius: var(--drawer-radius);
    border-top-right-radius: var(--drawer-radius);
    border-top: 1px solid var(--drawer-border);
    transform: translateY(100%);
  }

  .shadcn-drawer[data-state="open"] .shadcn-drawer-content {
    transform: translateY(0);
  }

  .shadcn-drawer-handle {
    width: 5rem;
    height: 0.3125rem;
    background-color: var(--drawer-muted);
    border-radius: 9999px;
    margin: 0.625rem auto 0.25rem;
    flex-shrink: 0;
    display: block;
  }
}

/* Desktop: Slide-over Drawer from Right */
@media (min-width: 640px) {
  .shadcn-drawer-content {
    top: 0;
    bottom: 0;
    right: 0;
    width: 100%;
    max-width: 28rem;
    height: 100vh;
    max-height: 100vh;
    border-left: 1px solid var(--drawer-border);
    transform: translateX(100%);
  }

  .shadcn-drawer[data-state="open"] .shadcn-drawer-content {
    transform: translateX(0);
  }

  .shadcn-drawer-handle {
    display: none;
  }
}

/* 3. Header */
.shadcn-drawer-header {
  padding: 1.125rem 1.25rem 0.875rem;
  border-bottom: 1px solid var(--drawer-border);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex-shrink: 0;
  background-color: var(--drawer-bg);
}

.shadcn-drawer-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.shadcn-drawer-title {
  font-size: 1.125rem;
  font-weight: 600;
  display: inline-flex !important;
  align-items: center !important;
  gap: 0.5rem !important;
  color: var(--drawer-fg);
  margin: 0;
  white-space: nowrap;
}

.shadcn-drawer-title svg {
  width: 22px !important;
  height: 22px !important;
  min-width: 22px !important;
  min-height: 22px !important;
  display: inline-block !important;
  vertical-align: middle;
  color: #2563eb !important;
  stroke: #2563eb !important;
  stroke-width: 2;
  flex-shrink: 0;
}

.shadcn-drawer-close-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0.375rem;
  border-radius: 0.375rem;
  color: var(--drawer-muted-fg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  width: 32px;
  height: 32px;
}

.shadcn-drawer-close-btn:hover {
  background-color: var(--drawer-muted);
  color: var(--drawer-fg);
}

.shadcn-drawer-close-btn svg {
  width: 18px !important;
  height: 18px !important;
  display: block;
}

.shadcn-drawer-description {
  font-size: 0.875rem;
  color: var(--drawer-muted-fg);
  margin: 0;
}

/* 4. Body (Scrollable Container) */
.shadcn-drawer-body {
  flex: 1 1 auto;
  min-height: 0; /* CRUCIAL: allows flex child to scroll properly and not push footer */
  padding: 1rem 1.25rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Cart Item Card */
.cart-drawer-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0.875rem;
  border: 1px solid var(--drawer-border);
  border-radius: 0.75rem;
  background-color: var(--drawer-bg);
  margin-bottom: 0.75rem;
  box-sizing: border-box;
}

.cart-item-image {
  width: 3.25rem;
  height: 3.25rem;
  border-radius: 0.5rem;
  overflow: hidden;
  background-color: var(--drawer-muted);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

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

.cart-item-info h3 {
  font-size: 0.875rem;
  font-weight: 600;
  margin: 0 0 0.25rem;
  color: var(--drawer-fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cart-item-info h3 a {
  color: inherit;
  text-decoration: none;
}

.cart-item-info p,
.cart-item-info .amount {
  font-size: 0.8125rem;
  color: var(--drawer-muted-fg);
  margin: 0;
  text-decoration: none !important;
}

/* Stepper Controls */
.cart-item-stepper {
  display: flex;
  align-items: center;
  gap: 0.125rem;
  border: 1px solid var(--drawer-border);
  border-radius: 0.5rem;
  padding: 0.125rem;
  background-color: #f8fafc;
  flex-shrink: 0;
}

.cart-qty-val {
  width: 1.5rem;
  text-align: center;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--drawer-fg);
  display: inline-block;
}

.cart-qty-minus,
.cart-qty-plus {
  width: 1.75rem !important;
  height: 1.75rem !important;
  min-width: 1.75rem;
  padding: 0 !important;
  border-radius: 0.375rem !important;
  border: 1px solid transparent !important;
  background: #ffffff !important;
  color: #334155 !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.cart-qty-minus:hover,
.cart-qty-plus:hover {
  background: #f1f5f9 !important;
  color: #0f172a !important;
}

.cart-qty-minus svg,
.cart-qty-plus svg {
  width: 12px !important;
  height: 12px !important;
  display: block !important;
  stroke: currentColor !important;
  stroke-width: 2.5 !important;
}

/* Total Price & Remove Button Column */
.cart-item-total {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.375rem;
  min-width: 4.5rem;
  flex-shrink: 0;
  text-align: right;
}

.cart-item-total p,
.cart-item-total .amount {
  font-size: 0.875rem;
  font-weight: 600;
  margin: 0;
  color: var(--drawer-fg);
  text-decoration: none !important;
}

/* Trash Remove Button - Explicitly styled and visible */
.cart-item-remove {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 26px !important;
  height: 26px !important;
  min-width: 26px !important;
  min-height: 26px !important;
  padding: 0 !important;
  border-radius: 0.375rem !important;
  border: 1px solid #fee2e2 !important;
  background-color: #fef2f2 !important;
  color: #dc2626 !important;
  cursor: pointer;
  transition: all 0.15s ease-in-out;
  box-sizing: border-box;
}

.cart-item-remove:hover {
  background-color: #fee2e2 !important;
  color: #b91c1c !important;
  border-color: #fca5a5 !important;
}

.cart-item-remove svg {
  width: 13px !important;
  height: 13px !important;
  min-width: 13px !important;
  min-height: 13px !important;
  display: block !important;
  stroke: currentColor !important;
  stroke-width: 2 !important;
  stroke-linecap: round !important;
  stroke-linejoin: round !important;
  fill: none !important;
}

/* Empty State */
.cart-empty-state {
  padding: 3rem 1rem;
  text-align: center;
}

.cart-empty-icon {
  width: 3.5rem !important;
  height: 3.5rem !important;
  margin: 0 auto 1rem;
  color: #94a3b8;
  opacity: 0.5;
  display: block;
}

.cart-empty-text {
  font-size: 0.9375rem;
  color: var(--drawer-muted-fg);
  margin-bottom: 1.25rem;
}

/* Order Summary */
.cart-summary {
  border-top: 1px solid var(--drawer-border);
  padding-top: 1rem;
  margin-top: 1.25rem;
}

.cart-summary .space-y-2 > * + * {
  margin-top: 0.5rem;
}

.cart-summary .flex {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.875rem;
}

.cart-summary .amount {
  text-decoration: none !important;
}

.cart-total-val,
.cart-total-val .amount {
  font-size: 1.125rem !important;
  font-weight: 700 !important;
  color: #0284c7 !important;
  text-decoration: none !important;
}

/* Coupon Form */
.cart-coupon {
  border-top: 1px solid var(--drawer-border);
  padding-top: 1rem;
  margin-top: 1rem;
}

.cart-coupon form {
  display: flex;
  gap: 0.5rem;
}

/* 5. Footer Buttons (Sticky at Bottom) */
.shadcn-drawer-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--drawer-border);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  background-color: var(--drawer-bg);
  flex-shrink: 0;
  box-sizing: border-box;
}

/* Common Shadcn Button & Input styling */
.shadcn-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 0.5rem;
  padding: 0.5rem 1rem;
  height: 2.5rem;
  cursor: pointer;
  text-decoration: none !important;
  transition: all 0.2s;
  box-sizing: border-box;
  text-align: center;
  line-height: 1;
}

.shadcn-btn-primary {
  background-color: #0f172a !important;
  color: #ffffff !important;
  border: 1px solid #0f172a !important;
}

.shadcn-btn-primary:hover {
  background-color: #1e293b !important;
  color: #ffffff !important;
}

.shadcn-btn-outline {
  background-color: #ffffff !important;
  color: var(--drawer-fg) !important;
  border: 1px solid var(--drawer-border) !important;
}

.shadcn-btn-outline:hover {
  background-color: var(--drawer-muted) !important;
}

.shadcn-btn.disabled,
.shadcn-btn[disabled] {
  opacity: 0.5;
  pointer-events: none;
  cursor: not-allowed;
}

.shadcn-input {
  flex: 1;
  height: 2.5rem;
  border-radius: 0.5rem;
  border: 1px solid var(--drawer-border);
  background-color: var(--drawer-bg);
  color: var(--drawer-fg);
  padding: 0 0.75rem;
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.2s;
  box-sizing: border-box;
}

.shadcn-input:focus {
  border-color: #0284c7;
  box-shadow: 0 0 0 1px #0284c7;
}
