/* Spatial floor plan — SVG rooms + HTML door/presence overlays (Turbo-safe).
   Room fills/fonts use SVG presentation attributes; CSS here is secondary. */

.spatial-house {
  position: relative;
  width: 100%;
  overflow: hidden;
  border-radius: 1rem;
  border: 1px solid #cbd5e1;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.06);
  background:
    radial-gradient(ellipse at 20% 10%, rgba(251, 191, 36, 0.12), transparent 45%),
    radial-gradient(ellipse at 80% 90%, rgba(56, 189, 248, 0.1), transparent 40%),
    linear-gradient(165deg, #e8eef5 0%, #d5dde8 45%, #c8d0dc 100%);
  color: #0f172a;
  /* Fixed drawing board — overlays (%) share this box with the SVG. */
  height: min(70vh, 520px);
  min-height: 360px;
}

.spatial-house__backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  z-index: 0;
  opacity: 0.92;
  pointer-events: none;
}

.spatial-house--has-image {
  background: #0f172a;
}

.spatial-camera-pin__fov {
  fill: rgba(14, 165, 233, 0.18);
  stroke: rgba(2, 132, 199, 0.55);
  stroke-width: 0.25;
  pointer-events: none;
}

.spatial-camera-pin__dot {
  fill: #0284c7;
  stroke: #ffffff;
  stroke-width: 0.35;
}

.spatial-camera-pin__dot.is-draggable {
  cursor: grab;
}

.spatial-camera-pin__label {
  fill: #0f172a;
  font-size: 2.2px;
  font-weight: 700;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, 0.85);
  stroke-width: 0.35px;
  pointer-events: none;
}

.spatial-house__svg {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.spatial-house__canvas {
  /* grid pattern rect — tint via parent color */
}

.spatial-house__overlays {
  position: absolute;
  inset: 0;
  z-index: 2;
  /* Keep none so SVG pins/sketch receive events; re-enable only interactive children. */
  pointer-events: none;
}

.spatial-house--editable .spatial-door {
  pointer-events: auto;
}

/* Draw mode: SVG is the hit target; doors temporarily ignore so strokes aren't stolen. */
.is-sketch-draw .spatial-house {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
  cursor: crosshair;
}

.is-sketch-draw .spatial-door,
.is-sketch-draw .spatial-camera-pin,
.is-sketch-draw .spatial-vert-handle {
  pointer-events: none !important;
}

.is-sketch-draw .spatial-house__svg {
  z-index: 4;
  pointer-events: auto;
  touch-action: none;
}

.spatial-room-label {
  position: absolute;
  transform: translate(-50%, -50%);
  z-index: 3;
  pointer-events: none;
  text-align: center;
  max-width: 28%;
  padding: 0.15rem 0.35rem;
  border-radius: 0.35rem;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.spatial-room-label__name {
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.15;
  color: #0f172a;
}

.spatial-room-label__meta {
  margin-top: 0.1rem;
  font-size: 0.6rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #64748b;
}

.spatial-door {
  position: absolute;
  z-index: 5;
  width: max-content;
  min-width: 2.75rem;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: auto;
}

.spatial-door__leaf {
  flex-shrink: 0;
  width: 1.35rem;
  height: 2rem;
  border: 2px solid #0f172a;
  border-radius: 2px 6px 6px 2px;
  background: linear-gradient(135deg, #92400e, #b45309 55%, #d97706);
  transform-origin: left center;
  transition: transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
  box-shadow: 2px 2px 0 rgba(15, 23, 42, 0.2);
}

.spatial-door--open .spatial-door__leaf {
  transform: rotate(-72deg);
  background: linear-gradient(135deg, #047857, #059669 55%, #34d399);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.35);
}

.spatial-door__label {
  margin-top: 0.15rem;
  max-width: 7.5rem;
  font-size: 11px;
  line-height: 1.1;
  text-align: center;
  color: #0f172a;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 999px;
  padding: 0.12rem 0.4rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
}

.spatial-door--selectable {
  cursor: pointer;
}

.spatial-door--selectable:hover .spatial-door__leaf,
.spatial-door--selected .spatial-door__leaf {
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.45);
}

.spatial-door--selected .spatial-door__label {
  background: #1d4ed8;
  color: #f8fafc;
}

.spatial-door__pulse {
  position: absolute;
  top: -0.55rem;
  right: -0.35rem;
  font-size: 0.55rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #065f46;
  background: #a7f3d0;
  border-radius: 999px;
  padding: 0.1rem 0.35rem;
  animation: spatial-door-pulse 0.9s ease-in-out infinite alternate;
}

@keyframes spatial-door-pulse {
  from { transform: scale(1); opacity: 1; }
  to { transform: scale(1.08); opacity: 0.75; }
}

.spatial-presence-marker {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  z-index: 4;
}

.spatial-presence-marker__dot {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 999px;
  background: #0f172a;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.35);
}

.spatial-presence-marker__label {
  margin-top: 0.15rem;
  font-size: 0.65rem;
  color: #0f172a;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 3px;
  padding: 0.05rem 0.3rem;
  white-space: nowrap;
}

.spatial-unlock-toast {
  border-radius: 0.5rem;
  border: 1px solid #a7f3d0;
  background: #ecfdf5;
  color: #065f46;
  padding: 0.45rem 0.65rem;
  font-size: 0.8rem;
  transition: opacity 0.6s ease;
}

.spatial-unlock-toast--fade {
  opacity: 0.35;
}

.spatial-house--editable .spatial-door {
  cursor: grab;
}

.spatial-house--editable .spatial-door:active {
  cursor: grabbing;
}

.spatial-vert-handle {
  cursor: grab;
  pointer-events: all;
}

.spatial-vert-handle:active,
.spatial-vert-handle.is-dragging {
  cursor: grabbing;
}

.spatial-layout-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.spatial-mode-toggle {
  display: inline-flex;
  border: 1px solid #cbd5e1;
  border-radius: 0.4rem;
  overflow: hidden;
}

.spatial-mode-btn {
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
  background: #fff;
  color: #475569;
}

.spatial-mode-btn.is-active {
  background: #0f172a;
  color: #fff;
}

.spatial-mode-btn[data-spatial-sketch-target="modeDraw"].is-active {
  background: #2563eb;
}

.spatial-house__sketch {
  pointer-events: none;
}

.is-sketch-draw .spatial-house__sketch {
  pointer-events: stroke;
}

.spatial-sketch-stroke.is-preview {
  stroke-dasharray: 1.2 0.8;
}

.spatial-layout-status {
  font-size: 0.75rem;
  color: #64748b;
}

/* Live person dots + journey trails (homography projection) */
.spatial-live-trails {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

.spatial-live-trail {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.spatial-live-dots {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 6;
}

.spatial-live-dot {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  transition: left 0.45s ease, top 0.45s ease, opacity 0.35s ease;
  pointer-events: auto;
}

.spatial-live-dot.is-stale {
  opacity: 0;
}

.spatial-live-dot__pulse {
  position: absolute;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.25;
  animation: spatial-live-pulse 1.6s ease-out infinite;
}

.spatial-live-dot__core {
  position: relative;
  min-width: 1.5rem;
  height: 1.5rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: currentColor;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1.5rem;
  text-align: center;
  box-shadow: 0 1px 3px rgb(15 23 42 / 0.35);
}

.spatial-live-dot__zone {
  font-size: 0.6rem;
  font-weight: 600;
  color: #0f172a;
  background: rgb(255 255 255 / 0.9);
  border: 1px solid rgb(148 163 184 / 0.6);
  border-radius: 0.25rem;
  padding: 0.05rem 0.3rem;
  white-space: nowrap;
}

.spatial-live-dot.is-household { color: #059669; }
.spatial-live-dot.is-unknown { color: #d97706; }
.spatial-live-dot.is-restricted { color: #dc2626; }

@keyframes spatial-live-pulse {
  0% { transform: scale(0.7); opacity: 0.4; }
  70% { transform: scale(1.5); opacity: 0; }
  100% { transform: scale(1.5); opacity: 0; }
}

/* Homography calibration drawer */
.spatial-cal-drawer {
  margin-top: 1rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.75rem;
  background: #fff;
  padding: 1rem;
}

.spatial-cal-drawer__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.spatial-cal-drawer__status {
  margin: 0.5rem 0 0.75rem;
  font-size: 0.75rem;
  color: #64748b;
}

.spatial-cal-frames {
  margin: 0.5rem 0 0.75rem;
}

.spatial-cal-frames__row {
  display: flex;
  gap: 0.45rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
}

.spatial-cal-frame {
  flex: 0 0 auto;
  width: 5.5rem;
  border: 1px solid #cbd5e1;
  border-radius: 0.4rem;
  background: #0f172a;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
}

.spatial-cal-frame img {
  display: block;
  width: 100%;
  height: 3.2rem;
  object-fit: cover;
}

.spatial-cal-frame span {
  display: block;
  font-size: 0.6rem;
  color: #e2e8f0;
  padding: 0.15rem 0.25rem;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.spatial-cal-frame.is-active {
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgb(37 99 235 / 0.35);
}

.spatial-cal-drawer__grid {
  display: grid;
  gap: 0.75rem;
}

@media (min-width: 768px) {
  .spatial-cal-drawer__grid {
    grid-template-columns: 1fr 1fr;
  }
}

.spatial-cal-pane {
  position: relative;
  aspect-ratio: 4 / 3;
  border: 1px dashed #94a3b8;
  border-radius: 0.5rem;
  background: #0f172a;
  overflow: hidden;
  cursor: crosshair;
}

.spatial-cal-pane--floor {
  background:
    var(--cal-floor-img, none) center / contain no-repeat,
    repeating-linear-gradient(0deg, transparent, transparent 9px, #e2e8f0 10px),
    repeating-linear-gradient(90deg, transparent, transparent 9px, #e2e8f0 10px),
    #f8fafc;
}

.spatial-cal-pane__img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.spatial-cal-pane__placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  text-align: center;
  font-size: 0.7rem;
  color: #94a3b8;
  pointer-events: none;
}

.spatial-cal-pane:has(img[src]) .spatial-cal-pane__placeholder {
  display: none;
}

.spatial-cal-marker {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 999px;
  background: #2563eb;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  border: 2px solid #fff;
  z-index: 2;
  pointer-events: none;
}

.spatial-cal-preview-dot {
  position: absolute;
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 999px;
  background: #059669;
  border: 2px solid #fff;
  transform: translate(-50%, -50%);
  z-index: 3;
  pointer-events: none;
  box-shadow: 0 0 0 3px rgb(5 150 105 / 0.35);
}

.spatial-cal-drawer__actions {
  margin-top: 0.75rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.spatial-cal-badge {
  font-size: 0.65rem;
  font-weight: 600;
  color: #b45309;
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-radius: 0.25rem;
  padding: 0.1rem 0.35rem;
}

.spatial-cal-badge.is-calibrated {
  color: #047857;
  background: #ecfdf5;
  border-color: #6ee7b7;
}

.spatial-edge-status {
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.6rem;
  padding: 0.1rem 0.35rem;
  border-radius: 0.25rem;
}

.spatial-edge-status--online {
  color: #047857;
  background: #ecfdf5;
}

.spatial-edge-status--reconnecting,
.spatial-edge-status--stale {
  color: #b45309;
  background: #fffbeb;
}

.spatial-edge-status--offline,
.spatial-edge-status--starting {
  color: #64748b;
  background: #f1f5f9;
}
