/* Shell: boot, sign-in, sidebar, top bar, banners, page header, footer. Notices are toasts (ui.js). */

/* The only no-JavaScript message. */
.noscript-note { margin: var(--s-6); padding: var(--s-4); border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent); border-radius: var(--r-md); background: var(--danger-soft); color: var(--text); }
@keyframes fade-in { from { opacity: 0; } }

/* ---------- Boot ---------- */
.boot { display: grid; place-content: center; justify-items: center; gap: var(--s-3); min-height: 100vh; padding: var(--s-8); text-align: center; }
.boot h1 { margin-top: var(--s-4); font-size: var(--fs-xl); line-height: var(--lh-xl); }
.boot-message { color: var(--text-2); font-size: var(--fs-sm); }
.boot-mark { position: relative; display: grid; place-items: center; width: 96px; height: 96px; }
.boot-orbit { position: absolute; inset: 0; border: 1.5px solid var(--line); border-top-color: var(--accent); border-radius: var(--r-full); animation: boot-spin 1.1s linear infinite; }
@keyframes boot-spin { to { transform: rotate(1turn); } }
@media (prefers-reduced-motion: reduce) { .boot-orbit { animation: none; border-top-color: var(--line); } }

/* ---------- Sign in ---------- */
.auth-layout { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); min-height: 100vh; }
.auth-intro {
  position: relative;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: var(--s-8);
  padding: clamp(var(--s-8), min(5vw, 6vh), var(--s-16));
  overflow: hidden;
  border-right: 1px solid var(--line-subtle);
  background: var(--surface);
}
.auth-brand { display: flex; align-items: center; gap: var(--s-3); font-size: var(--fs-lg); font-weight: 600; letter-spacing: -0.01em; }
.auth-brand-sub { padding-left: var(--s-3); border-left: 1px solid var(--line); color: var(--text-3); font-size: var(--fs-sm); font-weight: 500; }
.auth-story .eyebrow { margin-bottom: var(--s-4); }
.auth-story h1 { font-size: clamp(2.25rem, 3.6vw, 3.25rem); line-height: 1.06; letter-spacing: -0.035em; }
.auth-story h1 span { color: var(--accent); }
.intro-copy { max-width: 46ch; margin-top: var(--s-5); color: var(--text-2); font-size: var(--fs-lg); line-height: 1.6; }
/* Decorative (aria-hidden): the orbit takes the height the story leaves, 280–400px wide, and hides on short screens. */
.auth-visual { display: grid; justify-items: center; align-items: center; }
.auth-visual > .viz { width: 100%; min-width: 0; max-width: clamp(280px, calc(100vh - 520px), 400px); }
.auth-visual .viz-caption { display: none; }
.auth-visual:empty { display: none; }
.auth-principles { display: grid; gap: var(--s-4); margin: 0; padding: var(--s-6) 0 0; border-top: 1px solid var(--line-subtle); list-style: none; }
.auth-principles li { display: flex; align-items: flex-start; gap: var(--s-3); margin: 0; color: var(--text-2); font-size: var(--fs-sm); line-height: var(--lh-sm); }
.auth-principles strong { color: var(--text); font-weight: 600; }
.auth-principle-icon { display: grid; flex: none; place-items: center; width: 28px; height: 28px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--raised); color: var(--accent); }
@media (max-height: 1060px) { .auth-principles { display: none; } .auth-intro { gap: var(--s-6); } }
@media (max-height: 760px) { .auth-visual { display: none; } }
.auth-panel { display: grid; place-items: center; padding: var(--s-8) var(--s-6); }
.auth-card { width: min(100%, 420px); }
.auth-card h2 { font-size: var(--fs-display); line-height: var(--lh-display); letter-spacing: -0.024em; }
.auth-card > .muted { margin-top: var(--s-2); }
.auth-card form { display: grid; gap: var(--s-1); margin-top: var(--s-6); }
.auth-card .primary.full { margin-top: var(--s-5); }
.auth-switches { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--s-4); margin-top: var(--s-4); }
.security-note { margin-top: var(--s-8); padding-top: var(--s-5); border-top: 1px solid var(--line-subtle); color: var(--text-3); font-size: var(--fs-xs); line-height: var(--lh-xs); }
.auth-included { margin-top: var(--s-3); color: var(--text-2); font-size: var(--fs-sm); line-height: var(--lh-sm); }
.legal-links { display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-4); font-size: var(--fs-xs); }
.legal-links a { color: var(--text-2); text-decoration: underline; text-underline-offset: 2px; }
.legal-links a:hover { color: var(--text); }
.auth-card .legal-links { margin-top: var(--s-4); }

/* ---------- Shell grid ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; transition: grid-template-columns var(--t-short) var(--ease-move); }
.shell.is-collapsed { grid-template-columns: var(--sidebar-collapsed) minmax(0, 1fr); }

/* ---------- Sidebar ---------- */
.shell-sidebar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding: var(--s-4) var(--s-3) var(--s-3);
  overflow: hidden auto;
  border-right: 1px solid var(--line-subtle);
  background: var(--surface);
}
.shell-brand { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); min-height: 40px; padding: 0 var(--s-1) 0 var(--s-2); }
.shell-logo { display: flex; align-items: center; gap: var(--s-3); min-width: 0; color: var(--text); font-size: var(--fs-lg); font-weight: 650; letter-spacing: -0.015em; }
.shell-logo:hover, .shell-logo:visited { color: var(--text); text-decoration: none; }
.shell-logo img { border-radius: var(--r-sm); }

.shell-icon-button {
  display: inline-grid;
  flex: none;
  place-items: center;
  width: 36px;
  height: 36px;
  min-height: 0;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: background var(--t-micro) var(--ease-move), color var(--t-micro) var(--ease-move);
}
.shell-icon-button:hover:not(:disabled) { border-color: transparent; background: var(--neutral-soft); color: var(--text); }
.shell-icon-button:disabled, .shell-icon-button[aria-disabled="true"] { opacity: 0.45; cursor: progress; }
.shell-icon-button.is-spinning svg { animation: boot-spin 0.9s linear infinite; }
@media (prefers-reduced-motion: reduce) { .shell-icon-button.is-spinning svg { animation: none; } }

.shell-business { margin: var(--s-3) 0 var(--s-1); }
.shell-business-button {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  min-height: 48px;
  padding: var(--s-2) var(--s-3) var(--s-2) var(--s-2);
  border: 1px solid var(--line-subtle);
  border-radius: var(--r-md);
  background: var(--raised);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color var(--t-micro) var(--ease-move), background var(--t-micro) var(--ease-move);
}
.shell-business-button:hover { border-color: var(--line-strong); background: var(--raised); }
.shell-business-text { display: grid; flex: 1; min-width: 0; line-height: 1.25; }
.shell-business-name { overflow: hidden; font-size: var(--fs-sm); font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.shell-business-role { color: var(--text-3); font-size: var(--fs-xs); }
.shell-business-button > .icon { color: var(--text-3); }

.shell-nav { display: grid; align-content: start; gap: 0; margin-top: var(--s-2); padding-bottom: var(--s-5); }
.shell-nav-group { display: grid; gap: 1px; }
.shell-nav-group + .shell-nav-group { margin-top: 4px; }
.shell-nav-label { padding: 2px var(--s-3) 0; color: var(--text-3); font-size: var(--fs-xs); font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; }
.shell-nav a, .shell-nav-action, .shell-nav-more > summary, .shell-view-mode {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--s-3);
  min-height: 28px;
  padding: 0 var(--s-2) 0 var(--s-3);
  border-radius: var(--r-sm);
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: 500;
  transition: background var(--t-micro) var(--ease-move), color var(--t-micro) var(--ease-move);
}
.shell-nav a:visited { color: var(--text-2); }
.shell-nav a:hover { background: var(--neutral-soft); color: var(--text); text-decoration: none; }
.shell-nav-action, .shell-view-mode { width: 100%; border: 0; background: transparent; text-align: left; cursor: pointer; }
.shell-nav-action:hover, .shell-nav-more > summary:hover, .shell-view-mode:hover { background: var(--neutral-soft); color: var(--text); }
.shell-view-mode { min-height: 36px; margin-top: var(--s-3); border: 1px solid var(--line); }
.shell-nav-more { margin-top: var(--s-3); padding-top: var(--s-2); border-top: 1px solid var(--line); }
.shell-nav-more > summary { min-height: 36px; list-style: none; cursor: pointer; }
.shell-nav-more > summary::-webkit-details-marker { display: none; }
.shell-nav-more > summary::before { content: none; }
.shell-nav-more > summary > .icon:last-child { transition: transform var(--t-micro) var(--ease-move); }
.shell-nav-more[open] > summary > .icon:last-child { transform: rotate(180deg); }
.shell-nav a .icon { color: var(--text-3); transition: color var(--t-micro) var(--ease-move); }
.shell-nav a:hover .icon { color: var(--text-2); }
.shell-nav a[aria-current="page"] { background: var(--raised); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-subtle); }
.shell-nav a[aria-current="page"] .icon { color: var(--accent); }
.shell-nav a[aria-current="page"]::before { content: ''; position: absolute; top: 9px; bottom: 9px; left: 0; width: 2px; border-radius: var(--r-full); background: var(--accent); }
.shell-nav-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shell-nav-count {
  min-width: 22px;
  padding: 1px var(--s-2);
  border-radius: var(--r-full);
  background: var(--neutral-soft);
  color: var(--text-2);
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 18px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.shell-nav-count:empty { display: none; }
.shell-nav-count.is-attention { background: var(--warn-soft); color: var(--warn); }
/* Plan tag on nav items the current tier cannot edit (same anatomy as the count; letters, not numbers). */
.shell-nav-plan { background: var(--accent-soft); color: var(--accent); font-variant-numeric: normal; letter-spacing: 0.02em; }

/* When the navigation is taller than the viewport, its end fades instead of cutting off mid-row. */
.shell-sidebar { -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 28px), transparent); mask-image: linear-gradient(to bottom, #000 calc(100% - 28px), transparent); }

/* Collapsed rail: icons only, labels on hover through title tooltips. */
.shell.is-collapsed .shell-sidebar { padding-inline: var(--s-3); }
.shell.is-collapsed .shell-brand { flex-direction: column; justify-content: center; gap: var(--s-2); padding: 0; }
.shell.is-collapsed .shell-logo-text,
.shell.is-collapsed .shell-nav-label,
.shell.is-collapsed .shell-nav-text,
.shell.is-collapsed .shell-business-text,
.shell.is-collapsed .shell-business-button > .icon { display: none; }
.shell.is-collapsed .shell-nav a,
.shell.is-collapsed .shell-business-button { justify-content: center; padding: 0; }
.shell.is-collapsed .shell-view-mode, .shell.is-collapsed .shell-nav-action, .shell.is-collapsed .shell-nav-more > summary { justify-content: center; padding-inline: 0; }
.shell.is-collapsed :is(.shell-view-mode, .shell-nav-more > summary) > .icon:last-child { display: none; }
.shell.is-collapsed .shell-business-button { min-height: 48px; }
.shell.is-collapsed .shell-nav-group + .shell-nav-group { margin-top: var(--s-2); padding-top: var(--s-2); border-top: 1px solid var(--line-subtle); }
.shell.is-collapsed .shell-nav-count { position: absolute; top: 1px; right: 3px; min-width: 16px; padding: 0 4px; font-size: var(--fs-xs); line-height: 16px; }
.shell.is-collapsed .shell-nav-count:not(.is-attention) { display: none; }

/* ---------- Main column ---------- */
.shell-main { display: flex; flex-direction: column; min-width: 0; }
.shell-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2) var(--s-4);
  padding: var(--s-2) var(--gutter);
  border-bottom: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
  background: var(--warn-soft);
  color: var(--text);
  font-size: var(--fs-sm);
  overflow-wrap: anywhere;
}
.shell-banner-info { border-bottom-color: color-mix(in srgb, var(--info) 30%, transparent); background: var(--info-soft); }
/* Trial and trial-ended notices: quiet, in the neutral surface rather than a warning tint. */
.shell-banner-plan { border-bottom-color: var(--line-subtle); background: var(--raised); color: var(--text-2); }
.shell-banner-plan .icon { color: var(--accent); }
.shell-banner-plan a { color: var(--text); text-decoration: underline; text-underline-offset: 2px; }
.shell-banner-plan > span { flex: 1 1 12ch; min-width: 0; }
.shell-banner-plan button { margin-left: auto; }
.shell-banner button { min-height: 32px; padding: var(--s-1) var(--s-3); font-size: var(--fs-sm); }
.shell-banner-short { display: none; }
@media (max-width: 639px) { .shell-banner-long { display: none; } .shell-banner-short { display: inline; } }
/* Emergency Stop: the governance banner as a full-width strip above the top bar, on every page while engaged. */
.shell-halt .gov-banner { padding: var(--s-3) var(--gutter); border-width: 0 0 1px; border-radius: 0; }

.shell-topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  display: flex;
  align-items: center;
  gap: var(--s-3);
  min-height: var(--topbar);
  padding: calc(var(--s-3) + var(--safe-top)) var(--gutter);
  border-bottom: 1px solid var(--line-subtle);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
}
.shell-nav-toggle { display: none; }
.shell-search {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  width: min(380px, 100%);
  min-height: 36px;
  padding: 0 var(--s-2) 0 var(--s-3);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text-3);
  font: inherit;
  font-size: var(--fs-sm);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--t-micro) var(--ease-move), color var(--t-micro) var(--ease-move);
}
.shell-search:hover { border-color: var(--line-strong); color: var(--text-2); }
.shell-search-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shell-kbd { flex: none; }
.shell-topbar-end { display: flex; align-items: center; gap: var(--s-2); margin-left: auto; }
.shell-status { display: flex; align-items: center; gap: var(--s-2); margin: 0 var(--s-2) 0 0; color: var(--text-3); font-size: var(--fs-xs); white-space: nowrap; }
.live-dot { position: relative; flex: none; width: 8px; height: 8px; border-radius: var(--r-full); background: var(--text-3); }
.live-dot.is-live { background: var(--ok); }
.live-dot.is-live::after { content: ''; position: absolute; inset: -3px; border-radius: var(--r-full); background: var(--ok); opacity: 0.35; animation: live-pulse 2.4s var(--ease-move) infinite; }
.live-dot.is-retrying { background: var(--warn); }
@keyframes live-pulse { 0% { transform: scale(0.6); opacity: 0.45; } 70%, 100% { transform: scale(1.8); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .live-dot.is-live::after { animation: none; opacity: 0; } }
/* The status text changes as the stream connects, drops and recovers. Above 900px the longest label reserves its
   own width, so the refresh button and account menu never slide sideways on a change. Below 900px the mobile rule
   visually hides the text, leaving only the dot, so a 320px screen gains no width and never wraps. */
@media (min-width: 900px) {
  .shell-status { min-width: 36ch; }
}
.shell-account {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  max-width: 280px;
  min-height: 36px;
  padding: 0 var(--s-2) 0 var(--s-1);
  border: 1px solid transparent;
  border-radius: var(--r-full);
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: var(--fs-sm);
  cursor: pointer;
}
.shell-account:hover, .shell-account[aria-expanded="true"] { border-color: var(--line); background: var(--surface); color: var(--text); }
.shell-account-avatar { display: grid; flex: none; place-items: center; }
.shell-account-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.operation-controls { min-width: 0; margin: 0; padding: 0; border: 0; }
main { flex: 1; width: 100%; max-width: var(--content-max); margin-inline: auto; padding: var(--s-8) var(--gutter) var(--s-16); }
main:focus { outline: none; }
.page-heading { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s-4) var(--s-6); margin-bottom: var(--s-8); }
.page-heading > div:first-child { min-width: min(100%, 320px); max-width: 76ch; }
.page-heading .eyebrow { margin-bottom: var(--s-2); }
.page-heading h1 { overflow-wrap: anywhere; }
.page-heading p.muted { margin-top: var(--s-2); color: var(--text-2); font-size: var(--fs-md); }
.page-heading > :not(:first-child) { display: flex; flex-wrap: wrap; gap: var(--s-2); }
#content { display: grid; gap: var(--s-8); align-content: start; }
#content > * { min-width: 0; margin-top: 0; margin-bottom: 0; }

.shell-footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--s-2) var(--s-5); padding: var(--s-4) var(--gutter); border-top: 1px solid var(--line-subtle); color: var(--text-3); font-size: var(--fs-xs); }

.shell-scrim { position: fixed; inset: 0; z-index: calc(var(--z-overlay) - 1); background: var(--scrim); animation: fade-in var(--t-short) var(--ease-enter); }

/* ---------- Responsive ---------- */
@media (max-width: 1199px) {
  .shell { grid-template-columns: var(--sidebar-collapsed) minmax(0, 1fr); }
  .shell-account-email { display: none; }
}
@media (max-width: 1199px) and (min-width: 900px) {
  .shell:not(.is-expanded) .shell-sidebar { padding-inline: var(--s-3); }
  .shell:not(.is-expanded) .shell-brand { flex-direction: column; justify-content: center; gap: var(--s-2); padding: 0; }
  .shell:not(.is-expanded) .shell-logo-text,
  .shell:not(.is-expanded) .shell-nav-label,
  .shell:not(.is-expanded) .shell-nav-text,
  .shell:not(.is-expanded) .shell-business-text,
  .shell:not(.is-expanded) .shell-business-button > .icon { display: none; }
  .shell:not(.is-expanded) .shell-nav a,
  .shell:not(.is-expanded) .shell-business-button { justify-content: center; padding: 0; }
  .shell:not(.is-expanded) :is(.shell-view-mode, .shell-nav-action, .shell-nav-more > summary) { justify-content: center; padding-inline: 0; }
  .shell:not(.is-expanded) :is(.shell-view-mode, .shell-nav-more > summary) > .icon:last-child { display: none; }
  .shell:not(.is-expanded) .shell-nav-count { position: absolute; top: 1px; right: 3px; min-width: 16px; padding: 0 4px; font-size: var(--fs-xs); line-height: 16px; }
  .shell:not(.is-expanded) .shell-nav-count:not(.is-attention) { display: none; }
  .shell:not(.is-expanded) .shell-collapse { display: none; }
}
@media (max-width: 899px) {
  .shell { display: block; }
  .shell-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: var(--z-overlay);
    width: min(300px, 86vw);
    box-shadow: var(--shadow-overlay);
    transform: translateX(-104%);
    transition: transform var(--t-short) var(--ease-enter);
  }
  .shell.is-nav-open .shell-sidebar { transform: none; }
  .shell-collapse { display: none; }
  .shell-nav-toggle { display: inline-grid; }
  .shell-status span:last-child { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .shell-search { width: auto; flex: 1 1 0; min-width: 0; min-height: 40px; }
  /* The off-canvas drawer is touch-first whatever the pointer; the 28px density is for the desktop sidebar. */
  .shell-nav a { min-height: 40px; }
  .shell-view-mode, .shell-nav-action, .shell-nav-more > summary { min-height: 44px; }
  .shell-kbd { display: none; }
  main { padding-top: var(--s-6); }
  .page-heading { align-items: flex-start; margin-bottom: var(--s-6); }
  .auth-layout { grid-template-columns: 1fr; }
  .auth-intro { gap: var(--s-6); border-right: 0; border-bottom: 1px solid var(--line-subtle); }
  .auth-visual { display: none; }
}
@media (max-width: 639px) {
  /* Only a primary create action goes full width; secondary utilities (headingAction) keep their compact size. */
  .page-heading > .primary, .page-heading > a.button.primary { width: 100%; }
  .auth-principles { display: none; }
  .shell-footer { flex-direction: column; }
}

/* Coarse pointers: topbar controls reach 44px targets. */
@media (pointer: coarse) {
  .shell-icon-button { width: 44px; height: 44px; }
  .shell-search, .shell-account, .shell-nav a, .shell-view-mode, .shell-nav-action, .shell-nav-more > summary { min-height: 44px; }
}
@media (max-width: 359px) {
  .shell-search-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}

/* Touch targets the shell owns: the logo link and the banner button were measured under 44px on a coarse pointer. */
@media (pointer: coarse) {
  .shell-logo { min-height: 44px; }
  .shell-banner button { min-height: 44px; }
}

@media print {
  .shell { display: block; }
  .shell-sidebar, .shell-topbar, .shell-footer, .shell-banner, .ui-toasts { display: none !important; }
  main { max-width: none; padding: 0; }
}
