/* ===== 3D ISOMETRIC BUILDING VIEW ===== */

.building-container {
  perspective: 1600px;
  display: flex;
  justify-content: center;
  padding: 50px 20px 300px; /* Large bottom padding to accommodate the Z-axis tower */
  overflow: visible;
  min-height: 600px; /* Fixed height for Z stack spacing */
}

.building-wrapper {
  transform-style: preserve-3d;
  transform: rotateX(55deg) rotateZ(-45deg);
  position: relative;
  width: 480px; /* Base footprint width */
  height: 180px; /* Base footprint height */
  margin: 50px auto 0;
  transition: transform 0.5s ease;
}

/* Floor plate stack using absolute layout and Z-translation */
.iso-floor {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  transform-style: preserve-3d;
  transition: transform 0.4s cubic-bezier(0.25, 1, 0.5, 1), opacity 0.3s ease;
}

/* Vertical translation offsets */
.iso-floor.floor-ground  { --z: 0px;   --hover-z: 20px;  transform: translate3d(0, 0, var(--z)); }
.iso-floor.floor-1       { --z: 55px;  --hover-z: 75px;  transform: translate3d(0, 0, var(--z)); }
.iso-floor.floor-2       { --z: 110px; --hover-z: 130px; transform: translate3d(0, 0, var(--z)); }
.iso-floor.floor-3       { --z: 165px; --hover-z: 185px; transform: translate3d(0, 0, var(--z)); }
.iso-floor.floor-4       { --z: 220px; --hover-z: 240px; transform: translate3d(0, 0, var(--z)); }
.iso-floor.floor-5       { --z: 275px; --hover-z: 295px; transform: translate3d(0, 0, var(--z)); }
.iso-floor.floor-6       { --z: 330px; --hover-z: 350px; transform: translate3d(0, 0, var(--z)); }
.iso-floor.floor-rooftop { --z: 385px; --hover-z: 405px; transform: translate3d(0, 0, var(--z)); }

.iso-floor:hover {
  transform: translate3d(0, 0, var(--hover-z)) scale(1.02);
  z-index: 100;
}

/* filtered single floor reset */
.building-wrapper.single-floor .iso-floor {
  transform: translate3d(0, 0, 0px) !important;
}

/* Floor plate base */
.floor-plate {
  background: linear-gradient(135deg, #e8ecf1 0%, #d5dbe3 100%);
  border: 1px solid #c0c8d2;
  border-radius: 6px;
  padding: 12px;
  position: relative;
  box-shadow: 
    4px 4px 0 #b8c0cc,
    8px 8px 0 #a8b0bc,
    0 12px 24px rgba(0,0,0,0.1);
  min-height: 60px;
  transform-style: preserve-3d;
}

/* Floor label */
.floor-plate::before {
  content: attr(data-floor-label);
  position: absolute;
  left: -85px; top: 50%;
  transform: translateY(-50%) rotateZ(45deg);
  font-family: 'Poppins', sans-serif;
  font-size: 11px; font-weight: 700;
  color: var(--midnight);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Room count badge on floor label */
.floor-plate::after {
  content: attr(data-room-count);
  position: absolute;
  left: -40px; top: calc(50% + 16px);
  transform: translateY(-50%) rotateZ(45deg);
  font-size: 9px; font-weight: 600;
  color: #888;
  white-space: nowrap;
}

/* Room grid inside floor */
.iso-room-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Individual room block */
.iso-room {
  width: 52px; height: 42px;
  border-radius: 5px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
  border: 2px solid transparent;
  transform-style: preserve-3d;
}
.iso-room:hover {
  transform: translateY(-8px) scale(1.08);
  z-index: 20;
  box-shadow: 0 8px 20px rgba(0,0,0,0.25);
}

/* Room label */
.iso-room-id {
  font-family: 'Poppins', sans-serif;
  font-size: 10px; font-weight: 700;
  color: white;
  text-shadow: 0 1px 2px rgba(0,0,0,0.2);
  line-height: 1;
}
.iso-room-type {
  font-size: 7px; font-weight: 500;
  color: rgba(255,255,255,0.75);
  margin-top: 2px;
}

/* Status colors */
.iso-room.occupied {
  background: linear-gradient(135deg, #27AE60 0%, #2ECC71 100%);
  border-color: #1E8449;
  box-shadow: 0 3px 8px rgba(39,174,96,0.3);
}
.iso-room.vacant {
  background: linear-gradient(135deg, #3B82F6 0%, #60A5FA 100%);
  border-color: #2563EB;
  box-shadow: 0 3px 8px rgba(59,130,246,0.3);
}
.iso-room.reserved {
  background: linear-gradient(135deg, #F4B400 0%, #FFCA28 100%);
  border-color: #D4A00A;
  box-shadow: 0 3px 8px rgba(244,180,0,0.3);
}
.iso-room.reserved .iso-room-id { color: #333; text-shadow: none; }
.iso-room.reserved .iso-room-type { color: rgba(0,0,0,0.5); }

.iso-room.maintenance {
  background: linear-gradient(135deg, #9E9E9E 0%, #BDBDBD 100%);
  border-color: #757575;
  box-shadow: 0 3px 8px rgba(158,158,158,0.3);
}
.iso-room.partial {
  background: linear-gradient(135deg, #27AE60 0%, #F4B400 100%);
  border-color: #1E8449;
  box-shadow: 0 3px 8px rgba(39,174,96,0.3);
}

/* Occupancy dot */
.iso-room-dot {
  position: absolute; top: 3px; right: 3px;
  width: 6px; height: 6px; border-radius: 50%;
  background: white;
  border: 1px solid rgba(0,0,0,0.15);
}

/* Ground floor — special styling */
.iso-floor.ground .floor-plate {
  background: linear-gradient(135deg, #d5c4a1 0%, #c4b896 100%);
  border-color: #b0a580;
  box-shadow: 4px 4px 0 #a09470, 8px 8px 0 #908460, 0 12px 24px rgba(0,0,0,0.15);
}
.ground-area {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 8px;
  font-size: 10px; font-weight: 600;
  color: #5a4e35;
}
.ground-icon { font-size: 18px; }

/* Rooftop — special styling */
.iso-floor.rooftop .floor-plate {
  background: linear-gradient(135deg, #b8e0d2 0%, #a0d2c1 100%);
  border-color: #7bc0a8;
  box-shadow: 4px 4px 0 #6ab09a, 8px 8px 0 #5aa08a, 0 12px 24px rgba(0,0,0,0.1);
  min-height: 45px;
}
.rooftop-area {
  display: flex; align-items: center; gap: 8px;
  padding: 2px 8px;
  font-size: 10px; font-weight: 600;
  color: #2c6e55;
}

/* Terrace indicator on 6th floor */
.terrace-area {
  background: rgba(0,184,148,0.15);
  border: 1px dashed var(--emerald);
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 9px; font-weight: 600;
  color: var(--emerald);
  display: inline-flex; align-items: center; gap: 4px;
}

/* 2BHK Flat indicator (Floor 1 & 2) */
.flat-container {
  background: rgba(18,52,88,0.06);
  border: 1px solid rgba(18,52,88,0.12);
  border-radius: 6px;
  padding: 6px;
  display: flex;
  gap: 6px;
  position: relative;
}
.flat-container::before {
  content: attr(data-flat-label);
  position: absolute;
  top: -8px; left: 8px;
  background: white;
  padding: 0 4px;
  font-size: 7px; font-weight: 700;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
[data-theme="dark"] .flat-container::before { background: #1a1d27; color: #6b6f80; }

/* Hover popover for building view */
.building-popover {
  position: fixed; z-index: 1000;
  background: white;
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.2);
  padding: 0;
  min-width: 280px;
  max-width: 320px;
  border: 1px solid #eee;
  animation: pop-in 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: auto;
}
@keyframes pop-in {
  0%   { opacity: 0; transform: scale(0.9) translateY(8px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

.building-popover-header {
  padding: 14px 18px;
  border-bottom: 1px solid #f0f0f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.building-popover-header h4 {
  font-family: 'Poppins', sans-serif;
  font-size: 15px; font-weight: 700;
  color: var(--midnight);
}
.building-popover-body {
  padding: 14px 18px;
}
.popover-info-row {
  display: flex; justify-content: space-between;
  align-items: center;
  padding: 5px 0;
  font-size: 12px;
  border-bottom: 1px solid #f7f7f7;
}
.popover-info-row:last-child { border-bottom: none; }
.popover-info-label { color: #888; font-weight: 500; }
.popover-info-value { color: #333; font-weight: 600; }

.popover-tenant-card {
  background: #f8f9fb;
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 8px;
}
.popover-tenant-name {
  font-size: 13px; font-weight: 600; color: var(--midnight);
}
.popover-tenant-sub {
  font-size: 11px; color: #888; margin-top: 2px;
}
.popover-actions {
  display: flex; gap: 6px;
  padding: 12px 18px;
  border-top: 1px solid #f0f0f0;
}

/* Dark mode for building */
[data-theme="dark"] .floor-plate {
  background: linear-gradient(135deg, #1a1d27 0%, #22252f 100%);
  border-color: #2d3140;
  box-shadow: 4px 4px 0 #12141c, 8px 8px 0 #0a0d14, 0 12px 24px rgba(0,0,0,0.3);
}
[data-theme="dark"] .floor-plate::before { color: #7eb8ff; }
[data-theme="dark"] .floor-plate::after { color: #6b6f80; }

[data-theme="dark"] .iso-floor.ground .floor-plate {
  background: linear-gradient(135deg, #2a2520 0%, #33302a 100%);
  border-color: #4a4540;
  box-shadow: 4px 4px 0 #1a1815, 8px 8px 0 #100f0d, 0 12px 24px rgba(0,0,0,0.3);
}
[data-theme="dark"] .ground-area { color: #c4b896; }

[data-theme="dark"] .iso-floor.rooftop .floor-plate {
  background: linear-gradient(135deg, #152a24 0%, #1a332c 100%);
  border-color: #2a4a40;
  box-shadow: 4px 4px 0 #0d1f1a, 8px 8px 0 #091510, 0 12px 24px rgba(0,0,0,0.3);
}
[data-theme="dark"] .rooftop-area { color: #5ae8c5; }

[data-theme="dark"] .building-popover {
  background: #1a1d27; border-color: #2d3140;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
[data-theme="dark"] .building-popover-header { border-bottom-color: #2d3140; }
[data-theme="dark"] .building-popover-header h4 { color: #e4e6ef; }
[data-theme="dark"] .popover-info-row { border-bottom-color: #22252f; }
[data-theme="dark"] .popover-info-label { color: #6b6f80; }
[data-theme="dark"] .popover-info-value { color: #d0d3e0; }
[data-theme="dark"] .popover-tenant-card { background: #22252f; }
[data-theme="dark"] .popover-tenant-name { color: #e4e6ef; }
[data-theme="dark"] .popover-actions { border-top-color: #2d3140; }
[data-theme="dark"] .flat-container {
  background: rgba(255,255,255,.03);
  border-color: rgba(255,255,255,.08);
}
[data-theme="dark"] .terrace-area {
  background: rgba(0,184,148,0.08);
  border-color: rgba(0,184,148,0.3);
}

/* Iso room hover glow in dark mode */
[data-theme="dark"] .iso-room.occupied:hover { box-shadow: 0 8px 24px rgba(39,174,96,0.4); }
[data-theme="dark"] .iso-room.vacant:hover   { box-shadow: 0 8px 24px rgba(59,130,246,0.4); }
[data-theme="dark"] .iso-room.reserved:hover  { box-shadow: 0 8px 24px rgba(244,180,0,0.4); }

/* Building legend */
.building-legend {
  display: flex; gap: 20px; flex-wrap: wrap;
  padding: 16px 0;
  margin-bottom: 20px;
  border-bottom: 1px solid #eee;
}
[data-theme="dark"] .building-legend { border-bottom-color: #2d3140; }

.building-legend-item {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 500; color: #666;
}
[data-theme="dark"] .building-legend-item { color: #8b8fa3; }

.building-legend-dot {
  width: 14px; height: 14px; border-radius: 4px;
}

/* Building stats sidebar */
.building-stats {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 12px; margin-bottom: 24px;
}
.building-stat {
  text-align: center;
  padding: 14px 10px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
[data-theme="dark"] .building-stat { background: #1a1d27; }

.building-stat-val {
  font-family: 'Poppins', sans-serif;
  font-size: 24px; font-weight: 800;
}
.building-stat-label {
  font-size: 11px; color: #888; margin-top: 4px; font-weight: 500;
}

/* Floor filter toggle */
.floor-filter {
  display: flex; gap: 6px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.floor-filter-btn {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1.5px solid #eee;
  background: white;
  font-size: 11px; font-weight: 600;
  color: #666; cursor: pointer;
  transition: all 0.2s;
}
.floor-filter-btn:hover { border-color: var(--emerald); color: var(--emerald); }
.floor-filter-btn.active {
  background: var(--emerald); color: white; border-color: var(--emerald);
}
[data-theme="dark"] .floor-filter-btn {
  background: #1a1d27; border-color: #2d3140; color: #8b8fa3;
}
[data-theme="dark"] .floor-filter-btn.active {
  background: var(--emerald); color: white;
}

/* Responsive */
@media (max-width: 768px) {
  .building-container {
    padding: 20px 10px;
    min-height: auto;
  }
  .building-wrapper {
    transform: none !important; /* Disable 3D on mobile */
    position: relative !important;
    width: auto !important;
    height: auto !important;
    margin: 0 !important;
  }
  .iso-floor {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    width: 100% !important;
    transform: none !important;
    margin-bottom: 12px;
  }
  .floor-plate {
    box-shadow: var(--shadow-sm);
  }
  .floor-plate::before,
  .floor-plate::after { display: none; }
  .iso-room { width: 48px; height: 38px; }
  .building-stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .iso-room { width: 42px; height: 34px; }
  .iso-room-id { font-size: 9px; }
}

/* ===== FLAT VIEW & INLINE FLOOR HEADER STYLING ===== */
.building-wrapper.flat-view {
  transform: none !important;
  width: auto !important;
  height: auto !important;
  margin: 0 !important;
  perspective: none !important;
}

.building-wrapper.flat-view .iso-floor {
  position: relative !important;
  top: auto !important;
  left: auto !important;
  width: 100% !important;
  transform: none !important;
  margin-bottom: 20px !important;
}

.building-wrapper.flat-view .floor-plate {
  box-shadow: var(--shadow-sm);
  background: white;
  border-color: #eee;
  padding: 16px;
}

.building-wrapper.flat-view .floor-plate::before,
.building-wrapper.flat-view .floor-plate::after {
  display: none !important;
}

/* Inline floor headers are hidden in 3D view, visible in flat view */
.floor-header-inline {
  display: none;
  font-family: 'Poppins', sans-serif;
  font-size: 14px;
  font-weight: 700;
  color: var(--midnight);
  margin-bottom: 12px;
  border-bottom: 1.5px solid var(--light-grey);
  padding-bottom: 6px;
  text-align: left;
}

[data-theme="dark"] .floor-header-inline {
  color: #e4e6ef;
  border-bottom-color: #2d3140;
}

.building-wrapper.flat-view .floor-header-inline {
  display: block !important;
}

@media (max-width: 768px) {
  .floor-header-inline {
    display: block !important; /* Show inline headers on mobile by default */
  }
}

/* ===== MOBILE BOTTOM SHEET & POPOVER BACKDROP FIXES ===== */
.popover-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(18, 52, 88, 0.4);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 998;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  display: none;
}
.popover-backdrop.show {
  opacity: 1;
  pointer-events: all;
}

@media (max-width: 576px) {
  .popover-backdrop {
    display: block;
  }

  .room-popover,
  .building-popover {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 100% !important;
    border-radius: 20px 20px 0 0 !important;
    border: none !important;
    box-shadow: 0 -8px 30px rgba(0,0,0,0.2) !important;
    transform: translateY(100%) !important;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1) !important;
    animation: none !important;
    z-index: 999 !important;
    margin: 0 !important;
    /* top padding leaves room for the drag handle */
    padding: 28px 20px 40px 20px !important;
    background: white !important;
    display: block !important;
    max-height: 80vh !important;
    overflow-y: auto !important;
    /* drag handle indicator */
    --handle-color: #ddd;
  }

  /* Drag handle pill */
  .room-popover::before,
  .building-popover::before {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: var(--handle-color);
    margin: -16px auto 16px;
  }

  .room-popover.show,
  .building-popover.show {
    transform: translateY(0) !important;
  }

  /* Touch-friendly close button inside popovers */
  .room-popover .modal-close,
  .building-popover .modal-close {
    width: 32px !important;
    height: 32px !important;
    font-size: 16px !important;
    border-radius: 8px !important;
  }

  [data-theme="dark"] .room-popover,
  [data-theme="dark"] .building-popover {
    background: #1a1d27 !important;
    border: none !important;
    --handle-color: #3a3d4a;
  }
}


