/* Mobile CRM layout: one document scroll, persistent header/action row, fixed nav. */
:root {
  --app-safe-area-top: max(env(safe-area-inset-top, 0px), var(--safe-area-inset-top, 0px));
  --app-safe-area-right: max(env(safe-area-inset-right, 0px), var(--safe-area-inset-right, 0px));
  --app-safe-area-bottom: max(env(safe-area-inset-bottom, 0px), var(--safe-area-inset-bottom, 0px));
  --app-safe-area-left: max(env(safe-area-inset-left, 0px), var(--safe-area-inset-left, 0px));
  --crm-mobile-header-height: calc(73px + var(--app-safe-area-top));
}

@media (max-width: 767px) {
  html,
  body,
  #root {
    min-height: 100%;
  }

  body:has(.mobile-crm-shell) {
    height: auto !important;
    min-height: 100dvh !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior-y: auto;
  }

  .mobile-dashboard-shell:has(.mobile-crm-shell) {
    position: relative !important;
    display: flex !important;
    height: auto !important;
    min-height: 100dvh !important;
    overflow: visible !important;
    padding-bottom: calc(4rem + var(--app-safe-area-bottom)) !important;
  }

  .mobile-dashboard-shell:has(.mobile-crm-shell) .mobile-app-header {
    position: sticky !important;
    top: 0 !important;
    z-index: 80 !important;
    flex: 0 0 auto !important;
    min-height: var(--crm-mobile-header-height) !important;
    padding-top: calc(1rem + var(--app-safe-area-top)) !important;
    padding-right: calc(1rem + var(--app-safe-area-right)) !important;
    padding-left: calc(1rem + var(--app-safe-area-left)) !important;
    background: rgba(15, 15, 22, 0.98) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    transform: none !important;
  }

  .mobile-dashboard-shell:has(.mobile-crm-shell) .mobile-dashboard-main {
    position: relative !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  .mobile-dashboard-shell:has(.mobile-crm-shell) .mobile-dashboard-content {
    min-height: 0 !important;
    padding-bottom: calc(7rem + var(--app-safe-area-bottom)) !important;
  }

  .mobile-dashboard-shell:has(.mobile-crm-shell) .mobile-crm-shell {
    height: auto !important;
    min-height: calc(100dvh - var(--crm-mobile-header-height)) !important;
    overflow: visible !important;
  }

  /* The CRM title scrolls away; its action toolbar stays below the app header. */
  .mobile-dashboard-shell:has(.mobile-crm-shell) .mobile-crm-shell > div.flex.gap-4:first-child {
    display: contents !important;
  }

  .mobile-dashboard-shell:has(.mobile-crm-shell) .crm-mobile-action-toolbar {
    position: sticky !important;
    top: var(--crm-mobile-header-height) !important;
    z-index: 70 !important;
    display: flex !important;
    width: 100% !important;
    min-width: 0 !important;
    flex: 0 0 auto !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 5px !important;
    margin: 0 !important;
    padding: 7px 0 !important;
    overflow: visible !important;
    background: rgba(11, 11, 15, 0.98) !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    transform: none !important;
  }

  .mobile-dashboard-shell:has(.mobile-crm-shell) .crm-mobile-action-toolbar > button {
    flex: 0 0 36px !important;
    width: 36px !important;
    min-width: 36px !important;
    height: 38px !important;
    padding: 0 !important;
    justify-content: center !important;
  }

  .mobile-dashboard-shell:has(.mobile-crm-shell) .crm-mobile-action-toolbar > div {
    flex: 0 0 auto !important;
    min-height: 34px;
    padding-right: 8px !important;
    padding-left: 8px !important;
    white-space: nowrap;
  }

  .mobile-dashboard-shell:has(.mobile-crm-shell) .mobile-crm-shell > div.flex.overflow-x-auto.shrink-0 {
    position: static !important;
    inset: auto !important;
    z-index: auto !important;
    isolation: auto !important;
    transform: none !important;
    margin: 0 0 8px !important;
  }

  .mobile-dashboard-shell:has(.mobile-crm-shell) .mobile-bottom-nav {
    position: fixed !important;
    top: auto !important;
    bottom: calc(1rem + var(--app-safe-area-bottom)) !important;
    left: calc(1rem + var(--app-safe-area-left)) !important;
    right: calc(1rem + var(--app-safe-area-right)) !important;
    z-index: 100 !important;
    min-height: 3.5rem !important;
    overflow: visible !important;
    transform: none !important;
    isolation: isolate !important;
    background: transparent !important;
    border-color: transparent !important;
    box-shadow: none !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
  }

  .mobile-dashboard-shell:has(.mobile-crm-shell) .mobile-bottom-nav::before {
    content: "";
    position: absolute;
    z-index: -1;
    inset: -1px;
    border: 1px solid rgba(255, 255, 255, 0.17);
    border-radius: inherit;
    background-color: rgba(35, 35, 39, 0.62);
    background-image: linear-gradient(145deg, rgba(255, 255, 255, 0.09), rgba(255, 255, 255, 0.015) 48%, rgba(255, 255, 255, 0.045));
    -webkit-backdrop-filter: blur(12px) saturate(125%);
    backdrop-filter: blur(12px) saturate(125%);
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.25), inset 0 0.8px 0 rgba(255, 255, 255, 0.14), inset 0 -0.7px 0 rgba(255, 255, 255, 0.06);
    pointer-events: none;
  }

  /* Avoid mobile-browser page zoom when a small-text form field receives focus. */
  .mobile-crm-shell .fixed.inset-0 input,
  .mobile-crm-shell .fixed.inset-0 select,
  .mobile-crm-shell .fixed.inset-0 textarea {
    font-size: 16px !important;
  }

  .mobile-crm-shell .fixed.inset-0 > [role="dialog"],
  .mobile-crm-shell .fixed.inset-0 > section[role="dialog"],
  .mobile-crm-shell .fixed.inset-0 > div[role="dialog"] {
    max-height: calc(100dvh - 2rem - var(--app-safe-area-top) - var(--app-safe-area-bottom)) !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
  }
}

@media (min-width: 768px) {
  .mobile-dashboard-shell .mobile-bottom-nav { display: none !important; }
}
