/* App shell chrome: sidebar, top bar, main content frame. Loads on every page
   (split out of layout.css — see widgets.css / list.css / pages/*.css for the rest). */

:root {
  --cp-sidebar-w: 220px;

  /* Sidebar — hover tint shared by the collapse toggle and the account button */
  --cp-sidebar-hover-bg: rgb(255 255 255 / 6%);
}

/* App shell layout */
.cp-shell {
  display: flex;
  min-height: 100vh;
  align-items: flex-start;
}

/* Sidebar: full-height and sticky so it stays put while the page scrolls. Only
   .cp-sidebar-nav (the middle nav-groups list) scrolls internally — the
   sidebar's own box must stay overflow: visible, or it clips the user-block
   dropdown at the bottom (Popper's default boundary is the nearest ancestor
   with overflow != visible, so this isn't fixable by repositioning the menu
   alone; the scroll container just can't be an ancestor of it). */
.cp-sidebar {
  width: var(--cp-sidebar-w); flex: 0 0 var(--cp-sidebar-w);
  position: sticky; top: 0; align-self: flex-start;
  height: 100vh;

  /* Force the whole sidebar, dropdown included, above .cp-main */
  z-index: 1;
  transition: width .15s ease, flex-basis .15s ease;
}

.cp-sidebar-nav {
  overflow-y: auto; min-height: 0;
}

.cp-main {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--cp-canvas-bg);
}

/* Opt a page out of the default content-driven height and into filling the
   viewport exactly: the page never scrolls, and something inside it takes the
   leftover vertical space and scrolls instead. Put the class on the page's own
   root element; :has() is what lets the page opt in without the layout having
   to be told which page it is rendering.

   <main> becomes the flex column the page's own flex chain hangs off. A page
   that sizes itself with height: 100% rather than flex: 1 1 auto (the list
   pages) is unaffected by that, since the height it resolves against is
   definite either way.

   Used by .cp-wo-page and .cp-list-page. */
.cp-main:has(.cp-full-viewport-height-page) {
  height: 100vh;
  overflow: hidden;

  & > main {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
  }
}

/* Sidebar nav section labels */
.cp-nav-label {
  font-size: .6875rem;
  letter-spacing: .06em;
}

/* Sidebar nav items (Figma vertical-nav-item): leading icon · label · trailing chevron. */
.cp-nav-icon {
  font-size: 1rem;
  width: 1.25rem;
  text-align: center;
  flex: 0 0 auto;
}

.cp-nav-chevron {
  font-size: .75rem;
  opacity: .45;
  flex: 0 0 auto;
}

/* Header band. Explicit height because the collapsed rail hides the wordmark, and the
   wordmark's intrinsic height is what would otherwise size the band — it would shrink to
   the chevron. Children stretch to it (flex default). */
.cp-sidebar-head { min-height: 4.5rem; }

.cp-sidebar-brand {
  display: flex;
  align-items: center;
  padding-left: 1rem;
}

/* Collapse toggle: a full-bleed hit target. It fills the band from the wordmark out to
   the rail's inner edge, and the band's full height, so the small chevron isn't a small
   target. The chevron's inset comes from the button's own padding (clickable), not from
   margin or from padding on .cp-sidebar-head (which wouldn't be). Hover tint matches
   .cp-user-btn so the whole band reads as pressable. */
.cp-sidebar-toggle {
  line-height: 1; border: 0; border-radius: 0;
  justify-content: flex-end; padding: 0 1rem;
}
.cp-sidebar-toggle:hover { background: var(--cp-sidebar-hover-bg); }

/* Collapsed → icon-only rail: narrow the sidebar and hide everything but the icons +
   avatar. The label lives on each item's title= attribute (native tooltip) while
   collapsed. The collapsed state lives on <html data-sidebar-collapsed>, set before
   first paint by an inline blocking script in head.js and kept in sync by the
   hydrated sidebar component (reactive-components/sidebar.js) — driving CSS off
   <html> avoids the flash-then-collapse a button-attribute driver caused, since the
   button doesn't exist until the sidebar parses. It's a toggle button, not a
   disclosure: the nav narrows but is never hidden. */
:root[data-sidebar-collapsed] {
  --cp-sidebar-w: 64px;

  & :is(.cp-nav-text, .cp-nav-chevron, .cp-nav-label, .cp-sidebar-brand, .cp-user-btn .lh-sm) {
    display: none;
  }

  & .cp-nav-item {
    justify-content: center;
    gap: 0;
    padding-left: 0;
    padding-right: 0;
  }

  /* Brand is gone, so the toggle is the whole rail: center the chevron in it. */
  & :is(.cp-sidebar-toggle, .cp-user-btn) { justify-content: center; }
}

/* Sidebar user block */
.cp-user-btn:hover { background: var(--cp-sidebar-hover-bg); }

/* The print sheet on SCREEN. print.css strips the app shell when printing; this
   strips it the rest of the time, so the tab the Print List button opens looks
   like the sheet it is rather than an app screen whose body went missing. The
   two cannot share a rule: print.css is linked media="print".

   Same :has() page-opt-in as .cp-main:has(.cp-full-viewport-height-page) above,
   and here rather than with the print sheet's own styles because every selector
   it touches is one this file owns. */
.cp-shell:has(.cp-print-page) {
  /* !important for the reason print.css needs it on the same three elements:
     the sidebar carries Bootstrap's d-flex utility, which is itself
     !important, and a plain declaration loses to it however specific. */
  & .cp-sidebar,
  & .cp-topbar,
  & .cp-offline-banner {
    display: none !important;
  }

  /* The shell lays the sidebar and main out side by side; with the sidebar
     gone, main has the row to itself. */
  & .cp-main {
    background: var(--bs-body-bg);
  }
}
