/* =====================================================
   JOTTA Bake House — Cashier Display Menu
   Layout v4: split into ad panel (LEFT) + 3×4 product
   grid (RIGHT). Ad panel supports a real image at
   assets/images/ad.png and falls back to vertical
   Arabic text "مساحة إعلانية" when the image is absent.
   ===================================================== */

/* ---------- Local font: Kufam (with fallback chain) ---------- */
@font-face {
  font-family: 'Kufam';
  src: local('Kufam'),
       url('assets/fonts/Kufam-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Kufam';
  src: local('Kufam Bold'), local('Kufam-Bold'),
       url('assets/fonts/Kufam-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Kufam';
  src: local('Kufam Black'), local('Kufam-Black'),
       url('assets/fonts/Kufam-Black.woff2') format('woff2');
  font-weight: 900;
  font-style: normal;
  font-display: swap;
}

/* ---------- Brand tokens ---------- */
:root {
  --creme:        #E7D6BE;
  --creme-soft:   #EFE2CD;
  --auburn:       #6E1F26;
  --auburn-deep:  #4F1219;
  --almond:       #D9B79A;
  --popstar:      #F2B391;
  --ink:          #2C0E12;
  --shadow:       rgba(78, 18, 25, 0.18);

  /* Bestseller badge tokens (per spec) */
  --badge-bg:     #762836;
  --badge-fg:     #EDD9B6;

  --font-stack: 'Kufam', 'DIN Next Arabic', 'GE SS', 'Cairo', 'Tajawal',
                'Segoe UI', 'Tahoma', 'Arial', sans-serif;
}

/* ---------- Reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  /* Lock the menu to a single viewport — no scrolling. */
  overflow: hidden;
  background: var(--creme);
  color: var(--auburn);
  font-family: var(--font-stack);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* optimizeLegibility forces expensive kerning/ligature pass on every text node.
     For Arabic display text at menu sizes, optimizeSpeed removes that overhead
     with no visible quality difference. */
  text-rendering: optimizeSpeed;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

button {
  touch-action: manipulation;
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

img { display: block; max-width: 100%; }

/* ---------- Header ---------- */
.header {
  direction: ltr;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: clamp(16px, 2vw, 32px);
  padding: clamp(8px, 1.4vh, 16px) clamp(20px, 3.5vw, 56px) clamp(4px, 0.8vh, 10px);
}

.logo {
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.logo-img {
  height: clamp(40px, 5.5vh, 72px);
  width: auto;
  object-fit: contain;
}

.logo-text {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--auburn);
  letter-spacing: 0.04em;
}
.logo-text .logo-mark {
  font-weight: 900;
  font-size: clamp(28px, 3.8vh, 46px);
  line-height: 1;
  letter-spacing: 0.06em;
}
.logo-text .logo-sub {
  display: flex;
  flex-direction: column;
  font-weight: 600;
  font-size: clamp(10px, 1.4vh, 14px);
  line-height: 1.1;
  margin-top: 4px;
}
.logo-text .logo-reg {
  font-size: 0.55em;
  vertical-align: super;
  margin-inline-start: 2px;
  opacity: 0.85;
}

.header-line {
  flex: 1 1 auto;
  height: 1.5px;
  background: var(--auburn);
  border-radius: 2px;
  opacity: 0.95;
}

/* =====================================================
   Layout: ad panel (LEFT) + product grid (RIGHT)
   ===================================================== */
.layout {
  flex: 1 1 auto;            /* fills remaining vertical space below header */
  display: grid;
  grid-template-columns: clamp(140px, 22%, 280px) 1fr;
  gap: clamp(8px, 1vw, 18px);
  padding: clamp(6px, 1vh, 14px) clamp(10px, 1.4vw, 22px) clamp(10px, 1.4vh, 20px);
  /* Force LTR flow inside the layout so the ad sits on the visual LEFT
     and the grid on the visual RIGHT. RTL is restored on each child. */
  direction: ltr;
  min-height: 0;
}

/* ---------- Product grid (right) ----------
   Wireframe-exact: 4 columns × 3 rows = 12 cells.
   With 12 products (after removing انجلش كيك and تشوكلت بار)
   the grid fills perfectly with no empty cells and no scroll. */
.grid {
  direction: rtl;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: 1fr;
  gap: clamp(6px, 1vh, 12px) clamp(4px, 0.5vw, 10px);
  padding: 0;
  min-height: 0;
  min-width: 0;
}

/* ---------- Product card ----------
   Vertical layout: rectangular image on top, name + prices below.
   Internal structure unchanged so script.js renders cards as-is. */
.card {
  display: grid;
  grid-template-rows: 1fr auto auto;
  align-items: center;
  justify-items: center;
  gap: clamp(2px, 0.4vh, 6px);
  padding: clamp(4px, 0.7vh, 10px) clamp(2px, 0.3vw, 6px);
  border-radius: 14px;
  background: transparent;
  text-align: center;
  cursor: pointer;
  transition: transform 180ms ease, background-color 180ms ease, box-shadow 180ms ease;
  min-height: 0;
  min-width: 0;
  /* Layout containment: changes inside a card never force the browser
     to re-measure sibling cards (eliminates cross-card layout thrashing). */
  contain: layout style;
}
.card:hover { background-color: rgba(110, 31, 38, 0.04); }
.card:active {
  transform: scale(0.97);
  background-color: rgba(110, 31, 38, 0.07);
}
.card:focus { outline: none; }
.card:focus-visible {
  outline: 2px solid var(--auburn);
  outline-offset: 4px;
  border-radius: 14px;
}

/* Product image — fills the card width and the available vertical space.
   object-fit: cover preserves the image's aspect ratio (never stretched
   or compressed) and gently crops the edges to fill the card's
   rectangle uniformly across the grid. */
.card-image {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 12px;
}
.card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: brightness(0.9725);
  transition: transform 280ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.card:hover .card-image img { transform: scale(1.04); }

.card-image img[src^="assets/images/تارت-بيكان.webp"] { scale: 1.13; }

/* Align these taller subjects within the landscape card crop. */
.card-image img[src^="assets/images/english-cake.webp"] {
  object-position: center 24%;
}
.card-image img[src^="assets/images/قهوة-اليوم-١٥-لتر.webp"] {
  object-position: center 30%;
}

/* =====================================================
   "Best seller" badge — overlaid on the top-left of the
   product image. Pure decoration, no interaction.
   Shown on new products and bestsellers.
   Uses `left` (not `inset-inline-start`) so it stays on
   the visual LEFT even on the RTL page.
   ===================================================== */
.bestseller-badge {
  position: absolute;
  top: clamp(6px, 0.9vh, 10px);
  left: clamp(6px, 0.6vw, 10px);
  z-index: 3;

  background: var(--badge-bg);   /* #762836 */
  color: var(--badge-fg);        /* #EDD9B6 */

  font-family: var(--font-stack); /* Kufam + fallback chain */
  font-weight: 800;
  font-size: clamp(9px, 1.15vh, 12px);
  letter-spacing: 0.02em;
  line-height: 1;

  padding: clamp(4px, 0.7vh, 6px) clamp(8px, 0.9vw, 12px);
  border-radius: 999px;          /* fully-rounded pill */
  white-space: nowrap;

  box-shadow: 0 2px 6px rgba(44, 14, 18, 0.22);
  pointer-events: none;          /* never blocks clicks on the card */

  /* Subtle pop-in on render (auto-disabled by prefers-reduced-motion) */
  animation: badgePop 360ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@keyframes badgePop {
  from { transform: scale(0.85); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

/* Keep the touch hint and the animation outside the photograph. */
.card[data-id="14"] {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto auto;
}

.card-heading {
  display: contents;
}

.tap-hint {
  grid-area: 1 / 1;
  border-radius: 999px;
  padding: 3px 6px;
  background: var(--auburn-deep);
  color: var(--creme-soft);
  font-size: clamp(9px, 1.1vh, 12px);
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
  .card[data-id="14"] .card-image {
    outline: 2px solid transparent;
    outline-offset: 1px;
    animation: touchOutline 6s ease-out 1s infinite;
  }

  @keyframes touchOutline {
    0%, 10%, 20%, 100% { outline-color: transparent; }
    2%, 12% { outline-color: var(--auburn); }
  }
}

/* Branded auburn placeholder when an image fails to load */
.card-image .placeholder {
  width: 100%;
  height: 100%;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--auburn) 0%, var(--auburn-deep) 100%);
  color: var(--creme);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: clamp(14px, 2vh, 24px);
  font-weight: 800;
  font-size: clamp(14px, 1.8vh, 18px);
  line-height: 1.35;
  box-shadow: 0 6px 18px rgba(78, 18, 25, 0.22),
              inset 0 1px 0 rgba(255, 230, 210, 0.08);
  position: relative;
  overflow: hidden;
}
.card-image .placeholder::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(120% 60% at 100% 0%, rgba(242, 179, 145, 0.10) 0%, transparent 55%),
    radial-gradient(120% 60% at 0% 100%, rgba(242, 179, 145, 0.06) 0%, transparent 55%);
  pointer-events: none;
}
.card-image .placeholder::before {
  content: 'JOTTA';
  position: absolute;
  top: 10px;
  right: 14px;
  font-size: clamp(9px, 1.1vh, 11px);
  letter-spacing: 0.16em;
  opacity: 0.7;
  font-weight: 900;
  z-index: 1;
}

/* Product name */
.card-name {
  font-weight: 800;
  font-size: clamp(12px, 1.6vh, 17px);
  color: var(--auburn);
  line-height: 1.15;
  margin: 0;
  padding: 0 4px;
}

/* Prices block (under the product name) */
.card-prices {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: clamp(8px, 1.2vw, 18px);
  width: 100%;
  padding: 0 4px;
}

.price-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  line-height: 1;
}

.price-num {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-weight: 900;
  font-size: clamp(15px, 2.2vh, 23px);
  color: var(--auburn);
  line-height: 1;
  white-space: nowrap;
}
.price-num .num { line-height: 1; }

.riyal-icon {
  display: inline-block;
  height: 0.9em;
  width: auto;
  flex-shrink: 0;
  object-fit: contain;
  vertical-align: middle;
}

.price-label {
  font-size: clamp(10px, 1.3vh, 13px);
  font-weight: 700;
  color: var(--auburn);
  margin-top: 1px;
  line-height: 1;
  white-space: nowrap;
  unicode-bidi: plaintext;
}

.price-note {
  font-size: clamp(8px, 1vh, 11px);
  font-weight: 500;
  color: var(--auburn);
  opacity: 0.78;
  margin-top: 0;
  line-height: 1;
  white-space: nowrap;
}

.card-prices.single .price-num {
  font-size: clamp(18px, 2.7vh, 28px);
}

/* =====================================================
   Product details
   ===================================================== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  visibility: hidden;
}
.modal.is-open {
  visibility: visible;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(44, 14, 18, 0.40);
}

.modal-panel {
  position: relative;
  width: min(92vw, 1100px);
  max-height: 88vh;
  background: var(--creme-soft);
  color: var(--auburn);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(44, 14, 18, 0.35),
              0 4px 12px rgba(44, 14, 18, 0.18);
  overflow: hidden;
}

.modal-close {
  position: absolute;
  top: 14px;
  inset-inline-end: 18px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 30px;
  line-height: 1;
  font-weight: 700;
  color: var(--auburn);
  background: rgba(110, 31, 38, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 160ms ease, transform 160ms ease;
  z-index: 2;
}
.modal-close:hover { background: rgba(110, 31, 38, 0.16); }
.modal-close:active { transform: scale(0.92); }

.modal-body {
  display: grid;
  grid-template-columns: 0.9fr 1.1fr;
  gap: clamp(20px, 3vw, 44px);
  padding: clamp(28px, 4vh, 48px) clamp(28px, 4vw, 56px);
  align-items: center;
}

.modal-media {
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-image-wrap {
  width: 100%;
  aspect-ratio: 1 / 1;
  max-height: 56vh;
  border-radius: 14px;
  background: var(--creme);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 16px;
  position: relative;
}
.modal-image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: brightness(0.9725) drop-shadow(0 10px 22px rgba(78, 18, 25, 0.18));
}

.modal-image-wrap .placeholder {
  width: 90%;
  height: 90%;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--auburn) 0%, var(--auburn-deep) 100%);
  color: var(--creme);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  font-weight: 800;
  font-size: clamp(14px, 1.8vh, 18px);
  line-height: 1.3;
  position: relative;
}
.modal-image-wrap .placeholder::before {
  content: 'JOTTA';
  position: absolute;
  top: 14px;
  right: 18px;
  font-size: 12px;
  letter-spacing: 0.14em;
  opacity: 0.7;
  font-weight: 900;
}

.modal-info {
  display: flex;
  flex-direction: column;
  gap: clamp(12px, 1.8vh, 22px);
  min-width: 0;
}

.modal-title {
  font-weight: 900;
  font-size: clamp(24px, 3.6vh, 40px);
  color: var(--auburn-deep);
  margin: 0;
  line-height: 1.2;
}

.modal-desc {
  font-size: clamp(15px, 2vh, 19px);
  font-weight: 500;
  color: var(--auburn);
  line-height: 1.55;
  margin: 0;
  opacity: 0.92;
}

/* ---------- Option cards (size picker) ---------- */
.modal-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: clamp(10px, 1.4vw, 18px);
  margin-top: clamp(4px, 1vh, 10px);
}

.option-card {
  background: var(--creme);
  border: 2px solid rgba(110, 31, 38, 0.12);
  border-radius: 14px;
  padding: clamp(14px, 2vh, 22px) clamp(10px, 1.2vw, 16px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  cursor: pointer;
  transition: transform 160ms ease,
              border-color 200ms ease,
              background 200ms ease,
              box-shadow 200ms ease;
  position: relative;
}
.option-card:hover {
  background: #F3E5CD;
  border-color: rgba(110, 31, 38, 0.28);
}
.option-card:active { transform: scale(0.97); }

.option-card.is-active {
  background: #F0DFC4;
  border-color: var(--auburn);
  box-shadow: 0 6px 18px rgba(110, 31, 38, 0.18);
}
.option-card.is-active .opt-label,
.option-card.is-active .opt-price {
  color: var(--auburn-deep);
}

.option-card .opt-label {
  font-size: clamp(14px, 1.8vh, 18px);
  font-weight: 700;
  color: var(--auburn);
  line-height: 1.1;
  unicode-bidi: plaintext;
}
.option-card .opt-price {
  font-size: clamp(26px, 3.6vh, 38px);
  font-weight: 900;
  color: var(--auburn-deep);
  line-height: 1;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.option-card .opt-price .num { line-height: 1; }
.option-card .opt-note {
  font-size: clamp(12px, 1.4vh, 14px);
  font-weight: 500;
  color: var(--auburn);
  opacity: 0.75;
  line-height: 1.2;
}

.modal-options.single { grid-template-columns: minmax(200px, 360px); justify-content: center; }

/* =====================================================
   Responsive tweaks
   ===================================================== */

html, body {
  height: auto;
  overflow: visible;
}

html:has(.modal.is-open) { overflow: hidden; }

.header, .layout {
  width: min(100%, 980px);
  margin-inline: auto;
}

.layout {
  display: block;
  height: auto;
  padding: 6px 8px max(14px, env(safe-area-inset-bottom));
}

.grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: auto;
  gap: 12px 6px;
}

.card {
  grid-template-rows: auto auto auto;
  align-content: start;
  padding: 6px 4px 10px;
}

.card[data-id="14"] { grid-template-rows: repeat(4, auto); }

.card-image {
  height: auto;
  aspect-ratio: 1 / 1;
}

.card-name {
  font-size: clamp(13px, 3.5vw, 17px);
  line-height: 1.25;
}

.card-prices {
  flex-wrap: wrap;
  gap: 8px 10px;
}

.price-label { font-size: 12px; }
.price-note { font-size: 10px; }

.modal-panel {
  overflow-y: auto;
  overscroll-behavior: contain;
  max-height: 92vh;
  max-height: 92dvh;
}

.modal-body {
  grid-template-columns: 1fr;
  padding: 16px;
  gap: 14px;
}

.modal-image-wrap { max-height: min(36vh, 320px); }
.modal-options { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.modal-options.single { grid-template-columns: minmax(0, 270px); }
.option-card { min-height: 48px; }

@media (min-width: 640px) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .layout { padding-inline: 16px; }
}

@media (min-width: 900px) {
  .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

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