/* Cart styles ("طلبك"). See design/CART_SPEC.md and assets/js/cart.js.
   Logical properties throughout so RTL (Arabic) and LTR (English) share one sheet. */

:root {
  --cart-ink: var(--maroon-deep);
  --cart-pill: var(--saffron);
  --cart-pill-hover: #FFC63D;
  --cart-toast-bg: var(--surface);
  --cart-toast-line: var(--line);
  --cart-toast-shadow: 0 2px 0 rgba(78, 12, 9, 0.05), 0 22px 44px -18px rgba(78, 12, 9, 0.5);
  --cart-soon-bg: var(--maroon);
  --cart-soon-ink: #FFF4E2;
  --cart-scrim: rgba(26, 11, 9, 0.55);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --cart-toast-bg: #2E1613;
    --cart-toast-line: #52281F;
    --cart-toast-shadow: 0 2px 0 rgba(0, 0, 0, 0.3), 0 22px 44px -16px rgba(0, 0, 0, 0.9);
    --cart-soon-bg: #5C110C;
    --cart-scrim: rgba(0, 0, 0, 0.65);
  }
}
:root[data-theme="dark"] {
  --cart-toast-bg: #2E1613;
  --cart-toast-line: #52281F;
  --cart-toast-shadow: 0 2px 0 rgba(0, 0, 0, 0.3), 0 22px 44px -16px rgba(0, 0, 0, 0.9);
  --cart-soon-bg: #5C110C;
  --cart-scrim: rgba(0, 0, 0, 0.65);
}

/* ---------- Header button ---------- */
.cart-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 44px;
  min-height: 44px;
  margin-inline-start: 4px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: var(--cart-pill);
  color: var(--cart-ink);
  font: inherit;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: inset 0 -2px 0 rgba(78, 12, 9, 0.18);
  transition: background-color 0.15s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.cart-btn:hover { background: var(--cart-pill-hover); }
.cart-btn:active { transform: translateY(1px); }
.cart-btn .cart-btn-icon { width: 1.4em; height: 1.4em; stroke-width: 2.2; }
.cart-btn-label { line-height: 1; padding-top: 0.1em; }

.cart-badge {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--flame);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-body);
}
.cart-btn:not(.has-items) .cart-badge { display: none; }
.cart-badge.is-pop { animation: cart-pop 0.45s var(--ease-out, ease-out); }
@keyframes cart-pop {
  0% { transform: scale(1); }
  35% { transform: scale(1.45); }
  65% { transform: scale(0.9); }
  100% { transform: scale(1); }
}

/* Icon-only (phones and the crowded 900–1099px header): round button, badge on the corner */
@media (max-width: 479px), (min-width: 900px) and (max-width: 1099px) {
  .cart-btn { width: 44px; padding: 0; }
  .cart-btn-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
  .cart-badge {
    position: absolute;
    top: -3px;
    inset-inline-end: -5px;
    min-width: 21px;
    height: 21px;
    padding: 0 5px;
    font-size: 0.74rem;
    box-shadow: 0 0 0 2px var(--bg);
  }
}

/* ---------- Panel ---------- */
.cart {
  position: fixed;
  inset-block: 0;
  inset-inline-start: auto;
  inset-inline-end: 0;
  width: min(440px, 100%);
  max-width: 100%;
  height: 100%;
  max-height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  border-start-start-radius: var(--radius-lg);
  border-end-start-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  font-variant-numeric: tabular-nums;
}
.cart[open] { display: flex; }
.cart::backdrop { background: var(--cart-scrim); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }

.cart-sheet { display: flex; flex-direction: column; width: 100%; min-height: 0; }

.cart-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 16px 14px 20px;
  padding-inline: 20px 12px;
  background: var(--maroon);
  color: #FFF4E2;
}
.cart-head-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 50%;
  background: var(--saffron);
  color: var(--maroon-deep);
}
.cart-head-icon .icon { width: 1.4em; height: 1.4em; }
.cart-head-text { flex: 1; min-width: 0; }
.cart-title { font-family: var(--font-display); font-size: 1.75rem; line-height: 1.1; color: var(--saffron); }
.cart-count { font-size: var(--fs-sm); opacity: 0.85; }
.cart-close { color: inherit; flex: none; }
.cart-close:hover { background: rgba(255, 255, 255, 0.12); }

.cart-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 20px;
}
.cart-list { list-style: none; margin: 0; padding: 0; }

.cart-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 12px;
  padding-block: 16px;
  border-bottom: 1px solid var(--line);
}
.cart-item:last-child { border-bottom: 0; }
.cart-item-main { min-width: 0; }
.cart-item-name { font-weight: 700; line-height: 1.35; overflow-wrap: anywhere; }
.cart-item-detail { color: var(--muted); font-size: var(--fs-sm); line-height: 1.4; }
.cart-item-unit { margin-top: 2px; font-size: var(--fs-sm); color: var(--muted); }
.cart-item-unit span { opacity: 0.85; }
.cart-item-line {
  font-weight: 700;
  color: var(--price-ink);
  white-space: nowrap;
  text-align: end;
}
.cart-item-ctrl {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}

.cart-stepper {
  display: inline-flex;
  align-items: center;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
}
.cart-step {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
}
.cart-step:hover:not(:disabled) { background: var(--surface-2); }
.cart-step:disabled { color: var(--muted); opacity: 0.45; cursor: default; }
.cart-step .icon { stroke-width: 2.5; }
.cart-stepper input {
  width: 3ch;
  min-width: 36px;
  height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font-weight: 700;
  font-size: var(--fs-md);
  text-align: center;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
  appearance: textfield;
}
.cart-stepper input::-webkit-outer-spin-button,
.cart-stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.cart-remove {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 600;
  cursor: pointer;
}
.cart-remove:hover { background: color-mix(in srgb, var(--flame) 12%, transparent); color: var(--flame); }

/* Empty state */
.cart-empty {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 48px 8px 32px;
  text-align: center;
}
.cart-empty-art {
  display: grid;
  place-items: center;
  width: 88px;
  height: 88px;
  margin-bottom: 8px;
  border-radius: 50%;
  background: var(--price-bg);
  color: var(--price-ink);
}
.cart-empty-art .icon { width: 2.6em; height: 2.6em; stroke-width: 1.7; }
.cart-empty h3 { font-family: var(--font-display); font-size: 1.6rem; color: var(--accent); }
.cart-empty p { max-width: 30ch; color: var(--muted); }
.cart-empty .btn { margin-top: 12px; }

/* Footer */
.cart-foot {
  display: grid;
  gap: 10px;
  padding: 14px 20px calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.cart-foot[hidden] { display: none; }
.cart-total {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-weight: 600;
}
.cart-total b {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.9rem;
  line-height: 1;
  color: var(--flame);
}
:root[data-theme="dark"] .cart-total b { color: var(--saffron); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .cart-total b { color: var(--saffron); }
}
.cart-pay { color: var(--muted); font-size: var(--fs-sm); margin-top: -6px; }
.cart-actions { display: grid; gap: 8px; }
.cart-actions .btn { width: 100%; }
.cart-confirm .icon { stroke-width: 2.6; }

.cart-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Desktop: slide in from the inline-end edge */
@media (prefers-reduced-motion: no-preference) {
  .cart[open] { animation: cart-in 0.28s var(--ease-out, ease-out); }
  :root[dir="rtl"] .cart[open] { animation-name: cart-in-rtl; }
  .cart[open]::backdrop { animation: cart-fade 0.28s ease-out; }
}
@keyframes cart-in { from { transform: translateX(40px); opacity: 0.4; } to { transform: none; opacity: 1; } }
@keyframes cart-in-rtl { from { transform: translateX(-40px); opacity: 0.4; } to { transform: none; opacity: 1; } }
@keyframes cart-fade { from { opacity: 0; } to { opacity: 1; } }

/* Phones: bottom sheet */
@media (max-width: 599px) {
  .cart {
    inset: auto 0 0 0;
    width: 100%;
    height: auto;
    max-height: min(88dvh, 88vh);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
  .cart-sheet { max-height: inherit; }
  .cart-head { position: relative; padding-top: 22px; }
  .cart-head::before {
    content: "";
    position: absolute;
    top: 8px;
    inset-inline: 0;
    width: 40px;
    height: 4px;
    margin-inline: auto;
    border-radius: 4px;
    background: rgba(255, 244, 226, 0.4);
  }
  .cart-body { padding-inline: 16px; }
  .cart-foot { padding-inline: 16px; }
  .cart-actions { grid-template-columns: 1fr; }
}
@media (max-width: 599px) and (prefers-reduced-motion: no-preference) {
  .cart[open], :root[dir="rtl"] .cart[open] { animation: cart-up 0.26s var(--ease-out, ease-out); }
}
@keyframes cart-up { from { transform: translateY(40px); opacity: 0.5; } to { transform: none; opacity: 1; } }

/* ---------- Toasts ---------- */
.cart-toasts {
  position: fixed;
  z-index: 120;
  inset-inline-end: 24px;
  bottom: calc(96px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  width: min(380px, calc(100vw - 32px));
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
/* Inside an open panel/dialog (desktop): keep clear of the side panel */
.cart-toasts.in-dialog { inset-inline-end: auto; inset-inline-start: 24px; bottom: 24px; }
.cart-toasts:empty { display: none; }

/* Phones: drop in under the sticky header, away from the bottom bars */
@media (max-width: 719px) {
  .cart-toasts,
  .cart-toasts.in-dialog {
    top: calc(var(--header-h, 68px) + 10px + env(safe-area-inset-top));
    bottom: auto;
    inset-inline: 12px;
    width: auto;
    flex-direction: column-reverse;
  }
  /* With a bottom sheet open, sit at the bottom so the sheet's header and close button stay clear */
  .cart-toasts.in-dialog {
    top: auto;
    bottom: calc(12px + env(safe-area-inset-bottom));
    flex-direction: column;
  }
}

.cart-toast {
  pointer-events: auto;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: 12px;
  padding: 12px 6px 12px 14px;
  padding-inline: 14px 6px;
  border: 1px solid var(--cart-toast-line);
  border-radius: 18px;
  background: var(--cart-toast-bg);
  color: var(--text);
  box-shadow: var(--cart-toast-shadow);
  font-family: var(--font-body);
  line-height: 1.45;
}
.cart-toast-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--saffron);
  color: var(--maroon-deep);
}
.cart-toast-icon .icon { width: 1.3em; height: 1.3em; stroke-width: 2.4; }
.cart-toast-body { min-width: 0; padding-top: 1px; }
.cart-toast-title { font-weight: 700; }
.cart-toast-text { font-size: var(--fs-sm); color: var(--muted); overflow-wrap: anywhere; }
.cart-toast-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.cart-toast-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px;
  border: 2px solid var(--accent);
  border-radius: 999px;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}
.cart-toast-action:hover { background: var(--accent); color: var(--on-accent); }
.cart-toast-action .icon { width: 1.15em; height: 1.15em; }
.cart-toast-close {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-block: -6px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.cart-toast-close:hover { background: var(--surface-2); color: var(--text); }
.cart-toast-close .icon { width: 1.1em; height: 1.1em; }

/* "Added": compact, title and item on one block */
.cart-toast.kind-added .cart-toast-title { color: var(--accent); }

/* "Coming soon": the brand maroon card */
.cart-toast.kind-soon {
  border-color: transparent;
  background: var(--cart-soon-bg);
  color: var(--cart-soon-ink);
  box-shadow: var(--cart-toast-shadow), 0 0 0 2px var(--saffron);
}
.cart-toast.kind-soon .cart-toast-icon { width: 46px; height: 46px; }
.cart-toast.kind-soon .cart-toast-icon .icon { width: 1.5em; height: 1.5em; stroke-width: 2; }
.cart-toast.kind-soon .cart-toast-title { font-family: var(--font-display); font-weight: 400; font-size: 1.35rem; line-height: 1.2; color: var(--saffron); }
.cart-toast.kind-soon .cart-toast-text { color: rgba(255, 244, 226, 0.88); }
.cart-toast.kind-soon .cart-toast-action { border-color: var(--saffron); background: var(--saffron); color: var(--maroon-deep); min-height: 44px; }
.cart-toast.kind-soon .cart-toast-action:hover { background: #FFC63D; border-color: #FFC63D; }
.cart-toast.kind-soon .cart-toast-close { color: rgba(255, 244, 226, 0.8); }
.cart-toast.kind-soon .cart-toast-close:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.cart-toast.kind-soon :focus-visible { outline-color: var(--saffron); }

@media (prefers-reduced-motion: no-preference) {
  .cart-toast { animation: toast-in 0.32s var(--ease-out, ease-out); }
  .cart-toast.is-leaving { animation: toast-out 0.22s ease-in forwards; }
}
.cart-toast.is-leaving { pointer-events: none; }
@keyframes toast-in { from { opacity: 0; transform: translateY(14px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px) scale(0.98); } }
@media (max-width: 719px) {
  @keyframes toast-in { from { opacity: 0; transform: translateY(-14px) scale(0.97); } to { opacity: 1; transform: none; } }
}
