/* The shell's own layout (openspec change design-system-and-shell, design D8): only what the carried components
   lack. Design tokens only; no colour or font literal. */

/* The module list sits in a <nav> landmark inside the sidebar: the landmark takes the list's place in the sidebar's
   column, so the list still fills it and scrolls, and the foot stays at the bottom. */
.nav > nav { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* The development identity banner sits under the top bar, inside the page's gutter. */
.main > .banner { margin: 12px var(--gutter) 0; }

/* The Not found page's Go to Home link sits apart from the page header. */
#view .page-header + p { margin-top: 16px; }

/* ----------------------------------------------------------------- Home --- */
/* Home (openspec change home, design D11): a grid of 4 equal columns filled row by row in the saved order, one row
   height and one gap from the tokens. Spans: S 1×1, M 2×1, L 2×2, XL 4×2. The row height comes from the spacing
   token --gutter × 6 (144px, 192px from 1600px wide), never --stick, which the page rewrites at runtime. */
.home-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-flow: row;
  grid-auto-rows: calc(var(--gutter) * 6);
  gap: calc(var(--gutter) / 2);
}
.home-tile { display: flex; flex-direction: column; gap: 8px; min-width: 0; min-height: 0; overflow: hidden; }
.home-tile[hidden] { display: none; }
.home-tile[data-size="S"] { grid-column: span 1; grid-row: span 1; }
.home-tile[data-size="M"] { grid-column: span 2; grid-row: span 1; }
.home-tile[data-size="L"] { grid-column: span 2; grid-row: span 2; }
.home-tile[data-size="XL"] { grid-column: span 4; grid-row: span 2; }
.home-tile-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.home-tile-title { font-size: 14px; margin: 0; min-width: 0; flex: 1; }
.home-tile-body { flex: 1; min-height: 0; overflow: auto; }

/* The Customise controls sit in the tile's header: move up and down, one button per size, and hide. */
.home-tile-controls { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.home-tile-controls .btn { min-width: 26px; justify-content: center; }
.home-tile-controls .btn[aria-pressed="true"] { background: var(--accent-wash); color: var(--accent-strong); border-color: var(--accent); }

/* A refusal banner holds its message and, for the stale-tab refusal, the Reload button. */
.home-banner { align-items: center; }
.home-banner > span { flex: 1; }

/* Add a panel: the draft's addable tiles, each with its description and an Add button. */
.home-add-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.home-add-list > li { display: flex; align-items: flex-start; gap: 12px; }
.home-add-text { flex: 1; min-width: 0; }
.home-add-text p { margin: 2px 0 0; }

/* Recently viewed: the label, then the module name in a small muted line. */
.home-recent { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.home-recent > li { display: flex; flex-direction: column; min-width: 0; }
.home-recent-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Below 720 px wide the grid is one column: every tile spans it, at its own height. */
@media (max-width: 719.98px) {
  .home-grid { grid-template-columns: minmax(0, 1fr); grid-auto-rows: auto; }
  .home-tile[data-size] { grid-column: span 1; grid-row: auto; }
}

/* ------------------------------------------------------------- Programs --- */
/* The Programs screens (openspec change programs-screens, design D11): the carried .programs-* classes, .pill, .chip,
   .banner, .form-field, .meter and .table-wrap draw them; these rules add only what those lack. */
.programs-page { display: flex; flex-direction: column; }
.programs-page > .page-header { margin-bottom: 0; }
.programs-back { margin: 0; }
.programs-list { display: flex; flex-direction: column; gap: 12px; }
.programs-banner { align-items: center; }
.programs-banner > span { flex: 1; }
.programs-more { margin: 0; display: flex; justify-content: center; }

/* The tags cell holds its chips; the action cell its action and, for an administrator, Copy. */
.programs-action-cell { white-space: nowrap; }
.programs-action-cell > * + * { margin-left: 8px; }

/* Request to join opens its form in a full-width row under the program's row. */
table.data.programs-table td[colspan] { height: auto; max-width: none; white-space: normal; padding: 12px; background: var(--surface-2); }
.programs-join-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.programs-join-form .form-field { margin-bottom: 0; min-width: 0; }
.programs-join-form .form-field:nth-child(2) { flex: 1 1 280px; }

/* New program and Copy: the form, its fieldsets (Visibility, Tags, Members) and the errors under the fields. */
.programs-form { max-width: 560px; }
.programs-fieldset { border: 0; margin: 0 0 16px; padding: 0; min-width: 0; }
.programs-fieldset > legend {
  padding: 0; margin-bottom: 6px; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-3);
}
.programs-choice { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 8px; }
.programs-choice > input { margin: 3px 0 0; accent-color: var(--accent-strong); }
.programs-fieldset .programs-choice label {
  display: flex; flex-direction: column; gap: 2px; margin: 0; font-size: 13px; font-weight: 400; letter-spacing: normal;
  text-transform: none; color: var(--text-1);
}
.programs-member { align-items: center; }
.programs-member > label { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.programs-fieldset .programs-member > select {
  flex: none; width: auto; height: 30px; padding: 0 8px; border: 1px solid var(--line-control); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text-1); font: inherit; font-size: 12px;
}
.programs-field-error { margin: 4px 0 0; font-size: 12px; color: var(--red-text); }
.programs-form-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.programs-form > .banner { margin-bottom: 16px; }

/* The copy job's progress meter fills with the accent. */
.programs-page .meter .bar > span { background: var(--accent); }

/* Below 720 px wide each row of the Programs table is a card: the header row hidden, each cell on its own line; the
   filters wrap (the filter bar wraps at any width) and the search box takes the bar's width. */
@media (max-width: 719.98px) {
  .programs-table-wrap { overflow-x: visible; }
  table.data.programs-table, table.data.programs-table tbody { display: block; width: 100%; }
  table.data.programs-table thead { display: none; }
  table.data.programs-table tbody tr { display: block; padding: 10px 12px; border-bottom: 1px solid var(--line); }
  table.data.programs-table tbody tr:last-child { border-bottom: 0; }
  table.data.programs-table td, table.data.programs-table td:first-child {
    display: block; width: auto; height: auto; max-width: none; padding: 2px 0; border: 0; white-space: normal;
    overflow: visible; text-align: left;
  }
  table.data.programs-table td.programs-action-cell { white-space: normal; }
  .programs-filters input[type="search"] { flex: 1 1 100%; max-width: none; min-width: 0; }
}

/* ------------------------------------------------------------ Module UIs --- */
/* module-ui-pages D6: the organisation entries and, inside a program, its navigation scroll together in the <nav>. */
.nav > nav { overflow-y: auto; }
.nav > nav > .nav-list { flex: none; overflow-y: visible; }
.shell-program-nav { border-top: 1px solid var(--nav-2); padding-top: 8px; }
.shell-program-nav[hidden] { display: none; }

/* D8, D12: a module page while its code loads, and the unavailable panel's buttons. */
.module-loading { margin: 16px 0 0; }
.module-unavailable .empty-actions { display: flex; gap: 8px; justify-content: center; }

/* D13: the toast stack is a manual popover; the browser's popover box is undone so .toast-host places it. */
.shell-toasts[popover] {
  inset: auto; left: 50%; bottom: 24px; margin: 0; padding: 0; border: 0; background: transparent; color: inherit;
  overflow: visible;
}
.shell-toasts:not(:popover-open) { display: none; }
.shell-toast > svg { flex: none; }

/* module-ui-tiles-and-versions D7: the reload banner sits under the top bar like the development banner. */
.main > .shell-version-banner { align-items: center; }
.shell-version-banner > span { flex: 1; }

/* module-ui-pdf-viewer D6: the PDF viewer, a large dialog.modal in the top layer. */
dialog.modal.shell-pdf-viewer { width: min(1100px, calc(100vw - 32px)); height: calc(100vh - 96px); max-width: none; }
.shell-pdf-head { align-items: center; flex-wrap: wrap; }
.shell-pdf-title { flex: 1; min-width: 0; margin: 0; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shell-pdf-tools { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.shell-pdf-body {
  flex: 1; min-height: 0; overflow: auto; scrollbar-gutter: stable; padding: 16px; background: var(--surface-2);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.shell-pdf-canvas { display: block; box-shadow: var(--shadow); }
.shell-pdf-message { margin: auto 0 0; max-width: 420px; text-align: center; color: var(--text-2); }
.shell-pdf-message + .empty-actions { display: flex; gap: 8px; margin-bottom: auto; }

/* Sign-in (openspec change shell-sign-in, design D3): one column, centred in the content area. */
.sign-in { max-width: 420px; margin: 48px auto 0; }
.sign-in-card { display: flex; flex-direction: column; gap: 16px; }
.sign-in-form .form-field:last-of-type { margin-bottom: 0; }
.sign-in-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 16px; }
.sign-in-field-error { margin: 4px 0 0; font-size: 12px; color: var(--red-text); }
.sign-in-qr { margin: 0; display: flex; justify-content: center; }
.sign-in-qr img { width: 200px; height: 200px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.sign-in-secret { font-family: var(--mono); font-size: 14px; letter-spacing: 0.05em; overflow-wrap: anywhere; user-select: all; }
.sign-in-codes { margin: 0; padding-left: 24px; columns: 2; column-gap: 32px; font-family: var(--mono); font-size: 14px; }
.sign-in-codes li { padding: 2px 0; }
.sign-in-check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-1); }
/* Single sign-on (openspec change shell-single-sign-on, design D3). */
.sign-in-sources { display: flex; flex-direction: column; gap: 8px; }
.sign-in-source { width: 100%; justify-content: center; }
.sign-in-divider { display: flex; align-items: center; gap: 12px; margin: 0 0 12px; font-size: 12px; color: var(--text-2); }
.sign-in-divider::before, .sign-in-divider::after { content: ''; flex: 1; border-top: 1px solid var(--line); }
.sign-in-reference { margin: -8px 0 0; font-family: var(--mono); overflow-wrap: anywhere; }
@media (max-width: 479.98px) { .sign-in { margin-top: 16px; } .sign-in-codes { columns: 1; } }
/* At phone width, while a sign-in screen shows, the sidebar (empty when signed out) becomes a 56 px rail keeping only
   the theme button, the QR code scales down (keeping its square) and the top bar's title ends in an ellipsis. */
@media (max-width: 479.98px) {
  #app:has(.sign-in) > .nav { width: 56px; flex-basis: 56px; }
  #app:has(.sign-in) > .nav .nav-brand { display: none; }
  .sign-in-qr img { width: 100%; max-width: 200px; height: auto; aspect-ratio: 1; }
  .main:has(.sign-in) .topbar-where { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
}

/* Person menu and two-factor settings (openspec change shell-two-factor-settings, design D3). */
.shell-person { position: relative; min-width: 0; }
.shell-person-button { max-width: 240px; }
.shell-person-button [data-shell-user] { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shell-person-button:disabled { opacity: 1; cursor: default; }
.shell-person-menu { position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; min-width: 200px; display: flex; flex-direction: column; gap: 2px; padding: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow); }
.shell-person-menu[hidden] { display: none; }
/* The menu's z-index only counts inside the top bar's stacking context (sticky, z-index 40), which sits under the
   sidebar's (sticky, z-index 45): while the menu is open the top bar is lifted above the sidebar (still under the row
   menus at 55, the scrims at 60 and the toasts at 80), so a narrow column's menu never slides under the sidebar. */
.topbar:has(> .shell-person > .shell-person-menu:not([hidden])) { z-index: 46; }
.shell-person-item { display: block; width: 100%; padding: 8px 12px; border: 0; border-radius: var(--radius-xs); background: none; color: var(--text-1); font: inherit; font-size: 13px; text-align: left; cursor: pointer; }
.shell-person-item:hover, .shell-person-item:focus-visible { background: var(--surface-2); outline: none; box-shadow: inset 0 0 0 2px var(--focus); }
.shell-person-item:disabled { color: var(--text-3); cursor: default; }
.two-factor { max-width: 560px; }
.two-factor-card { display: flex; flex-direction: column; gap: 16px; }
.two-factor-state { display: flex; align-items: center; gap: 8px; margin: 0; }
.two-factor-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.sign-in-card [data-sign-in-link-account], .two-factor-card p { overflow-wrap: anywhere; }
@media (max-width: 479.98px) { .shell-person-button { max-width: 140px; } .two-factor-actions .btn { width: 100%; justify-content: center; } }
/* At phone width the signed-in column is narrow (the sidebar keeps its width): the top bar's title gives way, ending in
   an ellipsis, so the name button stays whole, and a long word in a two-factor title wraps, so the page never scrolls
   sideways (design D12 M13). */
@media (max-width: 479.98px) {
  .shell-person { flex: none; }
  .topbar-where { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .two-factor-card .page-title { overflow-wrap: anywhere; }
}
