/**
 * GatheringCloud (聚雲) Mobile & Tablet Touch Stylesheet
 * 
 * Supports both portrait and landscape orientations (decoupled from rigid max-width),
 * prevents desktop DOM memory exhaustion, and ensures a clean, touch-friendly 3D BIM viewport
 * unobstructed by endless floating panels.
 */

/* Default state: hide mobile dock and mobile content viewport on desktop */
.gc-mobile-dock,
.gc-mobile-content-view {
  display: none;
}

/* =========================================================================
   Mobile Shell Active States (body.gc-mobile-active)
   Covers portrait, landscape, tablets, and phones seamlessly.
   ========================================================================= */

html.gc-mobile-active,
body.gc-mobile-active {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  height: 100dvh !important;
  max-height: 100vh !important;
  max-height: 100dvh !important;
  overflow: hidden !important;
  touch-action: pan-y;
}

/* Bottom Navigation Dock (Always fixed at bottom with highest z-index) */
body.gc-mobile-active .gc-mobile-dock {
  display: flex !important;
  position: fixed !important;
  bottom: 0 !important;
  left: 0 !important;
  right: 0 !important;
  height: 56px !important;
  background: rgba(15, 23, 42, 0.98) !important;
  backdrop-filter: blur(12px) !important;
  -webkit-backdrop-filter: blur(12px) !important;
  border-top: 1px solid rgba(255, 255, 255, 0.12) !important;
  z-index: 9999 !important;
  align-items: center !important;
  justify-content: space-around !important;
  padding-bottom: max(env(safe-area-inset-bottom, 0px), 4px) !important;
}

.mobile-dock-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  padding: 6px 0;
  transition: all 0.2s ease;
}

.mobile-dock-btn.active {
  color: #38bdf8;
}

.dock-icon {
  font-size: 18px;
  margin-bottom: 2px;
}

.dock-label {
  font-size: 10px;
  font-weight: 600;
}

/* Mobile Content Container */
body.gc-mobile-active .gc-mobile-content-view {
  display: block !important;
  position: absolute !important;
  top: 48px !important;
  left: 0 !important;
  right: 0 !important;
  bottom: calc(56px + max(env(safe-area-inset-bottom, 0px), 4px)) !important;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;
  background: #0b0f19;
  z-index: 900;
}

/* When 3D BIM view is active on mobile, hide the content view so canvas is visible */
body.gc-mobile-active.gc-mobile-bim-active .gc-mobile-content-view {
  display: none !important;
}

/* =========================================================================
   Desktop DOM Hiding: Prevent mobile tab OOM crashes & layout conflicts
   ========================================================================= */
body.gc-mobile-active #mainContainer,
body.gc-mobile-active #bottomPanel,
body.gc-mobile-active #bottomSplitter,
body.gc-mobile-active .bottom-panel-splitter,
body.gc-mobile-active .pane-splitter,
body.gc-mobile-active #paneSplitter,
body.gc-mobile-active #pivotPaneSplitter,
body.gc-mobile-active #resourceView,
body.gc-mobile-active #procurementView,
body.gc-mobile-active #pivotView,
body.gc-mobile-active #docNetworkView,
body.gc-mobile-active #bimSplitSchedulePane,
body.gc-mobile-active #btnToggleBIMSplitMode {
  display: none !important;
}

/* Compact header on mobile */
body.gc-mobile-active .app-header {
  height: 48px !important;
  padding: 0 8px !important;
}

body.gc-mobile-active .brand-title {
  font-size: 13px !important;
}

body.gc-mobile-active .brand-subtitle,
body.gc-mobile-active .header-search-wrap,
body.gc-mobile-active .view-switcher-wrap {
  display: none !important;
}

/* Optimize touch target sizes */
body.gc-mobile-active button,
body.gc-mobile-active input,
body.gc-mobile-active select,
body.gc-mobile-active textarea {
  touch-action: manipulation;
}

/* =========================================================================
   3D BIM View Mobile Optimizations: Touch & Unobstructed Layout
   ========================================================================= */

/* Default on mobile: BIM View is hidden unless BIM tab is active */
body.gc-mobile-active #bimView {
  display: none !important;
}

/* When BIM tab is active, anchor BIM View cleanly between header and mobile dock */
body.gc-mobile-active.gc-mobile-bim-active #bimView {
  position: absolute !important;
  top: 48px !important;
  left: 0 !important;
  right: 0 !important;
  bottom: calc(56px + max(env(safe-area-inset-bottom, 0px), 4px)) !important;
  height: auto !important;
  max-height: none !important;
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column !important;
  z-index: 800 !important;
}

/* Touch-action: none on BIM 3D canvas so OrbitControls receives multi-touch gestures */
body.gc-mobile-active #bimView canvas,
body.gc-mobile-active #bimCanvasContainer canvas,
body.gc-mobile-active #bimCanvasContainer {
  touch-action: none !important;
}

/* Compact horizontal scrolling toolbar in 3D BIM view */
body.gc-mobile-active #bimToolbar {
  height: 36px !important;
  min-height: 36px !important;
  padding: 2px 6px !important;
  overflow-x: auto !important;
  white-space: nowrap !important;
  -webkit-overflow-scrolling: touch;
  flex-wrap: nowrap !important;
  flex-shrink: 0 !important;
}

body.gc-mobile-active #bimToolbarTitle,
body.gc-mobile-active #bimToolbarSubtitle {
  display: none !important;
}

/* Collapse site scan overlay into a non-obstructive drawer/pill */
body.gc-mobile-active #siteScanOverlayPanel {
  position: absolute !important;
  top: 44px !important;
  left: 8px !important;
  width: auto !important;
  max-width: calc(100vw - 16px) !important;
  z-index: 50 !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45) !important;
  font-size: 11px !important;
  transition: all 0.25s ease;
}

body.gc-mobile-active #siteScanOverlayPanel #siteScanPanelHeader {
  padding: 4px 8px !important;
  border-radius: 6px;
}

body.gc-mobile-active #siteScanOverlayPanel.collapsed #siteScanPanelBody,
body.gc-mobile-active #siteScanOverlayPanel #siteScanPanelBody.is-collapsed {
  display: none !important;
}

body.gc-mobile-active #siteScanOverlayPanel.expanded #siteScanPanelBody {
  display: flex !important;
  max-height: min(380px, calc(100vh - 160px)) !important;
  max-height: min(380px, calc(100dvh - 160px)) !important;
  width: min(340px, calc(100vw - 20px)) !important;
  overflow-y: auto !important;
}

/* Collapse BIM Color Legend so it does NOT obstruct the 3D model */
body.gc-mobile-active #bimColorLegend {
  position: absolute !important;
  bottom: auto !important;
  top: 80px !important;
  left: 8px !important;
  min-width: 0 !important;
  max-width: 170px !important;
  padding: 4px 8px !important;
  font-size: 10px !important;
  z-index: 30 !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35) !important;
}

body.gc-mobile-active #bimColorLegend #bimLegendHeader {
  padding: 0 !important;
}

body.gc-mobile-active #bimColorLegend.collapsed #bimLegendBody {
  display: none !important;
}

body.gc-mobile-active #bimColorLegend.expanded #bimLegendBody {
  display: flex !important;
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 8px;
  max-height: min(280px, calc(100vh - 180px)) !important;
  max-height: min(280px, calc(100dvh - 180px)) !important;
  overflow-y: auto;
  z-index: 100;
  width: min(240px, calc(100vw - 24px));
}

/* Hide desktop-only floating hints and oversized elements in 3D canvas */
body.gc-mobile-active #bimCompassHint,
body.gc-mobile-active #bimCanvasContainer [style*="left: 290px"] {
  display: none !important;
}

/* Responsive constraints on floating tool panels */
body.gc-mobile-active #bimInspectorDrawer {
  max-width: 88vw !important;
  z-index: 60 !important;
}

body.gc-mobile-active #bimMeasurePanel,
body.gc-mobile-active #bimSectionPanel,
body.gc-mobile-active #bimMarkersPanel,
body.gc-mobile-active #bimCommentsPanel,
body.gc-mobile-active #bimEquipmentPanel,
body.gc-mobile-active #bimEquipmentInspectCard,
body.gc-mobile-active #bimCoordInspectorHUD {
  max-width: calc(100vw - 16px) !important;
  max-height: min(420px, calc(100vh - 130px)) !important;
  max-height: min(420px, calc(100dvh - 130px)) !important;
  overflow-y: auto !important;
  right: 8px !important;
  left: auto !important;
  z-index: 70 !important;
}

/* 4D Timeline Simulation Bar: sits neatly at the bottom of #bimView directly above #gcMobileDock */
body.gc-mobile-active .bim-timeline-bar {
  position: relative !important;
  margin-bottom: 0 !important;
  height: auto !important;
  min-height: 44px !important;
  padding: 4px 10px !important;
  gap: 6px !important;
  flex-wrap: wrap !important;
  justify-content: space-between !important;
  align-items: center !important;
  z-index: 20 !important;
  background: rgba(15, 23, 42, 0.96) !important;
  backdrop-filter: blur(8px) !important;
  border-top: 1px solid rgba(255, 255, 255, 0.1) !important;
  flex-shrink: 0 !important;
}

body.gc-mobile-active .bim-timeline-bar > div:first-child {
  min-width: 0 !important;
  flex: 1 1 auto !important;
}

body.gc-mobile-active #bimSimDateLabel {
  font-size: 12px !important;
}

body.gc-mobile-active #bimSimMilestoneLabel {
  display: none !important;
}

/* Compact playback controls */
body.gc-mobile-active .bim-timeline-bar .btn-group {
  order: 2 !important;
  flex-shrink: 0 !important;
}

body.gc-mobile-active #btnBIMSimPlay {
  min-width: 65px !important;
  padding: 2px 6px !important;
  font-size: 10px !important;
}

body.gc-mobile-active #btnBIMStepPrev,
body.gc-mobile-active #btnBIMStepNext {
  display: none !important;
}

/* Time Slider row occupies bottom full-width of the bar */
body.gc-mobile-active .bim-timeline-bar > div:nth-child(3) {
  flex: 1 1 100% !important;
  order: 3 !important;
  margin-top: 2px !important;
  gap: 6px !important;
}

/* Hide bulky status legend on mobile timeline bar */
body.gc-mobile-active .bim-timeline-bar > div:last-child {
  display: none !important;
}

/* =========================================================================
   Mobile Tasks Dynamic UI: Search Bar & Filter Chips
   ========================================================================= */

.mobile-header-card {
  padding: 12px 14px;
  background: #0f172a;
  border-bottom: 1px solid #334155;
}

.mobile-tasks-search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.mobile-search-input {
  flex: 1;
  background: #1e293b;
  border: 1px solid #475569;
  border-radius: 6px;
  color: #f8fafc;
  padding: 7px 10px;
  font-size: 12px;
  outline: none;
  transition: border-color 0.2s;
}

.mobile-search-input:focus {
  border-color: #38bdf8;
}

.mobile-filter-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 8px 0 2px 0;
  -webkit-overflow-scrolling: touch;
}

.mobile-filter-chip {
  flex-shrink: 0;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 14px;
  background: #1e293b;
  color: #94a3b8;
  border: 1px solid #334155;
  cursor: pointer;
  transition: all 0.2s;
}

.mobile-filter-chip.active {
  background: #0284c7;
  color: #ffffff;
  border-color: #38bdf8;
}

/* =========================================================================
   Landscape Mode Specific Compact Overrides
   ========================================================================= */
@media (orientation: landscape) and (max-height: 520px) {
  body.gc-mobile-active .app-header {
    height: 38px !important;
  }
  body.gc-mobile-active .gc-mobile-dock {
    height: 44px !important;
    padding-bottom: max(env(safe-area-inset-bottom, 0px), 2px) !important;
  }
  body.gc-mobile-active .dock-icon {
    font-size: 15px !important;
    margin-bottom: 0 !important;
  }
  body.gc-mobile-active .dock-label {
    font-size: 9px !important;
  }
  body.gc-mobile-active.gc-mobile-bim-active #bimView {
    top: 38px !important;
    bottom: calc(44px + max(env(safe-area-inset-bottom, 0px), 2px)) !important;
  }
  body.gc-mobile-active .gc-mobile-content-view {
    top: 38px !important;
    bottom: calc(44px + max(env(safe-area-inset-bottom, 0px), 2px)) !important;
  }
  body.gc-mobile-active .bim-timeline-bar {
    min-height: 36px !important;
    padding: 2px 8px !important;
  }
}
