/* === Layout (Admin SPA Shell) === */
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden; /* critical: only sidebar menu + page-content scroll */
  font-family: var(--font-family);
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

#layout-root {
  height: 100%;
  display: flex;
  flex-direction: column;
}

#layout-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0; /* allow internal scroll containers */
  position: relative;
}

/* === Sidebar container === */
#side-menu {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden; /* only #sidebarScroll scrolls */
  background: #f5f5f5;
  border-right: 1px solid #ccc;
}

/* === Main content === */
#page-content {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: auto; /* page content scrolls */
  padding: 20px;
  background: #fff;
}

#mobile-topbar {
  display: none;
}

#mobile-sidebar-toggle {
  display: none;
}

#sidebar-backdrop {
  display: none;
}

/* === Loading visibility locks (keep your current behavior) === */
#page-body.page-loading,
#detailTabContent.page-loading {
  visibility: hidden;
}

body[data-page-loading="true"] #page-body,
body[data-page-loading="true"] #detailTabContent {
  visibility: hidden;
}

/* === Responsive: hamburger + overlay sidebar === */
@media (max-width: 960px) {
  #side-menu {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 40;
    width: min(82vw, 280px);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    background: #fff;
    border-right: 1px solid #ddd;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
  }

  #side-menu.mobile-open {
    transform: translateX(0);
  }

  #sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    border: 0;
    margin: 0;
    padding: 0;
    background: rgba(17, 24, 39, 0.35);
    opacity: 0;
    pointer-events: none;
    z-index: 30;
    transition: opacity 0.2s ease;
  }

  #sidebar-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
  }

  #mobile-topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
  }

  #mobile-sidebar-toggle {
    position: static;
    z-index: 25;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: #303030;
    cursor: pointer;
    padding: 0;
  }

  #mobile-sidebar-toggle:focus-visible {
    outline: 2px solid #8cb7f8;
    outline-offset: 2px;
  }

  #mobile-sidebar-toggle .hamburger-lines {
    position: relative;
    width: 18px;
    height: 14px;
    display: inline-flex;
    flex-direction: column;
    justify-content: space-between;
  }

  #mobile-sidebar-toggle .hamburger-line {
    width: 18px;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
    transition: transform 0.2s ease, opacity 0.2s ease;
    transform-origin: center;
  }

  #mobile-sidebar-toggle.is-open .hamburger-line:nth-child(1) {
    transform: translateY(6px) rotate(45deg);
  }

  #mobile-sidebar-toggle.is-open .hamburger-line:nth-child(2) {
    opacity: 0;
  }

  #mobile-sidebar-toggle.is-open .hamburger-line:nth-child(3) {
    transform: translateY(-6px) rotate(-45deg);
  }

  #mobile-entity-switcher {
    flex: 1;
    min-width: 0;
  }

  #mobile-entity-switcher .mobile-entity-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
  }

  #mobile-entity-switcher .mobile-entity-icon {
    width: 26px;
    height: 26px;
    border-radius: 8px;
    background: transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
  }

  #mobile-entity-switcher .mobile-entity-logo {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  #mobile-entity-switcher .mobile-entity-content {
    flex: 1;
    min-width: 0;
  }

  #mobile-entity-switcher .entity-picker-control {
    position: relative;
    min-height: 26px;
    display: flex;
    align-items: center;
  }

  #mobile-entity-switcher .entity-picker-trigger,
  #mobile-entity-switcher .mobile-entity-name {
    width: 100%;
    height: 26px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: #303030;
    font-size: 13px;
    font-weight: 500;
    padding: 0;
    box-sizing: border-box;
    text-align: left;
  }

  #mobile-entity-switcher .entity-picker-trigger {
    display: flex;
    align-items: center;
    background: transparent;
    cursor: pointer;
  }

  #mobile-entity-switcher .entity-picker-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #mobile-entity-switcher .entity-picker-chevron {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    color: #7b8086;
    pointer-events: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    line-height: 1;
    font-weight: 600;
  }

  #mobile-entity-switcher .entity-picker-panel {
    display: none;
    position: absolute;
    z-index: 85;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    border: 1px solid #d2d5d9;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.14);
    padding: 4px;
    max-height: 250px;
    overflow: auto;
  }

  #mobile-entity-switcher .entity-picker-control.open .entity-picker-panel {
    display: block;
  }

  #mobile-entity-switcher .entity-picker-option {
    width: 100%;
    border: 0;
    background: transparent;
    border-radius: 8px;
    min-height: 34px;
    padding: 4px 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: #303030;
    text-align: left;
  }

  #mobile-entity-switcher .entity-picker-option.active {
    background: #e7f0ff;
    color: #0b3c75;
  }

  #mobile-entity-switcher .entity-picker-option-logo {
    width: 18px;
    height: 18px;
    border-radius: 6px;
    background: #f1f5f9;
    color: #64748b;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    font-size: 10px;
    font-weight: 700;
  }

  #mobile-entity-switcher .entity-picker-option-logo-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  #mobile-entity-switcher .entity-picker-option-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #mobile-entity-switcher .entity-picker-trigger {
    padding-right: 18px;
  }

  #mobile-entity-switcher .mobile-entity-name {
    display: flex;
    align-items: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #page-content {
    padding: 14px;
  }
}
