/* Mobile / tablet sidebar overlay fixes */

@media (max-width: 990px) {
  body.sidebar-toggled {
    overflow: hidden !important;
  }

  body.sidebar-toggled #default-navbar {
    visibility: hidden !important;
    pointer-events: none !important;
    height: 0 !important;
    min-height: 0 !important;
    overflow: hidden !important;
    border: none !important;
  }

  body.sidebar-toggled #left-menu-toggle-mask {
    position: fixed;
    inset: 0;
    z-index: 1040;
    overflow: hidden !important;
    height: 100vh !important;
    width: 100vw !important;
  }

  body.sidebar-toggled #left-menu-toggle-mask::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1045;
    pointer-events: auto;
  }

  body.sidebar-toggled #left-menu-toggle-mask .page-container {
    visibility: hidden;
    pointer-events: none;
  }

  body.sidebar-toggled .sidebar.sidebar-off {
    width: min(280px, 85vw);
    z-index: 1055;
    height: 100vh !important;
    min-height: 100vh;
    max-height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: inherit;
  }

  /* Unified dark header row: logo | actions | close */
  body.sidebar-toggled .sidebar.sidebar-off::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 66px;
    background: inherit;
    z-index: 1060;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    pointer-events: none;
  }

  body.sidebar-toggled .sidebar .sidebar-brand.brand-logo-mini {
    display: block !important;
    position: absolute !important;
    top: 0;
    left: 0;
    width: 70px !important;
    height: 66px !important;
    padding: 15px !important;
    margin: 0;
    z-index: 1062;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    text-align: center;
  }

  body.sidebar-toggled .sidebar .sidebar-brand.brand-logo-mini .dashboard-image {
    max-height: 36px;
    width: auto;
  }

  body.sidebar-toggled .sidebar #left-menu-topbar-button-container {
    position: absolute !important;
    top: 0;
    left: 70px;
    right: 48px;
    height: 66px;
    float: none !important;
    display: flex !important;
    align-items: center;
    justify-content: flex-end;
    background: transparent !important;
    z-index: 1062;
    margin: 0;
    padding: 0 4px;
  }

  body.sidebar-toggled .sidebar #left-menu-topbar-button-container .menu-item {
    float: none !important;
    display: inline-flex !important;
    align-items: center;
    background: transparent !important;
    margin: 0;
  }

  body.sidebar-toggled .sidebar #left-menu-topbar-button-container .nav-link {
    padding: 12px !important;
    background: transparent !important;
  }

  body.sidebar-toggled .sidebar .sidebar-toggle-btn {
    position: absolute !important;
    top: 0;
    right: 0;
    left: auto !important;
    width: 48px;
    height: 66px;
    margin: 0 !important;
    padding: 0 !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    z-index: 1063;
    background: transparent !important;
    float: none !important;
  }

  body.sidebar-toggled .sidebar .sidebar-brand.brand-logo {
    display: none !important;
  }

  body.sidebar-toggled .sidebar .sidebar-scroll {
    flex: 1 1 auto;
    overflow-y: auto !important;
    margin-top: 66px;
    margin-bottom: 0;
    max-height: calc(100vh - 66px);
    -webkit-overflow-scrolling: touch;
  }

  body.sidebar-toggled #mobile-bottom-menu {
    display: none !important;
  }
}

@media (max-width: 767px) {
  body.sidebar-toggled .sidebar.sidebar-off {
    width: 100%;
  }

  body.sidebar-toggled .sidebar #left-menu-topbar-button-container {
    left: 70px;
    right: 48px;
  }
}

/* Mobile logo sizing — sidebar brand is position:fixed and stays visible when menu is closed */
@media (max-width: 990px) {
  body:not(.sidebar-toggled) .sidebar .sidebar-brand,
  body:not(.sidebar-toggled) .sidebar .sidebar-brand.brand-logo-mini {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
    opacity: 0 !important;
  }

  .sidebar .sidebar-brand .dashboard-image,
  .sidebar .sidebar-brand img,
  .sidebar .sidebar-brand.brand-logo-mini .dashboard-image,
  .sidebar .sidebar-brand.brand-logo-mini img {
    max-height: 36px !important;
    max-width: 40px !important;
    width: auto !important;
    height: auto !important;
    object-fit: contain !important;
  }

  #default-navbar .brand-logo .dashboard-image,
  #default-navbar .brand-logo img {
    max-height: 32px;
    max-width: 140px;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
  }

  #default-navbar .nav-item.d-block.d-sm-none {
    max-width: 150px;
    overflow: hidden;
    display: flex !important;
    align-items: center;
  }
}

/* Sidebar brand is position:fixed — unconstrained favicon/logo bleeds over dashboard */
.sidebar .sidebar-brand {
  overflow: hidden !important;
  box-sizing: border-box;
}

.sidebar .sidebar-brand .dashboard-image,
.sidebar .sidebar-brand img {
  max-height: 40px !important;
  max-width: 210px !important;
  width: auto !important;
  height: auto !important;
  object-fit: contain !important;
  display: block;
  margin-left: auto;
  margin-right: auto;
}

/* Desktop collapsed sidebar (cookie/minimized menu) — favicon in 70px box */
@media (min-width: 991px) {
  body.sidebar-toggled .sidebar .sidebar-brand.brand-logo-mini {
    width: 70px !important;
    height: 66px !important;
    padding: 15px !important;
    overflow: hidden !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    text-align: center;
  }

  body.sidebar-toggled .sidebar .sidebar-brand.brand-logo-mini .dashboard-image,
  body.sidebar-toggled .sidebar .sidebar-brand.brand-logo-mini img {
    max-height: 36px !important;
    max-width: 40px !important;
    width: auto !important;
    height: auto !important;
    object-fit: contain !important;
  }
}
