/* ===== General Formatting ===== */
html {
  overflow: hidden;
  height: 100%;
}
body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  height: 100%;
}
div {
  margin: 0;
  padding: 0;
}

/* ===== Sidebar ===== */
.main-row {
  padding: 0;
}
.sidebar {
  padding: 20px;
  overflow-x: hidden;
  overflow-y: auto;
  border-right: 1px solid #eee;
}
.nav-sidebar {
  margin-right: -21px;
  margin-bottom: 20px;
  margin-left: -20px;
}
.nav-sidebar > li > a {
  padding-right: 20px;
  padding-left: 20px;
}
.nav-sidebar > .active > a,
.nav-sidebar > .active > a:hover,
.nav-sidebar > .active > a:focus {
  color: #fff;
  background-color: #428bca;
}

/* ===== Main content ===== */
.main {
  padding: 0;
}

/* ===== Loading modal ===== */
#loading-modal {
  position: absolute;
  z-index: 10;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  padding: 20px;
  background-color: rgba(50, 50, 50, 0.9);
  display: none;
}
#loading-modal h1 {
  text-align: center;
  margin-top: 30%;
  color: #fff;
}

/* ===== Initial tab visibility ===== */
#viewer {
  display: none;
}
#floorplanner {
  display: block;
}
#add-items {
  display: none;
  padding: 20px;
  overflow-y: auto;
}

/* ===== Mobile Touch Support ===== */
#floorplanner-canvas {
  touch-action: none; /* Prevent default touch behaviors like scrolling and zooming */
  -webkit-touch-callout: none; /* Disable callout on long-press */
  -webkit-user-select: none; /* Disable text selection */
  user-select: none;
}

/* ===== Overlay controls ===== */
#main-controls {
  position: absolute;
  top: 20px;
  left: 20px;
  padding: 0;
}
#camera-controls {
  position: absolute;
  bottom: 20px;
  right: 0;
  padding: 0 20px;
  text-align: right;
}

#floorplanner-controls {
  position: absolute;
  left: 0;
  top: 0;
  margin: 20px 0;
  padding: 0 20px;
  width: 100%;
}

#draw-walls-hint {
  position: absolute;
  left: 20px;
  bottom: 20px;
  background-color: rgba(0, 0, 0, 0.5);
  color: #fff;
  padding: 5px 10px;
  z-index: 10;
  display: none;
}

/* File input styling & cards */
.add-item {
  cursor: pointer;
  transition: all 0.3s ease !important;
  border-radius: 8px !important;
  overflow: hidden;
  background: #fff;
  position: relative;
  display: block;
  pointer-events: auto;
}
.btn-file {
  display: inline-block;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.btn-file input[type="file"] {
  position: absolute;
  top: 0;
  right: 0;
  min-width: 100%;
  min-height: 100%;
  opacity: 0;
  cursor: inherit;
  display: block;
}
.add-item:hover {
  transform: translateY(-5px) scale(1.02) !important;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15) !important;
  border-color: #337ab7 !important;
  text-decoration: none !important;
}
.add-item img {
  transition: all 0.3s ease;
  border-radius: 4px;
  pointer-events: none; /* Prevent image from capturing clicks */
  user-select: none;
}
.add-item:hover img {
  transform: scale(1.1);
}
/* Ensure all child elements don't capture clicks */
.add-item * {
  pointer-events: none;
  user-select: none;
}

/* Do not block drags except on buttons */
#camera-controls,
#main-controls {
  pointer-events: none;
}
#camera-controls .btn,
#main-controls .btn {
  pointer-events: auto;
}

/* Prevent browser gestures on the WebGL canvas */
#viewer canvas {
  touch-action: none;
}

/* ===== Mobile Item Controls ===== */
#mobile-item-controls {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 9999;
  pointer-events: auto;
  display: none;
}
#mobile-item-controls .mic-grid {
  display: grid;
  grid-template-columns: 60px 80px 60px;
  grid-template-rows: 60px 60px;
  gap: 10px;
  align-items: center;
  justify-items: center;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(4px);
  border-radius: 14px;
  padding: 10px;
}
#mobile-item-controls .mic-btn {
  width: 40px;
  height: 60px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.85);
  font-size: 22px;
  line-height: 60px;
  text-align: center;
  user-select: none;
}
#mobile-item-controls .mic-rot-wrap {
  display: flex;
  gap: 10px;
}
#mobile-item-controls .mic-rot {
  width: 40px;
  height: 60px;
}
#mobile-item-controls .mic-step {
  width: 80px;
  font-size: 14px;
}

/* Show arrows only on small screens when item is selected */
@media (max-width: 768px) {
  #mobile-item-controls {
    display: none;
  } /* Hidden by default */
  #mobile-item-controls.show {
    display: block;
  } /* Show when item is selected */
}

/* ====== Off-canvas responsive sidebar ====== */
#sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 2000;
}

/* Desktop/tablet keep normal grid */
@media (min-width: 768px) {
  #sidebar {
    position: static;
    transform: none !important;
    box-shadow: none !important;
  }
  #sidebar-backdrop {
    display: none !important;
  }
}

/* Phones: slide-in drawer */
@media (max-width: 767px) {
  .main-row {
    height: auto;
  }
  #sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 82vw;
    max-width: 320px;
    background: #fff;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 2002;
    box-shadow: 2px 0 18px rgba(0, 0, 0, 0.18);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  #sidebar.open {
    transform: translateX(0);
  }
  #sidebar-backdrop.active {
    display: block;
  }
  .main {
    width: 100%;
  }
  #add-items {
    height: 100vh;
  }
}

/* Lock body when drawer open */
body.sidebar-open {
  overflow: hidden;
}

/* Tappable nav on phones */
@media (max-width: 767px) {
  .nav-sidebar > li > a {
    padding: 12px 20px;
  }
}

/* ===== Fix overlap: compact camera controls on mobile ===== */
@media (max-width: 768px) {
  #camera-controls {
    right: 12px !important;
    bottom: 12px !important;
    padding: 0 !important;
    display: flex;
    flex-direction: column;
    gap: 8px;
    text-align: right;
  }
  #camera-controls .btn-group-vertical,
  #move-left,
  #move-right,
  #move-up,
  #move-down {
    display: none !important;
  }
}

/* Extra tiny phones: shrink item controls */
@media (max-width: 360px) {
  #mobile-item-controls .mic-grid {
    grid-template-columns: 48px 64px 48px;
    grid-template-rows: 48px 48px;
    gap: 8px;
    padding: 8px;
  }
  #mobile-item-controls .mic-btn {
    width: 48px;
    height: 48px;
    line-height: 48px;
    font-size: 18px;
  }
  #mobile-item-controls .mic-step {
    width: 64px;
    font-size: 12px;
  }
}

/* ===== Hamburger vs #main-controls: move hamburger to top-right & nudge controls ===== */
@supports (top: max(0px)) {
  :root {
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
  }
}
@media (max-width: 767px) {
  #sidebar-toggle {
    left: auto !important;
    right: calc(12px + var(--safe-right, 0px)) !important;
    top: calc(10px + var(--safe-top, 0px)) !important;
  }
  #main-controls {
    top: calc(56px + var(--safe-top, 0px)) !important;
    left: calc(12px + var(--safe-left, 0px)) !important;
  }
}

@media (max-width: 767px) {
  .done_btn {
    margin-top: 11px;
    margin-right: 28px;
  }
}

#sidebar {
  background-color: #fafafa !important;
}

#floorplanner-controls {
  background-color: white !important;
  margin: 0 !important;
  padding: 30px !important;
}

#floorplanner-controls #move {
  background-color: #f5f5f5 !important;
  color: #0e0e0e !important;
  padding-top: 10px !important;
  padding-bottom: 10px !important;
  border-radius: 10px !important;
  border-color: transparent !important;
}
#floorplanner-controls #draw {
  background-color: #f5f5f5 !important;
  color: #0e0e0e !important;
  padding-top: 10px !important;
  padding-bottom: 10px !important;
  border-radius: 10px !important;
  border-color: transparent !important;
}
#floorplanner-controls #delete {
  background-color: #f5f5f5 !important;
  color: #0e0e0e !important;
  padding-top: 10px !important;
  padding-bottom: 10px !important;
  border-radius: 10px !important;
  border-color: transparent !important;
}

#update-floorplan {
  background-color: oklch(0.205 0 0) !important;
  border-radius: 10px;
}

#main-controls {
  width: 100% !important;
  top: 0 !important;
  padding-top: 10px !important;
  padding-bottom: 10px !important;
  padding-left: 15px !important;
  background-color: white !important;
  left: 0 !important;
}
#main-controls #new {
  background-color: #f5f5f5 !important;
  color: #0e0e0e !important;
  padding-top: 10px !important;
  padding-bottom: 10px !important;
  border-radius: 10px !important;
  border-color: transparent !important;
}
#main-controls #saveFile {
  background-color: #f5f5f5 !important;
  color: #0e0e0e !important;
  padding-top: 10px !important;
  padding-bottom: 10px !important;
  border-radius: 10px !important;
  border-color: transparent !important;
}

.btn.btn-sm.btn-default.btn-file {
  background-color: #f5f5f5 !important;
  color: #0e0e0e !important;
  padding-top: 10px !important;
  padding-bottom: 10px !important;
  border-radius: 10px !important;
  border-color: transparent !important;
}

ul.nav.nav-sidebar li:hover {
  background-color: oklch(0.97 0 0) !important;
}
ul.nav.nav-sidebar li a {
  color: oklch(0.145 0 0) !important;
}
ul.nav.nav-sidebar li.active a {
  background-color: oklch(0.97 0 0) !important;
  font-weight: bold !important;
}
