/* ──────────────────────────────────────────────────────────────────────
   3D viewer tools — Move, Reset view and Background photo
   (public/js/model-viewer-tools.js, markup in views/partials/viewer-tools.ejs).

   Everything here is an ordinary child of the <model-viewer> element on the
   product page and the AR page, so it stays on screen in pseudo-fullscreen
   (model-fullscreen.js shows only the viewer's own subtree there).

   The buttons ARE .mv-toggle-btn (round, translucent charcoal, brand brown
   when on, 44px in fullscreen — all in model-fullscreen.css, loaded on both
   pages); this file only places them and adds what that file does not have.
   ────────────────────────────────────────────────────────────────────── */

/* Move, Background and Reset view are plain buttons of the SAME column as Auto-rotate / Dimensions (.mv-toggles in
   model-fullscreen.css, which also wraps the column into a second one when the viewer is too short for it). The wrapper
   only carries the data attributes the script reads: it takes no box of its own, so its buttons are flex items of .mv-toggles. */
.mv-tools {
  display: contents;
}

/* These are action / toggle buttons, not the "feature is crossed out when off"
   switches next to them: off is the plain translucent button, no slash. */
.mv-tools .mv-toggle-btn[aria-pressed="false"]::before {
  content: none;
}
.mv-tools .mv-toggle-btn[aria-pressed="false"] i {
  opacity: 1;
}
/* "A photo is in use" looks like "on". */
.mv-tools .mv-toggle-btn.is-active {
  background-color: var(--color-primary-dark, #A8845E);
}
.mv-tools .mv-toggle-btn.is-active:hover {
  background-color: var(--color-brown-mid, #7A5C44);
}

/* Auto-rotate waits while Move is on (see the script). */
.mv-toggle-btn:disabled {
  opacity: 0.45;
  cursor: default;
}
.mv-toggle-btn:disabled:hover {
  background-color: rgba(44, 36, 24, 0.55);
}

/* ── Move: the drag surface ───────────────────────────────────────────
   Covers the viewer while Move is on, under every button (z-index 1 < 4),
   so model-viewer's own rotate never sees the drag. touch-action none = a
   finger drag moves the model instead of scrolling the page. */
.mv-pan-surface {
  position: absolute;
  inset: 0;
  z-index: 1;
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.mv-pan-surface[hidden] {
  display: none;
}
.mv-pan-surface.is-dragging {
  cursor: grabbing;
}

/* ── Background photo ─────────────────────────────────────────────────
   The photo is a CSS variable the script sets on the <model-viewer> host
   (a blob: address made in this browser). The canvas is transparent, so the
   photo shows behind the model and the model's shadow falls on it.
   Specificity: element + class (0,1,1) beats model-fullscreen.css's
   `.model-pseudo-fullscreen { background: #fff !important }` (0,1,0), so the
   photo also shows in fullscreen. */
model-viewer.mv-has-bg {
  background-image: var(--mv-bg-image) !important;
  background-size: cover !important;
  background-position: center !important;
  background-repeat: no-repeat !important;
  --poster-color: transparent;
}

/* The photo choices: a small panel that opens right BESIDE the Background button, level with it (model-viewer-tools.js places it from
   the button's own position, so it follows the button wherever the column sits). It covers only the corner it is in, and closes by
   itself as soon as a photo is chosen. On a very small viewer (.is-compact) it takes the width left of the buttons and may scroll. */
.mv-bg-panel {
  position: absolute;
  top: 8px;
  right: 56px;
  z-index: 5;
  box-sizing: border-box;
  width: 224px;
  max-width: calc(100% - 72px);
  max-height: calc(100% - 16px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 10px 10px;
  border-radius: var(--radius-lg, 12px);
  background-color: rgba(44, 36, 24, 0.9);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.3);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  color: #fff;
}
.mv-bg-panel[hidden] {
  display: none;
}
.mv-bg-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.mv-bg-title {
  font-family: var(--font-body, system-ui, sans-serif);
  font-size: var(--fs-xs, 0.75rem);
  font-weight: var(--fw-semibold, 600);
  line-height: 1.2;
  letter-spacing: 0.02em;
}
/* 44px tap target around a 28px visible button. */
.mv-bg-close {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 0.7rem;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.mv-bg-close::after {
  content: "";
  position: absolute;
  inset: -8px;
  border-radius: 50%;
}
.mv-bg-close:hover {
  background-color: rgba(255, 255, 255, 0.28);
}
.mv-bg-close:focus-visible {
  outline: 2px solid var(--color-primary, #C8A882);
  outline-offset: 2px;
}

/* The tiles wrap into rows of whatever fits the panel (4 in the normal width, 3 or 2 in a narrow one). */
.mv-bg-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, 44px);
  gap: 8px;
  justify-content: start;
  padding: 3px;
}

.mv-bg-item {
  position: relative;
  flex: 0 0 auto;
}

/* 44px tiles: also the minimum comfortable tap size. */
.mv-bg-tile {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: var(--radius-md, 8px);
  background-color: #fff;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  color: var(--color-brown-mid, #7A5C44);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.45);
  -webkit-tap-highlight-color: transparent;
}
.mv-bg-tile:focus-visible,
.mv-bg-remove:focus-visible {
  outline: 2px solid var(--color-primary, #C8A882);
  outline-offset: 2px;
}
.mv-bg-tile[aria-pressed="true"] {
  border-color: var(--color-primary, #C8A882);
  box-shadow: 0 0 0 2px #fff, 0 1px 5px rgba(0, 0, 0, 0.45);
}
.mv-bg-tile--add {
  background-color: rgba(255, 255, 255, 0.08);
  border: 2px dashed rgba(255, 255, 255, 0.7);
  box-shadow: none;
  color: #fff;
}
.mv-bg-tile--add:hover {
  background-color: rgba(255, 255, 255, 0.2);
}
.mv-bg-tile:disabled {
  opacity: 0.5;
  cursor: default;
}

/* The small × on the photo in use. Sits inside the tile; the ring around it
   makes the tap target about 36px without covering the neighbours. */
.mv-bg-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background-color: rgba(44, 36, 24, 0.85);
  color: #fff;
  font-size: 0.65rem;
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
}
.mv-bg-remove::after {
  content: "";
  position: absolute;
  inset: -8px;
  border-radius: 50%;
}

.mv-bg-note {
  max-width: 100%;
  margin: 6px 0 0;
  padding: 5px 8px;
  border-radius: var(--radius-md, 8px);
  background-color: rgba(255, 255, 255, 0.12);
  font-size: 0.75rem;
  line-height: 1.35;
  color: #fff;
}
.mv-bg-note:empty {
  display: none;
}
.mv-bg-note.is-error {
  border-left: 3px solid var(--color-danger, #B85C4A);
}
