/* ── App shell ───────────────────────────────────────────────────────── */
.app-shell {
  display: grid;
  /* minmax(0, 1fr), not bare 1fr: a bare 1fr track's minimum size defaults to its
     content's min-content width, so one wide descendant anywhere in the main column
     (e.g. an unwrapped Newick string) sets a content-based floor on the entire grid
     column — no min-width:0 further down the tree can override a constraint set at
     the grid track itself. minmax(0, ...) makes the track's minimum explicit. */
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100dvh;
}

/* ── Sidebar ─────────────────────────────────────────────────────────── */
.sidebar {
  position: sticky; top: 0; height: 100dvh; overflow-y: auto;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex; flex-direction: column;
  padding: var(--space-4) 0;
  z-index: 10;
}
.sidebar__brand {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 0 var(--space-4) var(--space-4);
  border-bottom: 1px solid var(--color-divider);
  margin-bottom: var(--space-2);
  cursor: pointer; text-decoration: none; color: inherit;
}
.brand-mark { flex-shrink: 0; width: 36px; height: 36px; color: var(--color-primary); }
.brand-mark svg { width: 100%; height: 100%; }
.sidebar__brand h1 { font-size: var(--text-sm); font-weight: 700; line-height: 1.2; }
.sidebar__nav { display: flex; flex-direction: column; gap: 1px; padding: 0 var(--space-2) var(--space-2); }
.nav-link {
  display: flex; align-items: center;
  width: 100%; padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm); font-weight: 500; text-align: left;
  border-radius: var(--radius-md); color: var(--color-text-muted);
  background: transparent; border: none; cursor: pointer; text-decoration: none;
}
.nav-link:hover    { background: var(--color-surface-offset); color: var(--color-text); }
.nav-link.is-active { background: var(--color-primary-subtle); color: var(--color-primary); font-weight: 600; }
.sidebar__section {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--color-divider);
  margin-top: var(--space-2);
  display: flex; flex-direction: column; gap: var(--space-3);
}
.sidebar__section h2 { font-size: var(--text-xs); font-weight: 600; color: var(--color-text-faint); text-transform: uppercase; letter-spacing: 0.06em; }
.sidebar__section--muted { margin-top: auto; }

/* ── Main area ───────────────────────────────────────────────────────── */
.app-main { display: flex; flex-direction: column; min-height: 100dvh; background: var(--color-bg); }

/* ── Top bar ─────────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 9;
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
  height: var(--header-h); padding: 0 var(--space-6);
  background: var(--color-surface); border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}
.topbar h2 { font-size: var(--text-base); font-weight: 600; }
.topbar__title { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.topbar__title > div { min-width: 0; overflow: hidden; }
.topbar__title h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar__actions { display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0; }

/* Hamburger toggle — hidden on desktop, the sidebar is always visible there. */
.nav-toggle {
  display: none; flex-shrink: 0; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: var(--radius-md);
  background: transparent; color: var(--color-text); border: none; cursor: pointer;
}
.nav-toggle:hover { background: var(--color-surface-offset); }

/* Backdrop behind the mobile nav drawer. Inert and invisible on desktop. */
.sidebar-backdrop {
  display: none; position: fixed; inset: 0; z-index: 40;
  background: oklch(0.2 0.01 80 / 0.45);
  opacity: 0; pointer-events: none;
  transition: opacity var(--transition);
}

/* ── Views ───────────────────────────────────────────────────────────── */
.view-container { flex: 1; min-width: 0; overflow-x: hidden; }
/* Prevent grid items from expanding beyond their column (causes side-scroll with wide charts) */
.panel-grid > *, .panel-grid--compact > *, .panel-grid--overview > * { min-width: 0; }
.view           { display: none; padding: var(--space-6); }
.view.is-visible { display: flex; flex-direction: column; gap: var(--space-5); }
/* Same fix, one level up: a flex column's items default to their content's min-content
   width, so a single wide descendant (e.g. an unwrapped Newick string in <pre>) stretches
   the whole column — and every sibling panel in it — to match. */
.view.is-visible > * { min-width: 0; }

/* ── Section heading ─────────────────────────────────────────────────── */
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); }
.section-heading h3 { font-size: var(--text-lg); font-weight: 700; margin-top: var(--space-1); }
.toolbar-group { display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0; flex-wrap: wrap; }
.toolbar-group label { display: flex; align-items: center; gap: var(--space-2); white-space: nowrap; font-size: var(--text-xs); color: var(--color-text-muted); font-weight: 500; }

/* ── Panel grids ─────────────────────────────────────────────────────── */
.panel-grid         { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
.panel-grid--compact{ display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.panel-grid--overview{ display: grid; grid-template-columns: 2fr 1fr; gap: var(--space-4); }
.kpi-grid           { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-3); }
.split-layout       { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }

/* ── Hero card ───────────────────────────────────────────────────────── */
.hero-card {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-6);
  padding: var(--space-6) var(--space-8);
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg);
}
.hero-card h3 { font-size: var(--text-lg); font-weight: 700; max-width: 44ch; margin: var(--space-2) 0; }
.hero-card__actions { display: flex; gap: var(--space-2); flex-shrink: 0; align-items: center; }

/* ── Footer ──────────────────────────────────────────────────────────── */
.footer {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
  padding: var(--space-4) var(--space-6); border-top: 1px solid var(--color-divider);
  font-size: var(--text-xs); color: var(--color-text-faint);
}
.footer__links { display: flex; gap: var(--space-4); }
.footer a { color: inherit; text-decoration: none; }
.footer a:hover { color: var(--color-text-muted); }

/* ── Skip link ───────────────────────────────────────────────────────── */
.skip-link {
  position: absolute; top: -100%; left: var(--space-4);
  background: var(--color-primary); color: var(--color-text-inverse);
  padding: var(--space-2) var(--space-4); border-radius: 0 0 var(--radius-md) var(--radius-md);
  z-index: 100; font-size: var(--text-sm); font-weight: 600;
}
.skip-link:focus { top: 0; }

/* ── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  /* minmax(0, 1fr), not bare 1fr — see the .app-shell comment above: a bare 1fr
     track's minimum still floors to its content's min-content width, and a Chart.js
     canvas's raw width attribute is wide enough to blow up the whole page on mobile. */
  .app-shell { grid-template-columns: minmax(0, 1fr); }

  /* Sidebar becomes an off-canvas drawer instead of a static column. Views set
     grid-template-columns / kpi column counts as inline styles (e.g. overview.js's
     `repeat(${cols},1fr)`); only !important here can out-rank those without rewriting
     every view to route column counts through a CSS custom property instead. */
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 50;
    width: min(280px, 82vw); height: 100dvh;
    transform: translateX(-100%);
    transition: transform var(--transition);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.is-open { transform: translateX(0); }
  .nav-toggle { display: inline-flex; }
  .nav-link   { padding: var(--space-3); } /* larger touch target inside the drawer */
  .sidebar-backdrop { display: block; }
  .sidebar-backdrop.is-open { opacity: 1; pointer-events: auto; }

  .topbar    { padding: 0 var(--space-4); }
  /* The eyebrow subtitle ("Aggregated benchmark health" etc.) plus the hamburger
     button don't both fit next to the title in var(--header-h)'s fixed height —
     it wraps and overflows into the view below it. Title alone is enough here. */
  .topbar #view-eyebrow { display: none; }
  .view      { padding: var(--space-4); }
  /* minmax(0, ...), not bare 1fr — same reasoning as .app-shell above. A wide
     JS-built child (e.g. createHeatmapGrid's own repeat(N,1fr) columns, which have
     the identical bare-1fr floor problem one level down) can otherwise set a
     min-content floor on the column that pushes the whole row past the viewport. */
  .kpi-grid  { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .panel-grid, .panel-grid--overview, .panel-grid--compact { grid-template-columns: minmax(0, 1fr) !important; }
  .panel--wide { grid-column: span 1; }
  .hero-card { flex-direction: column; align-items: flex-start; padding: var(--space-4); }
  .split-layout { grid-template-columns: minmax(0, 1fr) !important; }
  /* Same min-width:0 pattern as .view.is-visible > * above: once stacked into a
     column, each direct child (including views' own unstyled wrapper divs around a
     toolbar, e.g. runs.js) needs an explicit full width or it keeps the shrink-to-fit
     width dictated by its widest un-shrunk descendant. */
  .section-heading { flex-direction: column; }
  .section-heading > * { min-width: 0; width: 100%; }
  .panel__header    { flex-wrap: wrap; }
  /* Some views (e.g. rundetail.js's chart-type toggle + "Reset zoom" pair) put an
     inline-styled `display:flex` action row inside .panel__header that doesn't itself
     wrap; on a narrow panel that row can run past the edge. */
  .panel__header > [style*="display:flex"] { flex-wrap: wrap; row-gap: var(--space-2); }
  .table-shell { -webkit-overflow-scrolling: touch; }
  /* Several views set select[style="width:auto"] so these size to their content on
     desktop (e.g. a short "50" commit-count select); with long branch names as options,
     that content-based width can exceed the viewport. Flex items default to
     min-width:auto (floored at their content's min-content, ignoring width/max-width) —
     min-width:0 all the way down the chain removes that floor so a definite width on
     .toolbar-group can actually propagate to a shrunk/truncated select. */
  .toolbar-group        { width: 100%; min-width: 0; }
  .toolbar-group label  { min-width: 0; }
  .toolbar-group select.input { min-width: 0; max-width: 100%; }
}
@media (max-width: 540px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .footer   { flex-direction: column; text-align: center; }
}