/*
 * KLOWLA foldable layouts. Driven by <html data-kla-fold> (foldable.js).
 *   phone     → full-width bottom tab bar, alerts as a bottom sheet
 *   unfolded  → floating, centered tab bar; alerts slide in as a right side sheet
 *   book      → tab bar on the left screen only; alerts fill the right screen; nothing under the hinge
 *   tabletop  → product image on the top screen, details + tab bar on the bottom screen
 * No body padding on the sides: the theme's full-width sections must never overflow.
 */

/* ---------- Unfolded / tablet / book: side rail (like Instagram on large screens) ----------
 * Two floating pills on the right edge: Alerts, Wishlist, Compare on top; Shop, Cart, Account at the bottom
 * (thumb reach). Space is reserved on the right so the rail never covers page content. */
html[data-kla-fold="unfolded"], html[data-kla-fold="book"] {
  --kla-rail-w: 68px;
  --kla-rail-gap: calc(12px + env(safe-area-inset-right, 0px));
  --kla-rail-space: calc(var(--kla-rail-w) + var(--kla-rail-gap) + 12px);
}
html.kla-app[data-kla-fold="unfolded"] body,
html.kla-app[data-kla-fold="book"] body {
  padding-bottom: 0 !important;
  padding-right: var(--kla-rail-space) !important;
  box-sizing: border-box;
}
html[data-kla-fold="unfolded"] .kla-nav,
html[data-kla-fold="book"] .kla-nav {
  left: auto; right: var(--kla-rail-gap); width: var(--kla-rail-w);
  top: calc(var(--wp-admin--admin-bar--height, 0px) + 16px); bottom: calc(16px + var(--kla-safe-b)); height: auto;
  padding: 0; transform: none;
  display: flex; flex-direction: column; align-items: stretch;
  background: transparent; border: 0; box-shadow: none;
}
html[data-kla-fold="unfolded"] .kla-tab,
html[data-kla-fold="book"] .kla-tab {
  flex: 0 0 64px; min-height: 64px; gap: 0;
  background: var(--kla-cream) !important;
  border-left: 1px solid var(--kla-line); border-right: 1px solid var(--kla-line);
}
html[data-kla-fold="unfolded"] .kla-tab svg, html[data-kla-fold="book"] .kla-tab svg { width: 26px; height: 26px; }
html[data-kla-fold="unfolded"] .kla-avatar, html[data-kla-fold="book"] .kla-avatar { width: 30px; height: 30px; }
/* Icons only on the rail; names stay for screen readers. */
html[data-kla-fold="unfolded"] .kla-tab-label, html[data-kla-fold="book"] .kla-tab-label {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
/* Order and grouping. */
html[data-kla-fold] .kla-tab[data-tab="alerts"]   { order: 1; }
html[data-kla-fold] .kla-tab[data-tab="wishlist"] { order: 2; }
html[data-kla-fold] .kla-tab[data-tab="compare"]  { order: 3; }
html[data-kla-fold] .kla-tab[data-tab="shop"]     { order: 4; }
html[data-kla-fold] .kla-tab[data-tab="cart"]     { order: 5; }
html[data-kla-fold] .kla-tab[data-tab="account"]  { order: 6; }
html[data-kla-fold="phone"] .kla-tab, html[data-kla-fold="tabletop"] .kla-tab { order: 0 !important; }
html[data-kla-fold="unfolded"] .kla-tab[data-tab="alerts"], html[data-kla-fold="book"] .kla-tab[data-tab="alerts"] {
  border-top: 1px solid var(--kla-line); border-radius: 34px 34px 0 0; padding-top: 6px; flex-basis: 70px;
}
html[data-kla-fold="unfolded"] .kla-tab[data-tab="compare"], html[data-kla-fold="book"] .kla-tab[data-tab="compare"] {
  border-bottom: 1px solid var(--kla-line); border-radius: 0 0 34px 34px; padding-bottom: 6px; flex-basis: 70px;
  box-shadow: 0 10px 24px rgb(0 0 0 / .10);
}
html[data-kla-fold="unfolded"] .kla-tab[data-tab="shop"], html[data-kla-fold="book"] .kla-tab[data-tab="shop"] {
  margin-top: auto; border-top: 1px solid var(--kla-line); border-radius: 34px 34px 0 0; padding-top: 6px; flex-basis: 70px;
}
html[data-kla-fold="unfolded"] .kla-tab[data-tab="account"], html[data-kla-fold="book"] .kla-tab[data-tab="account"] {
  border-bottom: 1px solid var(--kla-line); border-radius: 0 0 34px 34px; padding-bottom: 6px; flex-basis: 70px;
  box-shadow: 0 10px 24px rgb(0 0 0 / .10);
}
/* Active marker: a gold bar on the inner (left) edge. */
html[data-kla-fold="unfolded"] .kla-tab[aria-current="page"]::before, html[data-kla-fold="unfolded"] .kla-tab[aria-expanded="true"]::before,
html[data-kla-fold="book"] .kla-tab[aria-current="page"]::before, html[data-kla-fold="book"] .kla-tab[aria-expanded="true"]::before {
  top: 30%; bottom: 30%; left: -1px; right: auto; width: 3px; height: auto; border-radius: 0 3px 3px 0;
}
html[data-kla-fold="unfolded"] .kla-badge, html[data-kla-fold="book"] .kla-badge { top: 8px; left: calc(50% + 6px); }
html[data-kla-fold="unfolded"] .kla-dot, html[data-kla-fold="book"] .kla-dot { top: 14px; left: calc(50% + 8px); }

/* Accessibility button: keep it clear of the rail. */
html.kla-app[data-kla-fold="unfolded"] #ea11y-root, html.kla-app[data-kla-fold="book"] #ea11y-root { bottom: calc(16px + var(--kla-safe-b)); }

html[data-kla-fold="unfolded"] .kla-alerts,
html[data-kla-fold="book"] .kla-alerts {
  /* Slides in beside the rail. */
  top: var(--wp-admin--admin-bar--height, 0px); left: auto; right: var(--kla-rail-space); bottom: 0; max-height: none;
  width: min(400px, 92vw); border-radius: 22px 0 0 22px; transform: none; padding-bottom: calc(16px + var(--kla-safe-b));
}
@media (prefers-reduced-motion: no-preference) {
  html[data-kla-fold="unfolded"] .kla-alerts:not([hidden]) { animation: kla-in .22s ease-out; }
}
@keyframes kla-in { from { opacity: 0; translate: 24px 0; } }

/* ---------- Book posture: hinge runs top to bottom ---------- */
html[data-kla-fold="book"] .kla-alerts { width: calc(var(--kla-seg-b, 50vw) - var(--kla-rail-space)); border-radius: 22px 0 0 22px; }
html[data-kla-fold="book"] .kla-scrim { left: calc(var(--kla-seg-a, 50vw) + var(--kla-hinge, 0px)); }

/* Standard WooCommerce product/cart markup: one pane per screen. Elementor templates are left as designed. */
html[data-kla-fold="book"] {
  --kla-left: calc(var(--kla-seg-a, 50vw) - 16px);
  --kla-right: calc(var(--kla-seg-b, 50vw) - 16px);
}
html[data-kla-fold="book"] .woocommerce div.product:has(> .summary) {
  display: grid; grid-template-columns: var(--kla-left) var(--kla-right); column-gap: var(--kla-hinge, 0px);
}
html[data-kla-fold="book"] .woocommerce div.product:has(> .summary) > * { grid-column: 1 / -1; }
html[data-kla-fold="book"] .woocommerce div.product > .woocommerce-product-gallery { grid-column: 1; width: auto !important; float: none !important; padding-right: 16px; box-sizing: border-box; }
html[data-kla-fold="book"] .woocommerce div.product > .summary { grid-column: 2; width: auto !important; float: none !important; padding-left: 16px; box-sizing: border-box; position: sticky; top: 16px; }

/* ---------- Tabletop: hinge runs left to right ---------- */
html[data-kla-fold="tabletop"] .woocommerce div.product > .woocommerce-product-gallery {
  height: calc(var(--kla-seg-a, 50vh) - var(--kla-gallery-top, 56px) - 8px); width: 100% !important; float: none !important;
  overflow: hidden; margin-bottom: calc(var(--kla-hinge, 0px) + 32px) !important;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
}
html[data-kla-fold="tabletop"] .woocommerce div.product > .woocommerce-product-gallery img {
  max-height: calc(var(--kla-seg-a, 50vh) - var(--kla-gallery-top, 56px) - 96px); width: auto; max-width: 100%; object-fit: contain; margin: 0 auto;
}
html[data-kla-fold="tabletop"] .woocommerce div.product > .summary { width: 100% !important; float: none !important; }
html[data-kla-fold="tabletop"] .kla-alerts { max-height: var(--kla-seg-b, 50vh); }

/* Side sheet sits above the floating bar on roomy screens. */
html[data-kla-fold="unfolded"] .kla-alerts, html[data-kla-fold="book"] .kla-alerts { z-index: 99996; }
