/* "Browse categories" panel on category and product pages.
   Brand tokens only (no new colours): cream panel, yellow wave + light-yellow open row, green icons, ink text.
   >= 1101px: sticky sidebar beside the content (theme 2.9.0, unchanged).
   <= 1100px: the same panel opens as a side drawer from the "Browse categories" button (theme 2.11.0).
   The drawer starts on the reading side: right in Arabic, left in English (logical properties). */

.shop-layout { display: block; }
.shop-side { display: none; }
.shop-side-open, .shop-side-backdrop, .shop-side-close { display: none; }

/* ---------- Panel contents (shared by sidebar and drawer) ---------- */
.shop-side-inner {
  display: flex; flex-direction: column;
  padding: 24px 14px 14px;
  border-radius: var(--radius); background: var(--cream);
}

/* Title + the yellow hand-drawn wave */
.shop-side-head { position: relative; padding-inline: 10px; margin-bottom: 18px; }
.shop-side-title { margin: 0; font-family: var(--font-display); font-weight: 700; font-size: 1.45rem; line-height: 1.35; color: var(--deep); }
.shop-side-wave { display: block; width: 112px; height: 10px; margin-top: 6px; color: var(--yellow); }

/* Search */
.shop-side-search { position: relative; display: block; margin: 0 4px 14px; }
.shop-side-search .icon { position: absolute; top: 50%; inset-inline-start: 14px; width: 18px; height: 18px; transform: translateY(-50%); color: var(--ink-soft); pointer-events: none; }
.shop-side-search input {
  width: 100%; min-height: 46px; padding: 8px 16px; padding-inline-start: 42px;
  border: 1.5px solid var(--line); border-radius: 999px; background: var(--paper); font-size: 1rem;
}
.shop-side-search input:focus { border-color: var(--green); outline: none; box-shadow: 0 0 0 4px rgba(57, 117, 71, .15); }

/* Category list scrolls inside the panel */
.shop-side-nav { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--line) transparent; margin-inline: -4px; padding-inline: 4px; }
.side-cats { display: grid; gap: 2px; }
.side-cat { border-radius: 16px; transition: background-color .2s ease; }
.side-cat.is-open { background: rgba(243, 215, 120, .34); }
.side-cat-row { display: flex; align-items: center; }
/* The open category's row stays visible while its items scroll inside the panel */
.side-cat.is-open .side-cat-row { position: sticky; top: 0; z-index: 1; border-radius: 16px 16px 0 0; background: linear-gradient(rgba(243, 215, 120, .34), rgba(243, 215, 120, .34)), var(--cream); }
.side-cat-link {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px;
  min-height: 48px; padding: 8px 10px; border-radius: 14px;
  font-weight: 600; font-size: 1rem; line-height: 1.4; text-decoration: none;
}
.side-cat:not(.is-open) .side-cat-link:hover { background: rgba(80, 56, 42, .05); }
.side-cat-icon { width: 24px; height: 24px; color: var(--green); }
.side-cat-name { flex: 1; min-width: 0; }
.side-cat.is-current .side-cat-name { font-weight: 700; color: var(--deep); }
.side-cat-toggle {
  display: grid; place-items: center; flex: none; width: 40px; height: 40px; margin-inline-end: 4px;
  border: 0; border-radius: 50%; background: none; color: var(--ink); cursor: pointer;
}
.side-cat-toggle:hover { background: rgba(80, 56, 42, .07); }
.side-cat-toggle .icon { width: 18px; height: 18px; transition: transform .2s ease; }
.side-cat-toggle[aria-expanded="true"] .icon { transform: rotate(180deg); }

/* Items: small round product photos, indented under the category icon */
.side-sub { display: grid; gap: 1px; padding: 0 8px 10px; padding-inline-start: 22px; }
.side-sub a {
  display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 4px 10px;
  border-radius: 12px; font-size: .92rem; line-height: 1.45; text-decoration: none; color: var(--ink);
}
.side-sub a:hover { background: rgba(255, 251, 243, .7); }
.side-sub a[aria-current="page"] { background: var(--paper); font-weight: 700; color: var(--deep); }
.side-thumb { flex: none; width: 30px; height: 30px; overflow: hidden; border-radius: 50%; background: var(--paper); box-shadow: 0 0 0 2px var(--paper); }
.side-thumb img { width: 100%; height: 100%; object-fit: cover; transform: scale(1.35); }
.side-empty { margin: 8px 12px; font-size: .92rem; line-height: 1.7; color: var(--ink-soft); }
.side-empty a { color: var(--green); font-weight: 700; }

/* Bottom call to action: one line + a text link, no extra box */
.shop-side-cta { flex: none; margin-top: 14px; padding: 16px 12px 4px; border-top: 1px solid var(--line); }
.shop-side-cta p { margin: 0 0 4px; font-size: .9rem; line-height: 1.6; color: var(--ink-soft); }
.shop-side-cta .text-link { min-height: 40px; font-size: .95rem; color: var(--green); }
.shop-side-cta .text-link .icon { width: 18px; height: 18px; }

/* ---------- Desktop: sticky sidebar ---------- */
@media (min-width: 1101px) {
  .shop-layout {
    display: grid; grid-template-columns: 308px minmax(0, 1fr);
    gap: clamp(36px, 4vw, 64px); align-items: stretch;
  }
  .shop-main { min-width: 0; }

  /* The aside stretches to the full row so the inner panel can stick while the page scrolls */
  .shop-side { display: block; }
  .shop-side-inner {
    position: sticky;
    top: calc(92px + 24px + var(--wp-admin--admin-bar--height, 0px));
    max-height: calc(100vh - 92px - 48px - var(--wp-admin--admin-bar--height, 0px));
  }
  .shop-side-search input { font-size: .95rem; }
  .side-cat-toggle { width: 36px; height: 36px; }

  /* Category page: the sidebar search replaces the grid search on desktop */
  .catalog.has-side .catalog-tools { display: none; }
  .catalog.has-side .product-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }

  /* Product page: facts in two columns beside the sidebar, related items become a rounded panel */
  .shop-main .fact-list { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 40px; }
  .side-related { margin-top: clamp(40px, 4vw, 56px); padding: clamp(28px, 3vw, 44px); border-radius: var(--radius-lg); background: var(--tone-bg); color: var(--tone-ink); }
  .side-related .section-head { margin-bottom: 28px; }
  .side-related h2 { font-size: clamp(1.6rem, 2.4vw, 2.2rem); }
  .side-related .product-grid.is-shelf { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 24px 18px; }
  .side-related .product-name { font-size: 1.05rem; }
  .side-related .product-media { margin-bottom: 12px; }
}

/* ---------- Tablet and mobile ---------- */
@media (max-width: 1100px) {
  /* Related panel goes back to the full-width colour band it was before */
  .side-related {
    margin: var(--section) calc(-1 * var(--gutter)) 0;
    padding: var(--section) var(--gutter); background: var(--tone-bg); color: var(--tone-ink);
  }

  /* The button: a pill at the bottom centre, clear of the WhatsApp bubble in the corner */
  .shop-side-open {
    position: fixed; z-index: 90; inset-inline-start: 50%;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    transform: translateX(50%);
    display: inline-flex; align-items: center; gap: 8px;
    min-height: 48px; padding: 10px 20px 10px 22px;
    border: 2px solid var(--deep); border-radius: 999px;
    background: var(--deep); color: var(--cream); white-space: nowrap;
    font: inherit; font-weight: 700; font-size: 1rem; line-height: 1.2;
    box-shadow: 0 6px 18px rgba(40, 89, 54, .22); cursor: pointer;
  }
  [dir="ltr"] .shop-side-open { transform: translateX(-50%); }
  .shop-side-open .side-cat-icon { width: 22px; height: 22px; color: var(--yellow); }
  .shop-side-open:focus-visible { outline: 3px solid var(--green); outline-offset: 3px; }
  body.nav-open .shop-side-open, html.side-lock .shop-side-open { display: none; }

  /* The drawer */
  .shop-side.has-drawer {
    --side-off: -100%;
    display: block; position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 100001;
    width: min(88vw, 380px); max-width: 100%;
    transform: translateX(var(--side-off)); visibility: hidden;
    transition: transform .28s ease, visibility 0s linear .28s;
  }
  [dir="rtl"] .shop-side.has-drawer { --side-off: 100%; }
  .shop-side.has-drawer.is-open { transform: none; visibility: visible; transition: transform .28s ease; }
  .shop-side.has-drawer .shop-side-inner {
    height: 100%; border-radius: 0;
    padding: calc(20px + env(safe-area-inset-top, 0px)) 12px calc(12px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 0 40px rgba(40, 89, 54, .18);
  }
  .shop-side.has-drawer .shop-side-head { padding-inline-end: 56px; }
  .shop-side-close {
    position: absolute; top: -4px; inset-inline-end: 4px;
    display: grid; place-items: center; width: 44px; height: 44px;
    border: 0; border-radius: 50%; background: var(--paper); color: var(--deep); cursor: pointer;
  }
  .shop-side-close svg { width: 22px; height: 22px; }
  .shop-side-close:focus-visible, .side-cat-toggle:focus-visible, .side-cat-link:focus-visible, .side-sub a:focus-visible {
    outline: 3px solid var(--green); outline-offset: 2px;
  }

  .shop-side-backdrop {
    position: fixed; inset: 0; z-index: 100000;
    background: rgba(40, 89, 54, .35);
  }
  .shop-side-backdrop:not([hidden]) { display: block; }

  html.side-lock { overflow: hidden; }
  html.side-lock #chaty-widget-0, html.side-lock .chaty { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  .side-cat-toggle .icon, .side-cat, .shop-side.has-drawer, .shop-side.has-drawer.is-open { transition: none; }
}
