/* ==========================================================================
   SchemCAD / PhoneBoard — Clean Native-App Mobile UX & Bottom-Sheet Workstation
   File: frontend/mobile_cad.css
   - Desktop (> 860px) remains 100% untouched!
   - Smartphones & Telegram Mini App (<= 860px):
     1. Zero-Overlap 46px Top Header (#mobHomeBtn + Flexible Search + 🌐 EN + ★)
     2. State-Driven Views:
        * data-mob-has-board="0": Clean Spacious Mobile Home Screen (#mobHomeLaunchpad)
          with 2x2 Category Cards, Local Upload & Quick Demo Boards (zero CAD clutter!)
        * data-mob-has-board="1": Full-Height PCB Stage + 32px Boardbar + 36px Pill Strip
     3. 2-Row Floating Bottom Pin Drawer (#mobPinQuickBar) with Inspector & AI Check
     4. 4-Tab Spacious Native Bottom Bar (#mobileBottomNav) + Unified Catalog Switcher
   ========================================================================== */

/* Prevent browser pinch-scroll hijack on PCB interactive canvas at any size */
#pcbCanvas {
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

/* Hide mobile-only injected UI on Desktop (> 860px) */
#mobBackBtn,
#mobHomeBtn,
#mobBoardBackBtn,
#mobRightBackBtn,
#mobHomeLaunchpad,
#mobCatalogSwitcher,
#mobileBottomNav,
#mobPinQuickBar,
#mobAiQuickTools,
.mob-flipx-lbl {
  display: none;
}

@media (min-width: 861px) {
  #mobBackBtn,
  #mobHomeBtn,
  #mobBoardBackBtn,
  #mobRightBackBtn,
  #mobHomeLaunchpad,
  #mobCatalogSwitcher,
  #mobileBottomNav,
  #mobPinQuickBar,
  #mobAiQuickTools,
  .mob-flipx-lbl {
    display: none !important;
  }
}

/* ==========================================================================
   NATIVE-APP MOBILE & TELEGRAM MINI APP WORKSTATION (<= 860px)
   ========================================================================== */
@media (max-width: 860px) {
  html,
  body,
  #app {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    overflow: hidden !important;
    overscroll-behavior: none;
  }

  /* ------------------------------------------------------------------------
     1. Zero-Overlap Mobile Top Header (46px height, fits even 320px iPhone SE)
     ------------------------------------------------------------------------ */
  .topbar {
    height: 46px !important;
    min-height: 46px !important;
    max-height: 46px !important;
    padding: 0 8px !important;
    gap: 6px !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    overflow: visible !important;
    z-index: 4100 !important;
  }

  .brand-nav {
    display: inline-flex !important;
    align-items: center !important;
    gap: 5px !important;
    min-width: 0 !important;
    flex-shrink: 0 !important;
  }

  /* Hide desktop brand elements & clutter buttons in .topbar on <= 860px */
  .brand-logo,
  .brand-title,
  .nav-mode-seg,
  #btnToggleLeft,
  #btnToggleRight,
  #btnBiosArchive,
  #btnControllerAtlas,
  #btnUploadFile,
  #btnOpenAiTab,
  .topbar-actions > *:not(#btnLangSwitch):not(#btnSaasAccount) {
    display: none !important;
  }

  /* Prominent Mobile Back Button (#mobBackBtn) in Topbar */
  #mobBackBtn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 32px;
    padding: 0 9px;
    border-radius: 7px;
    border: 1px solid rgba(245, 184, 75, 0.58);
    background: linear-gradient(180deg, rgba(220, 160, 58, 0.24) 0%, rgba(220, 160, 58, 0.12) 100%);
    color: #fef3c7;
    font-family: var(--sans, system-ui, -apple-system, sans-serif);
    font-size: 11.5px;
    font-weight: 700;
    white-space: nowrap;
    cursor: pointer;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
  }

  #mobBackBtn.hidden {
    display: none !important;
  }

  #mobBackBtn svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
  }

  #mobBackBtn:active {
    transform: scale(0.96);
    background: rgba(220, 160, 58, 0.32);
  }

  /* Left: Clean SchemCAD compact badge (#mobHomeBtn) */
  #mobHomeBtn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 5px;
    height: 32px;
    padding: 0 9px;
    border-radius: 7px;
    border: 1px solid rgba(220, 160, 58, 0.48);
    background: linear-gradient(180deg, #1b2230 0%, #121722 100%);
    box-shadow: inset 0 1px 0 rgba(255, 236, 194, 0.1);
    color: #f8fafc;
    font-family: var(--sans, system-ui, -apple-system, sans-serif);
    font-size: 11.5px;
    font-weight: 800;
    letter-spacing: -0.01em;
    white-space: nowrap;
    cursor: pointer;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
  }

  /* When #mobBackBtn is visible on narrow screens, collapse #mobHomeBtn text so Search stays wide */
  @media (max-width: 430px) {
    #mobBackBtn:not(.hidden) + #mobHomeBtn {
      padding: 0 7px;
    }
    #mobBackBtn:not(.hidden) + #mobHomeBtn .mob-home-txt {
      display: none;
    }
  }

  #mobHomeBtn:active {
    transform: scale(0.97);
    border-color: rgba(245, 184, 75, 0.85);
  }

  #mobHomeBtn .mob-home-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #34d399;
    box-shadow: 0 0 6px rgba(52, 211, 153, 0.75);
    flex-shrink: 0;
  }

  /* Center: Sleek flexible #omniSearchWrap */
  .topbar .omni-search-wrap,
  #omniSearchWrap {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    max-width: none !important;
    height: 32px !important;
    padding: 0 6px 0 8px !important;
    gap: 5px !important;
    border-radius: 8px !important;
  }

  /* 16px prevents iOS Safari / Telegram iOS WebView auto-zoom on input focus */
  .omni-search-input,
  #deviceFilter,
  #laptopFilter,
  #boardSearch,
  #chipFilter,
  #signalFilter,
  #aiPromptInput,
  #hubHeroSearch,
  .lib-search-input {
    font-size: 16px !important;
  }

  .omni-search-input::placeholder {
    font-size: 12.5px;
  }

  #omniKbdHint {
    display: none !important;
  }

  /* Omnisearch Dropdown: clean full-width mobile sheet below topbar */
  .omni-dropdown,
  #omniDropdown {
    position: fixed !important;
    left: 6px !important;
    right: 6px !important;
    top: 50px !important;
    width: calc(100vw - 12px) !important;
    max-width: calc(100vw - 12px) !important;
    max-height: calc(100vh - 116px) !important;
    max-height: calc(100dvh - 116px - env(safe-area-inset-bottom, 0px)) !important;
    border-radius: 10px !important;
    z-index: 4600 !important;
  }

  .omni-filter-bar {
    flex-wrap: wrap;
    gap: 5px;
    padding: 7px 8px;
  }

  .omni-item {
    padding: 10px;
  }

  .omni-footer > span {
    display: none !important;
  }

  .omni-footer {
    justify-content: center !important;
    padding: 7px 10px !important;
  }

  /* Right: ONLY #btnLangSwitch (32px) + #btnSaasAccount (32x32px) */
  .topbar-actions {
    display: inline-flex !important;
    align-items: center !important;
    gap: 5px !important;
    flex-shrink: 0 !important;
  }

  #btnLangSwitch.pb-lang-btn {
    height: 32px !important;
    padding: 0 7px !important;
    border-radius: 7px !important;
    font-size: 11px !important;
    gap: 3px !important;
  }

  #pbLangPopover {
    max-width: calc(100vw - 16px) !important;
  }

  #btnSaasAccount.saas-account-pill {
    width: 32px !important;
    min-width: 32px !important;
    height: 32px !important;
    padding: 0 !important;
    gap: 0 !important;
    border-radius: 7px !important;
    justify-content: center !important;
  }

  #btnSaasAccount .saas-pill-label {
    display: none !important;
  }

  #btnSaasAccount .saas-pill-star {
    font-size: 14px !important;
  }

  @media (max-width: 359px) {
    .topbar {
      padding: 0 6px !important;
      gap: 4px !important;
    }
    #mobHomeBtn {
      padding: 0 6px;
      font-size: 10.5px;
    }
    #mobHomeBtn .mob-home-dot {
      display: none;
    }
    #btnLangSwitch.pb-lang-btn {
      padding: 0 5px !important;
    }
  }

  /* ------------------------------------------------------------------------
     2. Full-Screen Workspace & 4-Tab Native Sheet Routing
     ------------------------------------------------------------------------ */
  .workspace {
    position: relative !important;
    display: flex !important;
    flex-direction: column !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: calc(100vh - 46px - 56px) !important;
    height: calc(100dvh - 46px - 56px - env(safe-area-inset-bottom, 0px)) !important;
    flex: none !important;
    min-height: 0 !important;
    overflow: hidden !important;
  }

  /* Tab 1 (Default): Board / Home Launchpad ("canvas") */
  body:not([data-mob-view]) #mobCatalogSwitcher,
  body:not([data-mob-view]) #sidebarLeft,
  body:not([data-mob-view]) #sidebarLaptops,
  body:not([data-mob-view]) #sidebarRight,
  body[data-mob-view="canvas"] #mobCatalogSwitcher,
  body[data-mob-view="canvas"] #sidebarLeft,
  body[data-mob-view="canvas"] #sidebarLaptops,
  body[data-mob-view="canvas"] #sidebarRight {
    display: none !important;
  }

  body:not([data-mob-view]) section.viewport-wrap,
  body[data-mob-view="canvas"] section.viewport-wrap {
    display: flex !important;
    flex-direction: column !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100% !important;
    flex: 1 1 auto !important;
    min-height: 0 !important;
  }

  /* Tab 2: Unified Catalog ("catalog") -> Segmented Switcher + Phones OR Laptops */
  body[data-mob-view="catalog"] section.viewport-wrap,
  body[data-mob-view="catalog"] #sidebarRight {
    display: none !important;
  }

  body[data-mob-view="catalog"] #mobCatalogSwitcher {
    display: flex !important;
    align-items: center;
    gap: 6px;
    padding: 7px 8px;
    background: #0d121b;
    border-bottom: 1px solid #222d40;
    flex-shrink: 0;
  }

  .mob-cat-seg {
    flex: 1 1 auto;
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.28fr);
    gap: 4px;
    padding: 3px;
    background: #080b11;
    border: 1px solid #263246;
    border-radius: 9px;
  }

  .mob-cat-seg-btn {
    height: 32px;
    padding: 0 8px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: #94a3b8;
    font-family: var(--sans, system-ui, sans-serif);
    font-size: 12px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
  }

  .mob-cat-seg-btn svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.65;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
  }

  .mob-cat-seg-btn span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mob-cat-seg-btn.active {
    background: linear-gradient(180deg, rgba(220, 160, 58, 0.26) 0%, rgba(220, 160, 58, 0.12) 100%);
    border-color: rgba(220, 160, 58, 0.65);
    color: #fef3c7;
    box-shadow: inset 0 1px 0 rgba(255, 238, 196, 0.15);
  }

  .mob-cat-home-btn {
    height: 36px;
    padding: 0 9px;
    border-radius: 8px;
    border: 1px solid #28354a;
    background: #141b27;
    color: #cbd5e1;
    font-family: var(--sans, system-ui, sans-serif);
    font-size: 11px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    flex-shrink: 0;
    cursor: pointer;
  }

  .mob-cat-home-btn svg {
    width: 14px;
    height: 14px;
    stroke: #f5b84b;
    fill: none;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .mob-cat-home-btn:active {
    transform: scale(0.96);
    border-color: rgba(220, 160, 58, 0.65);
  }

  /* Catalog sub-source = phones: strict flex-height chain so #deviceTree swipes smoothly! */
  body[data-mob-view="catalog"]:not([data-mob-cat="laptops"]) #sidebarLaptops {
    display: none !important;
  }

  body[data-mob-view="catalog"]:not([data-mob-cat="laptops"]) #sidebarLeft,
  body[data-mob-view="catalog"]:not([data-mob-cat="laptops"]) #sidebarLeft.collapsed {
    display: flex !important;
    flex-direction: column !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 0 !important;
    flex: 1 1 0% !important;
    min-height: 0 !important;
    max-height: 100% !important;
    overflow: hidden !important;
    border-right: none !important;
  }

  #sidebarLeft .tabs {
    flex: 0 0 auto !important;
  }

  #sidebarLeft .tab-pane.active {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 1 0% !important;
    height: 0 !important;
    min-height: 0 !important;
    overflow: hidden !important;
  }

  #sidebarLeft .search-box,
  #sidebarLeft .search-filters,
  #sidebarLeft .pane-hint,
  #sidebarLaptops .search-box,
  #sidebarLaptops .pane-hint {
    flex: 0 0 auto !important;
  }

  /* Horizontal single-row swipeable brand chips bar (#brandQuickBar) */
  #brandQuickBar.brand-quick-bar {
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    gap: 6px !important;
    padding: 6px 8px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-x !important;
    scrollbar-width: none !important;
    flex: 0 0 auto !important;
  }

  #brandQuickBar::-webkit-scrollbar {
    display: none !important;
  }

  #brandQuickBar .brand-chip {
    flex: 0 0 auto !important;
    height: 28px !important;
    padding: 0 10px !important;
    font-size: 11.5px !important;
    border-radius: 999px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    white-space: nowrap !important;
  }

  /* Guaranteed native touch vertical scrolling on all catalog & in-board lists */
  #deviceTree,
  #chipsList,
  #boardSearchResults,
  #signalsTree,
  #laptopTree,
  #sidebarLeft .scroll-list,
  #sidebarLaptops .scroll-list {
    flex: 1 1 0% !important;
    height: 0 !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
    overscroll-behavior-y: contain !important;
    padding-bottom: 34px !important;
  }

  /* Catalog sub-source = laptops: strict flex-height chain so #laptopTree swipes smoothly! */
  body[data-mob-view="catalog"][data-mob-cat="laptops"] #sidebarLeft {
    display: none !important;
  }

  body[data-mob-view="catalog"][data-mob-cat="laptops"] #sidebarLaptops,
  body[data-mob-view="catalog"][data-mob-cat="laptops"] #sidebarLaptops.collapsed {
    display: flex !important;
    flex-direction: column !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 0 !important;
    flex: 1 1 0% !important;
    min-height: 0 !important;
    max-height: 100% !important;
    overflow: hidden !important;
    border-right: none !important;
  }

  /* Remove redundant Laptop header since #mobCatalogSwitcher sits right above */
  #sidebarLaptops .lap-col-head {
    display: none !important;
  }

  /* Expose all 4 sub-tabs (Phones | ICs | Search | Signals) cleanly in Phones view */
  #sidebarLeft.inboard-mode .tab-btn[data-tab="devices"] {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
  }

  #sidebarLeft .tabs,
  #sidebarLeft.inboard-mode .tabs {
    grid-template-columns: repeat(4, 1fr) !important;
  }

  #sidebarLeft .tab-btn {
    min-height: 36px;
    font-size: 12px;
  }

  #sidebarLeft .board-item,
  #sidebarLeft .folder-header,
  #sidebarLeft .search-row {
    min-height: 40px;
    padding-top: 8px;
    padding-bottom: 8px;
    touch-action: pan-y;
  }

  #sidebarLaptops .lap-mode-tabs {
    padding: 6px 8px 4px;
    gap: 5px;
    flex: 0 0 auto !important;
  }

  #sidebarLaptops .lap-tab {
    min-height: 34px;
    font-size: 12px;
    border-radius: 6px;
  }

  #sidebarLaptops .lap-item,
  #sidebarLaptops .lap-brand-hdr {
    min-height: 40px;
    padding-top: 8px;
    padding-bottom: 8px;
    touch-action: pan-y;
  }

  /* Tabs 3 & 4: Inspector & AI & Tools (#sidebarRight full-screen) */
  body[data-mob-view="inspector"] #mobCatalogSwitcher,
  body[data-mob-view="inspector"] section.viewport-wrap,
  body[data-mob-view="inspector"] #sidebarLeft,
  body[data-mob-view="inspector"] #sidebarLaptops,
  body[data-mob-view="ai"] #mobCatalogSwitcher,
  body[data-mob-view="ai"] section.viewport-wrap,
  body[data-mob-view="ai"] #sidebarLeft,
  body[data-mob-view="ai"] #sidebarLaptops {
    display: none !important;
  }

  body[data-mob-view="inspector"] #sidebarRight,
  body[data-mob-view="inspector"] #sidebarRight.collapsed,
  body[data-mob-view="ai"] #sidebarRight,
  body[data-mob-view="ai"] #sidebarRight.collapsed {
    display: flex !important;
    flex-direction: column !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 0 !important;
    flex: 1 1 0% !important;
    min-height: 0 !important;
    max-height: 100% !important;
    overflow: hidden !important;
    border-left: none !important;
  }

  #sidebarRight .right-mode-bar {
    min-height: 40px;
    padding: 4px 8px;
    gap: 6px;
    flex: 0 0 auto !important;
  }

  /* Inline Back-to-Board button inside #sidebarRight header */
  #mobRightBackBtn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 28px;
    padding: 0 9px;
    border-radius: 6px;
    border: 1px solid rgba(245, 184, 75, 0.52);
    background: rgba(220, 160, 58, 0.16);
    color: #fef3c7;
    font-family: var(--sans, system-ui, sans-serif);
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
    flex-shrink: 0;
    cursor: pointer;
  }

  #mobRightBackBtn.hidden {
    display: none !important;
  }

  /* Unified smooth vertical scrolling on #rightPaneInspector so BGA box & pin cards never crush */
  #rightPaneInspector.active {
    display: block !important;
    flex: 1 1 0% !important;
    height: 0 !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
    overscroll-behavior-y: contain !important;
    padding-bottom: 32px !important;
  }

  #rightPaneInspector .chip-side-head {
    flex-wrap: wrap !important;
    gap: 6px !important;
    padding: 7px 10px !important;
  }

  #rightPaneInspector .chip-side-title {
    flex: 1 1 160px !important;
    min-width: 0 !important;
  }

  #rightPaneInspector .chip-side-actions {
    flex-wrap: wrap !important;
    gap: 5px !important;
  }

  #rightPaneInspector .chip-canvas-wrap {
    height: 165px !important;
  }

  #rightPaneInspector .chip-side-content {
    max-height: none !important;
    overflow: visible !important;
  }

  #rightPaneInspector .inspector-scroll,
  #inspectorBody {
    overflow: visible !important;
    height: auto !important;
    flex: none !important;
  }

  #rightPaneAi.active {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 1 0% !important;
    height: 0 !important;
    min-height: 0 !important;
    overflow: hidden !important;
  }

  #rightPaneAi #aiOutput {
    flex: 1 1 0% !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
    overscroll-behavior-y: contain !important;
  }

  /* ------------------------------------------------------------------------
     3A. Clean State-Driven Mobile Views: NO Board Open (data-mob-has-board="0")
         or Explicit Launchpad Sheet (data-mob-home-open="1")
     ------------------------------------------------------------------------ */
  /* Always hide X/Y status bar clutter on mobile so PCB & Home have max height */
  .viewport-wrap > .canvas-hud-bottom,
  .canvas-hud-bottom,
  #hoverTooltip {
    display: none !important;
  }

  /* When no board is loaded yet (or Launchpad sheet is open), hide ALL CAD bars! */
  body:not([data-mob-has-board="1"]) .canvas-boardbar,
  body:not([data-mob-has-board="1"]) .canvas-toolbar,
  body:not([data-mob-has-board="1"]) #layerStrip,
  body:not([data-mob-has-board="1"]) #mobPinQuickBar,
  body[data-mob-home-open="1"] .canvas-boardbar,
  body[data-mob-home-open="1"] .canvas-toolbar,
  body[data-mob-home-open="1"] #layerStrip,
  body[data-mob-home-open="1"] #mobPinQuickBar {
    display: none !important;
  }

  /* Canvas Overlay & Spacious Mobile Home Screen (#mobHomeLaunchpad) */
  .canvas-overlay,
  #canvasOverlay {
    align-items: stretch !important;
    justify-content: flex-start !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
    padding: 12px 12px 18px !important;
    background: radial-gradient(circle at 50% 0%, #141d2e 0%, #090d14 72%) !important;
  }

  /* Hide cluttered desktop .hub-card when idle; show it ONLY while decoding a board */
  #canvasOverlay:not(.is-loading) .overlay-card.hub-card {
    display: none !important;
  }

  #canvasOverlay.is-loading {
    align-items: center !important;
    justify-content: center !important;
  }

  #canvasOverlay.is-loading #mobHomeLaunchpad {
    display: none !important;
  }

  #canvasOverlay.is-loading .overlay-card.hub-card {
    width: 100% !important;
    max-width: 400px !important;
    padding: 18px 16px !important;
    border-radius: 12px !important;
    margin: auto !important;
  }

  /* Spacious Native Mobile Home Launchpad */
  #mobHomeLaunchpad {
    display: flex !important;
    flex-direction: column;
    gap: 14px;
    width: 100%;
    max-width: 460px;
    margin: auto;
  }

  .mob-home-return-btn {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 32px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid rgba(52, 211, 153, 0.5);
    background: rgba(16, 185, 129, 0.14);
    color: #a7f3d0;
    font-family: var(--sans, system-ui, sans-serif);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
  }

  .mob-home-return-btn.hidden {
    display: none !important;
  }

  .mob-home-hero {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 2px 2px 0;
  }

  .mob-home-kicker {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--mono, monospace);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: #f5b84b;
    text-transform: uppercase;
  }

  .mob-home-kicker-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #34d399;
    box-shadow: 0 0 8px rgba(52, 211, 153, 0.85);
  }

  .mob-home-title {
    margin: 0;
    font-family: var(--sans, system-ui, -apple-system, sans-serif);
    font-size: 21px;
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.18;
    color: #f8fafc;
  }

  .mob-home-sub {
    margin: 0;
    font-family: var(--sans, system-ui, sans-serif);
    font-size: 13px;
    font-weight: 500;
    line-height: 1.35;
    color: #94a3b8;
  }

  /* 2x2 Large Touch Category Grid (>= 78px comfortable cards) */
  .mob-home-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .mob-home-card {
    min-height: 82px;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid #243044;
    background: linear-gradient(165deg, #161e2c 0%, #101621 100%);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    text-align: left;
    cursor: pointer;
    transition: transform 0.1s ease, border-color 0.12s ease;
    -webkit-tap-highlight-color: transparent;
  }

  .mob-home-card:active {
    transform: scale(0.98);
  }

  .mob-home-card--phones {
    border-color: rgba(56, 189, 248, 0.36);
  }

  .mob-home-card--laptops {
    border-color: rgba(245, 184, 75, 0.42);
  }

  .mob-home-card--bios {
    border-color: rgba(52, 211, 153, 0.38);
  }

  .mob-home-card--pdf {
    border-color: rgba(248, 113, 113, 0.36);
  }

  .mob-hc-top {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
  }

  .mob-hc-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  .mob-hc-icon svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .mob-home-card--phones .mob-hc-icon {
    background: rgba(56, 189, 248, 0.14);
    color: #7dd3fc;
  }

  .mob-home-card--laptops .mob-hc-icon {
    background: rgba(245, 184, 75, 0.15);
    color: #fcd34d;
  }

  .mob-home-card--bios .mob-hc-icon {
    background: rgba(52, 211, 153, 0.14);
    color: #6ee7b7;
  }

  .mob-home-card--pdf .mob-hc-icon {
    background: rgba(248, 113, 113, 0.14);
    color: #fca5a5;
  }

  .mob-hc-count {
    font-family: var(--mono, monospace);
    font-size: 10.5px;
    font-weight: 700;
    padding: 3px 6px;
    border-radius: 6px;
    background: rgba(15, 23, 42, 0.72);
    border: 1px solid rgba(148, 163, 184, 0.2);
    color: #cbd5e1;
    white-space: nowrap;
  }

  .mob-hc-title {
    font-family: var(--sans, system-ui, sans-serif);
    font-size: 13.5px;
    font-weight: 700;
    line-height: 1.2;
    color: #f1f5f9;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Upload Local Board/PDF Compact Full-Width Button */
  .mob-home-upload-btn {
    width: 100%;
    min-height: 44px;
    padding: 0 14px;
    border-radius: 10px;
    border: 1px dashed rgba(220, 160, 58, 0.55);
    background: rgba(220, 160, 58, 0.1);
    color: #fde68a;
    font-family: var(--sans, system-ui, sans-serif);
    font-size: 12.5px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .mob-home-upload-btn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
  }

  .mob-home-upload-btn:active {
    background: rgba(220, 160, 58, 0.2);
    transform: scale(0.99);
  }

  /* Horizontal Scrollable Quick Demo Boards Row */
  .mob-home-demos {
    display: flex;
    flex-direction: column;
    gap: 7px;
  }

  .mob-home-demos-lbl {
    font-family: var(--sans, system-ui, sans-serif);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: #7c8ba1;
    padding: 0 2px;
  }

  .mob-home-demos-row {
    display: flex;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }

  .mob-home-demos-row::-webkit-scrollbar {
    display: none;
  }

  .mob-demo-chip {
    height: 34px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid #2b384e;
    background: #141c28;
    color: #e2e8f0;
    font-family: var(--sans, system-ui, sans-serif);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .mob-demo-chip::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #38bdf8;
    flex-shrink: 0;
  }

  .mob-demo-chip:active {
    border-color: #f5b84b;
    background: #1b2536;
    color: #fef3c7;
  }

  /* ------------------------------------------------------------------------
     3B. Board IS Loaded (data-mob-has-board="1"):
         Row 1: [← Catalog] + Board Title + ★
         Row 2: Swipeable Side A/B & Section 1..N Strip (#blockTabs) — ZERO overlap!
         Row 3: 36px Pill Toolbar (.canvas-toolbar)
         Top of Stage: Sleek Horizontal Swipeable Layer Strip (#layerStrip)
     ------------------------------------------------------------------------ */
  .canvas-boardbar {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    justify-content: center !important;
    height: auto !important;
    min-height: 34px !important;
    max-height: none !important;
    padding: 4px 8px !important;
    gap: 4px !important;
    overflow: hidden !important;
  }

  .canvas-boardbar .cbb-title-wrap {
    width: 100% !important;
    min-width: 0 !important;
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
    overflow: hidden !important;
  }

  #mobBoardBackBtn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 25px;
    padding: 0 8px;
    border-radius: 6px;
    border: 1px solid rgba(56, 189, 248, 0.45);
    background: rgba(14, 116, 144, 0.22);
    color: #bae6fd;
    font-family: var(--sans, system-ui, sans-serif);
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
    flex-shrink: 0;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  #mobBoardBackBtn:active {
    transform: scale(0.96);
    border-color: #38bdf8;
  }

  .ctb-board-title {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    font-size: 11.5px !important;
    font-weight: 600 !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
  }

  #btnFavBoard {
    margin-left: auto !important;
    flex-shrink: 0 !important;
  }

  .canvas-boardbar #blockTabs,
  .canvas-boardbar .block-tabs {
    position: static !important;
    top: auto !important;
    left: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    gap: 5px !important;
    padding: 3px 2px 2px !important;
    background: transparent !important;
    border: none !important;
    border-top: 1px solid rgba(38, 50, 70, 0.65) !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-x !important;
    scrollbar-width: none !important;
  }

  .canvas-boardbar #blockTabs.hidden,
  .canvas-boardbar .block-tabs.hidden {
    display: none !important;
  }

  .canvas-boardbar #blockTabs::-webkit-scrollbar,
  .canvas-boardbar .block-tabs::-webkit-scrollbar {
    display: none !important;
  }

  .canvas-boardbar #blockTabs button,
  .canvas-boardbar .block-tab {
    flex: 0 0 auto !important;
    height: 25px !important;
    padding: 0 9px !important;
    font-size: 11px !important;
    border-radius: 6px !important;
    border: 1px solid #283449 !important;
    background: #121824 !important;
    white-space: nowrap !important;
  }

  .canvas-boardbar #blockTabs button.active,
  .canvas-boardbar .block-tab.active {
    background: linear-gradient(180deg, rgba(220, 160, 58, 0.28) 0%, rgba(220, 160, 58, 0.14) 100%) !important;
    border-color: rgba(220, 160, 58, 0.72) !important;
    color: #ffe7ba !important;
  }

  /* Uncluttered Single-Row Pill Strip (36px height, 6px gap, 7 clear touch pills) */
  .canvas-toolbar {
    height: 36px !important;
    min-height: 36px !important;
    max-height: 36px !important;
    padding: 0 8px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
    touch-action: pan-x;
  }

  .canvas-toolbar::-webkit-scrollbar {
    display: none !important;
  }

  .canvas-toolbar .ctb-tools {
    display: inline-flex !important;
    align-items: center !important;
    gap: 6px !important;
    padding-right: 8px !important;
  }

  .canvas-toolbar .ctb-tools .tool-group {
    display: contents !important;
  }

  /* Hide redundant desktop CAD buttons so mobile toolbar stays clean & scannable */
  .canvas-toolbar .ctb-tools .sep,
  .canvas-toolbar .ctb-tools #btnZoomOut,
  .canvas-toolbar .ctb-tools #btnZoomIn,
  .canvas-toolbar .ctb-tools #btnFlipY,
  .canvas-toolbar .ctb-tools #btnToggleFlylines,
  .canvas-toolbar .ctb-tools #btnToggleEquBoxes,
  .canvas-toolbar .ctb-tools #btnToggleBright,
  .canvas-toolbar .ctb-tools #btnCmdPalette,
  .canvas-toolbar .ctb-tools #ctBtnCmdPalette {
    display: none !important;
  }

  /* Order essential touch pills: Fit, 90°, Flip X, Photo, Traces, Labels, Pinboard */
  .canvas-toolbar .ctb-tools #btnFit { order: 1; }
  .canvas-toolbar .ctb-tools #btnRotate { order: 2; }
  .canvas-toolbar .ctb-tools #btnFlipX { order: 3; }
  .canvas-toolbar .ctb-tools #btnPhotoOverlay { order: 4; }
  .canvas-toolbar .ctb-tools #btnToggleNetTraces { order: 5; }
  .canvas-toolbar .ctb-tools #btnToggleLabels { order: 6; }
  .canvas-toolbar .ctb-tools #btnPinboard { order: 7; }
  .canvas-toolbar .ctb-tools #btnLcfImage { order: 8; }

  .canvas-toolbar .ctb-tools .tool-btn,
  .canvas-toolbar .ctb-tools .tool-btn.icon-only {
    height: 28px !important;
    width: auto !important;
    min-width: 0 !important;
    padding: 0 10px !important;
    font-size: 11.5px !important;
    font-weight: 600 !important;
    border-radius: 999px !important;
    gap: 5px !important;
    flex-shrink: 0 !important;
    justify-content: center !important;
  }

  .canvas-toolbar .ctb-tools #btnFit span,
  .canvas-toolbar .ctb-tools #btnRotate span,
  .canvas-toolbar .ctb-tools #btnFlipX .mob-flipx-lbl,
  .canvas-toolbar .ctb-tools #btnPhotoOverlay span,
  .canvas-toolbar .ctb-tools #btnToggleNetTraces span,
  .canvas-toolbar .ctb-tools #btnToggleLabels span,
  .canvas-toolbar .ctb-tools #btnPinboard > span:not(.ct-pin-badge),
  .canvas-toolbar .ctb-tools #btnLcfImage span {
    display: inline !important;
  }

  /* Sleek Horizontal Swipeable Layer Strip at top of .canvas-stage (Zero overlap with PCB or Pin Card!) */
  .layer-strip,
  #layerStrip {
    position: absolute !important;
    top: 6px !important;
    left: 6px !important;
    right: 6px !important;
    width: auto !important;
    max-width: calc(100% - 12px) !important;
    height: auto !important;
    max-height: 32px !important;
    transform: none !important;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 4px !important;
    padding: 3px 5px !important;
    border-radius: 8px !important;
    background: rgba(13, 18, 27, 0.9) !important;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-x !important;
    scrollbar-width: none !important;
    z-index: 15 !important;
  }

  #layerStrip::-webkit-scrollbar {
    display: none !important;
  }

  #layerButtons,
  .layer-buttons {
    display: inline-flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 4px !important;
    flex-shrink: 0 !important;
  }

  #layerStrip .layer-pill {
    flex: 0 0 auto !important;
    min-width: 34px !important;
    height: 24px !important;
    padding: 0 7px !important;
    font-size: 10.5px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    white-space: nowrap !important;
  }

  /* ------------------------------------------------------------------------
     4. Interactive 2-Row Bottom Drawer / Pin Card (#mobPinQuickBar)
     ------------------------------------------------------------------------ */
  #mobPinQuickBar {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 10px;
    z-index: 34;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 11px;
    background: rgba(13, 18, 27, 0.94);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid rgba(220, 160, 58, 0.56);
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.72), inset 0 1px 0 rgba(255, 238, 196, 0.12);
    color: #f1f5fb;
    animation: mobPillIn 0.15s ease-out;
  }

  #mobPinQuickBar.hidden {
    display: none !important;
  }

  @keyframes mobPillIn {
    from {
      opacity: 0;
      transform: translateY(8px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .mob-pq-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
  }

  .mob-pq-info {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
    white-space: nowrap;
  }

  .mob-pq-ref {
    font-family: var(--mono, monospace);
    font-size: 13px;
    font-weight: 800;
    color: #fde68a;
    flex-shrink: 0;
  }

  .mob-pq-sep {
    color: #526077;
    font-size: 11px;
    flex-shrink: 0;
  }

  .mob-pq-val {
    font-family: var(--mono, monospace);
    font-size: 11px;
    font-weight: 700;
    color: #67e8f9;
    background: rgba(8, 145, 178, 0.22);
    border: 1px solid rgba(103, 232, 249, 0.36);
    padding: 2px 7px;
    border-radius: 999px;
    flex-shrink: 0;
    max-width: 118px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .mob-pq-net-lbl {
    font-family: var(--sans, system-ui, sans-serif);
    font-size: 10.5px;
    font-weight: 600;
    color: #7c8ba1;
    flex-shrink: 0;
  }

  .mob-pq-net {
    font-family: var(--mono, monospace);
    font-size: 12px;
    font-weight: 700;
    color: #cbd5e1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .mob-pq-net.is-sig {
    color: #86efac;
  }

  .mob-pq-net.is-gnd {
    color: #94a3b8;
  }

  .mob-pq-desc {
    font-family: var(--sans, system-ui, sans-serif);
    font-size: 11.5px;
    font-weight: 500;
    color: #cbd5e1;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 1px;
  }

  .mob-pq-desc.hidden {
    display: none !important;
  }

  .mob-pq-close-btn {
    width: 28px;
    height: 28px;
    padding: 0;
    border-radius: 7px;
    border: 1px solid #2b3648;
    background: #171f2d;
    color: #94a3b8;
    font-size: 16px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    cursor: pointer;
  }

  .mob-pq-bottom {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .mob-pq-btn {
    height: 36px;
    padding: 0 10px;
    border-radius: 8px;
    font-family: var(--sans, system-ui, sans-serif);
    font-size: 12px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .mob-pq-btn:active {
    transform: scale(0.98);
  }

  .mob-pq-btn--inspector {
    border: 1px solid rgba(220, 160, 58, 0.65);
    background: linear-gradient(180deg, rgba(220, 160, 58, 0.28) 0%, rgba(220, 160, 58, 0.14) 100%);
    color: #fff3d6;
  }

  .mob-pq-btn--ai {
    border: 1px solid rgba(52, 211, 153, 0.58);
    background: linear-gradient(180deg, rgba(16, 185, 129, 0.26) 0%, rgba(16, 185, 129, 0.12) 100%);
    color: #d1fae5;
  }

  /* ------------------------------------------------------------------------
     5. Quick Engineering Cards inside Tab 4 (AI & Tools -> #mobAiQuickTools)
     ------------------------------------------------------------------------ */
  #mobAiQuickTools {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
    padding: 8px 10px;
    background: #0e131d;
    border-bottom: 1px solid #232d3f;
    flex-shrink: 0;
  }

  .mob-ai-tool-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-height: 54px;
    padding: 8px 5px;
    border-radius: 9px;
    border: 1px solid #29364a;
    background: linear-gradient(180deg, #192231 0%, #121824 100%);
    color: #e2e8f0;
    font-family: var(--sans, system-ui, sans-serif);
    font-size: 11px;
    font-weight: 600;
    line-height: 1.15;
    text-align: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .mob-ai-tool-btn svg {
    width: 16px;
    height: 16px;
    stroke: #f5b84b;
    fill: none;
    stroke-width: 1.65;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .mob-ai-tool-btn:active {
    background: rgba(220, 160, 58, 0.18);
    border-color: rgba(220, 160, 58, 0.65);
  }

  /* ------------------------------------------------------------------------
     6. Clean 4-Tab Spacious Bottom Navigation Bar (#mobileBottomNav)
     ------------------------------------------------------------------------ */
  #mobileBottomNav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(56px + env(safe-area-inset-bottom, 0px));
    padding: 0 6px env(safe-area-inset-bottom, 0px);
    background: linear-gradient(180deg, #151b26 0%, #0d1118 100%);
    border-top: 1px solid #263144;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.5);
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    align-items: stretch;
    z-index: 4200;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }

  .mob-nav-tab {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 4px 4px 3px;
    border: none;
    background: transparent;
    color: #8897ad;
    font-family: var(--sans, system-ui, sans-serif);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: -0.01em;
    cursor: pointer;
    transition: color 0.12s ease, background 0.12s ease;
    min-width: 0;
  }

  .mob-nav-tab::before {
    content: "";
    position: absolute;
    top: 0;
    left: 24%;
    right: 24%;
    height: 2.5px;
    border-radius: 0 0 3px 3px;
    background: transparent;
    transition: background 0.12s ease;
  }

  .mob-nav-tab svg {
    width: 19px;
    height: 19px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
  }

  .mob-nav-tab span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.15;
  }

  .mob-nav-tab.active {
    color: #fde68a;
    background: radial-gradient(circle at 50% 0%, rgba(220, 160, 58, 0.16), transparent 74%);
  }

  .mob-nav-tab.active::before {
    background: #f5b84b;
  }

  .mob-nav-tab.active svg {
    stroke: #f5b84b;
  }

  .mob-nav-icon-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .mob-nav-dot {
    position: absolute;
    top: -2px;
    right: -5px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #34d399;
    box-shadow: 0 0 0 2px #131822, 0 0 8px rgba(52, 211, 153, 0.85);
  }

  .mob-nav-dot.hidden {
    display: none !important;
  }

  /* ------------------------------------------------------------------------
     7. Floating CAD Windows, Paywall Modal & Photo Popover -> Zero Collision
     ------------------------------------------------------------------------ */
  .cad-win,
  .cad-window {
    left: 6px !important;
    right: 6px !important;
    top: 50px !important;
    width: calc(100vw - 12px) !important;
    max-width: calc(100vw - 12px) !important;
    min-width: 0 !important;
    height: calc(100vh - 50px - 62px) !important;
    height: calc(100dvh - 50px - 62px - env(safe-area-inset-bottom, 0px)) !important;
    max-height: calc(100dvh - 50px - 62px - env(safe-area-inset-bottom, 0px)) !important;
    min-height: 0 !important;
    border-radius: 10px !important;
  }

  .cad-win-resize {
    display: none !important;
  }

  #cadWindowDock {
    bottom: calc(60px + env(safe-area-inset-bottom, 0px)) !important;
    left: 6px !important;
    right: 6px !important;
    max-width: calc(100vw - 12px) !important;
  }

  /* Library / BIOS Hub rows wrap gracefully inside narrow mobile CAD window */
  .lib-row {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  .lib-row-actions {
    width: 100%;
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  /* SaaS Paywall & Telegram Stars Modal */
  #saasModal.saas-modal-overlay {
    padding: 6px !important;
    align-items: flex-end !important;
  }

  #saasModal .saas-dialog {
    width: calc(100vw - 12px) !important;
    max-width: calc(100vw - 12px) !important;
    max-height: calc(100vh - 14px) !important;
    max-height: calc(100dvh - 14px - env(safe-area-inset-bottom, 0px)) !important;
    border-radius: 14px !important;
  }

  .saas-head {
    padding: 10px 12px !important;
  }

  .saas-user-chip {
    max-width: 118px !important;
  }

  .saas-body {
    padding: 12px !important;
  }

  /* Photo Overlay Popover: opens cleanly as a bottom sheet above #mobileBottomNav, clearing #layerStrip */
  #photoOverlayPopover,
  .photo-overlay-pop {
    top: auto !important;
    bottom: 10px !important;
    left: 8px !important;
    right: 8px !important;
    width: auto !important;
    max-width: calc(100vw - 16px) !important;
    max-height: min(68%, 420px) !important;
    overflow-y: auto !important;
    border-radius: 12px !important;
    z-index: 48 !important;
  }

  /* Chip & LCF Modals */
  #chipModal .modal-box,
  #lcfModal .modal-box {
    width: calc(100vw - 12px) !important;
    max-width: calc(100vw - 12px) !important;
    max-height: calc(100dvh - 20px - env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Keep toast notifications cleanly above #mobileBottomNav */
  .super-toast-stack,
  .lap-toast {
    right: 8px !important;
    left: 8px !important;
    bottom: calc(64px + env(safe-area-inset-bottom, 0px)) !important;
    max-width: calc(100vw - 16px) !important;
  }
}
