/* =============================================================
   Interactive 3D Tour Viewer (consumer side).
   Opens as a fullscreen `.modal-overlay` with three internal views:
     .tv-view-plan / .tv-view-room / .tv-view-pano
   ============================================================= */

.tv-modal {
  position: fixed; inset: 0;
  display: none;
  background: rgba(15, 23, 42, 0.95);
  z-index: 1900;
  flex-direction: column;
}
.tv-modal.show { display: flex; }
/* The viewer is full-bleed: neutralise the shared `.modal-overlay` centering
   (align-items/justify-content: center + padding) which would otherwise collapse
   the flex-column `.tv-stage` to zero width and hide the whole tour. */
.tv-modal.modal-overlay {
  align-items: stretch;
  justify-content: flex-start;
  padding: 0;
}

.tv-topbar {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  gap: var(--ds-space-3);
  padding: var(--ds-space-3) var(--ds-space-4);
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(8px);
  color: white;
  z-index: 2;
}
.tv-back, .tv-close {
  width: 44px; height: 44px;
  border: 0; background: rgba(255,255,255,0.1);
  color: white;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: var(--ds-fast);
}
.tv-back:hover, .tv-close:hover { background: rgba(255,255,255,0.2); }
.tv-modal:not(.tv-view-room):not(.tv-view-pano) .tv-back { visibility: hidden; }
.tv-title { text-align: center; min-width: 0; }
.tv-title h2 {
  margin: 0;
  font-size: var(--ds-text-base);
  font-weight: var(--ds-weight-bold);
  color: white;
}
.tv-subtitle {
  display: block;
  font-size: var(--ds-text-xs);
  color: rgba(255,255,255,0.7);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ─── stage holds the Konva canvas + pannellum frame ─────────── */
.tv-stage {
  position: relative;
  flex: 1;
  overflow: hidden;
  background: radial-gradient(ellipse at center, #1a2640 0%, #0f1729 100%);
}
.tv-konva {
  position: absolute; inset: 0;
  transform-origin: center center;
  transition: transform 600ms cubic-bezier(0.16, 1, 0.3, 1),
              opacity 400ms ease;
}
.tv-modal.tv-view-pano .tv-konva { opacity: 0; pointer-events: none; }

.tv-pano-frame {
  position: absolute; inset: 0;
  z-index: 3;
  background: #000;
}
.tv-pano { position: absolute; inset: 0; }

/* ─── room panel (slide-up on .tv-view-room) ─────────────────── */
.tv-room-panel {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: var(--ds-surface);
  border-top-left-radius: var(--ds-radius-xl);
  border-top-right-radius: var(--ds-radius-xl);
  box-shadow: 0 -16px 48px rgba(0,0,0,0.4);
  padding: var(--ds-space-4);
  transform: translateY(100%);
  transition: transform 500ms cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 4;
  max-height: 60vh;
  display: flex;
  flex-direction: column;
}
.tv-modal.tv-view-room .tv-room-panel { transform: translateY(0); }

.tv-room-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--ds-space-3);
  margin-bottom: var(--ds-space-3);
}
.tv-room-head h3 {
  margin: 0; font-size: var(--ds-text-xl);
  font-weight: var(--ds-weight-bold);
  color: var(--ds-ink-2);
}
.tv-room-meta { font-size: var(--ds-text-sm); color: var(--ds-muted); }
.tv-room-nav { display: flex; gap: var(--ds-space-2); }
.tv-room-nav button {
  width: 40px; height: 40px;
  border: 1px solid var(--ds-line);
  background: var(--ds-surface-2);
  color: var(--ds-ink-2);
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: var(--ds-fast);
}
.tv-room-nav button:hover { background: var(--ds-brand-50); border-color: var(--ds-brand); color: var(--ds-brand); }

/* ─── photo carousel ─────────────────────────────────────────── */
.tv-photo-carousel {
  display: flex;
  gap: var(--ds-space-3);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  padding-bottom: var(--ds-space-3);
}
.tv-photo-card {
  flex: 0 0 auto;
  width: clamp(220px, 70vw, 360px);
  aspect-ratio: 4 / 3;
  border-radius: var(--ds-radius-lg);
  overflow: hidden;
  background: var(--ds-surface-2);
  scroll-snap-align: center;
  cursor: pointer;
  position: relative;
  border: 1px solid var(--ds-line);
}
.tv-photo-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tv-photo-card.is-pano::after {
  content: '۳۶۰°';
  position: absolute; top: 8px; left: 8px;
  background: rgba(0,0,0,0.65); color: white;
  font-size: var(--ds-text-xs); padding: 4px 10px;
  border-radius: var(--ds-radius-pill);
  font-weight: var(--ds-weight-semi);
}
.tv-photo-card .tv-pano-cta {
  position: absolute; right: 8px; bottom: 8px;
  background: var(--ds-brand); color: white;
  font-size: var(--ds-text-xs); padding: 6px 12px;
  border-radius: var(--ds-radius-pill);
  display: inline-flex; align-items: center; gap: 4px;
  pointer-events: none;
}

.tv-room-foot {
  font-size: var(--ds-text-xs);
  color: var(--ds-muted);
  text-align: center;
}

/* ─── floor-plan view zoom-in transitions ────────────────────── */
.tv-modal.tv-view-room .tv-konva { transform: scale(1.6); opacity: 0.35; }

/* ─── mini-map button (visible during room view) ─────────────── */
.tv-mini-map {
  position: absolute;
  top: 88px; right: var(--ds-space-4);
  background: rgba(255,255,255,0.95);
  color: var(--ds-ink-2);
  border: 0;
  border-radius: var(--ds-radius-pill);
  padding: 10px 16px;
  font-size: var(--ds-text-sm);
  font-family: inherit;
  display: inline-flex; align-items: center; gap: 6px;
  cursor: pointer;
  box-shadow: var(--ds-shadow-md);
  z-index: 5;
}
.tv-modal:not(.tv-view-room) .tv-mini-map { display: none; }

/* ─── empty / fallback (no rooms but tour_3d_url) ────────────── */
.tv-empty {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; height: 100%;
  color: rgba(255,255,255,0.7); gap: var(--ds-space-3);
  text-align: center; padding: var(--ds-space-6);
}
.tv-empty i { font-size: 3rem; color: var(--ds-brand); }

/* ─── responsive ─────────────────────────────────────────────── */
@media (max-width: 600px) {
  .tv-room-panel { padding: var(--ds-space-3); max-height: 70vh; }
  .tv-room-head h3 { font-size: var(--ds-text-lg); }
  .tv-photo-card { width: 78vw; }
  .tv-mini-map { padding: 8px 12px; font-size: var(--ds-text-xs); }
}
