/* Research Portal — sidebar navigation shell.
   Loaded after style.css on every page, so it can restructure #app-view without
   editing the layout rules the chat and ingestion views already depend on.
   All colours come from the --nav-* / --brand-* custom properties that theme.js
   sets from the branding config; nothing here is a literal brand colour. */

/* #app-view is a flex COLUMN in style.css (topbar / banner / shell). With a rail
   it becomes a ROW, and the old column becomes .app-content inside it. */
.has-sidebar #app-view {
  flex-direction: row;
  align-items: stretch;
}

.app-content {
  flex: 1;
  min-width: 0;      /* lets the chat transcript shrink instead of pushing the rail */
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
/* The ingestion page scrolls as an ordinary document (data.css undoes the
   viewport pin on #app-view); its content column has to scroll with it. */
.has-sidebar #app-view.data-view .app-content {
  overflow: visible;
}

/* style.css sizes the chat shell as min(1600px, 92vw). vw is the VIEWPORT width
   and does not know about the rail, so at 1440px the shell asked for 1325px
   inside a 1137px column and the transcript ran under the sidebar. Percent is
   resolved against the containing block, which is the content column, so this
   tracks the rail width automatically as it collapses. */
.has-sidebar .chat-shell { max-width: min(1600px, 96%); }

/* ---------------- The rail ---------------- */
.sidebar {
  --rail: 248px;
  width: var(--rail);
  flex: 0 0 var(--rail);
  background: var(--nav-bg);
  color: var(--nav-ink);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--nav-line);
  /* Own scroll: six items fit anywhere, but a future longer nav must not push
     the synthetic-data footer off screen. */
  overflow-y: auto;
  transition: width 0.16s ease, flex-basis 0.16s ease;
}

.nav-collapsed .sidebar {
  --rail: 64px;
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 14px;
  border-bottom: 1px solid var(--nav-line);
  min-height: 64px;   /* matches the topbar height, so the two rules line up */
}

.brand-mark-wrap { display: inline-flex; flex-shrink: 0; color: var(--brand-primary); }
.brand-mark { width: 32px; height: 32px; display: block; }
/* A customer logo is whatever aspect ratio they send. Bound on both axes and
   letterboxed rather than stretched. */
.brand-logo {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  object-fit: contain;
  border-radius: 6px;
  background: #fff;
}

.sidebar-names {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.sidebar-platform {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.2px;
  color: #fff;
  /* One line, clipped. A two-line platform name would break the 64px alignment
     with the topbar on the very first customer with a long name. */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-tagline {
  font-size: 10px;
  text-transform: uppercase;
  /* 0.8px of tracking on a 25-character default tagline overflowed 177px and
     ellipsised "MULTIMODAL CLINICAL RES…". Tighter tracking plus a two-line
     allowance fits the default outright, and a longer custom tagline degrades
     to two lines before it clips. */
  letter-spacing: 0.4px;
  line-height: 1.25;
  color: var(--nav-ink-dim);
  margin-top: 2px;
  /* Two lines, then ellipsis. -webkit-line-clamp is the only cross-browser way
     to ellipsise multi-line text and is supported everywhere this runs. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Collapsed: icons only. The names are hidden and the mark centres itself. */
.nav-collapsed .sidebar-names,
.nav-collapsed .nav-label,
.nav-collapsed .nav-soon,
.nav-collapsed .sidebar-synthetic { display: none; }
.nav-collapsed .sidebar-head { justify-content: center; padding: 16px 8px; }
.nav-collapsed .nav-item { justify-content: center; padding: 10px 0; }

/* ---------------- Items ---------------- */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 8px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--nav-ink);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  /* The active item is marked with a left bar. A transparent one on every item
     keeps the label from shifting 3px when the active page changes. */
  border-left: 3px solid transparent;
  transition: background 0.12s ease, color 0.12s ease;
}
.nav-item:hover { background: var(--nav-bg-hover); color: #fff; }

.nav-item-active {
  background: var(--nav-bg-active);
  color: #fff;
  border-left-color: var(--brand-primary);
}
.nav-item-active .nav-icon { color: var(--brand-primary); }
.nav-collapsed .nav-item-active { border-left-color: transparent; }
/* Collapsed to icons there is no room for a left bar, so the accent moves to a
   ring — the active page must stay identifiable at 64px. */
.nav-collapsed .nav-item-active {
  box-shadow: inset 0 0 0 1.5px var(--brand-primary);
}

.nav-icon {
  width: 19px;
  height: 19px;
  flex-shrink: 0;
  color: var(--nav-ink-dim);
}
.nav-item:hover .nav-icon { color: #fff; }
.nav-label { overflow: hidden; text-overflow: ellipsis; }

/* "soon" chip on the four placeholder sections. Muted on purpose: it is a note,
   not a call to action. */
.nav-soon {
  margin-left: auto;
  font-size: 9.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--nav-ink-dim);
  border: 1px solid var(--nav-line);
  border-radius: 999px;
  padding: 1px 6px;
}

/* Pipeline health, on the rail rather than only inside the Pipeline Monitor page.
   Whoever owns the pipelines lands on the chat like everyone else, so "is
   anything broken" has to be answerable without navigating. A dot when all is
   well, a count when it is not - a number is only worth the space when it is
   actionable. Kept when the rail collapses to icons (unlike .nav-soon, which is
   hidden): the collapsed rail is the state a monitor sits in all day, which is
   exactly when a failure most needs to be visible. */
.nav-status {
  margin-left: auto;
  min-width: 8px;
  height: 8px;
  border-radius: 999px;
  flex-shrink: 0;
}
.nav-status-ok { background: var(--accent-teal, #17a2ab); }
.nav-status-warn { background: #d98a00; }
.nav-status-bad {
  /* Carries a count, so it needs to be a pill rather than a dot. */
  background: var(--danger, #c0392b);
  color: #fff;
  height: auto;
  min-width: 16px;
  padding: 1px 5px;
  font-size: 10px;
  font-weight: 800;
  line-height: 1.4;
  text-align: center;
}
/* Collapsed to icons: the dot moves onto the icon's top-right corner so it stays
   visible without a label to sit beside. */
.nav-collapsed .nav-item { position: relative; }
.nav-collapsed .nav-status {
  position: absolute;
  top: 6px;
  right: 50%;
  margin-left: 0;
  transform: translateX(14px);
}

.sidebar-foot {
  padding: 12px 14px 16px;
  border-top: 1px solid var(--nav-line);
}
.sidebar-synthetic {
  font-size: 10.5px;
  line-height: 1.4;
  color: var(--nav-ink-dim);
  display: block;
}

/* ---------------- Hamburger ---------------- */
.nav-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  margin-right: 4px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
}
.nav-toggle:hover { color: var(--brand-primary-dark); border-color: var(--brand-border); }
.nav-toggle svg { width: 18px; height: 18px; }

/* The rail replaces the brand block that used to sit in the topbar. Keeping both
   would print the platform name twice, 200px apart. */
.has-sidebar .topbar .brand-sm { display: none; }
/* The hamburger anchors the left edge and the controls the right. NOT
   `justify-content: flex-end`: the topbar is flex-wrap:wrap, so end-alignment
   put the lone toggle on the first line at the far right and wrapped the whole
   control cluster onto a second and third line - a 149px-tall header. */
.has-sidebar .topbar { justify-content: flex-start; }
.has-sidebar .topbar .user-box { margin-left: auto; }
/* The controls are one cluster that wraps internally; without this the row can
   break between the toggle and the controls before it breaks inside them. */
.has-sidebar .topbar .user-box { flex: 1 1 auto; min-width: 0; }

/* The rail costs the control row 248px, which was enough to push it from one
   line to three at 1440px. These trims buy it back without hiding anything:
   tighter gap and padding, and the engine <select> sized to its content instead
   of to its longest option. Reverting any of them re-wraps the header. */
.has-sidebar .topbar { padding: 10px 18px; gap: 10px; }
.has-sidebar .topbar .user-box { gap: 9px; }
.has-sidebar .topbar .arch-select { max-width: 150px; }
.has-sidebar .topbar .audience-toggle { margin-right: 0; }
.has-sidebar .topbar .arch-toggle { margin-right: 0; }
.has-sidebar .topbar .aud-btn { padding: 5px 9px; }
.has-sidebar .topbar .ghost-btn { padding: 6px 11px; }

/* The control cluster needs a fixed ~1035px: every item is nowrap and
   flex-shrink:0, so nothing gives and the row wraps instead. With the rail taking
   248px that runs out at 1400px, and a wrapped header is 94-132px tall. Rather
   than let it wrap, shed width in two graduated steps, cheapest information
   first. Measured widths at full size: audience 252, engine 202, email 168,
   role 197, buttons 172. */
.aud-abbr { display: none; }

/* Step 1 (<=1400px) — abbreviate rather than remove. "Exec / Clin / Tech" still
   names the mode, and the <select> options already say "Bedrock Agents" etc., so
   the "Engine" caption above them is the most redundant pixel in the row. */
@media (max-width: 1400px) {
  .has-sidebar .topbar .aud-full { display: none; }
  .has-sidebar .topbar .aud-abbr { display: inline; }
  .has-sidebar .topbar .arch-label { display: none; }
  .has-sidebar .topbar .arch-toggle { gap: 0; }
}

/* Step 2 (<=1260px) — drop the role pill. The role is not lost: #role-banner
   spells it out in prose on the line directly below ("Principal Investigator
   view — full multi-modal access…"), so the pill is a duplicate, whereas the
   audience toggle and engine select have no second home. */
@media (max-width: 1260px) {
  .has-sidebar .topbar .role-badge { display: none; }
}

/* Step 3 — the row must not wrap at all above the off-canvas breakpoint, and the
   email is what absorbs whatever is left over.
   THIS IS THE ACTUAL FIX, and the reason the two steps above are not enough on
   their own: with flex-wrap:wrap a flex row wraps BEFORE it shrinks, so no
   flexible item ever gives up a pixel and the header jumps straight from 55px to
   94px the moment the cluster is one pixel too wide. Measured at 1201px: the
   controls needed 882px inside 917px of space and still wrapped. Switching to
   nowrap makes the browser shrink instead, and the email is the only item
   allowed to, so the header is single-line at every width down to 901px.
   Kept off the mobile branch on purpose: below 901px the rail is off-canvas and
   .brand-sm comes back into the topbar, where wrapping IS the right behaviour. */
@media (min-width: 901px) {
  /* Both levels, because both wrap. .topbar is a wrapping flex row too, so even
     with a single-line .user-box the topbar pushed that whole cluster onto a
     second line as soon as its min-content (716px at 1000px wide) exceeded the
     space left beside the hamburger (708px) - a 94px header with the controls
     below an otherwise empty first row. */
  .has-sidebar .topbar { flex-wrap: nowrap; }
  .has-sidebar .topbar .user-box { flex-wrap: nowrap; }
  /* The one designated shrink target. Every other control is nowrap +
     flex-shrink:0, so without this the nowrap row would overflow rather than
     compress. An ellipsised address still identifies who is signed in, and the
     full value is in the title attribute. */
  .has-sidebar .topbar .user-email {
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

/* Customer name, when one is configured. Sits at the left of the topbar where a
   customer expects their own name. Absent by default (theme.js hides an unset
   optional field), which is why it must not carry layout of its own. */
.customer-chip {
  font-size: 13px;
  font-weight: 700;
  color: var(--brand-primary-dark);
  background: var(--brand-primary-light);
  border: 1px solid var(--brand-border);
  border-radius: 999px;
  padding: 4px 12px;
  white-space: nowrap;
  margin-right: auto;   /* pushes .user-box to the right edge */
  /* Bounded and ellipsised. The topbar is nowrap above 900px, so a long customer
     name ("Northwest Regional Children's Health System") shrank below its content
     and spilled under .user-box - a later sibling, so it painted OVER the chip and
     cut the name mid-word with no ellipsis and no right-hand border. The controls
     are what the presenter clicks, so the chip is what yields.
     flex-shrink is 0.1, not 1: at 1 the chip shrank in proportion to its width
     and lost 3px at 1440px, ellipsising "Acme Health" as "Acme Healt…" while
     there was still room to spare. At 0.1 a name that fits is never touched and
     only a genuinely oversized one is trimmed.
     max-width is a plain length: `min(280px, max-content)` is invalid CSS
     (max-content is not allowed inside min()), so the whole declaration was
     dropped and the chip ran to 320px unbounded. */
  flex: 0 0.1 auto;
  min-width: 0;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------------- Placeholder sections ---------------- */
.placeholder-shell {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 20px;
  overflow-y: auto;
}
.placeholder-panel {
  max-width: 560px;
  text-align: center;
}
.placeholder-icon {
  display: inline-flex;
  padding: 14px;
  border-radius: 14px;
  background: var(--brand-primary-light);
  color: var(--brand-primary);
  margin-bottom: 6px;
}
.placeholder-icon .nav-icon { width: 28px; height: 28px; color: inherit; }
.placeholder-panel h2 { margin: 8px 0 10px; font-size: 20px; }
.placeholder-blurb { color: var(--ink); font-size: 14.5px; line-height: 1.6; margin: 0 0 16px; }
.placeholder-status {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  color: #744210;
  background: #fefcbf;
  border-radius: 999px;
  padding: 5px 14px;
  margin: 0 0 18px;
}
.placeholder-backing {
  font-size: 12.5px;
  color: var(--muted);
  margin: 0;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.placeholder-backing span {
  display: block;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--muted);
  margin-bottom: 4px;
}

/* ---------------- Narrow screens ---------------- */
.nav-scrim { display: none; }

@media (max-width: 900px) {
  /* Off-canvas. The rail overlays the content instead of compressing it: at this
     width, subtracting 248px from the transcript makes the chat unusable. */
  .has-sidebar .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.18s ease;
  }
  /* Full labels while open, even if the desktop preference was collapsed — a
     transient overlay has the room, and icon-only is the wrong trade on a phone. */
  .nav-collapsed .sidebar { --rail: 248px; }
  .nav-collapsed .sidebar-names,
  .nav-collapsed .nav-label,
  .nav-collapsed .nav-soon,
  .nav-collapsed .sidebar-synthetic { display: block; }
  .nav-collapsed .sidebar-names { display: flex; }
  .nav-collapsed .sidebar-head { justify-content: flex-start; padding: 16px 14px; }
  .nav-collapsed .nav-item { justify-content: flex-start; padding: 10px 12px; box-shadow: none; }
  .nav-collapsed .nav-item-active { border-left-color: var(--brand-primary); }

  .nav-open .sidebar { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,0.4); }
  .nav-open .nav-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(14, 36, 54, 0.45);
  }
  /* The brand comes back into the topbar while the rail is off-canvas —
     otherwise a closed nav leaves the header with no product name at all.
     It has to be sized to do it: .brand-sm is flex-shrink:0 with a 22px nowrap
     name and a nowrap tagline, which measured 526px for the default
     "Research Data Platform / Multimodal Clinical Research" and overflowed a
     500px header by 44px. The tagline goes (the rail still carries it) and the
     name shrinks and ellipsises rather than pushing the controls off-screen. */
  .has-sidebar .topbar .brand-sm {
    display: block;
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
  }
  .has-sidebar .topbar .brand-sm .brand-name {
    font-size: 17px;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .has-sidebar .topbar .brand-sm .tagline { display: none; }
  .has-sidebar .topbar { justify-content: space-between; }
  .customer-chip { display: none; }   /* the narrow header has no room to spare */
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .nav-item { transition: none; }
}
