/* TheaCRM v2.8.437 – unified UI layers / overlay manager
   Jeden systém vrstev pro horní lištu, dropdowny, globální hledání, modály
   a mobilní spodní navigaci. Neřeší se lokálními z-index hotfixy v modulech. */
:root{
  --thea-z-content:1;
  --thea-z-sticky:900;
  --thea-z-header:1100;
  --thea-z-sidebar:1150;
  --thea-z-bottom-nav:1200;
  --thea-z-quick-add:1250;
  --thea-z-dropdown:1600;
  --thea-z-popover:1700;
  --thea-z-backdrop:2000;
  --thea-z-modal:2010;
  --thea-z-critical:3000;
  --thea-visible-viewport-height:100dvh;
  --thea-visible-viewport-top:0px;
  --thea-measured-bottom-nav-height:0px;
}

/* Základní pořadí vrstev. */
.header{z-index:var(--thea-z-header) !important;}
.sidebar{z-index:var(--thea-z-sidebar) !important;}
.sidebar-overlay{z-index:calc(var(--thea-z-sidebar) - 10) !important;}
.thea-mobile-bottom-nav{z-index:var(--thea-z-bottom-nav) !important;}
.thea-mobile-quick-add-backdrop{z-index:calc(var(--thea-z-quick-add) - 10) !important;}
.thea-mobile-quick-add{z-index:var(--thea-z-quick-add) !important;}
.flash-pill-overlay{z-index:var(--thea-z-critical) !important;}

/* Sticky hlavičky modulů nesmí přelézat přes globální overlaye. */
.sticky-top,
.email-toolbar,
.filter-bar,
.thea-sticky-actions,
.thea-toolbar-sticky,
.thea-mobile-sticky-actions,
body.thea-email-ui-page .email-toolbar,
body.thea-email-ui-page #toolbar-default,
body.thea-email-ui-page .email-action-more,
body.thea-email-ui-page .email-triage-dropdown,
body.thea-email-ui-page .pager-bar .dropdown{
  z-index:var(--thea-z-sticky) !important;
}

/* Bootstrap dropdowny a e-mailová menu jsou popover vrstva: nad obsahem/spodní lištou,
   ale pod skutečným modalem typu globální hledání. */
.dropdown-menu,
.dropdown-menu.show,
.email-action-more-menu,
.email-action-more-menu.show,
.email-triage-menu,
.email-triage-menu.show,
body.thea-email-ui-page .email-toolbar .dropdown-menu,
body.thea-email-ui-page .email-toolbar .dropdown-menu.show,
body.thea-email-ui-page .email-action-more-menu,
body.thea-email-ui-page .email-action-more-menu.show,
body.thea-email-ui-page .email-triage-menu,
body.thea-email-ui-page .email-triage-menu.show,
body.thea-email-ui-page .pager-bar .dropdown-menu,
body.thea-email-ui-page .pager-bar .dropdown-menu.show{
  z-index:var(--thea-z-popover) !important;
}

.dropdown,
.dropup,
.dropend,
.dropstart,
.email-toolbar,
#toolbar-default,
.email-action-more,
.email-triage-dropdown,
.pager-bar .dropdown{
  overflow:visible !important;
}

/* Horní dropdowny: zvonek a obálka. */
#notificationDropdown.thea-top-dropdown,
#mailDropdown.thea-top-dropdown,
.thea-top-dropdown{
  z-index:var(--thea-z-dropdown) !important;
  max-height:calc(var(--thea-visible-viewport-height, 100dvh) - var(--navbar-height,64px) - var(--thea-measured-bottom-nav-height,0px) - 24px) !important;
  overflow:hidden !important;
}
#notificationDropdown.thea-top-dropdown ul,
#mailDropdown.thea-top-dropdown ul,
.thea-top-dropdown ul{
  max-height:calc(var(--thea-visible-viewport-height, 100dvh) - var(--navbar-height,64px) - var(--thea-measured-bottom-nav-height,0px) - 122px) !important;
  overflow-y:auto !important;
  overscroll-behavior:contain;
}

/* Globální hledání je modal. Musí být nad e-mailovou lištou, dropdowny i spodní lištou. */
.thea-global-search-backdrop{
  z-index:var(--thea-z-backdrop) !important;
}
.thea-global-search-modal{
  z-index:var(--thea-z-modal) !important;
  height:var(--thea-visible-viewport-height,100dvh) !important;
  top:var(--thea-visible-viewport-top,0px) !important;
  bottom:auto !important;
}
body.thea-global-search-open .thea-mobile-bottom-nav,
body.thea-global-search-open .thea-mobile-quick-add,
body.thea-global-search-open .thea-mobile-quick-add-backdrop,
body.thea-global-search-open #notificationDropdown,
body.thea-global-search-open #mailDropdown{
  display:none !important;
}
body.thea-global-search-open .email-toolbar,
body.thea-global-search-open .filter-bar,
body.thea-global-search-open .sticky-top{
  z-index:0 !important;
}

/* Bootstrap modály a offcanvas necháváme výš než běžné popovery. */
.modal-backdrop{z-index:var(--thea-z-backdrop) !important;}
.modal{z-index:var(--thea-z-modal) !important;}
.offcanvas-backdrop{z-index:var(--thea-z-backdrop) !important;}
.offcanvas{z-index:var(--thea-z-modal) !important;}

@media (max-width:767.98px){
  .thea-global-search-modal{
    inset:auto 0 auto 0 !important;
    height:var(--thea-visible-viewport-height,100dvh) !important;
    padding:calc(env(safe-area-inset-top,0px) + 8px) 8px calc(12px + env(safe-area-inset-bottom,0px)) !important;
    align-items:stretch !important;
  }
  .thea-global-search-dialog{
    max-height:calc(var(--thea-visible-viewport-height,100dvh) - 20px - env(safe-area-inset-top,0px) - env(safe-area-inset-bottom,0px)) !important;
  }
  .thea-global-search-results{
    max-height:none !important;
    min-height:0;
  }
  .thea-layer-dropdown-menu,
  .dropdown-menu.show{
    max-width:calc(100vw - 18px) !important;
    overscroll-behavior:contain;
  }
  .thea-top-dropdown{
    width:min(420px, calc(100vw - 18px)) !important;
  }
}

/* TheaCRM v2.8.505 – mobile quick-add stacking context
   Keep the backdrop below the bottom nav when the quick-add panel is open. */
@media (max-width: 767.98px){
  .thea-mobile-bottom-nav.is-quick-add-open{
    z-index: calc(var(--thea-z-quick-add, 1250) + 20) !important;
  }
  .thea-mobile-bottom-nav.is-quick-add-open .thea-mobile-quick-add{
    z-index: calc(var(--thea-z-quick-add, 1250) + 30) !important;
  }
  .thea-mobile-quick-add-backdrop:not([hidden]){
    z-index: calc(var(--thea-z-quick-add, 1250) + 5) !important;
  }
}
