/* =============================================================================
 * Side-menu UI mode (second shell next to the top navbar)
 * -----------------------------------------------------------------------------
 * The root element (#sci-app-root) carries one of:
 *   .ui-mode-navbar   — classic top navbar (default; sidebar chrome hidden)
 *   .ui-mode-sidebar  — collapsible left rail + slim topbar + hamburger
 * plus optional .sidebar-collapsed (desktop rail) / .sidebar-mobile-open (drawer).
 * Mode is toggled client-side in callbacks/shell_ui_mode_cb.py.
 * =========================================================================== */

:root {
  --sci-sidebar-w: 264px;
  --sci-sidebar-w-collapsed: 76px;
  --sci-topbar-h: 60px;
  --sci-ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* Page column wraps the topbar + scrolling page shell in BOTH modes. */
.sci-main-col {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* Sidebar chrome is hidden in navbar mode (the default). */
.sci-sidebar,
.sci-sidebar-backdrop,
.sci-topbar {
  display: none;
}

/* =============================== SIDEBAR MODE ============================== */
.app-shell--main.ui-mode-sidebar {
  flex-direction: row;
  max-width: none;
  margin: 0;
  padding: 0;
  gap: 0;
}

.ui-mode-sidebar > .navbar {
  display: none !important;
}

.ui-mode-sidebar .sci-topbar {
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
  height: var(--sci-topbar-h);
  padding: 0 20px;
}

.ui-mode-sidebar .sci-main-col {
  height: 100vh;
  padding: 0 22px 0;
}
/* Breathing room between the top of the viewport (or topbar) and the page. */
.ui-mode-sidebar #sci-page-shell {
  padding-top: 18px;
}

/* ----------------------------- the rail ----------------------------------- */
.ui-mode-sidebar .sci-sidebar {
  display: flex;
  flex-direction: column;
  flex: 0 0 var(--sci-sidebar-w);
  width: var(--sci-sidebar-w);
  height: 100vh;
  box-sizing: border-box;
  background: linear-gradient(180deg, rgba(14, 22, 48, 0.94), rgba(9, 13, 28, 0.94));
  border-right: 1px solid var(--border);
  backdrop-filter: blur(12px);
  /* visible so the foot dropdowns (direction="up") are never clipped; labels are
     display:none when collapsed, so there is no horizontal overflow to clip. */
  overflow: visible;
  z-index: 1500;
  transition: flex-basis 0.28s var(--sci-ease), width 0.28s var(--sci-ease);
}

.ui-mode-sidebar.sidebar-collapsed .sci-sidebar {
  flex-basis: var(--sci-sidebar-w-collapsed);
  width: var(--sci-sidebar-w-collapsed);
}

/* Brand / head */
.sci-sidebar__head {
  display: flex;
  align-items: center;
  height: var(--sci-topbar-h);
  padding: 0 16px;
  flex: 0 0 auto;
  border-bottom: 1px solid var(--border);
}
.sci-sidebar__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text);
  overflow: hidden;
}
.sci-sidebar__logo {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  font-weight: 800;
  font-size: 18px;
  color: #06231a;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 6px 18px rgba(46, 230, 166, 0.28);
}
.sci-sidebar__brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  white-space: nowrap;
}
.sci-sidebar__brand-name {
  font-weight: 700;
  font-size: 15px;
}
.sci-sidebar__brand-tenant {
  font-size: 11px;
  font-family: var(--mono);
}

/* Nav list */
.sci-side-nav {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sci-side-nav::-webkit-scrollbar { width: 8px; }
.sci-side-nav::-webkit-scrollbar-thumb {
  background: rgba(231, 236, 255, 0.12);
  border-radius: 8px;
}

.sci-side-link {
  display: flex !important;
  align-items: center;
  gap: 13px;
  padding: 10px 12px !important;
  border-radius: 10px;
  color: var(--muted) !important;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  transition: background 0.18s var(--sci-ease), color 0.18s var(--sci-ease), transform 0.12s var(--sci-ease);
}
.sci-side-link:hover {
  background: rgba(45, 125, 255, 0.12);
  color: var(--text) !important;
}
.sci-side-link:active {
  transform: scale(0.98);
}
.sci-side-link.active {
  background: linear-gradient(90deg, rgba(46, 230, 166, 0.18), rgba(45, 125, 255, 0.12));
  color: var(--text) !important;
}
.sci-side-link.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(46, 230, 166, 0.6);
}
.sci-side-link__icon {
  flex: 0 0 auto;
  width: 22px;
  text-align: center;
  font-size: 18px;
  line-height: 1;
}
.sci-side-link__label {
  font-size: 14px;
  transition: opacity 0.18s var(--sci-ease);
}

/* Foot */
.sci-sidebar__foot {
  flex: 0 0 auto;
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sci-sidebar__switchers {
  gap: 8px;
  margin-bottom: 2px;
}
.sci-sidebar__switchers .nav-item + .nav-item {
  margin-top: 8px;
}
.sci-sidebar__switchers .dropdown-toggle.nav-link {
  color: var(--text) !important;
  padding: 8px 12px !important;
  border-radius: 10px;
  background: rgba(231, 236, 255, 0.04);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.sci-sidebar__switchers .dropdown-toggle.nav-link:hover {
  background: rgba(45, 125, 255, 0.14);
}

/* In-sidebar hamburger: collapse/expand the rail (desktop) / close the drawer (mobile). */
.sci-sidebar__collapse-btn {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(231, 236, 255, 0.04);
  color: var(--muted);
  cursor: pointer;
  transition: background 0.18s var(--sci-ease), color 0.18s var(--sci-ease),
    border-color 0.18s var(--sci-ease);
}
.sci-sidebar__collapse-btn:hover {
  background: rgba(45, 125, 255, 0.14);
  color: var(--text);
  border-color: rgba(45, 125, 255, 0.4);
}
.sci-sidebar__collapse-btn .sci-hamburger__box {
  flex: 0 0 auto;
  width: 20px;
  height: 14px;
}

/* ---------------------------- collapsed rail ------------------------------ */
.ui-mode-sidebar.sidebar-collapsed .sci-side-link__label,
.ui-mode-sidebar.sidebar-collapsed .sci-sidebar__brand-text,
.ui-mode-sidebar.sidebar-collapsed .sci-sidebar__switchers {
  opacity: 0;
  width: 0;
  display: none;
}
.ui-mode-sidebar.sidebar-collapsed .sci-side-link,
.ui-mode-sidebar.sidebar-collapsed .sci-sidebar__brand,
.ui-mode-sidebar.sidebar-collapsed .sci-sidebar__collapse-btn {
  justify-content: center;
  gap: 0;
}
.ui-mode-sidebar.sidebar-collapsed .sci-sidebar__collapse-btn {
  padding: 10px;
}
.ui-mode-sidebar.sidebar-collapsed .sci-sidebar__head {
  padding: 0;
  justify-content: center;
}

/* --------------------------------- topbar --------------------------------- */
.sci-topbar__spacer { flex: 1 1 auto; }
.sci-topbar__brand {
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
  text-decoration: none;
}

/* Hamburger button + bars-to-X animation */
.sci-hamburger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(231, 236, 255, 0.04);
  color: var(--text);
  cursor: pointer;
  transition: background 0.18s var(--sci-ease), border-color 0.18s var(--sci-ease);
}
.sci-hamburger:hover {
  background: rgba(45, 125, 255, 0.16);
  border-color: rgba(45, 125, 255, 0.45);
}
.sci-hamburger__box {
  position: relative;
  display: block;
  width: 20px;
  height: 14px;
}
.sci-hamburger__inner,
.sci-hamburger__inner::before,
.sci-hamburger__inner::after {
  position: absolute;
  left: 0;
  width: 20px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  transition: transform 0.28s var(--sci-ease), top 0.2s var(--sci-ease), background 0.1s ease;
}
.sci-hamburger__inner { top: 50%; transform: translateY(-50%); }
.sci-hamburger__inner::before { content: ""; top: -6px; }
.sci-hamburger__inner::after { content: ""; top: 6px; }
.sci-hamburger.is-active .sci-hamburger__inner { background: transparent; }
.sci-hamburger.is-active .sci-hamburger__inner::before { top: 0; transform: rotate(45deg); }
.sci-hamburger.is-active .sci-hamburger__inner::after { top: 0; transform: rotate(-45deg); }

/* ---------------------------- mobile drawer ------------------------------- */
.ui-mode-sidebar .sci-sidebar-backdrop {
  display: block;
  position: fixed;
  inset: 0;
  background: rgba(3, 6, 15, 0.55);
  backdrop-filter: blur(2px);
  opacity: 0;
  visibility: hidden;
  z-index: 1400;
  transition: opacity 0.3s var(--sci-ease), visibility 0.3s var(--sci-ease);
}

@media (max-width: 991.98px) {
  /* The slim header (with the menu button) only exists on mobile. */
  .ui-mode-sidebar .sci-topbar {
    display: flex;
  }
  .ui-mode-sidebar .sci-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    height: 100vh;
    /* On mobile, always show full-width labels regardless of desktop collapse. */
    flex-basis: var(--sci-sidebar-w);
    width: var(--sci-sidebar-w);
    transform: translateX(-100%);
    transition: transform 0.3s var(--sci-ease);
    box-shadow: none;
  }
  .ui-mode-sidebar.sidebar-collapsed .sci-side-link__label,
  .ui-mode-sidebar.sidebar-collapsed .sci-sidebar__brand-text,
  .ui-mode-sidebar.sidebar-collapsed .sci-sidebar__switchers {
    opacity: 1;
    width: auto;
    display: flex;
  }
  .ui-mode-sidebar.sidebar-collapsed .sci-side-link,
  .ui-mode-sidebar.sidebar-collapsed .sci-sidebar__brand {
    justify-content: flex-start;
    gap: 13px;
  }
  .ui-mode-sidebar.sidebar-collapsed .sci-sidebar__head {
    padding: 0 16px;
    justify-content: flex-start;
  }
  .ui-mode-sidebar.sidebar-mobile-open .sci-sidebar {
    transform: translateX(0);
    box-shadow: var(--shadow);
  }
  .ui-mode-sidebar.sidebar-mobile-open .sci-sidebar-backdrop {
    opacity: 1;
    visibility: visible;
  }
  .ui-mode-sidebar .sci-main-col {
    padding: 0 14px;
  }
}

/* Desktop: the backdrop never participates. */
@media (min-width: 992px) {
  .ui-mode-sidebar .sci-sidebar-backdrop {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ui-mode-sidebar .sci-sidebar,
  .sci-hamburger__inner,
  .sci-hamburger__inner::before,
  .sci-hamburger__inner::after,
  .sci-side-link {
    transition: none !important;
  }
}
