/* ==========================================================================
   Agency Virtual Tour Builder — viewer.css
   Public + embed + preview viewer. Dark immersive stage, glass controls.
   ========================================================================== */

:root {
  --v-bg:    #0c0f14;
  --v-glass: rgba(18, 22, 30, .58);
  --v-glass-2: rgba(18, 22, 30, .82);
  --v-line:  rgba(255, 255, 255, .14);
  --v-ink:   #f3f5f8;
  --v-ink-soft: rgba(243, 245, 248, .66);
  --v-accent: #4d7cff;
  --v-active: #ff4d8d;
  --v-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }
.viewer-body {
  margin: 0; background: var(--v-bg); color: var(--v-ink);
  font-family: var(--v-font); overflow: hidden;
  height: 100dvh;
}

/* --- Empty / unavailable --------------------------------------------------- */
.viewer-empty { display: grid; place-items: center; height: 100dvh; padding: 24px; text-align: center; }
.viewer-empty h1 { margin: 0 0 8px; font-size: 1.4rem; }
.viewer-empty p { margin: 0; color: var(--v-ink-soft); }

/* --- Preview bar ----------------------------------------------------------- */
.preview-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50; height: 40px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 16px; background: var(--v-glass-2); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--v-line); font-size: .85rem; color: var(--v-ink-soft);
}
.preview-bar a { color: var(--v-ink); text-decoration: none; font-weight: 600; }
.preview-bar a:hover { text-decoration: underline; }
.mode-preview .viewer { height: calc(100dvh - 40px); margin-top: 40px; }

/* --- Shell layout ---------------------------------------------------------- */
.viewer { display: flex; height: 100dvh; width: 100%; }
.stage { position: relative; flex: 1 1 auto; min-width: 0; height: 100%; background: #000; }
.pano { position: absolute; inset: 0; }
.pano .pnlm-container { background: #000 !important; }

/* --- Stage overlay (title + controls) -------------------------------------- */
.stage-overlay {
  position: absolute; inset: 0; pointer-events: none; z-index: 10;
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 16px; gap: 12px;
}
.scene-title {
  pointer-events: none; max-width: 60%;
  background: var(--v-glass); backdrop-filter: blur(8px);
  border: 1px solid var(--v-line); border-radius: 10px;
  padding: 8px 14px; font-size: .98rem; font-weight: 600;
  opacity: 0; transform: translateY(-6px); transition: opacity .25s, transform .25s;
}
.scene-title.show { opacity: 1; transform: none; }
.stage-controls { display: flex; gap: 8px; pointer-events: auto; }
.ctl {
  width: 40px; height: 40px; display: grid; place-items: center;
  background: var(--v-glass); backdrop-filter: blur(8px);
  border: 1px solid var(--v-line); border-radius: 10px;
  color: var(--v-ink); cursor: pointer; transition: background .15s;
}
.ctl:hover { background: var(--v-glass-2); }

/* --- Branding -------------------------------------------------------------- */
.branding {
  position: absolute; left: 16px; bottom: 16px; z-index: 10;
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--v-glass); backdrop-filter: blur(8px);
  border: 1px solid var(--v-line); border-radius: 999px;
  padding: 6px 14px; font-size: .82rem; color: var(--v-ink-soft);
  text-decoration: none; pointer-events: auto;
}
.branding strong { color: var(--v-ink); font-weight: 700; }
.branding[href]:hover { color: var(--v-ink); }
.branding img { display: block; }

/* --- Floor panel ----------------------------------------------------------- */
.floorpanel {
  flex: 0 0 320px; width: 320px; height: 100%;
  background: #11151c; border-left: 1px solid var(--v-line);
  display: flex; flex-direction: column; transition: transform .28s ease;
}
.no-floorplan .floorpanel { display: none; }
.floortabs { display: flex; gap: 6px; padding: 10px 12px; overflow-x: auto; border-bottom: 1px solid var(--v-line); }
.floortabs.hidden { display: none !important; }
.floortab {
  flex: 0 0 auto; padding: 7px 14px; border-radius: 999px;
  background: transparent; border: 1px solid var(--v-line); color: var(--v-ink-soft);
  font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.floortab:hover { color: var(--v-ink); }
.floortab.active { background: var(--v-accent); border-color: var(--v-accent); color: #fff; }

.floorplan-wrap { flex: 1 1 auto; overflow: auto; padding: 14px; display: grid; place-items: center; align-content: center; position: relative; }
.floorplan { position: relative; display: inline-block; max-width: 100%; }
.floorplan img { display: block; max-width: 100%; height: auto; border-radius: 8px; }

/* pins on the floor plan — zero-size wrapper anchored at (x%,y%).
   Dot + label NEVER move; only .pin-aim (the cone) rotates around the centre. */
.pins { position: absolute; inset: 0; pointer-events: none; }
.pin {
  position: absolute; width: 0; height: 0;
  transform: translate(-50%, -50%);
  pointer-events: none; --pin: var(--v-accent);
}
.pin .pin-dot {
  position: absolute; left: 0; top: 0;
  width: 12px; height: 12px; border-radius: 50%;
  background: rgba(255,255,255,.9); border: 2px solid rgba(30,45,70,.55);
  box-shadow: 0 1px 3px rgba(0,0,0,.45);
  transform: translate(-50%, -50%); z-index: 3;
  pointer-events: auto; cursor: pointer;
  transition: width .15s, height .15s;
}
.pin:hover .pin-dot { width: 15px; height: 15px; }
.pin.is-active { z-index: 6; }
.pin.is-active .pin-dot {
  width: 18px; height: 18px;
  background: #2f6bff; border: 3px solid #fff;
  box-shadow: 0 0 0 2px rgba(47,107,255,.35), 0 2px 7px rgba(0,0,0,.45);
}
/* pulsing "radar" accuracy ring — separate layer so the dot stays crisp */
.pin.is-active .pin-dot::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 16px; height: 16px; border-radius: 50%;
  transform: translate(-50%, -50%);
  animation: pinpulse 1.8s ease-out infinite;
}
@keyframes pinpulse {
  0%   { box-shadow: 0 0 0 0 rgba(47,107,255,.45); }
  70%  { box-shadow: 0 0 0 15px rgba(47,107,255,0); }
  100% { box-shadow: 0 0 0 0 rgba(47,107,255,0); }
}
.pin .pin-tag {
  position: absolute; left: 0; top: 0;
  transform: translate(-50%, calc(-100% - 14px));
  max-width: 150px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; font-size: .72rem; font-weight: 600;
  background: rgba(0,0,0,.85); color: #fff; padding: 3px 8px; border-radius: 6px;
  pointer-events: none; opacity: 0; transition: opacity .15s; z-index: 4;
}
.pin.is-active .pin-tag, .pin:hover .pin-tag { opacity: 1; }

/* viewing-direction cone (tour: only the active pin, rotates live) */
.pin-aim {
  position: absolute; left: 0; top: 0; width: 0; height: 0;
  transform-origin: 0 0; transform: rotate(var(--ang, 0deg));
  pointer-events: none; z-index: 1;
}
.pin .pin-cone { display: none; }
.pin.is-active .pin-cone {
  display: block; position: absolute; left: 0; top: 0;
  width: 96px; height: 120px;
  transform: translate(-50%, -100%);
  background: radial-gradient(ellipse at 50% 100%,
    rgba(47,107,255,.55) 0%, rgba(47,107,255,.20) 45%, rgba(47,107,255,0) 78%);
  clip-path: polygon(50% 100%, 12% 0, 88% 0);
}

/* --- Mobile: floor panel becomes a bottom sheet ---------------------------- */
@media (max-width: 820px) {
  .viewer { flex-direction: column; }
  .floorpanel {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    width: 100%; height: 46dvh; flex-basis: auto;
    border-left: 0; border-top: 1px solid var(--v-line);
    border-radius: 16px 16px 0 0; transform: translateY(calc(100% - 0px));
    box-shadow: 0 -8px 30px rgba(0,0,0,.4);
  }
  .has-floorplan .floorpanel.open { transform: translateY(0); }
  .has-floorplan .floorpanel { transform: translateY(101%); }
  .floorpanel::before {
    content: ""; position: absolute; top: 7px; left: 50%; transform: translateX(-50%);
    width: 40px; height: 4px; border-radius: 2px; background: var(--v-line);
  }
  .floortabs { padding-top: 18px; }
  .floortabs.hidden + .floorplan-wrap, .floortabs.hidden ~ .floorplan-wrap { padding-top: 22px; }
  .pin .pin-tag { font-size: .66rem; max-width: 110px; }
}

@media (max-width: 480px) {
  /* Only the active pin keeps its label on very small screens. */
  .pin:not(.is-active) .pin-tag { display: none; }
}

/* Pannellum tweaks: keep its load/error UI readable on our dark bg */
.pnlm-load-box { background: var(--v-glass-2) !important; }
/* Hide the right-click attribution/version menu on the public/embed viewer. */
.pnlm-about-msg { display: none !important; }

/* Floor navigation pins (scene hotspots) — clean "step here" dots */
.pnlm-hotspot.avtb-nav {
  width: 34px; height: 34px; margin: -17px 0 0 -17px;
  background-image: none !important; border-radius: 50%;
  background: radial-gradient(circle at 50% 38%, rgba(255,255,255,.96), rgba(96,150,255,.9) 70%, rgba(64,110,230,.92));
  border: 2px solid #fff; box-shadow: 0 3px 10px rgba(0,0,0,.5);
  transition: transform .12s;
}
.pnlm-hotspot.avtb-nav::after {
  content: ""; position: absolute; left: 50%; top: 46%; width: 9px; height: 9px;
  border-right: 2.5px solid #2c4ea8; border-bottom: 2.5px solid #2c4ea8;
  transform: translate(-50%, -50%) rotate(45deg);
}
.pnlm-hotspot.avtb-nav:hover { transform: scale(1.1); }

/* --- Simple tour map (no-floor-plan navigation graph) ---------------------- */
.tourmap-panel { display: flex; flex-direction: column; }
.tourmap-head { padding: 12px 14px 6px; }
.tourmap-title { display: block; font-weight: 700; font-size: .95rem; color: var(--v-ink); }
.tourmap-note { display: block; font-size: .7rem; color: var(--v-ink-soft); margin-top: 1px; }
.tourmap-wrap { flex: 1 1 auto; display: grid; place-items: center; padding: 10px 14px 16px; min-height: 0; }
.tourmap-svg { width: 100%; height: 100%; max-height: 70vh; overflow: visible; }
.tm-edge { stroke: rgba(120, 150, 220, .55); stroke-width: .5; }
.tm-dot {
  fill: rgba(255, 255, 255, .85); stroke: rgba(20, 30, 50, .6); stroke-width: .5;
  transition: fill .15s;
}
.tm-node:hover .tm-dot { fill: #fff; }
.tm-node.is-active .tm-dot { fill: var(--v-accent); stroke: #fff; stroke-width: .8; }
.tm-label {
  fill: var(--v-ink); font-size: 3.1px; font-weight: 600;
  paint-order: stroke; stroke: rgba(12, 15, 20, .85); stroke-width: .8; stroke-linejoin: round;
}
.tm-node.is-active .tm-label { fill: #cfe0ff; }

/* --- Expand button + enlarged floor-plan overlay --------------------------- */
.floor-expand {
  position: absolute; top: 8px; right: 8px; z-index: 5;
  width: 34px; height: 34px; display: grid; place-items: center;
  background: var(--v-glass); backdrop-filter: blur(8px);
  border: 1px solid var(--v-line); border-radius: 8px; color: var(--v-ink);
  cursor: pointer; font-size: 16px; line-height: 1;
}
.floor-expand:hover { background: var(--v-glass-2); }

.floor-overlay {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(0,0,0,.75);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.floor-overlay.hidden { display: none; }
.floor-overlay-panel {
  background: #fff; color: #1c2331; border-radius: 14px;
  width: min(920px, 96vw); max-height: 92vh;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.floor-overlay-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid #e3e7ee; flex: 0 0 auto;
}
.floor-overlay-title { font-weight: 700; font-size: 1rem; }
.floor-overlay-close {
  width: 34px; height: 34px; border: 0; background: #f1f3f7; border-radius: 8px;
  font-size: 22px; line-height: 1; cursor: pointer; color: #5a6473;
}
.floor-overlay-close:hover { background: #e6e9ef; }
.floor-overlay-body {
  flex: 1 1 auto; overflow: auto; padding: 18px;
  display: grid; place-items: center; background: #fff;
  -webkit-overflow-scrolling: touch;
}
#floorplanLg { position: relative; display: inline-block; max-width: 100%; }
#floorplanLg img { display: block; max-width: 100%; height: auto; border-radius: 8px; }
/* Inactive dots on the white overlay need a touch more contrast. */
.floor-overlay-body .pin .pin-dot { border-color: rgba(30,45,70,.7); }

@media (max-width: 640px) {
  .floor-overlay { padding: 10px; }
  .floor-overlay-panel { width: 100vw; max-height: 96vh; border-radius: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .floorpanel, .scene-title, .pin .pin-dot { transition: none !important; }
  .pin.is-active .pin-dot { animation: none !important; }
}
