/**
 * WallVision AR Viewer Styles
 * Mobile-first, RTL-aware, high-contrast UI for the AR and 3D viewer.
 * Uses CSS custom properties so colors can be overridden from admin settings.
 */

/* ─── CSS Custom Properties (overridden by PHP inline styles) ─────────────────── */
:root {
  --wv-primary:      #1a1a2e;
  --wv-accent:       #e94560;
  --wv-bg:           rgba(0, 0, 0, 0.92);
  --wv-surface:      rgba(255, 255, 255, 0.08);
  --wv-border:       rgba(255, 255, 255, 0.15);
  --wv-text:         #ffffff;
  --wv-text-muted:   rgba(255, 255, 255, 0.6);
  --wv-radius:       12px;
  --wv-transition:   0.2s ease;
  --wv-font:         'Inter', 'Cairo', system-ui, sans-serif;
  --wv-z-overlay:    999999;
}

/* ─── Body lock when viewer is open ─────────────────────────────────────────── */
body.wallvision-viewer-open {
  overflow: hidden;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   AR OVERLAY (WebXR mode — overlays camera feed)
═══════════════════════════════════════════════════════════════════════════════ */
#wallvision-ar-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--wv-z-overlay);
  pointer-events: none; /* Let touch events through to WebXR by default */
  font-family: var(--wv-font);
  font-size: 14px;
  color: var(--wv-text);
}

.wv-ar-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  padding-top: calc(16px + env(safe-area-inset-top));
  background: linear-gradient(to bottom, rgba(0,0,0,0.6) 0%, transparent 100%);
  pointer-events: all;
}

.wv-ar-close,
.wv-ar-screenshot {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--wv-transition);
  -webkit-tap-highlight-color: transparent;
}

.wv-ar-close:active,
.wv-ar-screenshot:active {
  background: rgba(0, 0, 0, 0.8);
  transform: scale(0.95);
}

.wv-ar-title {
  font-size: 15px;
  font-weight: 600;
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Status message — shown during scanning and after placement */
.wv-ar-status {
  position: absolute;
  bottom: 180px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(10px);
  border: 1px solid var(--wv-border);
  color: #fff;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  text-align: center;
  transition: opacity 0.3s;
}

/* Control bar — appears after artwork is placed */
.wv-ar-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 16px 20px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(0,0,0,0.75) 0%, transparent 100%);
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: all;
  flex-wrap: wrap;
  justify-content: center;
}

.wv-ctrl-btn {
  height: 44px;
  min-width: 44px;
  padding: 0 14px;
  border-radius: 22px;
  border: 1px solid var(--wv-border);
  background: rgba(255,255,255,0.12);
  backdrop-filter: blur(8px);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--wv-transition);
  -webkit-tap-highlight-color: transparent;
}

.wv-ctrl-btn:active {
  background: rgba(255,255,255,0.25);
  transform: scale(0.95);
}

.wv-add-cart {
  background: var(--wv-accent) !important;
  border-color: transparent !important;
  font-size: 14px !important;
  font-weight: 600;
  padding: 0 20px !important;
}

/* Frame selector buttons */
.wv-frame-selector {
  display: flex;
  gap: 8px;
  align-items: center;
}

.wv-frame-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all var(--wv-transition);
  -webkit-tap-highlight-color: transparent;
}

.wv-frame-btn.active {
  border-color: #fff;
  transform: scale(1.15);
  box-shadow: 0 0 0 2px rgba(255,255,255,0.3);
}

/* Instruction overlay */
.wv-ar-instructions {
  position: absolute;
  bottom: 140px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  pointer-events: none;
}

.wv-ar-instructions p {
  font-size: 13px;
  color: var(--wv-text-muted);
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
  margin: 4px 0;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   3D VIEWER (Three.js fallback — full screen)
═══════════════════════════════════════════════════════════════════════════════ */
#wallvision-3d-viewer {
  position: fixed;
  inset: 0;
  z-index: var(--wv-z-overlay);
  display: grid;
  grid-template-rows: 60px 1fr;
  grid-template-columns: 1fr 260px;
  background: #111;
  font-family: var(--wv-font);
  color: var(--wv-text);
}

#wv-3d-canvas {
  grid-column: 1;
  grid-row: 1 / 3;
  width: 100%;
  height: 100%;
  display: block;
}

.wv-3d-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 260px;
  height: 60px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--wv-border);
  z-index: 10;
}

.wv-3d-close,
.wv-3d-screenshot {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: 1px solid var(--wv-border);
  background: var(--wv-surface);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--wv-transition);
}

.wv-3d-close:hover,
.wv-3d-screenshot:hover {
  background: rgba(255,255,255,0.15);
}

.wv-3d-title {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
}

.wv-3d-title-text {
  font-size: 15px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wv-3d-badge {
  font-size: 11px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 12px;
  background: var(--wv-accent);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Sidebar */
.wv-3d-sidebar {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 260px;
  background: var(--wv-bg);
  border-left: 1px solid var(--wv-border);
  padding: 80px 20px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.wv-sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.wv-sidebar-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--wv-text-muted);
}

.wv-frame-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.wv-frame-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--wv-radius);
  border: 1px solid var(--wv-border);
  background: var(--wv-surface);
  color: var(--wv-text);
  cursor: pointer;
  font-size: 13px;
  font-family: var(--wv-font);
  transition: all var(--wv-transition);
  text-align: left;
}

.wv-frame-option:hover {
  background: rgba(255,255,255,0.12);
}

.wv-frame-option.active {
  border-color: var(--wv-accent);
  background: rgba(233, 69, 96, 0.12);
}

.wv-frame-swatch {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,0.2);
  flex-shrink: 0;
}

.wv-dim-text {
  font-size: 18px;
  font-weight: 600;
  color: var(--wv-text);
}

.wv-3d-add-cart {
  margin-top: auto;
  padding: 14px;
  border-radius: var(--wv-radius);
  border: none;
  background: var(--wv-accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--wv-font);
  cursor: pointer;
  transition: all var(--wv-transition);
}

.wv-3d-add-cart:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

/* Orbit hint */
.wv-3d-hint {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(8px);
  border: 1px solid var(--wv-border);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 12px;
  color: var(--wv-text-muted);
  pointer-events: none;
  animation: wv-fade-out 1s ease 4s forwards;
}

@keyframes wv-fade-out {
  to { opacity: 0; pointer-events: none; }
}

/* Loading state */
.wv-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #111;
  z-index: 5;
}

.wv-loading-spinner {
  width: 44px;
  height: 44px;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: var(--wv-accent);
  border-radius: 50%;
  animation: wv-spin 0.8s linear infinite;
  margin-bottom: 16px;
}

@keyframes wv-spin {
  to { transform: rotate(360deg); }
}

/* Toast notification */
.wv-toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.85);
  color: #fff;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 13px;
  z-index: calc(var(--wv-z-overlay) + 1);
  animation: wv-toast-in 0.3s ease, wv-toast-out 0.3s ease 2.7s forwards;
  white-space: nowrap;
}

@keyframes wv-toast-in {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
@keyframes wv-toast-out {
  to { opacity: 0; transform: translate(-50%, -10px); }
}

/* ─── Mobile responsiveness ──────────────────────────────────────────────────── */
@media (max-width: 768px) {
  #wallvision-3d-viewer {
    grid-template-columns: 1fr;
  }

  .wv-3d-header {
    right: 0;
  }

  .wv-3d-sidebar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    top: auto;
    max-height: 240px;
    border-left: none;
    border-top: 1px solid var(--wv-border);
    padding: 16px;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    gap: 16px;
  }

  .wv-sidebar-section {
    flex-shrink: 0;
    min-width: 140px;
  }

  .wv-frame-options {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .wv-frame-option {
    padding: 6px 10px;
    font-size: 12px;
  }

  .wv-3d-add-cart {
    margin-top: 0;
    flex-shrink: 0;
    white-space: nowrap;
  }
}

/* ─── RTL Support ─────────────────────────────────────────────────────────────── */
[dir="rtl"] .wv-ar-header,
[dir="rtl"] .wv-3d-header {
  flex-direction: row-reverse;
}

[dir="rtl"] .wv-3d-sidebar {
  right: auto;
  left: 0;
  border-left: none;
  border-right: 1px solid var(--wv-border);
}

[dir="rtl"] .wv-3d-header {
  left: 0;
  right: 0;
}

/* ─── Accessibility ───────────────────────────────────────────────────────────── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border-width: 0;
}

@media (prefers-reduced-motion: reduce) {
  .wv-loading-spinner {
    animation-duration: 2s;
  }
  .wv-ctrl-btn,
  .wv-3d-add-cart,
  .wv-frame-option {
    transition: none;
  }
}
