/* ──────────────────────────────────────────────────────────────────────
   CSS-driven "pseudo-fullscreen" for every <model-viewer> fullscreen
   button — see wireModelFullscreenButton() in model-fullscreen.js for why
   the native Fullscreen API isn't used. Escapes whatever small wrapper the
   model-viewer normally sits in, including a Bootstrap modal (hence the
   max z-index).
   ────────────────────────────────────────────────────────────────────── */
.model-pseudo-fullscreen {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  /* vh first as a fallback for browsers without dvh (which would drop the
     dvh line); dvh then tracks a mobile browser's collapsing address bar. */
  height: 100vh !important;
  height: 100dvh !important;
  max-width: 100vw !important;
  max-height: 100vh !important;
  max-height: 100dvh !important;
  /* A page's own min-height on the viewer (e.g. ar-viewer.css's 480px / 400px)
     beats max-height in CSS, so on a short landscape phone the "fullscreen"
     viewer used to overflow the screen. Fullscreen inherits no minimum size. */
  min-width: 0 !important;
  min-height: 0 !important;
  z-index: 2147483647 !important;
  background: #ffffff !important;
  margin: 0 !important;
  border-radius: 0 !important;
}

body.model-pseudo-fullscreen-lock {
  overflow: hidden !important;
}

/* Top-layer mode (see the long note in model-fullscreen.js): the browser's
   default [popover] styling centres the element, sizes it to its content and
   adds a border, padding and scrollbars — reset all of that so the viewer is
   exactly the full viewport, nothing else. Top-layer elements are positioned
   against the viewport itself, so no ancestor can shift or clip it. */
.model-pseudo-fullscreen[popover] {
  padding: 0 !important;
  border: 0 !important;
  overflow: hidden !important;
  color: inherit;
}

/* Fallback for browsers WITHOUT the Popover API (model-fullscreen.js adds
   body.model-fs-fallback only then). A fixed z-index can't lift the viewer above the
   navbar/chat button when an ancestor (here <main>'s page fade-in animation) forms a
   stacking context, so instead hide every other direct child of <body> — navbar, chat
   button, toasts, footer, modals — and keep just the viewer (a descendant of <main>)
   and the X. `visibility` is inherited but a descendant can opt back in, which is
   exactly what the viewer does. Nothing is moved, so the model doesn't reload. */
body.model-fs-fallback > *:not(.model-fs-close) {
  visibility: hidden !important;
}
body.model-fs-fallback .model-pseudo-fullscreen {
  visibility: visible !important;
}

/* Exit (X) button shown while a viewer is in pseudo-fullscreen. Lives on
   <body>, appended after the viewer's own DOM, so with the same max z-index
   it paints above it. Safe-area insets keep it clear of an iPhone notch. */
.model-fs-close {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top, 0px));
  right: calc(12px + env(safe-area-inset-right, 0px));
  z-index: 2147483647;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 50%;
  background: #ffffff;
  color: #2b2b2b;
  font-size: 1.1rem;
  line-height: 1;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.model-fs-close[hidden] {
  display: none;
}
/* Same reset for the X when it is a top-layer popover (default popover styling
   would centre it): pin it to the top-right corner, clear of a notch. */
.model-fs-close[popover] {
  inset: auto;
  top: calc(12px + env(safe-area-inset-top, 0px));
  right: calc(12px + env(safe-area-inset-right, 0px));
  margin: 0;
  padding: 0;
  overflow: visible;
}
/* Author `display` on .model-fs-close beats the popover UA rule that hides a
   closed popover, so restate it. (Its own rule: a browser that does not know
   :popover-open would otherwise discard the whole rule above along with it.) */
.model-fs-close[popover]:not(:popover-open) {
  display: none;
}
.model-fs-close:hover,
.model-fs-close:focus-visible {
  background: #f3f0ea;
}

/* ──────────────────────────────────────────────────────────────────────
   3D viewer toggles — Auto-rotate and Dimensions (model-viewer-toggles.js).
   Markup: a .mv-toggles box INSIDE the <model-viewer> element on the product
   page and the AR page, so the buttons stay visible in pseudo-fullscreen
   (only the viewer's own subtree is shown there).

   Same look as the fullscreen button they sit under (.pd-model-fullscreen-btn
   / .ar-model-fullscreen-btn: 34px round, translucent charcoal), stacked
   just below it in the top-right corner. Colours repeat those buttons' own
   values with the site tokens as the source, no new palette.
   ────────────────────────────────────────────────────────────────────── */
.mv-toggles {
  position: absolute;
  /* below the 34px fullscreen button, which sits at top/right: --space-4 */
  top: calc(var(--space-4, 1rem) + 34px + 8px);
  right: var(--space-4, 1rem);
  z-index: 4;
  display: flex;
  flex-direction: column;
  /* ONE vertical line of buttons (Auto-rotate, Dimensions, Move, Background, Reset view). Only on a viewer too short to hold the
     whole line (the product page's 4:3 box on a phone is 211-257px tall) does it carry on in a second column, to the LEFT of the
     first, instead of running off the bottom of the box. */
  flex-wrap: wrap-reverse;
  align-content: flex-start;
  max-height: calc(100% - var(--space-4, 1rem) - 34px - 8px - 8px);
  gap: 8px;
  /* model-viewer's default slot does not take pointer events; these must. */
  pointer-events: auto;
}

.mv-toggle-btn {
  position: relative;
  width: 34px;
  height: 34px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background-color: rgba(44, 36, 24, 0.55);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 150ms ease, color 150ms ease;
}
.mv-toggle-btn[hidden] {
  display: none;
}
/* The visible button stays 34px to match the fullscreen button; this
   invisible ring makes the tap target 44px on a touch screen. */
.mv-toggle-btn::after {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: 50%;
}
.mv-toggle-btn:hover {
  background-color: rgba(44, 36, 24, 0.8);
}
.mv-toggle-btn:focus-visible {
  outline: 2px solid var(--color-primary, #C8A882);
  outline-offset: 2px;
}

/* ON: filled with the brand's rattan brown. */
.mv-toggle-btn[aria-pressed="true"] {
  background-color: var(--color-primary-dark, #A8845E);
  color: #fff;
}
.mv-toggle-btn[aria-pressed="true"]:hover {
  background-color: var(--color-brown-mid, #7A5C44);
}

/* OFF: the neutral translucent button, icon dimmed, with a diagonal slash
   so the state does not depend on colour alone. */
.mv-toggle-btn[aria-pressed="false"] i {
  opacity: 0.7;
}
.mv-toggle-btn[aria-pressed="false"]::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 22px;
  height: 2px;
  border-radius: 1px;
  background-color: #fff;
  transform: translate(-50%, -50%) rotate(-45deg);
  pointer-events: none;
}

/* In pseudo-fullscreen the page's own fullscreen button is covered and the
   44px exit (X) button takes the corner instead (.model-fs-close: 12px from
   the top/right, plus the notch insets) — line the toggles up under it and
   give them the same 44px size. */
.model-pseudo-fullscreen .mv-toggles {
  top: calc(12px + 44px + 10px + env(safe-area-inset-top, 0px));
  /* --model-fs-scrollbar: width of the page's own scrollbar, set by
     model-fullscreen.js on entering fullscreen (the X is positioned clear
     of it; these buttons are positioned against the full-width viewer). */
  right: calc(12px + var(--model-fs-scrollbar, 0px) + env(safe-area-inset-right, 0px));
  max-height: calc(100% - 12px - 44px - 10px - 12px - env(safe-area-inset-top, 0px));
  gap: 10px;
}
.model-pseudo-fullscreen .mv-toggle-btn {
  width: 44px;
  height: 44px;
  font-size: 1.1rem;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}
.model-pseudo-fullscreen .mv-toggle-btn::after {
  inset: 0;
}
.model-pseudo-fullscreen .mv-toggle-btn[aria-pressed="false"]::before {
  width: 28px;
}

/* ──────────────────────────────────────────────────────────────────────
   Camera AR (WebXR) shows none of the viewer's controls (2026-11-12).
   model-viewer draws the DOM overlay of a WebXR session from its default
   slot, i.e. from every child of <model-viewer> WITHOUT a slot= attribute
   (ARRenderer.ts: overlay = shadowRoot.querySelector('div.default')). All
   of this viewer's controls are such children: Fit | Real size and "?"
   (.mv-topleft), the button column (.mv-toggles), the background photo
   panel, the Move drag surface and the two measuring drawings. Over the
   camera picture they are noise, and a Move surface would swallow the taps
   that place the product. The hotspot anchors keep their slot= and
   model-viewer already hides them in AR.
   Three states count as "in AR":
     ar-status="session-started" / "object-placed"  set by model-viewer;
     data-ar-launching  set by the AR page's Launch AR button for the moment
       between the session opening (the overlay is already on screen) and
       model-viewer's own status arriving, so nothing flashes first.
   Everything comes back by itself when AR ends: this only hides, it never
   touches a button's state, so Move / Real size / the photo stay as set.
   ────────────────────────────────────────────────────────────────────── */
model-viewer[ar-status="session-started"] > :not([slot]),
model-viewer[ar-status="object-placed"] > :not([slot]),
model-viewer[data-ar-launching] > :not([slot]) {
  display: none !important;
}
