/* Public / login: never show the company workspace (sidebar, KPIs, tables, logo rail).
   Resume must not paint books under the sign-in page. */
html body:not([data-auth-state="authenticated"]):not([data-auth-state="opening"]) > :not(#esb-public):not(#esb-mfa-dialog):not(#modal-root):not(#toast):not(script):not(link):not(style) {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}
html body[data-auth-state="opening"] > #esb-public {
  display: none !important;
}
html body[data-auth-state="opening"] #auth-status:not([hidden]) {
  display: grid !important;
  visibility: visible !important;
  pointer-events: auto !important;
}
html body[data-auth-state="opening"] #auth-status[hidden] {
  display: none !important;
}
html[data-esb-resume="1"] body[data-auth-state="opening"] #esb-public,
html[data-esb-resume="1"] body[data-auth-state="opening"] aside.sidebar,
html[data-esb-resume="1"] body[data-auth-state="opening"] main {
  display: none !important;
}
html[data-esb-resume="1"] body[data-auth-state="authenticated"] #esb-public,
html[data-esb-resume="1"] body[data-auth-state="authenticated"] #auth-status {
  display: none !important;
}
html[data-esb-resume="1"] body[data-auth-state="authenticated"] aside.sidebar,
html[data-esb-resume="1"] body[data-auth-state="authenticated"] aside.sidebar[hidden] {
  display: flex !important;
  visibility: visible !important;
  pointer-events: auto !important;
}
html[data-esb-resume="1"] body[data-auth-state="authenticated"] main,
html[data-esb-resume="1"] body[data-auth-state="authenticated"] main[hidden] {
  display: block !important;
  visibility: visible !important;
  pointer-events: auto !important;
  overflow: clip !important;
  height: 100dvh !important;
  max-height: 100dvh !important;
  min-width: 0 !important;
  padding-top: var(--sb-chrome-h, 84px) !important;
  box-sizing: border-box !important;
}
html[data-esb-resume="1"] body[data-auth-state="authenticated"] #global-menubar {
  display: flex !important;
  visibility: visible !important;
  pointer-events: auto !important;
  overflow: visible !important;
  z-index: 40060 !important;
}

html body:not([data-auth-state="authenticated"]) aside.sidebar,
html body:not([data-auth-state="authenticated"]) main,
html body:not([data-auth-state="authenticated"]) #modal-root,
html body:not([data-auth-state="authenticated"]) #toast,
html body:not([data-auth-state="authenticated"]) #global-menubar,
html body:not([data-auth-state="authenticated"]) #sidebar-toggle,
html body:not([data-auth-state="authenticated"]) .sidebar-toggle {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* The public setup interview is a dialog, never an authenticated workspace. */
html[data-company-interview="1"] body:not([data-auth-state="authenticated"]) #modal-root {
  z-index:2147483647!important;
  display:block!important;
  visibility:visible!important;
  pointer-events:auto!important;
}
html[data-company-interview="1"] body:not([data-auth-state="authenticated"]) #esb-public {
  z-index:120000!important;
}
html[data-company-interview="1"] body:not([data-auth-state="authenticated"]) #toast {
  display:block!important;
  visibility:visible!important;
  pointer-events:none!important;
}

@media screen {
  html body[data-auth-state="authenticated"] aside.sidebar,
  html body[data-auth-state="authenticated"] aside.sidebar[hidden] {
    display: flex !important;
    pointer-events: auto !important;
    visibility: visible !important;
  }
  html body[data-auth-state="authenticated"] {
    height: 100dvh !important;
    max-height: 100dvh !important;
    overflow: clip !important;
    --sb-menubar-h: 36px;
    --sb-topbar-h: 48px;
    --sb-chrome-h: 84px;
  }
  html body[data-auth-state="authenticated"] aside.sidebar,
  html body[data-auth-state="authenticated"] aside.sidebar[hidden] {
    height: 100dvh !important;
    max-height: 100dvh !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
  }
  html body[data-auth-state="authenticated"] main,
  html body[data-auth-state="authenticated"] main[hidden] {
    display: block !important;
    pointer-events: auto !important;
    visibility: visible !important;
    overflow: clip !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
    padding-top: var(--sb-chrome-h) !important;
  }
  html body[data-auth-state="authenticated"] #global-menubar {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    height: var(--sb-menubar-h) !important;
    min-height: var(--sb-menubar-h) !important;
    max-height: var(--sb-menubar-h) !important;
    flex: none !important;
    overflow: visible !important;
  }
  html body[data-auth-state="authenticated"] header.topbar {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    height: var(--sb-topbar-h) !important;
    min-height: var(--sb-topbar-h) !important;
    max-height: var(--sb-topbar-h) !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    overflow: visible !important;
  }
  html body[data-auth-state="authenticated"] #app.content,
  html body[data-auth-state="authenticated"] #app {
    min-height: 0 !important;
    min-width: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    height: calc(100dvh - var(--sb-chrome-h)) !important;
    max-height: calc(100dvh - var(--sb-chrome-h)) !important;
    overflow: auto !important;
    box-sizing: border-box !important;
  }
  html body[data-auth-state="authenticated"] #app .panel,
  html body[data-auth-state="authenticated"] #app .form-card,
  html body[data-auth-state="authenticated"] #app .cards,
  html body[data-auth-state="authenticated"] #app .dashMain,
  html body[data-auth-state="authenticated"] #app .table-wrap {
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
  }
  html body[data-auth-state="authenticated"] #app .table-wrap {
    overflow-x: auto !important;
  }
  #modal-root .modal-backdrop,
  .modal-backdrop {
    align-items: center !important;
    padding: 12px !important;
    box-sizing: border-box !important;
    overflow: auto !important;
  }
  #modal-root .modal,
  .modal {
    width: min(960px, calc(100vw - 24px)) !important;
    max-width: calc(100vw - 24px) !important;
    max-height: min(92dvh, calc(100dvh - 24px)) !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
  }
  #modal-root .modal .modal-body,
  .modal .modal-body {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow: auto !important;
  }
  html body[data-auth-state="authenticated"] #sidebar-toggle,
  html body[data-auth-state="authenticated"] .sidebar-toggle {
    display: grid !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    position: fixed !important;
    z-index: 2147483000 !important;
  }
}
html body[data-auth-state="authenticated"] > #esb-public,
html body[data-auth-state="opening"] > #esb-public,
html body[data-auth-state="authenticated"] > #auth-status {
  display: none !important;
}

#auth-status {
  position: fixed;
  inset: 0;
  z-index: 2147483647;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 12px;
  padding: 24px;
  background: #f5f7fb;
  color: #0c2340;
  font: 16px / 1.5 system-ui, sans-serif;
  text-align: center;
}
#auth-status h1,
#auth-status p { margin: 0; }

html body[data-auth-state="pending"] > #auth-status,
html body[data-auth-state="signed-out"] > #auth-status,
html body[data-auth-state="authenticated"] > #auth-status,
#auth-status[hidden] {
  display: none !important;
  pointer-events: none !important;
}

html body[data-auth-state="opening"] > #auth-status:not([hidden]) {
  display: grid;
}


/* Live company menu: one white bar beside the sidebar, dropdowns not clipped. */
@media screen {
html body[data-auth-state="authenticated"] #global-menubar.authmenu-authorized-menu {
  display: flex !important;
  overflow: visible !important;
  max-height: none !important;
  height: 36px !important;
  pointer-events: auto !important;
}
html body[data-auth-state="authenticated"] #global-menubar .global-menu:not(.open) > .global-menu-popup {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}
html body[data-auth-state="authenticated"] #global-menubar .global-menu.open > .global-menu-popup {
  display: block !important;
  visibility: visible !important;
  pointer-events: auto !important;
}
html body[data-auth-state="authenticated"] #global-menubar .global-menu.open.has-menu-cols > .global-menu-popup,
html body[data-auth-state="authenticated"] #global-menubar .global-menu.open > .global-menu-popup:has(> .menu-col) {
  display: grid !important;
}
}

/* Last-wins print sheet: chrome must not cover, clip, or hide the document. */
@media print {
  html, body, main, #app, #app.content, .content {
    display: block !important;
    visibility: visible !important;
    position: static !important;
    overflow: visible !important;
    height: auto !important;
    max-height: none !important;
    max-width: none !important;
    width: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    color: #111 !important;
    transform: none !important;
    opacity: 1 !important;
    filter: none !important;
  }
  html[data-esb-resume="1"] body aside.sidebar,
  html[data-esb-resume="1"] body #global-menubar,
  html body[data-auth-state="authenticated"] #global-menubar,
  html body[data-auth-state="authenticated"] #global-menubar.authmenu-authorized-menu,
  aside.sidebar,
  header.topbar,
  #global-menubar,
  .page-actions,
  #toast,
  #modal-root,
  #esb-public,
  #auth-status,
  .create-btn,
  #sidebar-toggle,
  .sidebar-toggle,
  .presentation-toolbar,
  .presentation-nav,
  .theme-toggle,
  .sb-settings-cover {
    display: none !important;
    visibility: hidden !important;
    height: 0 !important;
    overflow: hidden !important;
  }
  .qr-document,
  .doc-print,
  .dc-print,
  .sb-paper,
  .financial-sheet,
  .slipview-slip,
  .sb-stub,
  .listpage-paper,
  .chq-leaf,
  .presentation-stage,
  .qr-table-wrap-main,
  .table-wrap {
    overflow: visible !important;
    visibility: visible !important;
    background: #fff !important;
    color: #111 !important;
    box-shadow: none !important;
  }
  body:not(.sb-print-cheque):not(.sb-print-isolated) > *:not(main) {
    display: none !important;
  }
  html[data-esb-resume="1"] aside.sidebar,
  html[data-esb-resume="1"] aside.sidebar[hidden],
  html[data-esb-resume="1"] #global-menubar {
    display: none !important;
    visibility: hidden !important;
  }
  html, body {
    color-scheme: light !important;
    background: #fff !important;
    color: #111 !important;
  }
  body.sb-print-cheque > *:not(#cheque-print-root),
  body.sb-print-isolated > *:not(#sb-isolated-print) {
    display: none !important;
  }
  body.sb-print-cheque #cheque-print-root,
  body.sb-print-cheque #cheque-print-root *,
  body.sb-print-isolated #sb-isolated-print,
  body.sb-print-isolated #sb-isolated-print * {
    visibility: visible !important;
  }
  body.sb-print-cheque #cheque-print-root,
  body.sb-print-isolated #sb-isolated-print {
    display: block !important;
    position: static !important;
  }
}

/* Signed-in workspace: chrome and printouts are not a copy source. Fields still are. */
@media screen {
  body[data-auth-state="authenticated"] #app,
  body[data-auth-state="authenticated"] aside.sidebar,
  body[data-auth-state="authenticated"] #global-menubar,
  body[data-auth-state="authenticated"] header.topbar,
  body[data-auth-state="authenticated"] .qr-document,
  body[data-auth-state="authenticated"] .doc-print,
  body[data-auth-state="authenticated"] .dc-print,
  body[data-auth-state="authenticated"] .slipview-slip,
  body[data-auth-state="authenticated"] .sb-paper,
  body[data-auth-state="authenticated"] .financial-sheet,
  body[data-auth-state="authenticated"] .listpage-paper,
  body[data-auth-state="authenticated"] .chq-leaf,
  body[data-auth-state="authenticated"] .sb-report-preview-sheet,
  body[data-auth-state="authenticated"] .barcode-card,
  body[data-auth-state="authenticated"] .presentation-slide {
    -webkit-user-select: none;
    user-select: none;
  }
  body[data-auth-state="authenticated"] :is(input, textarea, select, [contenteditable="true"], .sb-allow-copy, #tok-copy, .esb-help-body, .esb-help-body *) {
    -webkit-user-select: text;
    user-select: text;
  }
}
