:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f1f0eb;
  --text: #1b2620;
  --muted: #5f6b65;
  --border: #e4e2da;
  --primary: #1d7349;
  --primary-hover: #175f3c;
  --primary-soft: #e2f1e7;
  --on-primary: #ffffff;
  --whatsapp: #25d366;
  --whatsapp-hover: #1fbf5b;
  --on-whatsapp: #06341a;
  --danger: #c0392b;
  --hero-from: #1d7349;
  --hero-to: #2e9a63;
  --toast-bg: #1b2620;
  --toast-text: #ffffff;
  --shadow: 0 1px 2px rgba(20, 30, 25, 0.05), 0 6px 18px rgba(20, 30, 25, 0.07);
  --shadow-lg: 0 18px 48px rgba(20, 30, 25, 0.22);
  --radius: 16px;
  --header-h: 68px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --thumb-s: 60%;
  --thumb-l-bg: 88%;
  --thumb-l-fg: 32%;
  --photo-bg: #f8f3eb; /* matches the cream studio background of the product photos */
  /* The store always uses this light look, even on phones and computers set to dark mode */
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  /* Keeps the scrollbar's space reserved, so the page doesn't get wider (and re-arrange
     every product card) when a window opens and scrolling is paused */
  scrollbar-gutter: stable;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: "Tajawal", system-ui, "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}

body:has(dialog[open]) {
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  touch-action: manipulation;
}

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--primary) 50%, transparent);
  outline-offset: 2px;
}

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

.container {
  width: 100%;
  max-width: 1200px;
  margin-inline: auto;
  padding-inline: 16px;
}

.icon svg {
  display: block;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Buttons ---------- */

a.btn {
  text-decoration: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 12px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

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

.btn-primary {
  background: var(--primary);
  color: var(--on-primary);
}

.btn-outline {
  background: transparent;
  color: var(--primary);
  box-shadow: inset 0 0 0 1.5px var(--primary);
}

.btn-whatsapp {
  background: var(--whatsapp);
  color: var(--on-whatsapp);
}

.btn-block {
  width: 100%;
  height: 50px;
  font-size: 1.05rem;
}

.btn-link {
  padding: 6px 4px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 0.9rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.btn-link-danger {
  color: var(--danger);
  font-weight: 700;
}

.icon-btn {
  display: inline-grid;
  flex-shrink: 0;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.icon-btn-sm {
  width: 36px;
  height: 36px;
  background: transparent;
  color: var(--muted);
}

.icon-btn-sm .icon svg {
  width: 18px;
  height: 18px;
}

@media (hover: hover) {
  .btn-primary:hover {
    background: var(--primary-hover);
  }

  .btn-outline:hover {
    background: var(--primary-soft);
  }

  .btn-whatsapp:hover {
    background: var(--whatsapp-hover);
  }

  .btn-link:hover {
    color: var(--text);
  }

  .icon-btn:hover {
    background: var(--primary-soft);
    color: var(--primary);
  }

  .icon-btn-sm:hover {
    color: var(--danger);
    background: color-mix(in srgb, var(--danger) 10%, transparent);
  }
}

/* ---------- Announcement bar ---------- */

.announcement {
  padding: 9px 16px;
  background: var(--primary-hover);
  color: #fff;
  text-align: center;
}

.announcement p {
  max-width: 1200px;
  margin: 0 auto;
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.5;
}

/* ---------- Header ---------- */

.site-header {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 10;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  transition: box-shadow 0.2s ease;
}

.site-header.is-scrolled {
  box-shadow: 0 4px 18px rgba(20, 30, 25, 0.08);
}

.header-inner {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  min-height: var(--header-h);
  padding-block: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
  font-size: 1.35rem;
  font-weight: 800;
}

.brand > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-mark {
  display: grid;
  flex-shrink: 0;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--primary);
  color: var(--on-primary);
}

.search {
  position: relative;
  justify-self: center;
  width: 100%;
  max-width: 520px;
}

.search > .icon {
  position: absolute;
  top: 50%;
  inset-inline-start: 14px;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.search input {
  width: 100%;
  height: 44px;
  padding-inline: 44px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 16px; /* 16px stops phones from zooming in when typing */
}

.search input:focus {
  border-color: var(--primary);
  background: var(--surface);
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent);
}

.cart-button {
  position: relative;
}

.cart-badge {
  position: absolute;
  top: -4px;
  inset-inline-end: -4px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--primary);
  color: var(--on-primary);
  font-size: 0.75rem;
  font-weight: 800;
  line-height: 22px;
  text-align: center;
  box-shadow: 0 0 0 2px var(--surface);
}

.bump {
  animation: bump 0.35s ease;
}

@keyframes bump {
  50% {
    transform: scale(1.25);
  }
}

/* ---------- Hero ---------- */

.hero {
  margin-top: 20px;
  padding: 32px 28px;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--hero-from), var(--hero-to));
  color: #fff;
}

.hero h1,
.hero h2 {
  margin: 0 0 6px;
  font-size: clamp(1.4rem, 4vw, 2.2rem);
  font-weight: 800;
  line-height: 1.3;
}

.hero p {
  margin: 0;
  opacity: 0.92;
}

.steps {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
}

.steps li {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  font-size: 0.9rem;
  font-weight: 500;
}

.steps span {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  color: #1d7349;
  font-size: 0.8rem;
  font-weight: 800;
}

/* ---------- Categories and toolbar ---------- */

.categories {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 24px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  height: 40px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

@media (hover: hover) {
  .chip:hover {
    border-color: var(--primary);
  }
}

.chip[aria-pressed="true"] {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--on-primary);
}

.chip-count {
  min-width: 24px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  text-align: center;
}

.chip[aria-pressed="true"] .chip-count {
  background: rgba(255, 255, 255, 0.22);
  color: inherit;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  margin: 16px 0;
}

.results-info {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.sort {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.sort select {
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
}

/* ---------- Product grid ---------- */

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
}

.product {
  position: relative; /* keeps everything inside the card, even in the sideways-scrolling best-sellers row */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.product.in-cart {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

@media (hover: hover) {
  .product:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow);
  }

  .product.in-cart:hover {
    box-shadow: 0 0 0 1px var(--primary), var(--shadow);
  }

  .product:hover .product-thumb img {
    transform: scale(1.04);
  }

  .product-name-btn:hover {
    color: var(--primary);
  }
}

.product-media {
  position: relative;
  aspect-ratio: 1 / 1;
  cursor: pointer;
}

/* Labels on the product photo, stacked in one corner so they never overlap */
.media-badges {
  position: absolute;
  top: 10px;
  inset-inline-end: 10px;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  pointer-events: none;
}

.in-cart-tag {
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--primary);
  color: var(--on-primary);
  font-size: 0.75rem;
  font-weight: 700;
}

.product-thumb {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: hsl(var(--hue) var(--thumb-s) var(--thumb-l-bg));
  color: hsl(var(--hue) var(--thumb-s) var(--thumb-l-fg));
  font-size: 3rem;
  font-weight: 800;
}

.product-thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain; /* show the whole photo without cropping */
  background: var(--photo-bg);
  transition: opacity 0.4s ease, transform 0.3s ease;
  /* Makes saving photos harder: no long-press "Save image" menu on phones, no selecting or dragging */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
}

.product-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 6px;
  padding: 14px;
  border-top: 1px solid var(--border);
}

.product-category {
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 700;
}

.product-name {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.45;
}

.product-name-btn {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font-weight: inherit;
  line-height: inherit;
  text-align: start;
  text-decoration: none;
  cursor: pointer;
}

.product-desc {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.65;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* Price: what the customer pays, then the old price crossed out */
.price {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 8px;
  font-variant-numeric: tabular-nums;
}

.price-now {
  font-weight: 800;
}

.price-old {
  color: var(--muted);
  font-size: 0.82em;
  font-weight: 500;
  text-decoration-thickness: 1.5px;
}

.product-price {
  margin: auto 0 4px;
  padding-top: 6px;
  font-size: 1.15rem;
}

.discount-tag {
  padding: 2px 8px;
  border-radius: 8px;
  background: var(--danger);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.cart-control .btn {
  width: 100%;
}

.stepper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 44px;
  border-radius: 12px;
  background: var(--primary-soft);
}

.stepper-btn {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--primary);
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

@media (hover: hover) {
  .stepper-btn:hover {
    background: color-mix(in srgb, var(--primary) 14%, transparent);
  }
}

.stepper-qty {
  min-width: 2ch;
  font-weight: 800;
  text-align: center;
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 48px 16px;
  color: var(--muted);
  text-align: center;
}

.empty p {
  margin: 0 0 8px;
}

.empty-icon,
.state-icon {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--muted);
}

.empty-icon .icon svg,
.state-icon .icon svg {
  width: 32px;
  height: 32px;
}

/* ---------- Best sellers and out of stock ---------- */

.featured {
  margin-top: 24px;
}

.section-title {
  margin: 0 0 12px;
  font-size: 1.25rem;
  font-weight: 800;
}

/* One row that scrolls sideways */
.featured-row {
  display: grid;
  grid-auto-columns: minmax(200px, 230px);
  grid-auto-flow: column;
  gap: 16px;
  padding: 4px 2px 10px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-padding-inline: 2px; /* cards snap into place with the same gap as the padding */
  scrollbar-width: thin;
}

.featured-row .product {
  scroll-snap-align: start;
}

.soldout-tag {
  padding: 2px 8px;
  border-radius: 8px;
  background: var(--text);
  color: var(--surface);
  font-size: 0.75rem;
  font-weight: 700;
}

.product.is-soldout .product-thumb img {
  filter: grayscale(0.7);
}

.btn-soldout,
.btn-soldout:disabled {
  background: var(--surface-2);
  color: var(--muted);
  cursor: not-allowed;
}

.dialog-soldout {
  margin: 0;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 700;
}

#order-now:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

@media (max-width: 640px) {
  .featured {
    margin-top: 16px;
  }

  .featured-row {
    grid-auto-columns: 160px;
    gap: 10px;
    margin-inline: -16px;
    padding-inline: 16px;
    scroll-padding-inline: 16px; /* keeps the 16px gap at the screen edge when cards snap */
    scrollbar-width: none;
  }

  .featured-row::-webkit-scrollbar {
    display: none;
  }
}

/* ---------- Loading placeholders and motion ---------- */

/* Soft moving light used on placeholders while things load */
.shimmer {
  background: linear-gradient(100deg, var(--surface-2) 30%, #faf8f3 50%, var(--surface-2) 70%) var(--surface-2);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

@keyframes shimmer {
  from {
    background-position: 150% 0;
  }
  to {
    background-position: -50% 0;
  }
}

.chip-placeholder {
  flex-shrink: 0;
  width: 110px;
  height: 40px;
  border-radius: 999px;
}

.chip-placeholder:first-child {
  width: 70px;
}

.card-placeholder {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.ph-photo {
  aspect-ratio: 1 / 1;
}

.ph-line {
  height: 12px;
  margin: 16px 14px 0;
  border-radius: 6px;
}

.ph-short {
  width: 55%;
  margin-top: 10px;
}

.ph-button {
  height: 42px;
  margin: 20px 14px 14px;
  border-radius: 12px;
}

/* A photo shows a soft shimmer until it has loaded, then fades in */
.product-thumb.has-photo {
  background: var(--photo-bg);
}

.product-thumb.has-photo > span {
  visibility: hidden; /* the colored letter only shows when there is no photo */
}

.product-thumb.is-loading {
  background: linear-gradient(100deg, var(--photo-bg) 30%, #fffcf7 50%, var(--photo-bg) 70%) var(--photo-bg);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

.product-thumb img {
  opacity: 0;
}

.product-thumb img.is-loaded {
  opacity: 1;
}

/* Cards rise gently into place when the products appear or the category changes */
.product.enter {
  animation: card-in 0.45s cubic-bezier(0.2, 0.8, 0.2, 1) backwards;
  animation-delay: calc(var(--i, 0) * 45ms);
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
}

/* Small press feedback on buttons people tap a lot */
.chip:active,
.stepper-btn:active,
.icon-btn:active {
  transform: scale(0.94);
}

.chip,
.stepper-btn,
.icon-btn {
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

/* ---------- A product's own page (sallatalafia.com/products/...) ---------- */

.product-page {
  margin-top: 20px;
}

.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.breadcrumb a {
  color: var(--primary);
  font-weight: 700;
  text-decoration: none;
}

.product-page-inner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 28px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
}

.product-page-media {
  align-self: start;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: 16px;
  background: var(--photo-bg);
}

.product-page-media img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  /* Same protection as the other product photos */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
}

.product-page-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.product-page-name {
  margin: 0;
  font-size: clamp(1.3rem, 3vw, 1.8rem);
  line-height: 1.4;
}

.product-page-body .dialog-price .price {
  color: var(--primary);
  font-size: 1.6rem;
}

.product-page-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-block: 4px 8px;
}

.product-page-actions:empty {
  display: none; /* before app.js adds the buttons, or when the product is no longer sold */
}

.product-page-actions .btn,
.product-page-actions .stepper {
  height: 50px;
}

@media (max-width: 640px) {
  .product-page-inner {
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
    padding: 14px;
  }
}

/* ---------- Footer ---------- */

/* Every product page, listed under a fold (made by make-website-folder.ps1) */
.footer-products {
  max-width: 900px;
  margin: 16px auto;
  text-align: start;
}

.footer-products summary {
  color: var(--primary);
  font-weight: 700;
  text-align: center;
  cursor: pointer;
}

.footer-products h3 {
  margin: 16px 0 6px;
  color: var(--text);
  font-size: 0.95rem;
}

.footer-products ul {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 4px 16px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.88rem;
}

.footer-products a {
  color: var(--muted);
  text-decoration: none;
}

.site-footer {
  margin-top: 56px;
  padding: 32px 0;
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  text-align: center;
}

.site-footer p {
  margin: 4px 0;
}

.footer-name {
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 800;
}

.footer-copy {
  font-size: 0.85rem;
}

/* ---------- Bottom cart bar (phones) ---------- */

.cart-bar {
  display: none;
}

/* ---------- Dialogs (product details and cart) ---------- */

dialog {
  padding: 0;
  border: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

/* Windows fade or slide in and out. Browsers without these newer features
   simply open and close them instantly. */
/* The page behind a window is blurred and dimmed. Only the dimming fades in and out;
   the blur stays fixed, because fading a blur over the whole page makes opening slow. */
dialog::backdrop {
  background: rgba(10, 15, 12, 0);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  transition: background-color 0.25s ease, overlay 0.25s allow-discrete, display 0.25s allow-discrete;
}

dialog[open]::backdrop {
  background: rgba(10, 15, 12, 0.5);
}

@starting-style {
  dialog[open]::backdrop {
    background: rgba(10, 15, 12, 0);
  }
}

/* Dialogs take focus themselves when opened, so no button shows a focus ring until Tab is pressed */
dialog:focus,
dialog:focus-visible {
  outline: none;
}

/* Product details. Only the text side scrolls, so the photo, the close button
   and the order buttons always stay in view, even with a long description. */
.product-dialog {
  width: min(820px, calc(100% - 32px));
  max-width: none;
  max-height: calc(100dvh - 32px);
  border-radius: 20px;
  overflow: hidden;
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  transition: opacity 0.22s ease, transform 0.22s ease, overlay 0.22s allow-discrete, display 0.22s allow-discrete;
  will-change: transform, opacity;
}

.product-dialog[open] {
  opacity: 1;
  transform: none;
}

@starting-style {
  .product-dialog[open] {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
}

/* Still used by the control panel's windows (admin.css) */
@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
}

.product-dialog .dialog-inner {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); /* two equal halves, whatever the text length */
}

.dialog-close {
  position: absolute;
  top: 12px;
  inset-inline-end: 12px;
  z-index: 2;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.dialog-share {
  position: absolute;
  top: 12px;
  inset-inline-end: 64px; /* next to the close button */
  z-index: 2;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.dialog-media {
  align-self: start; /* a square photo that a long description can't stretch */
  aspect-ratio: 1 / 1;
}

.dialog-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  max-height: calc(100dvh - 32px);
  padding: 28px 28px 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.dialog-name {
  margin: 0;
  font-size: 1.4rem;
  line-height: 1.4;
}

.dialog-price {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dialog-price .price {
  color: var(--primary);
  font-size: 1.5rem;
}

.dialog-price .price-old {
  font-size: 0.65em;
}

.price-saving {
  margin: 0;
  color: var(--danger);
  font-size: 0.9rem;
  font-weight: 700;
}

.dialog-desc {
  margin: 0;
  color: var(--muted);
  line-height: 1.8;
  white-space: pre-line; /* keeps the line breaks exactly as typed in the control panel */
  overflow-wrap: anywhere;
}

.dialog-actions {
  position: sticky;
  bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: auto -28px 0;
  padding: 14px 28px 24px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* Cart drawer: slides in from the left side of the screen */
.cart-drawer {
  width: min(440px, 100%);
  max-width: 100%;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
  margin-inline-start: auto;
}

.cart-drawer {
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), overlay 0.3s allow-discrete, display 0.3s allow-discrete;
  will-change: transform; /* lets the browser prepare the slide in advance */
}

.cart-drawer[open] {
  transform: none;
}

@starting-style {
  .cart-drawer[open] {
    transform: translateX(-100%);
  }
}

.cart-drawer .dialog-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px 12px 20px;
  border-bottom: 1px solid var(--border);
}

.drawer-header h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 1.2rem;
}

.title-count {
  padding: 0 10px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.85rem;
  font-weight: 800;
}

.title-count:empty {
  display: none;
}

.drawer-content {
  flex: 1;
  padding: 16px 20px 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.cart-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 48px 8px;
  text-align: center;
}

.cart-state h3 {
  margin: 8px 0 0;
  font-size: 1.2rem;
}

.cart-state p {
  margin: 0 0 12px;
  color: var(--muted);
}

.state-icon-success {
  background: var(--primary-soft);
  color: var(--primary);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-head h3 {
  margin: 0;
  font-size: 1rem;
}

.cart-items {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.cart-item {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  gap: 4px 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
}

.cart-item-thumb {
  width: 64px;
  height: 64px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.cart-item-thumb .product-thumb {
  font-size: 1.4rem;
}

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

.cart-item-info p {
  margin: 0;
}

.cart-item-name {
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.4;
}

.cart-item-price {
  color: var(--muted);
  font-size: 0.8rem;
}

.cart-item-price .price {
  display: inline-flex;
  gap: 0 6px;
}

.cart-item-price .price-now {
  font-weight: 700;
}

.confirm-clear {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.9rem;
}

.cart-item-actions {
  display: flex;
  grid-column: 1 / -1;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
}

.cart-item-actions .cart-control {
  width: 132px;
}

.cart-item-actions .stepper,
.cart-item-actions .stepper-btn {
  height: 40px;
}

.cart-item-total {
  font-weight: 800;
}

.checkout {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field label {
  font-size: 0.9rem;
  font-weight: 700;
}

.optional {
  color: var(--muted);
  font-weight: 400;
}

.field input,
.field textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  font-size: 16px; /* 16px stops phones from zooming in when typing */
  resize: vertical;
}

.field input[dir="ltr"] {
  text-align: right;
}

.field input::placeholder,
.field textarea::placeholder {
  color: color-mix(in srgb, var(--muted) 70%, transparent);
}

.field input:focus,
.field textarea:focus {
  border-color: var(--primary);
  background: var(--surface);
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent);
}

.field input[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 18%, transparent);
}

.field-error {
  margin: 0;
  color: var(--danger);
  font-size: 0.85rem;
  font-weight: 500;
}

.drawer-footer {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 20px calc(14px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 0 -8px 24px rgba(20, 30, 25, 0.06);
}

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

.cart-total strong {
  font-size: 1.35rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.cart-savings {
  margin: -6px 0 0;
  color: var(--danger);
  font-size: 0.85rem;
  font-weight: 700;
  text-align: end;
}

.checkout-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  inset-inline: 0;
  z-index: 100;
  width: fit-content;
  max-width: calc(100% - 32px);
  margin-inline: auto;
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--toast-bg);
  color: var(--toast-text);
  font-weight: 500;
  text-align: center;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: none;
}

/* ===================== Phones ===================== */

@media (max-width: 640px) {
  :root {
    --header-h: 60px;
  }

  .container {
    padding-inline: 16px;
  }

  .header-inner {
    grid-template-columns: 1fr auto;
    gap: 8px 12px;
    padding-block: 8px 10px;
  }

  .brand {
    font-size: 1.2rem;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 10px;
  }

  .search {
    grid-column: 1 / -1;
    grid-row: 2;
    max-width: none;
  }

  .search input {
    height: 42px;
  }

  .hero {
    margin-top: 12px;
    padding: 18px 16px;
    border-radius: 16px;
  }

  /* The 3 steps already explain how to order, so the sentence is hidden to save space */
  .hero p {
    display: none;
  }

  .steps {
    gap: 6px;
    margin-top: 10px;
  }

  .steps li {
    padding: 4px 6px 4px 10px;
    font-size: 0.78rem;
  }

  .steps span {
    width: 20px;
    height: 20px;
    font-size: 0.7rem;
  }

  /* Categories scroll sideways in one row */
  .categories {
    flex-wrap: nowrap;
    margin: 16px -16px 0;
    padding: 0 16px 4px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .categories::-webkit-scrollbar {
    display: none;
  }

  .chip {
    height: 38px;
    padding: 0 14px;
    font-size: 0.9rem;
  }

  .toolbar {
    margin: 12px 0;
  }

  .results-info,
  .sort {
    font-size: 0.85rem;
  }

  .sort select {
    height: 36px;
    padding: 0 8px;
  }

  .product-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .product {
    border-radius: 14px;
  }

  .product-body {
    gap: 4px;
    padding: 10px;
  }

  .product-category {
    font-size: 0.7rem;
  }

  .product-name {
    font-size: 0.9rem;
  }

  .product-desc {
    font-size: 0.78rem;
    line-height: 1.55;
  }

  .product-price {
    font-size: 1rem;
  }

  .cart-control .btn {
    height: 40px;
    padding: 0 8px;
    gap: 6px;
    font-size: 0.88rem;
  }

  .cart-control .btn .icon svg {
    width: 18px;
    height: 18px;
  }

  .product-body .stepper,
  .product-body .stepper-btn {
    height: 40px;
  }

  .product-body .stepper-btn {
    width: 40px;
  }

  /* Bottom cart bar */
  .cart-bar {
    position: fixed;
    inset-inline: 16px;
    bottom: calc(12px + var(--safe-bottom));
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 10px;
    height: 56px;
    padding: 0 16px 0 10px;
    border: 0;
    border-radius: 16px;
    background: var(--primary);
    color: var(--on-primary);
    font-weight: 700;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    animation: bar-in 0.25s ease;
  }

  @keyframes bar-in {
    from {
      opacity: 0;
      transform: translateY(20px);
    }
  }

  .cart-bar-count {
    display: grid;
    place-items: center;
    min-width: 34px;
    height: 34px;
    padding: 0 8px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.2);
    font-weight: 800;
  }

  .cart-bar-label {
    flex: 1;
    text-align: start;
  }

  .cart-bar-total {
    font-size: 1.05rem;
    font-weight: 800;
  }

  body.has-cart-bar .site-footer {
    padding-bottom: calc(96px + var(--safe-bottom));
  }

  body.has-cart-bar .toast {
    bottom: calc(80px + var(--safe-bottom));
  }

  /* Product details become a bottom sheet */
  .product-dialog {
    width: 100%;
    max-height: 92dvh;
    margin: auto 0 0;
    border-radius: 20px 20px 0 0;
  }

  /* On phones the details slide up from the bottom, and back down when closed */
  .product-dialog {
    opacity: 1;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), overlay 0.3s allow-discrete, display 0.3s allow-discrete;
  }

  .product-dialog[open] {
    transform: none;
  }

  @starting-style {
    .product-dialog[open] {
      transform: translateY(100%);
    }
  }

  .product-dialog .dialog-inner {
    grid-template-columns: minmax(0, 1fr);
  }

  .dialog-media {
    height: min(34dvh, 70vw);
    aspect-ratio: auto;
  }

  /* The photo is narrower than the screen here: center it and fade its side edges into the
     cream background, so its own slightly different shade doesn't show as a line. */
  .dialog-media .product-thumb img {
    width: auto;
    max-width: 100%;
    margin-inline: auto;
    -webkit-mask-image: linear-gradient(to right, transparent, #000 10%, #000 90%, transparent);
    mask-image: linear-gradient(to right, transparent, #000 10%, #000 90%, transparent);
  }

  .dialog-body {
    gap: 8px;
    max-height: calc(92dvh - min(34dvh, 70vw));
    padding: 16px 16px 0;
  }

  .dialog-name {
    font-size: 1.2rem;
  }

  .dialog-price {
    font-size: 1.3rem;
  }

  .dialog-actions {
    margin-inline: -16px;
    padding: 12px 16px calc(12px + var(--safe-bottom));
  }

  /* Cart takes the whole screen */
  .cart-drawer {
    width: 100%;
  }

  .drawer-content {
    padding: 14px 16px 20px;
  }

  .drawer-footer {
    padding-inline: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
