/* =====================================================================
   SYNAPSE.EXE SIDEBAR -- one navy panel, identical on every page.

   Reference implementation: tools/design-preview/preview.src.html
   (.sidebar / .nav / .side-foot). Tokens come from UnifiedAppShell.css
   (--sx-*); each one carries a hard fallback so this file also works on the
   few pages that do not load the shared shell stylesheet.

   Page-to-page navigation is a plain instant cut, on purpose. Chromium already
   holds the old page on screen until the new page has painted its first frame
   (paint holding), so a hard cut looks seamless once pages paint quickly. No
   cross-document view transition is declared: it faded old and new page at the
   same time and added ~300ms to every switch.

   Everything that draws the sidebar is scoped to #sidebar (id specificity), so
   it renders the same regardless of the page's body class (mode-clinician or
   mode-play) or any other stylesheet the page loads. Edit here instead of
   adding per-page sidebar overrides elsewhere.

   The sidebar's structure is finished off by ScalableSidebar.js (brand row,
   icon sprite, profile chip moved to the bottom). The legacy
   .sidebar-utility block stays in the DOM but is hidden: Progress Monitoring
   now lives in the Workspace list and Settings is the profile chip.
   ===================================================================== */

:root {
  --sidebar-width: 268px;
}

body {
  margin: 0;
  font-family: var(--sx-font-body, 'Sora', 'Segoe UI', system-ui, sans-serif);
  background: var(--sx-bg, #f2f6fc);
  color: var(--sx-ink, #0b1b46);
}

/* ---------------------------------------------------------------------
   Panel
   --------------------------------------------------------------------- */
#sidebar.sidebar-container {
  --sb-pad: 14px;
  --sb-pb: 16px;
  --sb-text: #c5d2f5;
  --sb-label: #7f93d1;
  --sb-muted: #8fa1d8;
  --sb-icon: #aebcf0;
  --sb-hover: rgba(255, 255, 255, 0.07);
  --sb-active: rgba(255, 255, 255, 0.11);
  --sb-line: rgba(255, 255, 255, 0.1);
  --sb-cyan: var(--sx-cyan, #2ad0f1);

  position: fixed;
  top: 0;
  left: 0;
  z-index: 200;
  box-sizing: border-box;
  width: var(--sidebar-width);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 20px var(--sb-pad) var(--sb-pb);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.22) transparent;
  border-right: 1px solid rgba(255, 255, 255, 0.07);
  background: linear-gradient(180deg, #0a2364, var(--sx-navy-900, #071751));
  color: var(--sb-text);
  font-family: var(--sx-font-body, 'Sora', 'Segoe UI', system-ui, sans-serif);
  font-size: 14.5px;
  line-height: 1.5;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#sidebar.sidebar-container *,
#sidebar.sidebar-container *::before,
#sidebar.sidebar-container *::after {
  box-sizing: border-box;
}

/* the SVG icon sprite injected by ScalableSidebar.js takes no space */
#sidebar .sx-icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

/* ---------------------------------------------------------------------
   Brand row (top)
   --------------------------------------------------------------------- */
#sidebar .sidebar-brand {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 10px 18px;
  color: #ffffff;
  font-family: var(--sx-font-display, 'Space Grotesk', 'Sora', 'Segoe UI', system-ui, sans-serif);
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
  cursor: default;
}

#sidebar .sidebar-brand svg {
  width: 28px;
  height: 28px;
  flex: none;
}

#sidebar .sidebar-brand em {
  font-style: normal;
  color: var(--sb-cyan);
}

/* ---------------------------------------------------------------------
   Navigation
   --------------------------------------------------------------------- */
#sidebar .nav-list {
  flex: none;
  margin: 0 0 16px;
  padding: 0;
  overflow: visible;
}

#sidebar #nav-root {
  display: block;
  margin: 0;
  padding: 0;
  list-style: none;
}

#sidebar .sidebar-section-label {
  margin: 16px 10px 6px;
  color: var(--sb-label);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  line-height: 1.5;
  text-transform: uppercase;
}

#sidebar .nav-section {
  margin: 0;
}

#sidebar .nav-item,
#sidebar button.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  margin: 0;
  padding: 9px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: inherit;
  font-family: inherit;
  font-size: 14.5px;
  font-weight: 500;
  line-height: 1.5;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  box-shadow: none;
  transition: background-color 0.12s ease, color 0.12s ease;
}

#sidebar .nav-item:hover {
  background: var(--sb-hover);
  color: #ffffff;
}

#sidebar .nav-item:focus {
  outline: none;
}

#sidebar .nav-item:focus-visible {
  outline: 2px solid var(--sb-cyan);
  outline-offset: 1px;
  background: var(--sb-hover);
  color: #ffffff;
}

#sidebar .nav-item.active,
#sidebar .nav-item[aria-current="page"] {
  background: var(--sb-active);
  color: #ffffff;
}

/* the 3px cyan "you are here" marker, flush with the panel's left edge */
#sidebar .nav-item.active::before,
#sidebar .nav-item[aria-current="page"]::before {
  content: "";
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: calc(-1 * var(--sb-pad));
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--sb-cyan);
}

#sidebar .nav-item-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Instant press feedback while the next page loads (see initNavigationFeel
   in ScalableSidebar.js). */
#sidebar .nav-item.is-pending {
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
  transition: background-color 0.08s ease;
}

/* ---- icons: data-nav-icons on <html> picks the style ("color" default) ---- */
#sidebar .nav-ico {
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  color: var(--sb-icon);
}

#sidebar .nav-ico svg {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#sidebar .nav-item:hover .nav-ico,
#sidebar .nav-item:focus-visible .nav-ico,
#sidebar .nav-item.active .nav-ico,
#sidebar .nav-item[aria-current="page"] .nav-ico {
  color: #ffffff;
}

html[data-nav-icons="color"] #sidebar .nav-ico {
  color: #ffffff;
}

html[data-nav-icons="color"] #sidebar .nav-ico svg {
  filter: drop-shadow(0 1px 1px rgba(7, 23, 81, 0.35));
}

html[data-nav-icons="color"] #sidebar .nav-ico.c-orange {
  background: linear-gradient(160deg, var(--sx-orange-lt, #fda640), var(--sx-orange, #fb5a45));
}

html[data-nav-icons="color"] #sidebar .nav-ico.c-green {
  background: linear-gradient(160deg, var(--sx-green-lt, #a1e58f), var(--sx-green, #38b49c));
}

html[data-nav-icons="color"] #sidebar .nav-ico.c-amber {
  background: linear-gradient(160deg, var(--sx-amber-lt, #fed94c), var(--sx-amber, #fca642));
}

html[data-nav-icons="color"] #sidebar .nav-ico.c-blue {
  background: linear-gradient(160deg, var(--sx-cyan, #2ad0f1), var(--sx-blue-500, #3376d9));
}

html[data-nav-icons="color"] #sidebar .nav-ico.c-cyan {
  background: linear-gradient(160deg, var(--sx-cyan-200, #b8f0fb), var(--sx-sky, #33a3e6));
}

html[data-nav-icons="color"] #sidebar .nav-ico.c-lime {
  background: linear-gradient(160deg, #e1ef74, #7fd06a);
}

/* nested groups (not used by the current menu, kept for the data format) */
#sidebar .nav-expand {
  margin-left: auto;
  pointer-events: none;
}

#sidebar .nav-children {
  margin: 0;
  padding: 0 0 0 18px;
  list-style: none;
  border-left: 1px solid var(--sb-line);
}

/* Recording indicator dot next to "Record" */
#sidebar .nav-record-dot {
  display: none;
  flex: none;
  width: 8px;
  height: 8px;
  margin-left: auto;
  border-radius: 50%;
  background: var(--sx-orange, #fb5a45);
}

#sidebar .nav-item.recording .nav-record-dot {
  display: inline-block;
  box-shadow: 0 0 0 0 rgba(251, 90, 69, 0.8);
  animation: sx-side-record-pulse 1.2s infinite ease-out;
}

@keyframes sx-side-record-pulse {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(251, 90, 69, 0.8);
  }
  70% {
    transform: scale(1.25);
    box-shadow: 0 0 0 8px rgba(251, 90, 69, 0);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(251, 90, 69, 0);
  }
}

/* ---------------------------------------------------------------------
   Group-session panel (rendered by renderGroupSessionSidebar in the JS)
   --------------------------------------------------------------------- */
#sidebar .group-session-panel {
  flex: none;
  margin: 0 0 16px;
  padding: 12px 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
}

#sidebar .group-session-title {
  margin: 0 0 8px;
  color: var(--sx-cyan-200, #b8f0fb);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

#sidebar .group-session-client-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#sidebar .group-session-client-btn {
  position: relative;
  width: 100%;
  margin: 0;
  padding: 8px 10px;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.07);
  color: #dbe4ff;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.12s ease, color 0.12s ease;
}

#sidebar .group-session-client-btn:hover {
  background: rgba(255, 255, 255, 0.13);
  color: #ffffff;
}

#sidebar .group-session-client-btn:focus {
  outline: none;
}

#sidebar .group-session-client-btn:focus-visible {
  outline: 2px solid var(--sb-cyan);
  outline-offset: 1px;
}

#sidebar .group-session-client-btn.active {
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
  box-shadow: inset 3px 0 0 var(--sb-cyan);
}

/* ---------------------------------------------------------------------
   Legacy utility block: kept in the DOM (handlers still bind to it), hidden.
   --------------------------------------------------------------------- */
#sidebar .sidebar-utility {
  display: none;
}

/* ---------------------------------------------------------------------
   Profile chip (bottom): avatar, name, "Settings" caption, gear
   --------------------------------------------------------------------- */
#sidebar .profile-switcher {
  order: 9;
  flex: none;
  /* pinned to the bottom edge; stays reachable if the panel has to scroll.
     The negative margin swallows the panel's own bottom padding. */
  position: sticky;
  bottom: calc(-1 * var(--sb-pb));
  margin-top: auto;
  margin-bottom: calc(-1 * var(--sb-pb));
  background: var(--sx-navy-900, #071751);
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) 20px;
  grid-template-rows: auto auto;
  column-gap: 10px;
  align-items: center;
  padding: 14px 8px var(--sb-pb);
  border: 0;
  border-top: 1px solid var(--sb-line);
  border-radius: 0;
  cursor: pointer;
}

#sidebar .profile-switcher:focus {
  outline: none;
}

#sidebar .profile-switcher:focus-visible {
  outline: 2px solid var(--sb-cyan);
  outline-offset: 2px;
  border-radius: 10px;
}

#sidebar .profile-pic {
  grid-area: 1 / 1 / 3 / 2;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  width: 36px !important;
  height: 36px !important;
  overflow: hidden;
  border: 0;
  border-radius: 50% !important;
  background: rgba(255, 255, 255, 0.14) !important;
  color: #ffffff;
  font-family: var(--sx-font-display, 'Space Grotesk', 'Sora', 'Segoe UI', system-ui, sans-serif);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  box-shadow: none;
}

#sidebar .profile-pic svg {
  width: 22px;
  height: 22px;
}

#sidebar .profile-pic svg * {
  fill: currentColor;
}

#sidebar .profile-name {
  grid-area: 1 / 2;
  align-self: end;
  min-width: 0;
  overflow: hidden;
  color: #ffffff;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#sidebar .profile-caption {
  grid-area: 2 / 2;
  align-self: start;
  color: var(--sb-muted);
  font-size: 12px;
  line-height: 1.3;
  transition: color 0.12s ease;
}

#sidebar .profile-gear {
  grid-area: 1 / 3 / 3 / 4;
  width: 20px;
  height: 20px;
  color: var(--sb-muted);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: color 0.12s ease;
}

#sidebar .profile-switcher:hover .profile-caption,
#sidebar .profile-switcher:hover .profile-gear,
#sidebar .profile-switcher:focus-visible .profile-caption,
#sidebar .profile-switcher:focus-visible .profile-gear {
  color: #ffffff;
}

/* the old profile dropdown is retired (the chip opens Settings) */
#sidebar .profile-dropdown {
  display: none;
}

#sidebar .profile-list {
  display: none;
  position: absolute;
  right: 8px;
  bottom: calc(100% + 6px);
  left: 8px;
  z-index: 10;
  margin: 0;
  padding: 4px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  background: var(--sx-navy-800, #0b2a6f);
  color: #ffffff;
  list-style: none;
}

#sidebar .profile-list li {
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}

#sidebar .profile-list li:hover,
#sidebar .profile-list li:focus {
  outline: none;
  background: rgba(255, 255, 255, 0.1);
}

#sidebar .profile-list li:focus-visible {
  outline: 2px solid var(--sb-cyan);
}

/* ---------------------------------------------------------------------
   Mobile drawer toggle + scrim
   --------------------------------------------------------------------- */
.sidebar-toggle {
  display: none;
}

#sidebarToggle {
  position: fixed;
  top: 18px;
  left: 18px;
  z-index: 300;
  min-width: 44px;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  background: var(--sx-navy-900, #071751);
  color: #ffffff;
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(7, 23, 81, 0.28);
  transition: background-color 0.12s ease;
}

#sidebarToggle:hover {
  background: var(--sx-navy-800, #0b2a6f);
}

#sidebarToggle:focus-visible {
  outline: 2px solid var(--sx-cyan, #2ad0f1);
  outline-offset: 2px;
}

.sidebar-scrim {
  display: none;
}

/* ---------------------------------------------------------------------
   Page content offset
   --------------------------------------------------------------------- */
.main-content {
  margin-left: var(--sidebar-width);
  padding: 40px 32px;
  min-height: 100vh;
  min-height: 100dvh;
  background: transparent;
  transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* The shared legal footer is appended after .main-content as a sibling of
   the sidebar, not inside it -- without this it centers across the full
   viewport instead of the visible content area next to the sidebar. */
.sidebar-container ~ .sx-legal-footer {
  margin-left: var(--sidebar-width);
}

/* ---------------------------------------------------------------------
   Tablet: collapsed rail (icon over label)
   --------------------------------------------------------------------- */
@media (min-width: 701px) and (max-width: 1024px) {
  :root {
    --sidebar-width: 140px;
  }

  #sidebar.sidebar-container {
    --sb-pad: 8px;
    --sb-pb: 12px;
    padding: 16px var(--sb-pad) var(--sb-pb);
  }

  #sidebar .sidebar-brand {
    flex-direction: column;
    gap: 4px;
    padding: 2px 0 12px;
    font-size: 13px;
    text-align: center;
  }

  /* section labels collapse into a hairline divider */
  #sidebar .sidebar-section-label {
    height: 1px;
    margin: 10px 8px;
    padding: 0;
    overflow: hidden;
    background: var(--sb-line);
    font-size: 0;
    line-height: 0;
  }

  #sidebar .nav-item,
  #sidebar button.nav-item {
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    padding: 8px 4px;
    font-size: 11.5px;
    line-height: 1.2;
    text-align: center;
  }

  #sidebar .nav-item-label {
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
    overflow: visible;
  }

  #sidebar .nav-record-dot {
    position: absolute;
    top: 8px;
    right: 14px;
    margin: 0;
  }

  #sidebar .group-session-panel {
    margin: 0 0 12px;
    padding: 10px 6px;
  }

  #sidebar .group-session-title {
    font-size: 10px;
    text-align: center;
  }

  #sidebar .group-session-client-btn {
    padding: 8px 4px;
    font-size: 11.5px;
    text-align: center;
  }

  #sidebar .profile-switcher {
    display: flex;
    justify-content: center;
    padding: 12px 0 var(--sb-pb);
  }

  #sidebar .profile-name,
  #sidebar .profile-caption,
  #sidebar .profile-gear {
    display: none;
  }

  .main-content {
    margin-left: var(--sidebar-width);
  }
}

/* ---------------------------------------------------------------------
   Phone: off-canvas drawer opened by the hamburger
   --------------------------------------------------------------------- */
@media (max-width: 700px) {
  #sidebar.sidebar-container {
    width: min(86vw, 320px);
    min-width: min(86vw, 320px);
    --sb-pb: calc(16px + env(safe-area-inset-bottom, 0px));
    z-index: 3000;
    transform: translateX(-100%);
    box-shadow: none;
  }

  #sidebar.sidebar-container.open {
    transform: translateX(0);
    box-shadow: 2px 0 30px rgba(7, 23, 81, 0.35);
  }

  .sidebar-toggle {
    display: block;
  }

  #sidebarToggle {
    z-index: 4000;
  }

  body.sidebar-open #sidebarToggle {
    left: min(calc(86vw - 54px), 266px);
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.1);
    box-shadow: none;
  }

  .sidebar-scrim {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: min(86vw, 320px);
    z-index: 2900;
    display: block;
    border: 0;
    background: rgba(7, 23, 81, 0.55);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
  }

  body.sidebar-open .sidebar-scrim {
    opacity: 1;
    pointer-events: auto;
  }

  body.sidebar-open {
    overflow: hidden;
  }

  .main-content {
    margin-left: 0;
    padding: 76px 12px 24px;
  }

  .sidebar-container ~ .sx-legal-footer {
    margin-left: 0;
  }

  #profileOverlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 5000 !important;
    display: flex;
    justify-content: center;
    align-items: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  #sidebar.sidebar-container,
  .main-content,
  .sidebar-scrim {
    transition: none;
  }

  #sidebar .nav-item,
  #sidebar .nav-item.is-pending,
  #sidebar .group-session-client-btn,
  #sidebar .profile-caption,
  #sidebar .profile-gear,
  #sidebarToggle {
    transition: none;
  }

  #sidebar .nav-item.recording .nav-record-dot {
    animation: none;
  }
}
