/* =====================================================
   HAFFLER INDUSTRIAL AI — MOBILE RESPONSIVE ENGINE
   Clean, modern, uncluttered mobile experience
   ===================================================== */

/* 1. Global Viewport Boundary Lock */
html, body {
  overflow-x: hidden !important;
  max-width: 100vw !important;
  width: 100% !important;
  margin: 0;
  padding: 0;
}

*, *::before, *::after {
  box-sizing: border-box;
}

/* 2. Container Protections against Horizontal Blowout */
#publicShowcase,
#appPortal,
main,
nav,
header,
footer,
section {
  max-width: 100vw !important;
  width: 100% !important;
  overflow-x: hidden !important;
}

/* 3. Media & Content Containment */
img, svg, video, canvas {
  max-width: 100%;
  height: auto;
}

pre, code {
  max-width: 100%;
  white-space: pre-wrap;
  word-break: break-all;
}

/* 4. Table Containers: Always swipeable on mobile */
.showcase-glass-card,
.overflow-x-auto,
table {
  -webkit-overflow-scrolling: touch;
}

/* =====================================================
   MOBILE VIEWPORT ONLY (Screens < 640px)
   ===================================================== */
@media (max-width: 639px) {

  /* --- Top Public Navbar --- */
  nav.sticky.top-0 {
    padding-left: 12px !important;
    padding-right: 12px !important;
    padding-top: 8px !important;
    padding-bottom: 8px !important;
  }

  /* --- Hero Header Typography & Spacing --- */
  header.relative.overflow-hidden {
    padding-top: 24px !important;
    padding-bottom: 32px !important;
    padding-left: 14px !important;
    padding-right: 14px !important;
  }

  header.relative.overflow-hidden h1 {
    font-size: 1.35rem !important;
    line-height: 1.45 !important;
    letter-spacing: -0.01em !important;
  }

  header.relative.overflow-hidden h1 span {
    font-size: 1.05rem !important;
    line-height: 1.4 !important;
  }

  header.relative.overflow-hidden p {
    font-size: 0.8rem !important;
    line-height: 1.6 !important;
  }

  /* Restrict ambient glow size on phones */
  header.relative.overflow-hidden .w-\[600px\] {
    width: 260px !important;
    height: 180px !important;
  }

  /* --- Main Content Section Paddings --- */
  main.max-w-7xl {
    padding-left: 12px !important;
    padding-right: 12px !important;
    padding-top: 24px !important;
    padding-bottom: 40px !important;
  }

  /* Reduce gap between stacked sections */
  .space-y-20 > * + * { margin-top: 36px !important; }
  .space-y-16 > * + * { margin-top: 28px !important; }
  .space-y-12 > * + * { margin-top: 20px !important; }
  .space-y-8 > * + *  { margin-top: 16px !important; }

  /* Section Title Cleanups */
  section h2 {
    font-size: 1.25rem !important;
    line-height: 1.4 !important;
  }

  section p {
    font-size: 0.8rem !important;
    line-height: 1.6 !important;
  }

  /* Card paddings */
  .p-6, .p-8 {
    padding: 14px !important;
  }
  .p-4 {
    padding: 10px !important;
  }
  .rounded-3xl {
    border-radius: 18px !important;
  }
  .rounded-2xl {
    border-radius: 14px !important;
  }

  /* Grid: Collapse to single column on mobile */
  .grid-cols-2:not(.keep-2col),
  .grid-cols-3,
  .grid-cols-4,
  .sm\:grid-cols-2,
  .md\:grid-cols-3,
  .lg\:grid-cols-4 {
    grid-template-columns: 1fr !important;
  }

  /* --- Sticky Mobile Quick Nav Bar --- */
  div.sticky.top-16 {
    padding: 8px 10px !important;
    gap: 6px !important;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  div.sticky.top-16::-webkit-scrollbar {
    display: none;
  }
  div.sticky.top-16 a {
    padding: 6px 12px !important;
    font-size: 11px !important;
    white-space: nowrap;
    scroll-snap-align: start;
    flex-shrink: 0;
  }

  /* --- Floating Support / Call Buttons --- */
  aside.fixed.bottom-5.left-5 {
    bottom: 82px !important;
    left: 10px !important;
    gap: 8px !important;
  }
  aside.fixed.bottom-5.left-5 a {
    padding: 9px !important;
    border-radius: 9999px !important;
  }
  aside.fixed.bottom-5.left-5 span {
    display: none !important;
  }

  /* Back to App Floating Banner */
  #backToAppBanner {
    bottom: 82px !important;
    right: 10px !important;
    padding: 8px 12px !important;
    border-radius: 9999px !important;
  }
  #backToAppBanner span {
    display: none !important;
  }

  /* Login Modal on Mobile */
  #loginScreen {
    padding: 12px !important;
  }
  #loginScreen > div {
    max-width: 100% !important;
    padding: 20px 16px !important;
    border-radius: 22px !important;
  }

  /* Exploded 3D Modal on Mobile */
  #explodedHardwareModal {
    padding: 8px !important;
  }
  #explodedHardwareModal > div {
    height: 88vh !important;
    max-height: none !important;
    border-radius: 20px !important;
  }

  /* App Portal Container on Mobile - Strict 100dvh Lock */
  #appPortal {
    height: 100vh !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    min-height: 100dvh !important;
    overflow: hidden !important;
  }

  /* App Portal Header: Symmetrical 56px (h-14) height, balanced padding */
  #appPortal header {
    height: 56px !important;
    min-height: 56px !important;
    max-height: 56px !important;
    padding: 0 10px !important;
    gap: 6px !important;
    background: rgba(255, 255, 255, 0.95) !important;
    backdrop-filter: blur(16px) !important;
    border-bottom: 1px solid #e2e8f0 !important;
    justify-content: space-between !important;
  }
  #appPortal header nav {
    display: none !important;
  }
  #adminPortalModeToggle {
    display: none !important;
  }
  #appPortalLangBtn {
    display: none !important;
  }
  #machineSelectTrigger {
    max-width: 125px !important;
    padding: 4px 8px !important;
    font-size: 11px !important;
    background: #ffffff !important;
    border: 1px solid #cbd5e1 !important;
    color: #0f172a !important;
    border-radius: 12px !important;
  }
  #machineSelectActiveTitle {
    font-size: 10.5px !important;
    color: #0f172a !important;
    font-weight: 700 !important;
  }
  #machineSelectNumberBadge {
    background-color: #e0f2fe !important;
    border-color: #bae6fd !important;
    color: #0369a1 !important;
  }
  #hamburgerBtn {
    width: 36px !important;
    height: 36px !important;
    background: #ffffff !important;
    border: 1px solid #cbd5e1 !important;
    color: #334155 !important;
    border-radius: 12px !important;
  }
  #hamburgerBtn svg {
    color: #334155 !important;
    stroke: #334155 !important;
  }
  #machineDropdownMenu {
    left: 8px !important;
    right: 8px !important;
    width: auto !important;
    top: 54px !important;
  }

  /* Bottom Meniscus Nav Dock: Balanced 56px height matching the top header */
  #meniscusDockNav {
    height: 56px !important;
    bottom: 8px !important;
    width: min(94vw, 360px) !important;
    z-index: 40 !important;
  }
}

/* =====================================================
   APP PORTAL SPECIFIC (< 1024px)
   ===================================================== */
@media (max-width: 1023px) {
  #appPortal main {
    padding-bottom: 64px !important;
  }
  #chatMessages {
    padding-bottom: 12px !important;
  }
  #chatInputDeck {
    margin-bottom: 0 !important;
    padding-left: 8px !important;
    padding-right: 8px !important;
    padding-top: 6px !important;
    padding-bottom: 6px !important;
    background: rgba(255, 255, 255, 0.95) !important;
    backdrop-filter: blur(12px) !important;
    border-top: 1px solid #e2e8f0 !important;
  }
  #chatDeckNormalTopBar {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
  }
  #chatDeckNormalTopBar::-webkit-scrollbar {
    display: none !important;
  }
  #view-telemetry,
  #view-ideademo,
  #view-files,
  #view-deploy,
  #view-reports {
    padding-bottom: 68px !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }
  #telemetryDashboard {
    grid-template-columns: 1fr !important;
  }
}

/* Hide bottom meniscus dock when typing on phone */
body:has(#messageInput:focus) #meniscusDockNav {
  display: none !important;
}
body:has(#messageInput:focus) #appPortal main {
  padding-bottom: 0 !important;
}

/* =====================================================
   GLOBAL SVG ICON CONSTRAINTS & FRACTIONAL UTILITIES
   Guarantees SVG icons in buttons, cards and badges never blowout
   ===================================================== */
a > svg, button > svg, .bento-icon, .btn-icon {
  flex-shrink: 0 !important;
}

.w-3\.5 { width: 0.875rem !important; }
.h-3\.5 { height: 0.875rem !important; }
.w-4\.5 { width: 1.125rem !important; }
.h-4\.5 { height: 1.125rem !important; }
.w-5\.5 { width: 1.375rem !important; }
.h-5\.5 { height: 1.375rem !important; }
.w-6\.5 { width: 1.625rem !important; }
.h-6\.5 { height: 1.625rem !important; }

/* =====================================================
   HAFFLER AI WELCOME BANNER FIX (ZERO-FOUC & ZERO-CLS)
   ===================================================== */
#hafflerWelcomeAiBanner {
  position: fixed !important;
  bottom: 6rem !important;
  right: 1.5rem !important;
  left: auto !important;
  top: auto !important;
  z-index: 40 !important;
  width: 420px !important;
  max-width: calc(100vw - 2rem) !important;
  background-color: #ffffff !important;
  border: 2px solid rgba(14, 165, 233, 0.7) !important;
  border-radius: 1.5rem !important;
  box-shadow: 0 25px 50px -12px rgba(12, 74, 110, 0.25) !important;
  padding: 1.25rem !important;
  box-sizing: border-box !important;
}

html.haffler-host-handled #hafflerWelcomeAiBanner {
  display: none !important;
}

@media (max-width: 640px) {
  #hafflerWelcomeAiBanner {
    bottom: 5.5rem !important;
    right: 1rem !important;
    left: 1rem !important;
    width: calc(100vw - 2rem) !important;
    max-width: calc(100vw - 2rem) !important;
    padding: 1rem !important;
  }
}

/* =====================================================
   DESKTOP & TABLET TOP NAVIGATION RESPONSIVE RECOVERY
   ===================================================== */
#topDesktopNav {
  display: none !important;
}

@media (min-width: 640px) {
  .sm\:inline { display: inline !important; }
  .sm\:inline-block { display: inline-block !important; }
  .sm\:block { display: block !important; }
  .sm\:flex { display: flex !important; }
  .sm\:hidden { display: none !important; }
}

@media (min-width: 768px) {
  .md\:flex { display: flex !important; }
  .md\:inline-flex { display: inline-flex !important; }
  .md\:block { display: block !important; }
  .md\:inline { display: inline !important; }
  .md\:hidden { display: none !important; }

  #topDesktopNav {
    display: flex !important;
  }
  #mobileTopViewSwitcher {
    display: none !important;
  }
  #btnPublicMobileToggle {
    display: none !important;
  }
}

@media (min-width: 1024px) {
  .lg\:flex { display: flex !important; }
  .lg\:inline-flex { display: inline-flex !important; }
  .lg\:block { display: block !important; }
  .lg\:hidden { display: none !important; }
}

@media (min-width: 1280px) {
  .xl\:flex { display: flex !important; }
  .xl\:hidden { display: none !important; }
}

/* =====================================================
   MOBILE CLEANUP & UNCLUTTERED VIEWPORT SAFEGUARDS (< 768px)
   Apple HIG & Zero-Defect Layout Integrity
   ===================================================== */
@media (max-width: 767px) {
  /* 1. Never show the oversized entrance card uninvited */
  #geminiLiveEntranceCard {
    display: none !important;
  }

  /* 2. Floating AI Assistant Orb Button: Refined 48px ergonomic size */
  #hafflerUniversalAiFloatingContainer {
    bottom: 16px !important;
    right: 16px !important;
  }

  #hafflerVoiceSignalOrb {
    width: 48px !important;
    height: 48px !important;
    border-width: 1.5px !important;
    box-shadow: 0 4px 16px rgba(6, 182, 212, 0.45) !important;
  }

  #hafflerVoiceSignalOrb img {
    border-radius: 9999px !important;
  }

  /* 3. Toast notifications safe spacing below header */
  #toastContainer {
    top: 68px !important;
    left: 12px !important;
    right: 12px !important;
    width: auto !important;
    max-width: calc(100vw - 24px) !important;
  }

  /* 4. Chat Drawer Mobile Screen Lock */
  #hafflerUniversalChatDrawer {
    width: calc(100vw - 16px) !important;
    right: 8px !important;
    bottom: 8px !important;
    max-height: 85vh !important;
    height: 85vh !important;
    border-radius: 20px !important;
  }
}


