/* The signed in app: topbar across the top, rail on the left, the page in the middle, one quiet footer line.
   Topbar and rail are solid chrome; only the page area is the blue canvas with its corner glow. */

.app-shell {
  display: grid; grid-template-columns: var(--rail) minmax(0, 1fr); min-height: 100vh;
  transition: grid-template-columns .24s ease;
}
html.rail-collapsed .app-shell { grid-template-columns: var(--rail-collapsed) minmax(0, 1fr); }

/* ---------- Topbar ---------- */
.topbar {
  grid-column: 1 / -1; position: sticky; top: var(--banner-h, 0px); z-index: 40;
  height: var(--topbar); display: flex; align-items: center; gap: 14px; padding: 0 18px 0 0;
  background: var(--chrome);
  border-bottom: 1px solid var(--line);
}
/* The brand block is exactly as wide as the rail, and its border continues the rail border up through the topbar. */
.topbar-brand {
  --logo-h: 12px;
  display: flex; align-items: center; gap: 12px; flex: none; align-self: stretch;
  width: var(--rail); padding: 0 12px; border-right: 1px solid var(--line); transition: width .24s ease;
}
.topbar-brand .brand { min-width: 0; }
html.rail-collapsed .topbar-brand { width: var(--rail-collapsed); padding: 0; justify-content: center; }
html.rail-collapsed .topbar-brand .brand { display: none; }

.brand { display: flex; align-items: center; color: var(--ink); flex: none; }

/* The wordmark file carries a lot of empty space above and below the letters; the crop shows only the letters. */
.brandlogo { height: var(--logo-h, 14px); width: auto; max-width: none; aspect-ratio: 12 / 1; object-fit: cover; }

.rail-toggle {
  display: grid; place-items: center; flex: none;
  width: 34px; height: 34px; border-radius: var(--r-m);
  background: none; border: 1px solid var(--line); color: var(--ink-3); cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.rail-toggle:hover { background: var(--panel-3); color: var(--ink); }
.rail-toggle svg { width: 17px; height: 17px; transition: transform .22s ease; }
html.rail-collapsed .rail-toggle svg { transform: rotate(180deg); }

.top-sep { display: none; width: 1px; height: 22px; background: var(--line); flex: none; }
.top-crumbs { display: flex; align-items: center; gap: 7px; min-width: 0; flex: 1; font-size: var(--fs-s); color: var(--ink-3); }
.top-crumbs a { color: var(--ink-3); white-space: nowrap; }
.top-crumbs a:hover { color: var(--ink); }
.top-crumbs .sep { color: var(--ink-5); }
.top-crumbs > :last-child:not(.sep):not(.btn) { color: var(--ink); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topright { margin-left: auto; display: flex; align-items: center; gap: 6px; }

/* ---------- Rail ---------- */
.rail {
  position: sticky; top: calc(var(--topbar) + var(--banner-h, 0px)); align-self: start;
  height: calc(100vh - var(--topbar) - var(--banner-h, 0px)); overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
  padding: 14px 12px 24px;
  background: var(--chrome); border-right: 1px solid var(--line);
  transition: padding .24s ease;
}
.rail .group {
  margin: 16px 10px 6px; transition: opacity .16s ease .06s;
  font-size: var(--fs-2xs); font-weight: 600; letter-spacing: var(--tr-caps); text-transform: uppercase; color: var(--ink-4);
}
.rail .group:first-child { margin-top: 2px; }
.rail .spacer { flex: 1; }

.rail a.nav {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: var(--r-m);
  color: var(--ink-3); font-size: var(--fs-s); font-weight: 500; line-height: 1.3;
  transition: padding .24s ease, gap .24s ease, background .15s ease, color .15s ease;
}
.rail a.nav:hover { background: var(--panel-3); color: var(--ink); }
.rail a.nav.active { background: var(--brand-soft); color: var(--brand-text); font-weight: 600; }
.rail a.nav .ic { display: grid; place-items: center; width: 18px; flex: none; color: var(--ink-4); transition: color .15s ease; }
.rail a.nav:hover .ic { color: var(--ink-2); }
.rail a.nav.active .ic { color: var(--brand-text); }
.rail a.nav svg { width: 16px; height: 16px; }
.rail a.nav .lbl, .rail a.nav .count {
  display: inline-block; max-width: 170px; overflow: hidden; white-space: nowrap;
  transition: max-width .24s ease, opacity .16s ease .06s;
}
.rail a.nav .count {
  margin-left: auto; padding: 1px 7px; border-radius: var(--r-full);
  background: var(--panel-3); color: var(--ink-3);
  font-size: var(--fs-2xs); font-weight: 600; font-variant-numeric: tabular-nums;
}
.rail a.nav.active .count { background: var(--brand); color: var(--on-brand); }
.rail a.nav.soon { opacity: .55; cursor: default; }
.rail a.nav.soon:hover { background: transparent; color: var(--ink-3); }

/* A section with pages under it opens and closes in place; the grid row animates the height. */
.rail .nav-group { display: flex; flex-direction: column; }
.rail .nav-parent .chev { margin-left: auto; display: inline-flex; transition: transform .25s ease; }
.rail .nav-parent .chev svg { width: 14px; height: 14px; }
.rail .nav-group.open .nav-parent .chev { transform: rotate(180deg); }
.rail .nav-sub-wrap { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .28s var(--ease); }
.rail .nav-group.open .nav-sub-wrap { grid-template-rows: 1fr; }
.rail .nav-sub-wrap > .nav-sub { min-height: 0; overflow: hidden; opacity: 0; transition: opacity .2s ease, margin .28s var(--ease); }
.rail .nav-group.open .nav-sub-wrap > .nav-sub { opacity: 1; }
.rail .nav-sub {
  display: flex; flex-direction: column; gap: 1px;
  margin: 0 0 0 18px; padding-left: 10px; border-left: 1px solid var(--line);
}
.rail .nav-group.open .nav-sub { margin-block: 4px 6px; }
.rail .nav-sub a {
  display: flex; align-items: center; gap: 8px; padding: 5px 10px; border-radius: var(--r-s);
  color: var(--ink-3); font-size: var(--fs-s);
  transition: background .15s ease, color .15s ease;
}
.rail .nav-sub a svg { width: 14px; height: 14px; color: var(--ink-4); }
.rail .nav-sub a.on svg { color: var(--brand-text); }
.rail .nav-sub a:hover { background: var(--panel-3); color: var(--ink); }
.rail .nav-sub a.on { color: var(--brand-text); font-weight: 600; }

html.rail-collapsed .rail { padding: 14px 10px 24px; }
/* Collapsed, every item is the same centred square, and a group label becomes a thin divider instead of empty space. */
html.rail-collapsed .rail a.nav { justify-content: center; width: 44px; height: 40px; margin-inline: auto; padding: 0; gap: 0; }
html.rail-collapsed .rail a.nav .lbl,
html.rail-collapsed .rail a.nav .count { max-width: 0; opacity: 0; transition: max-width .24s ease, opacity .1s ease; }
html.rail-collapsed .rail a.nav .count { margin: 0; padding: 0; }
html.rail-collapsed .rail .group { height: 1px; margin: 10px 12px; overflow: hidden; font-size: 0; background: var(--line); }
html.rail-collapsed .rail .nav-parent .chev,
html.rail-collapsed .rail .nav-sub-wrap { display: none; }

.nav-scrim { display: none; }

/* ---------- Page ---------- */
.main {
  min-width: 0; display: flex; flex-direction: column;
  background-color: var(--bg);
}
.page { flex: 1; padding: 24px 28px; }
.page-wide { width: 100%; max-width: 1560px; margin-inline: auto; }

.crumbs { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; font-size: var(--fs-xs); color: var(--ink-4); }
.crumbs a { color: var(--ink-3); }
.crumbs .sep { color: var(--ink-5); }

/* Emptiness fills the page instead of leaving a card floating at the top. */
.page:has(> .emptystate),
.page:has(> .card > .card-body > .emptystate.inline),
.page:has(> .card > .emptystate.inline) { display: flex; flex-direction: column; }
.page:has(> .emptystate) > .emptystate { flex: 1 1 auto; }
.page > .card:has(> .card-body > .emptystate.inline),
.page > .card:has(> .emptystate.inline) { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }

/* ---------- Grids ---------- */
.grid { display: grid; gap: 16px; }
.grid.top { align-items: start; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.split-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stack { display: flex; flex-direction: column; gap: 16px; }

/* ---------- Footer ---------- */
.appfoot {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  margin-top: auto; padding: 12px 96px 12px 28px;
  border-top: 1px solid var(--canvas-line);
  font-size: var(--fs-xs); color: var(--ink-4);
}
.appfoot .links { display: flex; gap: 16px; margin-left: auto; flex-wrap: wrap; }
.appfoot a { color: var(--ink-3); }
.appfoot a:hover { color: var(--ink); }

@media (min-width: 1800px) {
  .page-wide { max-width: 1760px; }
  .page { padding: 28px 40px 40px; }
}

/* On very wide screens the page uses the whole width instead of a centred column. */
@media (min-width: 2200px) {
  .page-wide { max-width: none; }
}

@media (max-width: 1080px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split-2-1 { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .app-shell, html.rail-collapsed .app-shell { grid-template-columns: minmax(0, 1fr); }
  .topbar { padding-left: 12px; gap: 10px; }
  .topbar-brand, html.rail-collapsed .topbar-brand { width: auto; padding: 0; border-right: 0; }
  .top-sep { display: block; }
  html.rail-collapsed .topbar-brand .brand { display: flex; }

  .rail {
    position: fixed; top: var(--banner-h, 0px); bottom: 0; left: 0; z-index: 90;
    width: min(280px, 84vw); height: calc(100vh - var(--banner-h, 0px)); padding: 14px 12px 24px;
    transform: translateX(-105%); transition: transform .2s ease; box-shadow: var(--sh-float);
    border-right: 0;
  }
  html.rail-collapsed .rail a.nav { justify-content: flex-start; width: auto; height: auto; margin-inline: 0; padding: 7px 10px; gap: 10px; }
  html.rail-collapsed .rail a.nav .lbl,
  html.rail-collapsed .rail a.nav .count { max-width: 170px; opacity: 1; }
  html.rail-collapsed .rail a.nav .count { margin-left: auto; padding: 1px 7px; }
  html.rail-collapsed .rail .group { height: auto; margin: 16px 10px 6px; overflow: visible; font-size: var(--fs-2xs); background: none; }
  body.nav-open .rail { transform: none; }
  body.nav-open .nav-scrim { display: block; position: fixed; inset: 0; z-index: 80; background: var(--scrim); }

  .page { padding: 18px 16px 24px; }
  .g2 { grid-template-columns: 1fr; }
  .appfoot { padding: 12px 80px 12px 16px; }
}

@media (max-width: 700px) {
  .g4 { grid-template-columns: 1fr; }
}

@media (max-width: 420px) {
  .page { padding: 14px 12px 24px; }
}

/* Back is always blue and top right, in the top bar of every detail page. */
.top-crumbs > .top-back { margin-left: auto; flex-shrink: 0; }
.top-crumbs .pill { flex: none; }
.top-crumbs > .crumb-meta:last-child { color: var(--ink-4); font-weight: 400; }
.top-crumbs > .crumb-current { color: var(--ink); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 700px) { .top-crumbs > .crumb-meta, .top-crumbs > .crumb-meta-sep { display: none; } }

/* Tabs with the page actions on the same row, at the tabs' height. */
.tabrow { display: flex; align-items: stretch; gap: 10px 16px; flex-wrap: wrap; }
.tabrow .subnav { margin: 0; }
.tabrow .right { margin-left: auto; display: flex; align-items: stretch; gap: 8px; flex-wrap: wrap; }
.tabrow .right > form { display: flex; }
.tabrow .right .btn { min-height: 0; }
.tabrow .right .pill { align-self: center; }

/* A list page is one card that fills the page, whether it holds rows or its empty state. */
.page:has(> .card.fill) { display: flex; flex-direction: column; }
.page > .card.fill { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }

/* The wizard steps take the top bar in place of the page title. */
.top-steps { flex: 1; min-width: 0; margin: 0 24px 0 4px; }
.top-steps .srail { margin: 0; padding: 0; }
.top-steps .srail .dot { width: 22px; height: 22px; }
.top-steps .srail .s { gap: 7px; }
.top-steps .srail .bar { margin: 0 10px; }
@media (max-width: 1400px) {
  .top-steps .srail .lbl { display: none; }
  .top-steps .srail .s.now .lbl { display: block; }
}
@media (max-width: 800px) {
  .top-steps { display: none; }
}
