/*
 * Reusable pieces: buttons, form controls, tabs, chips, badges/pills,
 * small status/text treatments, and the LorenzoScript editor and rendered
 * text (.ls-editor, .ls-content; ADR 0106) - the generic subset curated from
 * apps/inventory-web's and apps/account-hub's own components.css.
 * Anything domain-specific (item cards, board columns, catalog rows,
 * tenant cards) stays local to the app that needs it, not here - see
 * ADR 0098 and docs/guides/adding-a-package.md's "don't generalize before
 * a second consumer needs it" rule.
 *
 * Uses the semantic tokens from tokens.css (identity.md §6.6) throughout -
 * never a --brand- or --utility- primitive directly.
 */

a .brand,
a.brand,
.brand a {
  color: inherit;
  text-decoration: inherit;
}

/* Sized relative to the surrounding text so an icon sits correctly next to
   a label at any font-size, and nudged to align with the text baseline
   (identity.md §17.3/§15.6 - see icons.svg/icons.manifest.yaml). */
.icon {
  width: 1em;
  height: 1em;
  display: inline-block;
  vertical-align: -0.125em;
}

.icon.big {
  flex: none;
  width: 2em;
  height: 2em;
}

/* A generic bordered, rounded surface - the base every more specific card
   (a tenant card, an item card, a preview swatch) is built from
   (identity.md §8.2's "clean information records"). Deliberately unpadded
   - some cards want edge-to-edge media (a swatch color, an image) with
   only a caption padded; add .card-body for a simple fully-padded card. */
.card {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  background: var(--surface-default);
  overflow: hidden;
}

.card-body {
  padding: var(--space-4);
}

/* .card used directly on an <a> (a whole card is the click target) - reset
   the base link color/decoration so it reads as a card first, not as blue
   underlined link text that happens to contain a heading. */
a.card {
  display: block;
  color: inherit;
  text-decoration: none;
}

/* A bare, unclassed <button> still gets a sensible default (identity.md
   §17's "buttons are their own layer" - never plain --action) - add
   .btn-secondary/.btn-danger explicitly to opt out of this default. */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 500;
  background: var(--button-primary-bg);
  color: var(--button-primary-fg);
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
}

button:hover {
  background: var(--button-primary-hover);
}

button:disabled {
  opacity: 0.6;
  cursor: default;
}

/* .btn on an <a> gets the same visual language as a <button> - anchors
   don't inherit the `button` element rule above. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  min-height: var(--hit, 36px);
  padding: 0 var(--space-3);
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease);
}

.btn-primary,
.btn.btn-primary {
  background: var(--button-primary-bg);
  color: var(--button-primary-fg);
}

.btn-primary:hover {
  background: var(--button-primary-hover);
}

.btn-secondary {
  background: var(--button-secondary-bg);
  color: var(--button-secondary-fg);
  border-color: var(--button-secondary-border);
}

.btn-secondary:hover {
  background: var(--fill-soft);
}

.btn-danger {
  background: var(--button-danger-bg);
  color: var(--button-danger-fg);
}

.btn-danger:hover {
  opacity: 0.9;
}

/* Form controls */
.text-input {
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--surface-default);
  border: 1px solid var(--border-control);
  border-radius: var(--radius-control);
  min-height: var(--hit, 36px);
  padding: var(--space-1) var(--space-2h);
  width: 100%;
  transition: border-color var(--dur-fast) var(--ease);
}

textarea.text-input {
  padding-block: var(--space-2);
}

.text-input:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.field-label {
  font-size: 13px;
  color: var(--text-secondary);
}

/* A single-line create/invite form (text input + submit + status). */
.inline-form {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* A toolbar icon button: no edge (the icon is the affordance), as tall as a control. */
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: var(--hit, 36px);
  height: var(--hit, 36px);
  padding: 0 var(--space-2);
  border: 0;
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--fs-meta);
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease);
}

.icon-button:hover {
  background: var(--fill-soft);
}

.icon-button .icon {
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
}

/* A key, as it is written in a hint. */
kbd {
  display: inline-block;
  padding: 0 6px;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  background: var(--fill-soft);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: var(--fs-code);
  line-height: 1.5;
}

/* A segmented control: a few mutually exclusive choices in one edge. Buttons with
   aria-pressed (a toggle each) or role="radio" with aria-checked. */
.segmented-control {
  display: inline-flex;
  border: 1px solid var(--border-control);
  border-radius: var(--radius-control);
  overflow: hidden;
}

.segmented-control > button {
  font-family: var(--font-ui);
  font-size: var(--fs-meta);
  min-height: calc(var(--hit, 36px) - 2px);
  padding: 0 var(--space-3);
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease);
}

.segmented-control > button:hover {
  background: var(--fill-soft);
}

.segmented-control > button + button {
  border-inline-start: 1px solid var(--border-control);
}

.segmented-control > button[aria-pressed="true"],
.segmented-control > button[aria-checked="true"] {
  background: var(--surface-selected);
  color: var(--text-primary);
  font-weight: 500;
}

.segmented-control > button:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: -2px;
}

@media (max-width: 720px), (pointer: coarse) {
  .segmented-control > button {
    min-height: var(--target-min);
  }
}

/* Tabs */
.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--border-subtle);
}

/* A row of tabs that does not fit a phone wraps onto a second line instead of running off the
   screen (identity.md 8.5). */
@media (max-width: 720px) {
  .tabs {
    flex-wrap: wrap;
  }
}

.tab {
  font-family: var(--font-ui);
  font-size: 14px;
  background: none;
  color: var(--text-secondary);
  border: none;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
}

.tab:hover {
  color: var(--text-primary);
}

.tab[aria-selected="true"],
.tab[aria-current="page"] {
  color: var(--text-primary);
  font-weight: 600;
  border-bottom-color: var(--action);
}

/* Chips - removable multi-select tags */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  background: var(--fill-soft);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  padding: var(--space-1) var(--space-2);
  font-size: 13px;
}

/* A chip reads the same whether or not it links somewhere: the link takes the chip's own
   colour and no underline, and only underlines once the pointer is on it. */
.chip a {
  color: inherit;
  text-decoration: none;
}

.chip a:hover {
  color: inherit;
  text-decoration: underline;
}

.chip-remove {
  background: none;
  border: none;
  color: var(--text-tertiary);
  padding: 0;
  width: 16px;
  height: 16px;
  line-height: 1;
  border-radius: 50%;
  cursor: pointer;
}

.chip-remove:hover {
  background: var(--border-subtle);
}

/* Combobox - a text field with a list of suggestions under it. The list is an elevated surface
   like a dialog, so it gets the border and the shadow both. */
.combobox {
  position: relative;
}

.combobox-suggestions {
  position: absolute;
  inset-block-start: calc(100% + var(--space-1));
  inset-inline: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  max-height: 240px;
  overflow-y: auto;
  margin: 0;
  padding: 0;
  list-style: none;
  background: var(--surface-default);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-control);
  box-shadow: 0 8px 24px color-mix(in srgb, var(--brand-ink) 20%, transparent);
}

.combobox-suggestion button {
  display: block;
  width: 100%;
  background: none;
  color: var(--text-primary);
  text-align: left;
  font-size: 14px;
  border-radius: 0;
  padding: var(--space-2) var(--space-3);
}

.combobox-suggestion button:hover {
  background: var(--fill-soft);
}

/* A labeled color preview chip - e.g. showing what a design token or a
   user's chosen accent color actually looks like. Built on .card; the
   color itself is necessarily an inline style (there's no class for "some
   arbitrary token's current value"). */
.swatch-color {
  height: 56px;
}

.swatch-label {
  display: block;
  padding: var(--space-2);
  font-family: var(--font-mono);
  font-size: 12px;
}

/* A small, uppercase role/kind tag next to a name - non-interactive. */
.badge {
  display: inline-block;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--text-tertiary);
  background: var(--fill-soft);
  border-radius: var(--radius-pill);
  padding: 2px var(--space-2);
}

/* Status pills - success/warning/danger only (§6.6); canonical and
   restricted-visibility get their own, differently-shaped treatments
   below, since neither is a "status." */
.pill {
  display: inline-flex;
  align-items: center;
  font-size: 13px;
  font-weight: 500;
  padding: 4px var(--space-2);
  border-radius: var(--radius-pill);
}

.pill-success {
  background: var(--success-surface);
  color: var(--success);
}

.pill-warning {
  background: var(--warning-surface);
  color: var(--warning);
}

.pill-danger {
  background: var(--danger-surface);
  color: var(--danger);
}

/* Restricted visibility - one neutral treatment for every non-public
   tier (private, GM-only, a selected group); only the icon/label
   differs. Public gets no badge at all - see identity.md §6.6/§18. */
.badge-visibility {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  padding: 4px var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--visibility-restricted-surface);
  color: var(--visibility-restricted-text);
  border: 1px solid var(--visibility-restricted-border);
}

/* An unread count or similar "needs attention" marker - gold, per
   identity.md §1.4's "gold is punctuation": marks significance, not a
   permanent surface treatment. */
.canonical-marker:not(h1, h2, h3, h4, h5) {
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  color: var(--canonical);
}

h1.canonical-marker,
h2.canonical-marker,
h3.canonical-marker,
h4.canonical-marker,
h5.canonical-marker {
  color: var(--canonical);
}

h1 a,
h2 a,
h3 a,
h4 a,
h5 a {
  color: inherit;
  text-decoration: inherit;
}

/* A bordered list of records with inline actions (characters, beings,
   members) - identity.md §8.2's "clean information records." */
.list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.list > li {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  background: var(--surface-default);
}

/* Small, muted status/progress text next to a button or form -
   "Saving…", an inline error, or nothing at all. */
.status-text {
  font-size: 13px;
  color: var(--text-secondary);
}

.error-text {
  color: var(--danger);
}

/* A page or section's own intro paragraph - muted, and capped to a
   comfortable reading width regardless of its container. */
.lede {
  color: var(--text-secondary);
  max-width: 60ch;
}

pre {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--fill-soft);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  padding: var(--space-3);
  overflow-x: auto;
}

/* Dialogs - a bare <dialog> gets a sensible default with no class needed.
   Both a border and a shadow here, not just the shadow §8.2's binary
   policy would otherwise suggest for an elevated surface: a non-modal
   <dialog> (opened via show(), not showModal()) never gets a ::backdrop
   at all - that's a platform behavior, not something this stylesheet
   controls - so unlike a modal one, it has nothing else separating it
   from whatever happens to be behind it. */
dialog {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-surface);
  padding: var(--space-4);
  background: var(--surface-canvas);
  color: var(--text-primary);
  max-width: min(480px, 92vw);
  box-shadow: 0 18px 48px rgb(0 0 0 / 0.28);
}

/* Only a modal dialog (showModal()) ever gets this: a plain scrim, with no blur, so the page
   behind stays legible (docs/design/web, D25). */
dialog::backdrop {
  background: rgb(0 0 0 / 0.42);
}

/* A dialog fades in. It does not move, so its box is its final box the moment it opens; and it
   closes at once, so nothing is left on the page that a script or a test could still reach.
   Reduced motion removes the fade (motion.css). */
@keyframes brand-dialog-in {
  from {
    opacity: 0;
  }
}

dialog[open] {
  animation: brand-dialog-in var(--dur-med) var(--ease);
}

dialog[open]::backdrop {
  animation: brand-dialog-in var(--dur-med) var(--ease);
}

dialog h2,
dialog h3 {
  font-size: var(--fs-heading);
  font-weight: 600;
  line-height: 1.3;
  margin: 0 0 var(--space-2);
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.sheet-grip {
  display: none;
  width: 36px;
  height: 4px;
  margin: 0 auto var(--space-3);
  border-radius: 2px;
  background: var(--border-control);
}

/* A phone: a dialog is a bottom sheet (identity.md 8.6), full width with a grip, clear of the
   safe area, with stacked full-width actions. */
@media (max-width: 720px) {
  dialog {
    width: 100%;
    max-width: none;
    max-height: 86dvh;
    margin: auto 0 0;
    border-width: 1px 0 0;
    border-radius: var(--radius-surface) var(--radius-surface) 0 0;
    padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
    overflow: auto;
  }

  dialog .sheet-grip {
    display: block;
  }

  .dialog-actions {
    flex-direction: column-reverse;
  }

  .dialog-actions > .btn,
  .dialog-actions > button {
    width: 100%;
    min-height: var(--target-min);
  }
}

/* A menu: a small surface of commands. Where it sits is the page's job (anchored, or a bottom
   sheet with .as-sheet on a phone); role="menu" with role="menuitem" and arrow keys, or a plain
   list of buttons. */
.menu {
  min-width: 240px;
  max-width: 340px;
  padding: 6px;
  background: var(--surface-canvas);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.22);
}

.menu-head {
  padding: 10px 10px 8px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border-subtle);
}

.menu-label {
  padding: 8px 10px 4px;
  font-size: var(--fs-micro);
  font-weight: 500;
  color: var(--text-tertiary);
}

.menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-2h);
  width: 100%;
  min-height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--fs-ui);
  text-align: start;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease);
}

.menu-item:hover,
.menu-item[data-active] {
  background: var(--surface-selected);
}

.menu-item:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: -2px;
}

.menu-item .grow {
  flex: 1;
}

.menu-item.danger {
  color: var(--danger);
}

.menu-item[aria-checked="true"] {
  font-weight: 500;
}

.menu-sep {
  margin: 6px 0;
  border-top: 1px solid var(--border-subtle);
}

@media (max-width: 720px) {
  .menu.as-sheet {
    position: fixed;
    inset: auto 0 0;
    max-width: none;
    border-width: 1px 0 0;
    border-radius: var(--radius-surface) var(--radius-surface) 0 0;
    padding: var(--space-3) var(--space-3)
      calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
  }

  .menu.as-sheet .menu-item {
    min-height: 48px;
  }
}

/* Toasts: a fixed region (role="status", aria-live="polite") holding a stack of messages. A
   message with a timer shows .toast-bar draining over --toast-ms; an error has no timer and
   stays until it is closed (identity.md 15.7). Focus inside a toast pauses the timer. */
.toast-region {
  position: fixed;
  z-index: 60;
  inset-inline: 0;
  bottom: var(--space-4);
  margin-inline: auto;
  width: min(380px, calc(100% - 24px));
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}

.toast-card {
  position: relative;
  overflow: hidden;
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: var(--space-2h);
  padding: var(--space-2h) var(--space-3);
  background: var(--surface-canvas);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.2);
  font-size: var(--fs-ui);
  animation: brand-toast-in var(--dur-med) var(--ease) both;
}

.toast-card.out {
  animation: brand-toast-out var(--dur-med) var(--ease) both;
}

.toast-card[data-kind="error"] {
  border-color: var(--danger);
}

.toast-card .toast-text {
  flex: 1;
  min-width: 0;
}

.toast-card .toast-title {
  font-weight: 500;
}

.toast-card .icon {
  margin-top: 2px;
}

.toast-card[data-kind="ok"] .icon {
  color: var(--success);
}

.toast-card[data-kind="error"] .icon {
  color: var(--danger);
}

.toast-bar {
  position: absolute;
  inset: auto 0 0 0;
  height: 3px;
  background: var(--border-control);
  transform-origin: left;
  animation: brand-toast-timer var(--toast-ms, 6000ms) linear forwards;
}

.toast-card[data-kind="error"] .toast-bar {
  display: none;
}

.toast-card:focus-within .toast-bar {
  animation-play-state: paused;
}

@keyframes brand-toast-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
}

@keyframes brand-toast-out {
  to {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

@keyframes brand-toast-timer {
  to {
    transform: scaleX(0);
  }
}

@media (max-width: 720px) {
  .toast-region {
    bottom: calc(var(--space-6) + env(safe-area-inset-bottom, 0px));
  }
}

/* Tree view - nested <details>/<summary>, native disclosure semantics
   (keyboard-operable, no JS required for expand/collapse). */
.tree,
.tree ul {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  list-style: none;
  margin: 0;
  padding: 0;
}

.tree ul {
  padding-inline-start: var(--space-4);
  margin-top: var(--space-1);
}

.tree summary {
  cursor: pointer;
  border-radius: var(--radius-control);
}

.tree summary,
.tree li:not(:has(summary)) {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
}

.tree summary::-webkit-details-marker {
  display: none;
}

.tree summary::marker {
  content: "";
}

.tree summary:hover {
  background: var(--fill-soft);
}

/* Fades a scrolling element's top and bottom edges while there is more to
   scroll to on that side (pair with .vertical-window). Scroll-driven, so the
   animation sits behind @supports like motion.css's other scroll effects;
   without it the edges stay fully opaque. */
@property --scroll-fade-top {
  syntax: "<number>";
  inherits: false;
  initial-value: 1;
}

/* The same fade for a row that scrolls sideways (a table, a matrix, a strip of tabs). */
@property --scroll-fade-start {
  syntax: "<number>";
  inherits: false;
  initial-value: 1;
}

@property --scroll-fade-end {
  syntax: "<number>";
  inherits: false;
  initial-value: 1;
}

.horizontal-mask {
  --fade-size: var(--space-4);
  --fade-distance: var(--space-3);
  --scroll-fade-start: 1;
  --scroll-fade-end: 1;

  mask-image: linear-gradient(
    to right,
    rgb(0 0 0 / var(--scroll-fade-start)) 0,
    #000 var(--fade-size),
    #000 calc(100% - var(--fade-size)),
    rgb(0 0 0 / var(--scroll-fade-end)) 100%
  );
}

@supports (animation-timeline: scroll()) {
  .horizontal-mask {
    animation-name: scroll-fade-start, scroll-fade-end;
    animation-timing-function: linear, linear;
    animation-fill-mode: both, both;
    animation-timeline: scroll(self inline), scroll(self inline);
    animation-range:
      0 var(--fade-distance),
      calc(100% - var(--fade-distance)) 100%;
  }
}

@keyframes scroll-fade-start {
  from {
    --scroll-fade-start: 1;
  }

  to {
    --scroll-fade-start: 0;
  }
}

@keyframes scroll-fade-end {
  from {
    --scroll-fade-end: 0;
  }

  to {
    --scroll-fade-end: 1;
  }
}

@property --scroll-fade-bottom {
  syntax: "<number>";
  inherits: false;
  initial-value: 1;
}

.vertical-mask {
  --fade-size: var(--space-6);
  --fade-distance: var(--space-3);
  --scroll-fade-top: 1;
  --scroll-fade-bottom: 1;

  mask-image: linear-gradient(
    to bottom,
    rgb(0 0 0 / var(--scroll-fade-top)) 0,
    #000 var(--fade-size),
    #000 calc(100% - var(--fade-size)),
    rgb(0 0 0 / var(--scroll-fade-bottom)) 100%
  );
}

@supports (animation-timeline: scroll()) {
  .vertical-mask {
    animation-name: scroll-fade-top, scroll-fade-bottom;
    animation-timing-function: linear, linear;
    animation-fill-mode: both, both;
    animation-timeline: scroll(self block), scroll(self block);
    animation-range:
      0 var(--fade-distance),
      calc(100% - var(--fade-distance)) 100%;
  }
}

@keyframes scroll-fade-top {
  from {
    --scroll-fade-top: 1;
  }
  to {
    --scroll-fade-top: 0;
  }
}

@keyframes scroll-fade-bottom {
  from {
    --scroll-fade-bottom: 0;
  }
  to {
    --scroll-fade-bottom: 1;
  }
}

/* A lineage: what something inherits from, nearest first. Each level indents under
   the one it comes from, a ↳ marking the step, and the first one is set apart. A DAG,
   not always a chain: something reachable through two parents (diamond inheritance)
   appears twice, once per real path, rather than being flattened into one misleading
   line. A <ul class="lineage"> of <li>s, each with its own nested <ul> of parents. */
.lineage {
  font-size: 13px;
  color: var(--text-tertiary);
}

.lineage > li {
  color: var(--text-secondary);
  font-weight: 600;
}

.lineage ul {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding-inline-start: var(--space-4);
  margin-top: var(--space-1);
  color: var(--text-tertiary);
  font-weight: 400;
}

/* Likewise a name in a lineage looks the same linked or not. */
.lineage a {
  color: inherit;
  text-decoration: none;
}

.lineage a:hover {
  color: inherit;
  text-decoration: underline;
}

.lineage ul li::before {
  content: "↳ ";
  color: var(--text-tertiary);
}

/* Names and values in two aligned columns: a <dl class="key-values"> of <dt>/<dd>
   pairs, such as an item's stats. Values are monospaced. */
.key-values {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-1) var(--space-3);
  margin: 0;
}

.key-values dt {
  color: var(--text-tertiary);
  font-size: 13px;
}

.key-values dd {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 13px;
}

/* One column on a phone: the name above its value, each pair set apart
   from the next (§8.5). */
@media (max-width: 720px) {
  .key-values {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .key-values dd {
    margin-bottom: var(--space-2);
  }
}

/* A wrapping row of pictures, each at most 240px: a <div class="gallery"> of <figure>s. */
.gallery {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.gallery figure {
  margin: 0;
}

.gallery img {
  display: block;
  max-width: 240px;
  max-height: 240px;
  border-radius: var(--radius-control);
}

/* Small print about where something comes from: "From Longsword". */
.caption {
  margin: 0;
  font-size: 12px;
  color: var(--text-tertiary);
}

/* A labelled row of choices, such as radios: the label gives every group the same width,
   so the choices line up down a list of groups. A <div class="option-group" role="group">
   of an .option-group-label and the choices. */
.option-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

.option-group-label {
  min-width: 8rem;
  font-weight: 600;
}
/* .tree-toggle, not the generic .icon - a summary row often carries a
   second, semantic icon (a type marker) alongside the disclosure chevron,
   and only the chevron itself should rotate open. */
@media (prefers-reduced-motion: no-preference) {
  .tree summary .tree-toggle {
    transition: transform 150ms ease;
  }
}

.tree details[open] > summary .tree-toggle {
  transform: rotate(90deg);
}

/* Outline: a chain whose links say what they are, such as the repositories
   a repository is built on (identity.md §18). It is a plain nested list, so
   it reads in order with a screen reader and needs no script; a node that
   can be opened holds a link or a button.

   The rule down the left of a nested list is the edge. Solid is a direct
   relationship; .outline-derived is dashed for one that is derived or
   passes through another (§18.2). The line is never the only thing saying
   so: every node carries its state as words in .outline-state, so the
   outline reads the same in grayscale. The current selection is a fill,
   separate from meaning (§18.1). */
.outline,
.outline ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.outline ul {
  margin-inline-start: var(--space-3);
  padding-inline-start: var(--space-3);
  border-inline-start: 2px solid var(--border-strong);
}

.outline ul.outline-derived {
  border-inline-start-style: dashed;
}

.outline-node {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-2);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-control);
}

.outline-node[aria-current="true"] {
  background: var(--surface-selected);
}

.outline-name {
  font-weight: 600;
}

/* Something that cannot be read (not invited, not published) stays in the
   outline, quieter: its state says why, so the fade is not the message. */
.outline-node--muted .outline-name {
  color: var(--text-tertiary);
  font-weight: 500;
}

.outline-state {
  font-size: 13px;
  color: var(--text-secondary);
}

/* What to do about a node, on a line of its own beneath it. */
.outline-hint {
  flex-basis: 100%;
  margin: 0;
  font-size: 13px;
  color: var(--text-secondary);
}

/* Form fields beyond .text-input */
textarea.text-input {
  min-height: 96px;
  resize: vertical;
}

/* A single-line <select> gets its own chevron (native ones look
   inconsistent across browsers/OSes) via two small gradients rather than
   an SVG data URI, since a data URI's own fill/stroke can't reference a
   design token - a plain gradient can. Excludes [multiple] and a sized
   listbox below, which render as a scrollable box, not a one-line
   dropdown, and shouldn't get a chevron at all. */
select.text-input:not([multiple]):not([size]) {
  cursor: pointer;
  appearance: none;
  padding-right: calc(var(--space-3) + 18px);
  background-repeat: no-repeat;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-secondary) 50%),
    linear-gradient(135deg, var(--text-secondary) 50%, transparent 50%);
  background-position:
    calc(100% - 20px) center,
    calc(100% - 15px) center;
  background-size: 5px 5px;
}

/* A multi-select listbox - still a .text-input for border/font
   consistency, but no chevron and no forced single line. */
select.text-input[multiple],
select.text-input[size] {
  cursor: pointer;
  padding: var(--space-2);
}

/* Browsers italicize an <optgroup> label by default - this design system
   has no italics anywhere else, so it gets the same treatment as any
   other secondary label instead. */
optgroup {
  font-style: normal;
  font-weight: 600;
  color: var(--text-secondary);
}

input[type="checkbox"],
input[type="radio"] {
  width: 16px;
  height: 16px;
  accent-color: var(--action);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--action);
}

/* A color swatch button - full .text-input width would stretch a small
   fixed-size native control absurdly wide, so it gets its own compact
   sizing instead. */
input[type="color"] {
  width: 48px;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--border-control);
  border-radius: var(--radius-control);
  background: var(--surface-default);
  cursor: pointer;
}

/* A file input's native "choose file" button, restyled to match .btn-
   secondary rather than the browser's own default button chrome. */
input[type="file"] {
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--text-secondary);
}

input[type="file"]::file-selector-button {
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  background: var(--button-secondary-bg);
  color: var(--button-secondary-fg);
  border: 1px solid var(--button-secondary-border);
  border-radius: var(--radius-control);
  padding: var(--space-1) var(--space-2);
  margin-right: var(--space-2);
  cursor: pointer;
}

input[type="file"]::file-selector-button:hover {
  background: var(--fill-soft);
}

/* An image-button submit control - not a text field, so no .text-input
   border/padding, just a focus ring and a pointer cursor to read as
   interactive. */
input[type="image"] {
  cursor: pointer;
  border-radius: var(--radius-control);
}

input[type="image"]:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
}

.field-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* A group of related controls under one question: a set of radios, a few checkboxes. A bare
   <fieldset> needs no class; its <legend> is the question, labelled like .field-label is for a
   single control. The controls stack, and min-width: 0 undoes the browser's own, which would
   otherwise let a long label push the box wider than its container. A class that sets its own
   layout (a .grid, say) wins over the stacking. */
fieldset {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
  margin: 0;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
}

legend {
  padding-inline: var(--space-2);
  font-size: 13px;
  color: var(--text-secondary);
}

fieldset:disabled {
  opacity: 0.6;
}

/* A toggle switch - not a native input type, built from a checkbox
   visually hidden under a track/thumb pair. */
.switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}

.switch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.switch-track {
  position: absolute;
  inset: 0;
  background: var(--border-control);
  border-radius: var(--radius-pill);
  transition: background-color var(--dur-fast) var(--ease);
  pointer-events: none;
}

.switch-track::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: var(--surface-default);
  border-radius: 50%;
  transition: transform var(--dur-fast) var(--ease);
}

.switch input:checked + .switch-track {
  background: var(--action);
}

.switch input:checked + .switch-track::before {
  transform: translateX(16px);
}

.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* A custom editor surface - compose with .card for the outer chrome
   (<div class="card"><div class="editor-toolbar">...<div class=
   "editor-content" contenteditable>). */
.editor-toolbar {
  display: flex;
  gap: var(--space-1);
  padding: var(--space-2);
  background: var(--surface-muted);
  border-bottom: 1px solid var(--border-subtle);
}

.editor-toolbar button {
  background: transparent;
  color: var(--text-secondary);
  width: 28px;
  height: 28px;
  padding: 0;
}

.editor-toolbar button:hover {
  background: var(--fill-soft);
  color: var(--text-primary);
}

.editor-toolbar .divider {
  width: 1px;
  align-self: stretch;
  background: var(--border-subtle);
  margin-inline: var(--space-1);
}

.editor-content {
  padding: var(--space-3);
  min-height: 160px;
  outline: none;
}

.editor-content:empty::before {
  content: attr(data-placeholder);
  color: var(--text-tertiary);
}

/* The LorenzoScript editor (RFC 0027, ADR 0106): packages/lorenzoscript-editor
   wraps a textarea and its preview in .card.ls-editor, after an .editor-toolbar.
   data-layout is "split" (side by side, stacked when the editor itself is
   narrow, whatever the viewport) or "tabs". */
.ls-editor {
  container-type: inline-size;
}

.ls-editor .editor-toolbar {
  flex-wrap: wrap;
  align-items: center;
}

.ls-editor .editor-toolbar button:disabled {
  opacity: 0.4;
  cursor: default;
}

.ls-editor .editor-toolbar .tabs {
  margin-inline-start: auto;
  border-bottom: none;
}

/* Tabs are buttons too, but not the toolbar's square icon ones. */
.ls-editor .editor-toolbar .tab {
  width: auto;
  height: auto;
  padding: var(--space-1) var(--space-2);
  border-radius: 0;
}

.ls-editor-panes {
  display: grid;
}

.ls-editor[data-layout="split"] .ls-editor-panes {
  grid-template-columns: 1fr 1fr;
}

.ls-editor[data-layout="split"] .ls-preview {
  border-inline-start: 1px solid var(--border-subtle);
}

@container (max-width: 760px) {
  .ls-editor[data-layout="split"] .ls-editor-panes {
    grid-template-columns: 1fr;
  }

  .ls-editor[data-layout="split"] .ls-preview {
    border-inline-start: none;
    border-top: 1px solid var(--border-subtle);
  }
}

.ls-editor textarea.editor-content {
  width: 100%;
  min-height: 320px;
  border: none;
  border-radius: 0;
  resize: vertical;
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
}

/* A wide table scrolls the preview sideways instead of squeezing its words. */
.ls-editor .ls-preview {
  min-width: 0;
  overflow-x: auto;
}

/* Rendered LorenzoScript, wherever it's shown: wrap the renderer's output
   in .ls-content. Its own classes all start with ls-. Table cells keep the
   renderer's align attribute, so nothing here sets their text-align. */
.ls-content {
  overflow-wrap: break-word;
}

.ls-content > :first-child {
  margin-top: 0;
}

/* normalize.css strips every list's markers; written lists need theirs. */
.ls-content ul,
.ls-content ol {
  margin-block: var(--space-2);
  padding-inline-start: var(--space-5);
}

.ls-content ul {
  list-style: disc;
}

.ls-content ol {
  list-style: decimal;
}

.ls-content ul ul {
  list-style: circle;
}

.ls-content blockquote {
  margin-inline: 0;
  padding-inline-start: var(--space-3);
  border-inline-start: 3px solid var(--border-subtle);
  color: var(--text-secondary);
}

.ls-content hr {
  border: none;
  border-top: 1px solid var(--border-subtle);
  margin-block: var(--space-4);
}

.ls-content table {
  border-collapse: collapse;
  margin-block: var(--space-3);
}

.ls-content th,
.ls-content td {
  border: 1px solid var(--border-subtle);
  padding: var(--space-1) var(--space-2);
}

.ls-content th {
  background: var(--surface-muted);
}

.ls-content img {
  max-width: 100%;
  height: auto;
}

.ls-content abbr[title] {
  text-decoration: underline dotted;
  cursor: help;
}

.ls-content .ls-task {
  list-style: none;
}

.ls-content .ls-task input {
  margin-inline-end: var(--space-1);
}

.ls-content .ls-entity {
  text-decoration-style: dotted;
}

.ls-content .ls-cal {
  font-style: italic;
}

.ls-content math[display="block"] {
  margin-block: var(--space-3);
}

.ls-content .ls-math {
  color: var(--text-secondary);
}

.ls-content .ls-toc {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  padding: var(--space-2) var(--space-3);
}

.ls-content .ls-toc ul {
  margin: 0;
  padding-inline-start: var(--space-4);
  list-style: none;
}

.ls-content .ls-toc > ul {
  padding-inline-start: 0;
  list-style: none;
}

.ls-content .ls-footnotes {
  margin-top: var(--space-5);
  padding-top: var(--space-2);
  border-top: 1px solid var(--border-subtle);
  font-size: 0.875em;
  color: var(--text-secondary);
}

.ls-content .ls-fnref a,
.ls-content .ls-backref {
  text-decoration: none;
}

/* Touch targets (identity.md §8.5): at phone widths and for a coarse
   pointer, anything pressed is at least --target-min tall. The same rule
   serves a narrowed desktop window and a tablet in landscape, which is why
   it is two conditions and not a guess about the device. It only raises a
   minimum: a control already taller is untouched, and desktop sizes with a
   fine pointer are exactly what they were. Placed last so nothing above it
   can set a smaller height after it. */
@media (max-width: 720px), (pointer: coarse) {
  button,
  .btn,
  .text-input,
  .tab,
  .sidebar a,
  .tree summary,
  .tree li:not(:has(summary)),
  .outline-node,
  .site-navigation > summary {
    min-height: var(--target-min);
  }

  /* The mobile navigation's toggle is a summary, not a block of its own;
     centre its label the way a header link's is. */
  .site-navigation > summary {
    display: flex;
    align-items: center;
    cursor: pointer;
  }

  /* An inline link in a header is not a block, so min-height would be
     ignored; make it one that centres its text. */

  .site-header nav {
    align-items: stretch;
  }

  .site-header nav a {
    display: flex;
    align-items: center;
    min-height: var(--target-min);
  }

  /* A chip's remove mark is 16px and sits inside a 25px chip; making the
     mark 44px would change the chip. Its pressable area grows instead,
     past its edges and under neighbouring text, not its look. */
  .chip-remove {
    position: relative;
  }

  .chip-remove::after {
    content: "";
    position: absolute;
    inset: calc((var(--target-min) - 16px) / -2);
  }

  .card-body .card-body {
    padding: var(--space-3);
  }

  .card-body .card-body .card-body {
    padding: var(--space-2);
  }
}

/* ---------------------------------------------------------------------------------------
   The web shell (docs/design/web, ADR 0410, ADR 0414): a global bar, an app bar, a state
   strip, a status bar, a phone tab bar, an apps drawer and the palette. Widths are the
   viewport's here; the pieces are built to sit in a full-width page.
   --------------------------------------------------------------------------------------- */

/* A state: an icon, a word and a pattern, so it survives greyscale. --c is its colour. */
.state-chip {
  --c: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px 2px 8px;
  border: 1px solid var(--c);
  border-radius: var(--radius-pill);
  background-color: var(--surface-canvas);
  font-size: var(--fs-meta);
  line-height: 20px;
  white-space: nowrap;
}

.state-chip .icon {
  color: var(--c);
}

.state-chip > span {
  padding: 0 2px;
  border-radius: 4px;
  background: var(--surface-canvas);
}

.state-chip[data-state="synced"] {
  --c: var(--success);
}

.state-chip[data-state="waiting"],
.state-chip[data-state="stale"] {
  --c: var(--warning);
}

.state-chip[data-state="conflict"] {
  --c: var(--danger);
}

.state-chip[data-state="waiting"] {
  background-image: repeating-linear-gradient(
    45deg,
    color-mix(in srgb, var(--c) 30%, transparent) 0 2px,
    transparent 2px 6px
  );
}

.state-chip[data-state="stale"] {
  background-image: radial-gradient(
    color-mix(in srgb, var(--c) 45%, transparent) 1px,
    transparent 1.6px
  );
  background-size: 6px 6px;
}

.state-chip[data-state="conflict"] {
  background-image:
    repeating-linear-gradient(
      45deg,
      color-mix(in srgb, var(--c) 30%, transparent) 0 2px,
      transparent 2px 6px
    ),
    repeating-linear-gradient(
      -45deg,
      color-mix(in srgb, var(--c) 30%, transparent) 0 2px,
      transparent 2px 6px
    );
}

/* Icons in the shell are a little larger than the text beside them. */
.shell-bar .icon,
.shell-strip-in .icon,
.shell-status .icon,
.state-chip .icon,
.palette .icon {
  flex: none;
  width: 1.25em;
  height: 1.25em;
}

.avatar .icon {
  flex: none;
  width: 20px;
  height: 20px;
}

/* Global bar: brand, library switcher, palette button, notifications, account. */
.shell-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2h);
  min-height: 52px;
  padding: 4px var(--space-4);
  background: var(--surface-canvas);
}

.shell-bar .grow {
  flex: 1;
}

.shell-bar .brand-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--hit, 36px);
  min-height: var(--hit, 36px);
  color: var(--canonical);
}

.shell-field-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--hit, 36px);
  padding: 0 var(--space-2h);
  border: 1px solid var(--border-control);
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--fs-ui);
  text-align: start;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease);
}

.shell-field-btn:hover,
.shell-field-btn[aria-expanded="true"] {
  background: var(--fill-soft);
}

.shell-field-btn.palette-btn {
  width: min(320px, 100%);
  color: var(--text-secondary);
}

.shell-field-btn.palette-btn > span {
  flex: 1;
}

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 999px;
  background: var(--fill-soft);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--fs-micro);
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease);
}

.avatar:hover {
  background: color-mix(in srgb, var(--text-primary) 12%, transparent);
}

/* App bar: the app's name and its links as tabs (aria-current="page" marks the open one). */
.shell-apps {
  display: flex;
  align-items: flex-end;
  gap: var(--space-1);
  min-height: 44px;
  padding: 0 var(--space-4);
  background: var(--surface-canvas);
  border-bottom: 1px solid var(--border-subtle);
}

.shell-apps .prod {
  align-self: center;
  margin-inline-end: var(--space-2h);
  font-weight: 600;
}

.shell-apps nav {
  display: flex;
  gap: var(--space-1);
  align-self: stretch;
}

.shell-apps .tab {
  position: relative;
  display: flex;
  align-items: center;
  padding: 0 var(--space-2h);
  border-bottom: 0;
  text-decoration: none;
  font-size: var(--fs-ui);
}

.shell-apps .tab::after {
  content: "";
  position: absolute;
  inset: auto var(--space-2h) -1px;
  height: 2px;
  background: var(--text-primary);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform var(--dur-med) var(--ease);
}

.shell-apps .tab[aria-current="page"] {
  font-weight: 500;
}

.shell-apps .tab[aria-current="page"]::after {
  transform: scaleX(1);
}

/* State strip: shown only when something needs attention, and then it grows open. */
.shell-strip {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows var(--dur-med) var(--ease);
}

.shell-strip[data-open] {
  grid-template-rows: 1fr;
}

.shell-strip > div {
  overflow: hidden;
}

.shell-strip-in {
  --c: var(--warning);
  display: flex;
  align-items: center;
  gap: var(--space-2h);
  min-height: 36px;
  padding: 4px var(--space-4);
  border-bottom: 1px solid var(--c);
  background-color: var(--surface-canvas);
}

.shell-strip-in .msg {
  padding: 0 4px;
  border-radius: 4px;
  background: var(--surface-canvas);
}

.shell-strip-in .icon {
  color: var(--c);
}

.shell-strip-in .grow {
  flex: 1;
}

.shell-strip-in[data-kind="offline"],
.shell-strip-in[data-kind="waiting"] {
  background-image: repeating-linear-gradient(
    45deg,
    color-mix(in srgb, var(--c) 22%, transparent) 0 2px,
    transparent 2px 7px
  );
}

.shell-strip-in[data-kind="conflict"] {
  --c: var(--danger);
  background-image:
    repeating-linear-gradient(
      45deg,
      color-mix(in srgb, var(--c) 22%, transparent) 0 2px,
      transparent 2px 7px
    ),
    repeating-linear-gradient(
      -45deg,
      color-mix(in srgb, var(--c) 22%, transparent) 0 2px,
      transparent 2px 7px
    );
}

/* Status bar: slim, always shown: sync state, the app's meta, the real date and time. */
.shell-status {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 32px;
  padding: 0 var(--space-4);
  border-top: 1px solid var(--border-subtle);
  background: var(--surface-canvas);
  font-size: var(--fs-meta);
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
}

.shell-status .btn {
  min-height: 24px;
  padding: 0 var(--space-2);
  font-size: var(--fs-meta);
}

.shell-status .grow {
  flex: 1;
}

.shell-status .sync {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.shell-status .sync .icon {
  color: var(--success);
}

.shell-status .sync[data-kind="waiting"] .icon,
.shell-status .sync[data-kind="offline"] .icon {
  color: var(--warning);
}

/* Phone tab bar: the app's links at the bottom, clear of the safe area. */
.shell-tabbar {
  display: none;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-top: 1px solid var(--border-subtle);
  background: var(--surface-canvas);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.shell-tabbar a,
.shell-tabbar button {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 56px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text-secondary);
  text-decoration: none;
  font-family: var(--font-ui);
  font-size: var(--fs-micro);
  cursor: pointer;
}

.shell-tabbar .icon {
  width: 1.4rem;
  height: 1.4rem;
}

.shell-tabbar a[aria-current="page"] {
  color: var(--text-primary);
  font-weight: 600;
}

.shell-tabbar a[aria-current="page"]::before {
  content: "";
  position: absolute;
  inset: -1px 20% auto;
  height: 2px;
  background: var(--text-primary);
}

/* Apps drawer: every app by job, the legal links, the version. A sheet from the status bar. */
.shell-drawer {
  padding: var(--space-4);
  background: var(--surface-canvas);
  border-top: 1px solid var(--border-strong);
}

.shell-drawer .cols {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 1fr);
  gap: var(--space-5);
}

.shell-drawer .apps {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-4);
}

.shell-drawer a.l {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 30px;
  color: var(--text-primary);
  text-decoration: none;
  font-size: var(--fs-ui);
}

.shell-drawer a.l:hover {
  text-decoration: underline;
}

.shell-drawer .foot {
  margin-top: var(--space-3);
  padding-top: var(--space-2h);
  border-top: 1px solid var(--border-subtle);
  font-size: var(--fs-meta);
  color: var(--text-tertiary);
}

/* The palette: a dialog with a search field, scope buttons, grouped options and a key hint. */
dialog.palette {
  font-size: var(--fs-ui);
  display: flex;
  flex-direction: column;
  width: min(660px, calc(100% - 24px));
  max-width: none;
  max-height: calc(100dvh - 96px);
  margin: 72px auto auto;
  padding: 0;
  overflow: hidden;
}

dialog.palette:not([open]) {
  display: none;
}

.palette .p-body {
  display: flex;
  flex: 1;
  min-height: 0;
}

.palette .p-prev {
  display: none;
  flex: 0 0 300px;
  padding: var(--space-3);
  border-inline-start: 1px solid var(--border-subtle);
  background: var(--surface-muted);
}

.palette .p-opt .p-end {
  color: var(--text-tertiary);
  font-size: var(--fs-meta);
  white-space: nowrap;
}

.palette .p-foot .p-foot-end {
  margin-inline-start: auto;
}

@media (min-width: 1100px) {
  dialog.palette {
    width: min(940px, calc(100% - 48px));
  }

  .palette .p-prev {
    display: block;
  }
}

.palette .p-in {
  display: flex;
  align-items: center;
  gap: var(--space-2h);
  min-height: 52px;
  padding: 0 var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
}

.palette .p-in input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-size: var(--fs-sub);
}

.palette .p-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
}

.palette .p-tabs button {
  padding: 4px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: var(--fs-meta);
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease);
}

.palette .p-tabs button[aria-selected="true"] {
  background: var(--surface-selected);
  border-color: var(--border-control);
  color: var(--text-primary);
  font-weight: 500;
}

.palette .p-list {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  overflow: auto;
}

.palette .p-group {
  padding: 10px 8px 4px;
  font-size: var(--fs-micro);
  font-weight: 500;
  color: var(--text-tertiary);
}

.palette .p-opt {
  display: flex;
  align-items: center;
  gap: var(--space-2h);
  min-height: 40px;
  padding: 0 8px;
  border-radius: var(--radius-control);
  cursor: pointer;
}

.palette .p-opt[aria-selected="true"] {
  background: var(--surface-selected);
}

.palette .p-opt .grow {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.palette .p-opt mark {
  background: transparent;
  color: inherit;
  font-weight: 600;
}

.palette .p-opt .meta {
  margin-inline-start: 8px;
  color: var(--text-tertiary);
  font-size: var(--fs-meta);
}

.palette .p-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  padding: 8px var(--space-3);
  border-top: 1px solid var(--border-subtle);
  font-size: var(--fs-micro);
  color: var(--text-tertiary);
}

.palette .p-empty {
  padding: var(--space-4) var(--space-3);
  color: var(--text-secondary);
}

/* The shell's bars follow the width of the .shell-container they sit in (layout.css), not the
   window, so the same markup works in a full page and in a pane. A dialog is the window's. */
@container shell (max-width: 720px) {
  .shell-apps,
  .only-wide {
    display: none;
  }

  .shell-tabbar {
    display: grid;
  }

  .shell-field-btn.palette-btn {
    display: none;
  }

  .shell-bar .shell-field-btn {
    max-width: 190px;
    overflow: hidden;
  }

  .shell-status .wide {
    display: none;
  }

  .shell-drawer {
    display: none;
  }
}

@container shell (min-width: 721px) {
  .only-phone {
    display: none !important;
  }
}

/* On a phone the palette is a full screen. */
@media (max-width: 720px) {
  dialog.palette {
    width: 100%;
    max-height: none;
    height: 100dvh;
    margin: 0;
    border: 0;
    border-radius: 0;
  }

  .palette .p-foot {
    display: none;
  }

  .palette .p-opt {
    min-height: 48px;
  }
}

/* The save bar: a form with effects that cannot be undone saves from here. It opens only when
   there is something to save, with a border and no shadow. Rewrite its buttons only when the
   number of changes changes, never on every edit, or a click on Save that follows an edit can be
   lost (found while building the prototypes). */
.save-bar {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows var(--dur-med) var(--ease);
}

.save-bar[data-open] {
  grid-template-rows: 1fr;
}

.save-bar > div {
  overflow: hidden;
}

.save-bar-in {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-2h);
  padding: var(--space-2) var(--space-4);
  border-top: 1px solid var(--border-subtle);
  background: var(--surface-canvas);
}

.save-bar-in .grow {
  flex: 1;
}

/* The floating form: a bar that sticks to the bottom of its own scrolling region. */
.save-bar--float {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--surface-canvas);
  border: 1px solid var(--border-control);
  border-radius: var(--radius-card);
}

/* Skeleton rows: for a wait that is not a single field. A skeleton, never a spinner, stands where
   the real rows will be; .skeleton (motion.css) gives each bar its pulse. */
.skeleton-line {
  height: 14px;
  border-radius: 6px;
}

.skeleton-rows {
  display: grid;
}

.skeleton-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 120px;
  gap: var(--space-2h);
  align-items: center;
  min-height: var(--row-h, 48px);
  border-bottom: 1px solid var(--border-subtle);
}

.toast-card .toast-meta {
  color: var(--text-tertiary);
  font-size: var(--fs-meta);
}

.toast-card .toast-action {
  align-self: center;
}

/* ---------------------------------------------------------------------------------------
   Graph and matrix grammar (identity.md section 18, docs/design/web/social, ADR 0424). One small
   vocabulary for direct, derived, unknown, selected and restricted, shared by the graph, the
   matrix, the list and the timeline: a number, a quiet bar, a mark and a word, never colour
   alone, and a selection that is a fill and never a new shape.
   --------------------------------------------------------------------------------------- */

/* A standing: a number, a quiet bar, and a mark and a word saying how it is known. */
.standing {
  display: inline-grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 2px var(--space-2);
  min-width: 4.8rem;
}

.standing-num {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.standing-bar {
  height: 6px;
  min-width: 2.4rem;
  border-radius: 3px;
  background: var(--border-subtle);
  overflow: hidden;
}

.standing-bar > i {
  display: block;
  height: 100%;
  background: var(--text-secondary);
}

/* Below zero is hatched, so it reads without colour. */
.standing-bar > i.neg {
  background: repeating-linear-gradient(
    135deg,
    var(--text-secondary) 0 3px,
    transparent 3px 6px
  );
}

.standing-mark {
  grid-column: 1 / -1;
  font-size: var(--fs-micro);
  color: var(--text-secondary);
}

.standing[data-state="derived"] .standing-bar {
  outline: 1px dashed var(--text-secondary);
  outline-offset: 1px;
}

.standing[data-state="inherited"] .standing-bar {
  outline: 1px solid var(--border-control);
  outline-offset: 1px;
}

.standing[data-state="unknown"] .standing-num {
  font-style: italic;
}

.standing[data-state="unknown"] .standing-bar {
  outline: 1px dotted var(--text-secondary);
  outline-offset: 1px;
  background: transparent;
}

.standing[data-state="none"] .standing-num {
  color: var(--text-tertiary);
}

/* Graph: solid is direct, dashed is derived or through, dotted is unknown; an arrowhead is
   direction; a selection is a fill and a heavier line, never a new shape. */
.graph {
  display: block;
  width: 100%;
  height: 100%;
  color: var(--text-secondary);
  touch-action: none;
}

.graph:focus-visible {
  outline: 2px solid var(--action);
  outline-offset: -2px;
}

/* A label is outside whatever takes focus, and has a halo so it reads over a line. */
.graph text {
  fill: var(--text-primary);
  font-size: 11px;
  paint-order: stroke;
  stroke: var(--surface-muted);
  stroke-width: 3px;
}

.graph-edge path:not(.hit) {
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

.graph-edge .hit {
  stroke: transparent;
  stroke-width: 16;
  fill: none;
}

.graph-edge[data-kind="derived"] path:not(.hit),
.graph-edge[data-kind="through"] path:not(.hit) {
  stroke-dasharray: 6 4;
}

.graph-edge[data-kind="unknown"] path:not(.hit) {
  stroke-dasharray: 1.5 4;
  stroke-linecap: round;
}

.graph-edge[aria-selected="true"] path:not(.hit) {
  stroke: var(--action);
  stroke-width: 3.5;
  color: var(--action);
}

.graph-edge:focus-visible .hit {
  stroke: var(--action);
  stroke-opacity: 0.35;
}

.graph-node circle {
  fill: var(--surface-default);
  stroke: var(--text-primary);
  stroke-width: 2;
}

.graph-node[aria-selected="true"] circle {
  fill: var(--surface-selected);
  stroke: var(--action);
  stroke-width: 3;
}

.graph-node[data-state="pending"] circle {
  stroke: var(--action);
  stroke-dasharray: 4 3;
  stroke-width: 3;
}

.graph-node:focus-visible circle {
  stroke: var(--action);
  stroke-width: 4;
}

.graph-edge,
.graph-node {
  cursor: pointer;
  outline: none;
  transition: opacity var(--dur-med) var(--ease);
}

/* Focus mode: everything but the selection and its neighbours steps back. */
.graph-edge.dim,
.graph-node.dim {
  opacity: 0.2;
}

/* A lens line: says what a date lens or "as read by" switch has on, and clears it. */
.lens-line {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-1) var(--space-1) var(--space-3);
  background: var(--surface-default);
  border: 1px solid var(--action);
  border-radius: var(--radius-card);
}

.lens-line .btn {
  min-height: var(--target-min);
}

.graph-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--surface-default);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  font-size: var(--fs-meta);
  color: var(--text-secondary);
}

.graph-legend > span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* The matrix: the same facts as the graph, in a grid that edits where the cell is. */
.graph-matrix {
  border-collapse: separate;
  border-spacing: 0;
}

.graph-matrix th {
  position: sticky;
  padding: var(--space-1) var(--space-2);
  background: var(--surface-default);
  font-weight: 500;
  text-align: start;
}

.graph-matrix thead th {
  top: 0;
  z-index: 2;
  max-width: 7rem;
  vertical-align: bottom;
}

.graph-matrix tbody th {
  left: 0;
  z-index: 1;
  border-inline-end: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.graph-matrix .corner {
  left: 0;
  z-index: 3;
}

.graph-matrix td {
  min-width: 7rem;
  height: 56px;
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--border-subtle);
  border-width: 0 1px 1px 0;
  vertical-align: middle;
}

.graph-matrix td.diag {
  background: repeating-linear-gradient(
    135deg,
    var(--border-subtle) 0 2px,
    transparent 2px 6px
  );
}

.graph-matrix td[data-cell] {
  cursor: text;
}

.graph-matrix td[data-cell]:focus-visible {
  outline: 3px solid var(--action);
  outline-offset: -3px;
  background: var(--surface-selected);
}

.graph-matrix td[aria-selected="true"] {
  background: var(--surface-selected);
}

.graph-matrix td[data-state="conflict"] {
  outline: 2px solid var(--text-primary);
  outline-offset: -3px;
}

.graph-matrix td[data-state="derived"] {
  outline: 1px dashed var(--text-secondary);
  outline-offset: -3px;
}

.graph-matrix td[data-state="unknown"] {
  outline: 1px dotted var(--text-secondary);
  outline-offset: -3px;
}

.graph-matrix td[data-state="draft"] {
  background: color-mix(in srgb, var(--action) 8%, transparent);
  box-shadow: inset 3px 0 0 var(--action);
}

.graph-matrix td[data-state="refused"] {
  box-shadow: inset 3px 0 0 var(--danger);
}

.graph-matrix td.editing {
  padding: 2px;
}

.graph-matrix td.editing .text-input {
  min-width: 0;
}

/* A time filter: a strip of the calendar's own spans and marks with a range chosen by two
   handles (Sessions, Calendars, Social). It draws; the page owns the range. */
.time-filter {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
  background: var(--surface-default);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
}

.time-filter-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2h);
}

.time-filter-out {
  font-weight: 500;
}

.time-filter-strip {
  position: relative;
  height: 56px;
  touch-action: none;
  cursor: crosshair;
  user-select: none;
}

.time-filter-segs {
  display: flex;
  gap: 2px;
  height: 22px;
}

.time-filter-seg {
  padding: 3px 5px;
  overflow: hidden;
  border-radius: 4px;
  background: var(--surface-muted);
  color: var(--text-secondary);
  font-size: var(--fs-micro);
  white-space: nowrap;
}

.time-filter-seg[data-mark="festival"] {
  background: var(--surface-selected);
}

.time-filter-marks {
  position: absolute;
  inset: 26px 0 auto;
  height: 16px;
}

.time-filter-marks > i {
  position: absolute;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  border-radius: 1px;
  background: var(--action);
  opacity: 0.7;
}

.time-filter-range {
  position: absolute;
  top: 0;
  height: 44px;
  background: color-mix(in srgb, var(--action) 14%, transparent);
  border-inline: 2px solid var(--action);
  pointer-events: none;
}

.time-filter-handle {
  position: absolute;
  top: 14px;
  width: 20px;
  height: 32px;
  margin-left: -10px;
  border: 2px solid var(--surface-default);
  border-radius: 6px;
  background: var(--action);
  box-shadow: 0 2px 6px color-mix(in srgb, var(--brand-ink) 25%, transparent);
  cursor: ew-resize;
  touch-action: none;
}

.time-filter-handle:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

@media (pointer: coarse) {
  .time-filter-strip {
    height: 60px;
  }

  .time-filter-handle {
    top: 6px;
    width: 44px;
    height: 44px;
    margin-left: -22px;
  }
}
