/* ───────────────────────────────────────────────
   XR Transition Animations
   Driven by body classes toggled from xrStateMachine events in viewSwitcher.js

   Phase 1 — PREPARE:     body.xr-undocking         (0–100 ms)
   Phase 2 — DISSOLVE:    body.xr-ambient-mode       (100–350 ms)
   Phase 3 — MATERIALIZE: body.xr-ambient-mode stays  (350–600 ms)

   Spec section 14: workspace appear 500–700ms, total cycle ~600ms.
   Docking reverses: remove xr-ambient-mode, then xr-undocking
─────────────────────────────────────────────── */

/* Phase 1: PREPARE — will-change hints for GPU compositing (desktop only) */
body.xr-undocking .workspace-panel {
  will-change: opacity;
}

/* Phase 2: DISSOLVE — desktop workspace fades behind ambient overlay.
   The full layout stays intact — no panels are hidden or removed.
   The ambient gradient ::after overlay covers everything. */

/* Phase 3: Ambient overlay — dark frosted glass that blocks the Tool UI (desktop).
   Barely transparent so the UI is hidden, with a heavy blur for depth. */
body.xr-ambient-mode::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 7000; /* XR ambient backdrop — above tours/concierge */
  pointer-events: none;
  background: rgba(10, 10, 14, 0.88);
  backdrop-filter: blur(32px) saturate(0.6);
  -webkit-backdrop-filter: blur(32px) saturate(0.6);
  opacity: 1;
  transition: opacity var(--duration-normal) var(--ease-smooth);
}

/* XR pairing modal hides when spatial mode activates */
body.xr-ambient-mode #xr-pair-modal {
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--duration-normal) var(--ease-smooth), visibility 0s var(--duration-normal);
  pointer-events: none;
}

/* ── Reverse animation for docking ────────────────────────────── */
body.xr-undocking:not(.xr-ambient-mode) #xr-pair-modal {
  opacity: 1;
  visibility: visible;
  transition: opacity var(--duration-normal) var(--ease-in-out), visibility 0s;
  pointer-events: auto;
}

body.xr-undocking:not(.xr-ambient-mode)::after {
  opacity: 0;
  transition: opacity var(--duration-normal) var(--ease-in-out);
}

/* ── Prefers reduced motion ───────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  /* A short crossfade instead of the dissolve: still says "something changed". */
  body.xr-ambient-mode::after,
  body.xr-undocking:not(.xr-ambient-mode)::after {
    transition: opacity var(--duration-fast) linear;
  }
  body.xr-ambient-mode #xr-pair-modal {
    transition: opacity var(--duration-fast) linear, visibility 0s var(--duration-fast);
  }
  body.xr-undocking:not(.xr-ambient-mode) #xr-pair-modal {
    transition: opacity var(--duration-fast) linear, visibility 0s;
  }
}

/* ═══════════════════════════════════════════════════════════════
   Desktop Ambient Overlay (shown during SPATIAL state)
   Floating orb + "Spatial workspace active" + Dock button
═══════════════════════════════════════════════════════════════ */
.xr-ambient-overlay {
  position: fixed;
  inset: 0;
  z-index: 7001; /* Above XR ambient backdrop */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--duration-normal) var(--ease-smooth) var(--duration-micro);
}
.xr-ambient-overlay.hidden { display: none; }
.xr-ambient-overlay.active { opacity: 1; visibility: visible; }

.xr-ambient-orb {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, color-mix(in srgb, var(--color-accent) 40%, transparent), color-mix(in srgb, var(--color-accent) 8%, transparent) 70%);
  box-shadow: 0 0 60px color-mix(in srgb, var(--color-accent) 30%, transparent), 0 0 120px color-mix(in srgb, var(--color-accent) 10%, transparent);
  animation: xr-orb-breathe calc(var(--duration-slowest) * 4) var(--ease-in-out) infinite;
}

/* Image variant of the orb (replaces CSS gradient with mixx-ai.png) */
.xr-ambient-orb--img {
  width: 100px;
  height: 100px;
  border-radius: 20px;
  background: none;
}

@keyframes xr-orb-breathe {
  0%, 100% { transform: scale(1); opacity: 0.8; }
  50% { transform: scale(1.08); opacity: 1; }
}

.xr-ambient-label {
  font-size: 1.2rem;
  font-weight: 700;
  color: rgba(255,255,255,0.9);
  letter-spacing: 0.04em;
}

.xr-ambient-hint {
  font-size: 0.9rem;
  color: rgba(255,255,255,0.5);
}

.xr-ambient-dock-btn {
  pointer-events: auto;
  padding: 12px 32px;
  border-radius: 12px;
  border: 1.5px solid color-mix(in srgb, var(--color-accent) 30%, transparent);
  background: rgba(24,24,31,0.7);
  color: #e7e7ea;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(12px);
  transition: border-color var(--duration-fast) var(--ease-sharp), background var(--duration-fast) var(--ease-sharp);
}
.xr-ambient-dock-btn:hover {
  border-color: color-mix(in srgb, var(--color-accent) 60%, transparent);
  background: rgba(34,34,45,0.8);
}

/* ── XR connected indicator dot on the XR button ─────────────── */
.xr-indicator-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-success);
  position: absolute;
  top: 4px;
  right: 4px;
  box-shadow: 0 0 6px color-mix(in srgb, var(--color-success) 60%, transparent);
}
.xr-indicator-dot.hidden { display: none; }

/* ── Feature-flag-gated XR button hidden state ────────────────── */
.view-switcher-row button.hidden {
  display: none;
}

/* ═══════════════════════════════════════════════════════════════
   AVP Spatial Visual Treatment
   Applied via body.xr-webspatial when running inside the
   WebSpatial app shell. Makes the Tool feel like a spatial
   console rather than a flat webpage — transparent root,
   glass panel surfaces, preserved layout.
═══════════════════════════════════════════════════════════════ */
body.xr-webspatial {
  background: transparent !important;
}

body.xr-webspatial .main-layout {
  background: rgba(0, 0, 0, 0.05);
}

body.xr-webspatial .navbar {
  background: rgba(20, 20, 20, 0.6);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

body.xr-webspatial .sidebar {
  background: rgba(30, 30, 30, 0.7);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

body.xr-webspatial .workspace-panel {
  background: rgba(30, 30, 30, 0.7);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

body.xr-webspatial #mixx-ai-panel {
  background: rgba(30, 30, 30, 0.7);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

/* ═══════════════════════════════════════════════════════════════
   Spatial Panel Placeholder
   Overlaid on in-Tool panel when content is expanded to space.
   Panel content is visibility:hidden + opacity:0 underneath.
═══════════════════════════════════════════════════════════════ */

.xr-spatial-placeholder {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(12, 12, 20, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: inherit;
  animation: xr-placeholder-fadein var(--duration-normal) var(--ease-smooth) both;
}

@keyframes xr-placeholder-fadein {
  from { opacity: 0; }
  to { opacity: 1; }
}

.xr-spatial-placeholder__content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}

.xr-spatial-placeholder__icon {
  color: color-mix(in srgb, var(--color-accent) 60%, transparent);
}

.xr-spatial-placeholder__text {
  font-size: 0.9rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.6);
  margin: 0;
}

.xr-spatial-placeholder__collapse-btn {
  padding: 8px 20px;
  border-radius: 8px;
  border: 1px solid color-mix(in srgb, var(--color-accent) 25%, transparent);
  background: rgba(24, 24, 31, 0.6);
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color var(--duration-fast) var(--ease-sharp), background var(--duration-fast) var(--ease-sharp);
}
.xr-spatial-placeholder__collapse-btn:hover {
  border-color: color-mix(in srgb, var(--color-accent) 50%, transparent);
  background: rgba(34, 34, 45, 0.8);
}

/* ═══════════════════════════════════════════════════════════════
   AVP Headset Waiting Overlay
   Shown after pairing, before spatial activation. Hides the full
   tool UI and presents a minimal "Connected / Bring to Space" screen.
═══════════════════════════════════════════════════════════════ */

/* Hide the main app UI while the headset is waiting */
body.xr-headset-waiting .navbar,
body.xr-headset-waiting .sidebar,
body.xr-headset-waiting .workspace,
body.xr-headset-waiting .view-switcher-row,
body.xr-headset-waiting .mode-selector,
body.xr-headset-waiting .panel-slot,
body.xr-headset-waiting #controlPanel,
body.xr-headset-waiting #mixx-ai-panel,
body.xr-headset-waiting .timeline-slider-container {
  display: none !important;
}

.xr-headset-overlay {
  position: fixed;
  inset: 0;
  z-index: 9500; /* XR headset takeover — highest UI tier */
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(
    ellipse at 50% 40%,
    rgba(20, 20, 30, 0.95) 0%,
    rgba(10, 10, 15, 0.98) 100%
  );
  animation: xr-headset-fadein var(--duration-slow) var(--ease-smooth) both;
}

@keyframes xr-headset-fadein {
  from { opacity: 0; }
  to { opacity: 1; }
}

.xr-headset-overlay--dismissing {
  animation: xr-headset-fadeout var(--duration-normal) var(--ease-in-out) both;
}

@keyframes xr-headset-fadeout {
  from { opacity: 1; }
  to { opacity: 0; }
}

.xr-headset-overlay__card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 48px 56px;
  border-radius: 24px;
  border: 1px solid color-mix(in srgb, var(--color-accent) 15%, transparent);
  background: rgba(28, 28, 38, 0.6);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  text-align: center;
  max-width: 400px;
}

.xr-headset-overlay__logo {
  border-radius: 14px;
  animation: xr-icon-pulse calc(var(--duration-slowest) * 3) var(--ease-in-out) infinite;
}

.xr-headset-overlay__subtitle {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.4);
  margin: -12px 0 0;
  display: none;
}

@keyframes xr-icon-pulse {
  0%, 100% { opacity: 0.7; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.05); }
}

.xr-headset-overlay__status {
  font-size: 1.1rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.7);
  margin: 0;
  transition: color var(--duration-normal) var(--ease-sharp);
}

.xr-headset-overlay__status[data-state="connected"] {
  color: var(--color-success);
}

.xr-headset-overlay__undock-btn {
  padding: 14px 40px;
  border-radius: 14px;
  border: 1.5px solid color-mix(in srgb, var(--color-accent) 30%, transparent);
  background: color-mix(in srgb, var(--color-accent) 15%, transparent);
  color: #e7e7ea;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(12px);
  transition: border-color var(--duration-fast) var(--ease-sharp), background var(--duration-fast) var(--ease-sharp), opacity var(--duration-fast) var(--ease-sharp), transform var(--duration-fast) var(--ease-sharp);
}

.xr-headset-overlay__undock-btn:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--color-accent) 60%, transparent);
  background: color-mix(in srgb, var(--color-accent) 25%, transparent);
  transform: scale(1.02);
}

.xr-headset-overlay__undock-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.xr-headset-overlay__undock-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.xr-headset-overlay__hint {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.35);
  margin: 0;
}

/* ═══════════════════════════════════════════════════════════════
   Spatial Control Buttons
   "Expand Map to Space"
   Shown during SPATIAL state on AVP devices.
═══════════════════════════════════════════════════════════════ */
.xr-spatial-controls {
  display: none;
}

body.xr-undocked .xr-spatial-controls {
  display: flex;
  gap: 8px;
  padding: 4px 0;
}

.xr-spatial-btn {
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--color-accent) 20%, transparent);
  background: color-mix(in srgb, var(--color-accent) 10%, transparent);
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background var(--duration-fast) var(--ease-sharp), border-color var(--duration-fast) var(--ease-sharp), opacity var(--duration-fast) var(--ease-sharp);
}

.xr-spatial-btn:hover {
  background: color-mix(in srgb, var(--color-accent) 20%, transparent);
  border-color: color-mix(in srgb, var(--color-accent) 40%, transparent);
}

.xr-spatial-btn:active {
  transform: scale(0.97);
}

.xr-spatial-btn[aria-pressed="true"],
.xr-spatial-btn[data-expanded="true"] {
  background: color-mix(in srgb, var(--color-accent) 25%, transparent);
  border-color: color-mix(in srgb, var(--color-accent) 50%, transparent);
  color: rgba(255, 255, 255, 0.95);
}

.xr-spatial-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ═══════════════════════════════════════════════════════════════
   Spatial Workspace Appear Animation (spec: 500–700ms)
   Applied to body.xr-webspatial when first entering spatial mode.
═══════════════════════════════════════════════════════════════ */
body.xr-webspatial.xr-workspace-appearing .main-layout,
body.xr-webspatial.xr-workspace-appearing .navbar,
body.xr-webspatial.xr-workspace-appearing .sidebar {
  animation: xr-workspace-appear var(--duration-slow) var(--ease-smooth) both;
}

@keyframes xr-workspace-appear {
  from {
    opacity: 0;
    transform: scale(0.96) translateZ(-20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateZ(0);
  }
}

/* The map-expansion animation and the spatial fallback toast lived here.
   The animation keyed on [data-spatial-expanding], an attribute no script ever
   set, and the toast's only function was never called from anywhere. */

/* ═══════════════════════════════════════════════════════════════
   Reduced Motion — Spatial Animations
   Disables all spatial animations when user prefers reduced motion.
═══════════════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  /* Nothing scales or moves; things that appear or leave crossfade. */
  body.xr-webspatial.xr-workspace-appearing .main-layout,
  body.xr-webspatial.xr-workspace-appearing .navbar,
  body.xr-webspatial.xr-workspace-appearing .sidebar {
    animation: xr-placeholder-fadein var(--duration-fast) linear both;
  }

  .xr-headset-overlay {
    animation: xr-headset-fadein var(--duration-fast) linear both;
  }

  .xr-headset-overlay--dismissing {
    animation: xr-headset-fadeout var(--duration-fast) linear both;
  }

  .xr-headset-overlay__logo {
    animation: none;
  }

  .xr-ambient-orb {
    animation: none;
    opacity: 1;
  }

  .xr-ambient-overlay {
    transition: opacity var(--duration-fast) linear;
  }
}
