/* MegaFlow collapsible sidebar shell
   Builds on the ops-console.css theme variables. */

:root {
  --sb-width: 256px;
  --sb-width-collapsed: 76px;
  --sb-bg: #111827;
  --topbar-h: 60px;
  scrollbar-gutter: stable;
}

@supports not (scrollbar-gutter: stable) {
  body {
    overflow-y: scroll;
  }
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

.mf-sidebar-pref-collapsed .app-shell:not(.no-sidebar) .app-sidebar,
.mf-sidebar-pref-collapsed .app-shell:not(.no-sidebar) .app-main {
  transition: none;
}
.mf-sidebar-booting .app-shell:not(.no-sidebar) .app-sidebar,
.mf-sidebar-booting .app-shell:not(.no-sidebar) .app-main,
.mf-sidebar-booting .app-shell:not(.no-sidebar) .nav-section-title::after {
  transition: none !important;
}

/* ---------- Sidebar ---------- */
.app-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  height: 100vh;
  height: 100dvh;
  width: var(--sb-width);
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--sb-bg);
  color: #fff;
  z-index: 1030;
  transition: width 0.2s ease, transform 0.2s ease;
  box-shadow: 1px 0 0 rgba(255, 255, 255, 0.06);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 1rem 1.15rem;
  min-height: var(--topbar-h);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  overflow: hidden;
  white-space: nowrap;
}

.sidebar-brand img {
  height: 30px;
  width: auto;
  flex: 0 0 auto;
}

.sidebar-brand .brand-logo-mark { display: none; height: 34px; }

.sidebar-brand .brand-text {
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  font-weight: 700;
  font-size: 1.18rem;
  letter-spacing: 0;
  color: #fff;
}

.sidebar-nav {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.5rem 0.6rem 1rem;
}

.sidebar-nav::-webkit-scrollbar { width: 8px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.18); border-radius: 8px; }

.nav-section { margin-top: 0.9rem; }
.nav-section:first-child { margin-top: 0.35rem; }

.nav-section-title {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  /* The caret is absolutely positioned inside the right padding, so a label
     wider than the box used to run straight over it -- which is how
     "Configuration & Compliance" lost its expand/collapse affordance entirely.
     Clipping here keeps that padding reserved whatever the label says. */
  overflow: hidden;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: rgba(255, 255, 255, 0.5);
  padding: 0.4rem 1.8rem 0.3rem 0.8rem;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: color 0.15s ease;
}
.nav-section-title:hover { color: rgba(255, 255, 255, 0.75); }
.nav-section-title:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.38);
  outline-offset: 2px;
  border-radius: 8px;
}
.nav-section-title i:not(.nav-section-caret) { font-size: 0.95rem; vertical-align: -1px; }

/* A label never pushes past the sidebar: it truncates instead. Applies to links
   as well as section titles, so a long entry stays readable rather than being
   cut mid-word at the edge. */
.nav-section-title .nav-label,
.sidebar-link .nav-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-link { overflow: hidden; }

/* Accordion caret */
.nav-section-title::after {
  content: "\f078"; /* chevron-down */
  font-family: "Font Awesome 5 Free";
  font-weight: 900;
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.62rem;
  opacity: 0.55;
  transition: transform 0.18s ease;
}
.nav-section.section-collapsed .nav-section-title::after { transform: translateY(-50%) rotate(-90deg); }

/* Hide a category's body when accordion-collapsed while the sidebar is expanded. */
.app-shell:not(.sidebar-collapsed) .nav-section.section-collapsed > :not(.nav-section-title) {
  display: none;
}

/* Sub-heading inside a section (e.g. "Reports" under AWS) */
.nav-subhead {
  display: block;
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.34);
  padding: 0.55rem 0.8rem 0.15rem;
  white-space: nowrap;
}
.app-shell.sidebar-collapsed .nav-subhead,
.mf-sidebar-collapsed .app-shell:not(.no-sidebar) .nav-subhead { display: none; }

/* Disabled / placeholder nav item */
.sidebar-link.disabled {
  opacity: 0.45;
  cursor: default;
  pointer-events: none;
}
.soon-badge {
  margin-left: 0.4rem;
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.05rem 0.35rem;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.16);
  color: rgba(255, 255, 255, 0.75);
  vertical-align: 1px;
}
/* The AWS, Azure, Operations, Automation and Settings sections were removed by
   #212; their selectors matched nothing and are gone with them. */
.nav-section-overview .nav-section-title { color: #93c5fd; }
.nav-section-platform .nav-section-title { color: #cbd5e1; }
/* When collapsed, each section title remains as an icon-only accordion handle. */
.app-shell.sidebar-collapsed .nav-section-title,
.mf-sidebar-collapsed .app-shell:not(.no-sidebar) .nav-section-title {
  justify-content: center;
  width: 100%;
  min-height: 34px;
  padding: 0.3rem 0;
  border-radius: 8px;
}
.app-shell.sidebar-collapsed .nav-section-title:hover,
.app-shell.sidebar-collapsed .nav-section-title:focus,
.mf-sidebar-collapsed .app-shell:not(.no-sidebar) .nav-section-title:hover,
.mf-sidebar-collapsed .app-shell:not(.no-sidebar) .nav-section-title:focus {
  background: rgba(255, 255, 255, 0.08);
}
.app-shell.sidebar-collapsed .nav-section-title::after,
.mf-sidebar-collapsed .app-shell:not(.no-sidebar) .nav-section-title::after {
  right: 0.2rem;
  font-size: 0.48rem;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.6rem 0.8rem;
  margin: 0.12rem 0;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.82);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.94rem;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.sidebar-link i {
  flex: 0 0 22px;
  width: 22px;
  text-align: center;
  font-size: 1.02rem;
}

.sidebar-link:hover,
.sidebar-link:focus {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.sidebar-link.active {
  background: #1d4ed8;
  color: #fff;
  box-shadow: none;
}

.sidebar-footer {
  flex: 0 0 auto;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding: 0.7rem 0.8rem max(0.7rem, env(safe-area-inset-bottom));
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: #fff;
}

.sidebar-user .avatar {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.16);
  font-size: 0.95rem;
}

.sidebar-user .user-meta {
  min-width: 0;
  line-height: 1.1;
  overflow: hidden;
}
.sidebar-user .user-name,
.sidebar-user .user-sub {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user .user-name { font-weight: 600; font-size: 0.9rem; }
.sidebar-user .user-sub { font-size: 0.74rem; color: rgba(255, 255, 255, 0.55); }

/* ---------- Main column ---------- */
.app-main {
  flex: 1 1 auto;
  min-width: 0;
  margin-left: var(--sb-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left 0.2s ease;
}

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 1020;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 1.25rem;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--ops-border);
  box-shadow: var(--ops-shadow-soft);
}

.topbar-left {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  min-width: 0;
}
.topbar-right {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.4rem;
  min-width: 0;
  white-space: nowrap;
}

.topbar-section {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--ops-text);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-sep { color: var(--ops-border); font-weight: 400; }
.topbar-provider { flex: 0 0 auto; font-weight: 700; display: inline-flex; align-items: center; gap: 0.3rem; }
.topbar-provider.aws { color: #ec7211; }
.topbar-provider.azure { color: #0a7bd4; }
.topbar-cat { flex: 0 0 auto; font-weight: 700; color: var(--ops-text-muted); }

.sidebar-toggle {
  flex: 0 0 40px;
  border: none;
  background: transparent;
  color: var(--ops-text);
  font-size: 1.15rem;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.15s ease;
}
.sidebar-toggle:hover { background: var(--ops-surface-muted); }

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  font-weight: 700;
  color: var(--ops-text);
  text-decoration: none;
}
.topbar-brand img { height: 26px; }

.topbar-link {
  height: 36px;
  display: inline-flex;
  align-items: center;
  color: var(--ops-text-muted);
  text-decoration: none;
  font-weight: 500;
  padding: 0.45rem 0.7rem;
  border-radius: 8px;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.topbar-link:hover { background: var(--ops-surface-muted); color: var(--ops-primary-strong); }

/* The Help link to this screen's manual pages (DEC-0032). */
.topbar-help .fa-question-circle { margin-right: 0.3rem; color: var(--ops-primary); }
.manual-help-menu { min-width: 300px; max-width: 360px; }
.manual-help-menu .dropdown-item { white-space: normal; font-size: 0.9rem; }
.manual-help-menu .dropdown-item { padding-top: 0.4rem; padding-bottom: 0.4rem; }
.manual-help-type {
  display: block;
  color: var(--ops-text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.topbar-user-chip {
  flex: 0 1 240px;
  width: clamp(172px, 18vw, 240px);
  height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  background: var(--ops-surface-muted);
  border: 1px solid var(--ops-border);
  color: var(--ops-text);
  font-weight: 600;
  font-size: 0.88rem;
}
.topbar-user-chip i {
  flex: 0 0 auto;
}
.topbar-user-name,
.topbar-user-chip .username-hint {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-user-name {
  flex: 1 1 auto;
}
.topbar-user-chip .username-hint {
  flex: 0 1 auto;
  color: var(--ops-text-muted);
  font-weight: 400;
  font-size: 0.8rem;
}

.app-content { flex: 1 1 auto; }

.app-footer {
  flex: 0 0 auto;
  border-top: 1px solid var(--ops-border, #d8e0ea);
  padding: 0.6rem 1rem max(0.6rem, env(safe-area-inset-bottom));
  color: var(--ops-text-muted, #64748b);
  font-size: 0.75rem;
  text-align: center;
}

/* ---------- Collapsed state (desktop) ---------- */
.app-shell.sidebar-collapsed .app-sidebar { width: var(--sb-width-collapsed); }
.app-shell.sidebar-collapsed .app-main { margin-left: var(--sb-width-collapsed); }
.mf-sidebar-collapsed .app-shell:not(.no-sidebar) .app-sidebar { width: var(--sb-width-collapsed); }
.mf-sidebar-collapsed .app-shell:not(.no-sidebar) .app-main { margin-left: var(--sb-width-collapsed); }
.app-shell.sidebar-collapsed .brand-text,
.app-shell.sidebar-collapsed .nav-label,
.app-shell.sidebar-collapsed .sidebar-user .user-meta,
.mf-sidebar-collapsed .app-shell:not(.no-sidebar) .brand-text,
.mf-sidebar-collapsed .app-shell:not(.no-sidebar) .nav-label,
.mf-sidebar-collapsed .app-shell:not(.no-sidebar) .sidebar-user .user-meta { display: none; }
/* Collapsed sidebar: show only the compact company logo mark */
.app-shell.sidebar-collapsed .brand-logo-full { display: none; }
.app-shell.sidebar-collapsed .brand-logo-mark { display: block; }
.app-shell.sidebar-collapsed .sidebar-link { justify-content: center; gap: 0; }
.app-shell.sidebar-collapsed .sidebar-brand { justify-content: center; padding-left: 0; padding-right: 0; }
.app-shell.sidebar-collapsed .sidebar-user { justify-content: center; }
.app-shell.sidebar-collapsed .nav-section { margin-top: 0.6rem; border-top: 1px solid rgba(255,255,255,0.08); padding-top: 0.4rem; }
.app-shell.sidebar-collapsed .nav-section:first-child { border-top: none; }
.mf-sidebar-collapsed .app-shell:not(.no-sidebar) .brand-logo-full { display: none; }
.mf-sidebar-collapsed .app-shell:not(.no-sidebar) .brand-logo-mark { display: block; }
.mf-sidebar-collapsed .app-shell:not(.no-sidebar) .sidebar-link { justify-content: center; gap: 0; }
.mf-sidebar-collapsed .app-shell:not(.no-sidebar) .sidebar-brand { justify-content: center; padding-left: 0; padding-right: 0; }
.mf-sidebar-collapsed .app-shell:not(.no-sidebar) .sidebar-user { justify-content: center; }
.mf-sidebar-collapsed .app-shell:not(.no-sidebar) .nav-section { margin-top: 0.6rem; border-top: 1px solid rgba(255,255,255,0.08); padding-top: 0.4rem; }
.mf-sidebar-collapsed .app-shell:not(.no-sidebar) .nav-section:first-child { border-top: none; }

@media (min-width: 993px) {
  /* Compact sidebar has its own accordion state so expanded-sidebar preferences stay independent. */
  .app-shell.sidebar-collapsed .nav-section.compact-section-collapsed > :not(.nav-section-title),
  .mf-sidebar-collapsed .app-shell:not(.no-sidebar) .nav-section.compact-section-collapsed > :not(.nav-section-title) {
    display: none;
  }
}

/* ---------- No sidebar (anonymous / login) ---------- */
.app-shell.no-sidebar .app-main { margin-left: 0; }

/* ---------- Backdrop (mobile) ---------- */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(6, 18, 36, 0.45);
  z-index: 1025;
}

/* ---------- Responsive ---------- */
@media (max-width: 992px) {
  .app-main { margin-left: 0; }
  .app-sidebar { transform: translateX(-100%); width: var(--sb-width); }
  .app-shell.sidebar-collapsed .app-main { margin-left: 0; }
  .app-shell.sidebar-collapsed .app-sidebar { width: var(--sb-width); }
  .mf-sidebar-collapsed .app-shell:not(.no-sidebar) .app-main { margin-left: 0; }
  .mf-sidebar-collapsed .app-shell:not(.no-sidebar) .app-sidebar { width: var(--sb-width); }
  .app-shell.sidebar-collapsed .brand-text,
  .app-shell.sidebar-collapsed .nav-label,
  .app-shell.sidebar-collapsed .sidebar-user .user-meta,
  .mf-sidebar-collapsed .app-shell:not(.no-sidebar) .brand-text,
  .mf-sidebar-collapsed .app-shell:not(.no-sidebar) .nav-label,
  .mf-sidebar-collapsed .app-shell:not(.no-sidebar) .sidebar-user .user-meta { display: revert; }
  .app-shell.sidebar-collapsed .sidebar-link { justify-content: flex-start; gap: 0.8rem; }
  .app-shell.sidebar-collapsed .brand-logo-full { display: block; }
  .app-shell.sidebar-collapsed .brand-logo-mark { display: none; }
  .mf-sidebar-collapsed .app-shell:not(.no-sidebar) .sidebar-link { justify-content: flex-start; gap: 0.8rem; }
  .mf-sidebar-collapsed .app-shell:not(.no-sidebar) .brand-logo-full { display: block; }
  .mf-sidebar-collapsed .app-shell:not(.no-sidebar) .brand-logo-mark { display: none; }
  .app-shell.sidebar-collapsed .nav-section-title,
  .mf-sidebar-collapsed .app-shell:not(.no-sidebar) .nav-section-title {
    justify-content: flex-start;
    width: auto;
    min-height: 0;
    padding: 0.4rem 1.8rem 0.3rem 0.8rem;
  }
  .app-shell.sidebar-collapsed .nav-section-title::after,
  .mf-sidebar-collapsed .app-shell:not(.no-sidebar) .nav-section-title::after {
    right: 0.75rem;
    font-size: 0.62rem;
  }
  .app-shell.sidebar-open .app-sidebar { transform: translateX(0); }
  .app-shell.sidebar-open .sidebar-backdrop { display: block; }
  .app-topbar {
    gap: 0.65rem;
    padding: 0 0.75rem;
  }
  .topbar-right {
    gap: 0.25rem;
  }
  .topbar-user-chip {
    width: 44px;
    flex-basis: 44px;
    justify-content: center;
    padding: 0.4rem 0;
  }
  .topbar-user-name,
  .topbar-user-chip .username-hint {
    display: none;
  }
  .topbar-link {
    padding: 0.45rem 0.55rem;
  }
}

/* Keep the legacy content container override from breaking the fluid layout */
.app-content > .container-fluid { width: 100%; }

/* --------------------------------------------------------------------------
   Provider switcher (#212)

   Sits between the brand and the nav, because it scopes everything below it:
   a project is an app team, an app runs on one cloud, and no project spans both
   (DEC-0028), so the tree underneath belongs to exactly one provider.

   In the collapsed rail only the mark survives, matching how .sidebar-brand and
   .nav-section-title already behave there.
   -------------------------------------------------------------------------- */

.provider-switcher {
  position: relative;
  flex: 0 0 auto;
  padding: 0.6rem 0.6rem 0;
}

.provider-current,
.provider-option {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.55rem 0.6rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.92);
  font: inherit;
  text-align: left;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
}

.provider-current { cursor: pointer; }
.provider-current:hover { background: rgba(255, 255, 255, 0.09); }
.provider-current:focus-visible { outline: 2px solid rgba(255, 255, 255, 0.5); outline-offset: 1px; }

.provider-current > i:first-child,
.provider-option > i:first-child { font-size: 1.05rem; flex: 0 0 auto; width: 1.2rem; text-align: center; }

.provider-text { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; }
.provider-name { font-size: 0.82rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.provider-count { font-size: 0.72rem; color: rgba(255, 255, 255, 0.55); overflow: hidden; text-overflow: ellipsis; }
.provider-caret { font-size: 0.7rem; color: rgba(255, 255, 255, 0.5); flex: 0 0 auto; }

.provider-menu {
  display: none;
  position: absolute;
  z-index: 40;
  left: 0.6rem;
  right: 0.6rem;
  margin-top: 0.3rem;
  padding: 0.25rem;
  border-radius: 8px;
  background: #1d2532;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.38);
}

.provider-switcher.is-open .provider-menu { display: block; }

.provider-menu .provider-option { border: 0; background: transparent; margin: 0; }
.provider-menu .provider-option:hover { background: rgba(255, 255, 255, 0.08); }
.provider-menu .provider-option.is-active { background: rgba(255, 255, 255, 0.06); }
.provider-check { font-size: 0.75rem; color: #4ade80; flex: 0 0 auto; }

/* Offered with its reason rather than hidden: an unreachable provider still
   tells the operator the cloud exists and why it is not available. */
.provider-menu .provider-option.disabled { opacity: 0.5; cursor: not-allowed; }
.provider-menu .provider-option.disabled:hover { background: transparent; }

.app-shell.sidebar-collapsed .provider-text,
.app-shell.sidebar-collapsed .provider-caret,
.mf-sidebar-collapsed .app-shell:not(.no-sidebar) .provider-text,
.mf-sidebar-collapsed .app-shell:not(.no-sidebar) .provider-caret { display: none; }

.app-shell.sidebar-collapsed .provider-current,
.mf-sidebar-collapsed .app-shell:not(.no-sidebar) .provider-current { justify-content: center; padding: 0.55rem 0; }

.app-shell.sidebar-collapsed .provider-menu,
.mf-sidebar-collapsed .app-shell:not(.no-sidebar) .provider-menu { left: 0.3rem; width: 210px; right: auto; }

.app-shell.sidebar-collapsed .provider-menu .provider-text,
.mf-sidebar-collapsed .app-shell:not(.no-sidebar) .provider-menu .provider-text { display: flex; }

/* The switcher boundary: everything below it is provider-independent (#212). */
.nav-section-boundary {
  margin-top: 1.4rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}
