/* ============================================
   PB-SNB-20261027-0005 — Mobile App Shell
   Bottom tab bar + touch sheets + crypto chips
   Load LAST (via mobile-sidebar-fix.css import)
   ============================================ */

:root {
  --pb-m-bottom-nav: 56px;
  --pb-m-safe-bottom: env(safe-area-inset-bottom, 0px);
  --pb-m-tap: 44px;
  --pb-m-accent: #8b5cf6;
  --pb-m-bg: #0a0a1a;
  --pb-m-card: #12122a;
  --pb-m-border: rgba(139, 92, 246, 0.28);
}

/* Desktop: hide app chrome */
.pb-bottom-nav,
.pb-sheet-root,
.pb-mobile-only {
  display: none !important;
}

@media screen and (max-width: 768px) {
  .pb-bottom-nav {
    display: flex !important;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10060;
    height: calc(var(--pb-m-bottom-nav) + var(--pb-m-safe-bottom));
    padding: 0 4px var(--pb-m-safe-bottom);
    background: rgba(10, 10, 26, 0.96);
    border-top: 1px solid var(--pb-m-border);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    align-items: stretch;
    justify-content: space-around;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.45);
  }

  .pb-bottom-nav button {
    flex: 1;
    min-height: var(--pb-m-tap);
    min-width: 0;
    border: none;
    background: transparent;
    color: #94a3b8;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.02em;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    padding: 6px 2px;
  }

  .pb-bottom-nav button .pb-nav-ico {
    font-size: 20px;
    line-height: 1;
  }

  .pb-bottom-nav button.active {
    color: #c4b5fd;
  }

  .pb-bottom-nav button.active .pb-nav-ico {
    transform: translateY(-1px);
  }

  .pb-bottom-nav button:active {
    background: rgba(139, 92, 246, 0.12);
  }

  /* Room for bottom nav + keep hamburger usable */
  body.pb-mobile-app .main-container {
    height: calc(100vh - 52px - var(--pb-m-bottom-nav) - var(--pb-m-safe-bottom)) !important;
    padding-bottom: 0 !important;
  }

  body.pb-mobile-app .content {
    padding-bottom: 12px !important;
  }

  body.pb-mobile-app .sidebar {
    height: calc(100vh - 52px - var(--pb-m-bottom-nav) - var(--pb-m-safe-bottom)) !important;
    padding-bottom: 16px !important;
  }

  /* Compact header — kill tiny dropdown clutter */
  body.pb-mobile-app .dashboard-header .search-bar-trigger,
  body.pb-mobile-app .dashboard-header #workspace-selector-container,
  body.pb-mobile-app .dashboard-header #system-status,
  body.pb-mobile-app .dashboard-header #bot-count,
  body.pb-mobile-app .dashboard-header #tasks-today,
  body.pb-mobile-app .dashboard-header .cache-clear-btn {
    display: none !important;
  }

  body.pb-mobile-app .dashboard-header {
    min-height: 52px !important;
    height: auto !important;
    padding: 8px 12px 8px 64px !important;
    align-items: center !important;
  }

  body.pb-mobile-app .dashboard-header .logo h1 {
    font-size: 15px !important;
    margin: 0 !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 46vw;
  }

  body.pb-mobile-app .dashboard-header .status-indicators {
    gap: 6px !important;
    margin-left: auto;
  }

  body.pb-mobile-app .menu-toggle {
    width: 44px !important;
    height: 44px !important;
    top: 8px !important;
    left: 8px !important;
  }

  /* Sidebar items = real thumb targets */
  body.pb-mobile-app .sidebar .bot-button,
  body.pb-mobile-app .sidebar .view-button {
    min-height: var(--pb-m-tap) !important;
    padding: 10px 12px !important;
    margin: 4px 0 !important;
    border-radius: 10px !important;
    font-size: 14px !important;
  }

  body.pb-mobile-app .sidebar .bot-desc,
  body.pb-mobile-app .sidebar .bot-sublabel {
    font-size: 11px !important;
  }

  /* ===== Bottom sheets for submenus ===== */
  .pb-sheet-root {
    display: block !important;
    position: fixed;
    inset: 0;
    z-index: 10070;
    pointer-events: none;
    visibility: hidden;
  }

  .pb-sheet-root.open {
    pointer-events: auto;
    visibility: visible;
  }

  .pb-sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    opacity: 0;
    transition: opacity 0.2s ease;
  }

  .pb-sheet-root.open .pb-sheet-backdrop {
    opacity: 1;
  }

  .pb-sheet-panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: min(78vh, 640px);
    background: var(--pb-m-card);
    border-radius: 16px 16px 0 0;
    border: 1px solid var(--pb-m-border);
    border-bottom: none;
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.55);
    transform: translateY(110%);
    transition: transform 0.28s cubic-bezier(0.3, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    padding-bottom: calc(12px + var(--pb-m-safe-bottom));
    overflow: hidden;
  }

  .pb-sheet-root.open .pb-sheet-panel {
    transform: translateY(0);
  }

  .pb-sheet-handle {
    width: 40px;
    height: 4px;
    border-radius: 4px;
    background: rgba(148, 163, 184, 0.45);
    margin: 10px auto 6px;
    flex-shrink: 0;
  }

  .pb-sheet-title {
    padding: 4px 16px 10px;
    font-size: 15px;
    font-weight: 700;
    color: #e2e8f0;
    flex-shrink: 0;
  }

  .pb-sheet-list {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 8px 8px;
  }

  .pb-sheet-item {
    width: 100%;
    min-height: var(--pb-m-tap);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    margin: 4px 0;
    border: 1px solid transparent;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.03);
    color: #e2e8f0;
    font-size: 15px;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .pb-sheet-item.active {
    background: rgba(139, 92, 246, 0.18);
    border-color: rgba(139, 92, 246, 0.45);
    color: #ddd6fe;
  }

  .pb-sheet-item:active {
    background: rgba(139, 92, 246, 0.28);
  }

  /* Sheet trigger replaces broken nested dropdowns */
  .pb-sheet-trigger {
    display: flex !important;
    width: 100%;
    min-height: var(--pb-m-tap);
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 14px;
    margin: 0 0 10px;
    border-radius: 12px;
    border: 1px solid var(--pb-m-border);
    background: rgba(139, 92, 246, 0.1);
    color: #e2e8f0;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .pb-sheet-trigger .pb-sheet-trigger-arrow {
    color: #a78bfa;
    font-size: 12px;
  }

  /* Hide old mobile-tab collapse UI when sheet system owns it */
  body.pb-mobile-app .mobile-tab-toggle {
    display: none !important;
  }

  body.pb-mobile-app .admin-menu,
  body.pb-mobile-app .settings-tabs,
  body.pb-mobile-app .bcc-tabs,
  body.pb-mobile-app .dc-sidebar,
  body.pb-mobile-app .ch-sidebar,
  body.pb-mobile-app .apps-sidebar {
    display: none !important;
  }

  /* ===== Crypto: readable horizontal chips ===== */
  body.pb-mobile-app .crypto-sidebar,
  body.pb-mobile-app .crypto-menu {
    width: 100% !important;
    position: sticky !important;
    top: 0 !important;
    z-index: 20;
    background: var(--pb-m-bg) !important;
  }

  body.pb-mobile-app .crypto-menu {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    gap: 8px;
    padding: 8px 4px 12px !important;
    scrollbar-width: none;
  }

  body.pb-mobile-app .crypto-menu::-webkit-scrollbar {
    display: none;
  }

  body.pb-mobile-app .crypto-nav-btn {
    flex: 0 0 auto !important;
    min-height: var(--pb-m-tap) !important;
    min-width: auto !important;
    padding: 8px 14px !important;
    margin: 0 !important;
    border-radius: 999px !important;
    border: 1px solid rgba(139, 92, 246, 0.25) !important;
    background: rgba(255, 255, 255, 0.04) !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 6px !important;
  }

  body.pb-mobile-app .crypto-nav-btn .nav-text {
    display: inline !important;
    font-size: 13px !important;
    font-weight: 700 !important;
    white-space: nowrap;
  }

  body.pb-mobile-app .crypto-nav-btn .nav-icon {
    font-size: 16px !important;
  }

  body.pb-mobile-app .crypto-nav-btn.active {
    background: rgba(139, 92, 246, 0.22) !important;
    border-color: rgba(139, 92, 246, 0.55) !important;
    color: #ddd6fe !important;
  }

  body.pb-mobile-app .crypto-tabs,
  body.pb-mobile-app .crypto-trade-tabs,
  body.pb-mobile-app .ap-desk-row,
  body.pb-mobile-app [class*="desk-tabs"] {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    gap: 8px;
    padding-bottom: 8px;
  }

  body.pb-mobile-app .crypto-tab,
  body.pb-mobile-app .crypto-trade-tab,
  body.pb-mobile-app .ap-desk-btn {
    flex: 0 0 auto !important;
    min-height: var(--pb-m-tap) !important;
    padding: 8px 14px !important;
    font-size: 13px !important;
    border-radius: 999px !important;
  }

  /* Kill hover-only / blur traps that break touch */
  body.pb-mobile-app .sidebar-overlay,
  body.pb-mobile-app .sidebar-overlay.active {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    filter: none !important;
  }

  body.pb-mobile-app .pinky-control-dropdown,
  body.pb-mobile-app #ws-header-dropdown {
    max-width: calc(100vw - 24px);
  }

  /* Generic 44px taps for common controls */
  body.pb-mobile-app button,
  body.pb-mobile-app .btn,
  body.pb-mobile-app .btn-neon,
  body.pb-mobile-app .view-button,
  body.pb-mobile-app .bot-button {
    min-height: 40px;
  }

  body.pb-mobile-app input,
  body.pb-mobile-app select,
  body.pb-mobile-app textarea {
    font-size: 16px !important; /* prevent iOS zoom */
  }

  /* PWA install chip in More / header */
  .pb-pwa-install-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: var(--pb-m-tap);
    padding: 10px 14px;
    margin: 8px 10px;
    width: calc(100% - 20px);
    border-radius: 12px;
    border: 1px solid rgba(139, 92, 246, 0.4);
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.2), rgba(99, 102, 241, 0.15));
    color: #e9d5ff;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
  }
}

@media screen and (max-width: 400px) {
  body.pb-mobile-app .main-container {
    height: calc(100vh - 48px - var(--pb-m-bottom-nav) - var(--pb-m-safe-bottom)) !important;
  }
  body.pb-mobile-app .sidebar {
    top: 48px !important;
    height: calc(100vh - 48px - var(--pb-m-bottom-nav) - var(--pb-m-safe-bottom)) !important;
  }
}

/* Standalone PWA: slightly tighter top chrome */
@media all and (display-mode: standalone) {
  body.pb-mobile-app .dashboard-header {
    padding-top: max(8px, env(safe-area-inset-top)) !important;
  }
}
