/* The compatibility layer's stylesheet (docs/runeui-migration.md; docs/plugin-contract.md): what
 * the rune_ui gem's sheets styled, kept for plugins until 7.0, so the names they write keep
 * working: the old token names (defined from runeui's, below), the bare elements (the page,
 * headings, links, inputs, selects, textareas, tables, forms as flex columns), the classes (btn,
 * icon-button, pill, card, list-row, field, badge, count, tabs, alert, table, dl.details, empty,
 * stack, grid-2, button-row, separator, kbd, muted, faint, small, visually-hidden, the settings
 * rows, switches, menus, popovers, dialogs, sheets) and rune's breadcrumb.
 *
 * rune_ui's CSS as it was (revision c909a1a), in one cascade layer (`runeui.rune`), so Runwell's
 * own unlayered sheets win over it. At the end of the file, unlayered: what dresses a runeui
 * component a compat helper draws (RuneCompatHelper) so it sits right among the classes above.
 * The core's own views use only a few of these (utilities: muted, button-row, stack,
 * visually-hidden); it all goes when the plugins have moved to runeui (phase 10, then 7.0). */

/* rune's layers sit between runeui's base and its components, which only a layer inside
   `runeui` can do (layers nest: a sibling of `runeui` is over or under all of it). So the old
   `rune` layer is `runeui.rune` here (the order is appearance.css's, linked first). Over
   runeui's base, which resets every button and field inside a runeui part (font, colour, border
   colour): what a compat helper's block holds is rune markup (btn, icon-button, bare inputs), and
   it keeps its look inside a runeui card or dialog. Under runeui's components, so a runeui
   control (a native input or button with a ui- class) still beats the bare-element rules here. */
@layer ui-sdk, runeui.tokens, runeui.base, runeui.rune, runeui.components, runeui.utilities, runwell.theme;

/* ---- The old token names, from runeui's ---- */
/* rune_ui's names (--page, --panel, --text, --line, --s-1…) and the few of Fizzy's that plugins
   still read (--color-link, --inline-space…), each defined from runeui's tokens (shadcn's,
   runeui/tokens.css, as Settings > Appearance and a custom theme set them: appearance.css), so
   they follow every scheme, corner, font and custom theme. For plugins and this layer's own
   classes until 7.0; Runwell's own sheets read runeui's names.
   Two names are runeui's now and mean what shadcn means: --accent (the quiet hover fill; the
   brand's colour is --primary) and --ring (a colour; the focus shadow is --ui-focus-ring). A
   plugin stylesheet's var(--accent) and var(--ring) are read as --primary and --ui-focus-ring
   until 7.0 (lib/rails_ext/propshaft_plugin_stylesheets.rb rewrites them as it serves the sheet). */

@layer runeui.rune.tokens, runeui.rune.base, runeui.rune.components, runeui.rune.utilities;

@layer runeui.rune.tokens {
  :root {
    --page: var(--sidebar);
    --panel: var(--background);
    --layer-1: color-mix(in oklab, var(--muted) 50%, var(--background));
    --layer-2: var(--muted);
    --layer-3: light-dark(color-mix(in oklab, var(--foreground) 6%, var(--muted)), color-mix(in oklab, var(--foreground) 14%, var(--muted)));
    --text: var(--foreground);
    --text-muted: var(--muted-foreground);
    --text-faint: var(--faint-foreground);
    --line: var(--border);
    --line-strong: var(--input);
    --hover: light-dark(color-mix(in oklab, var(--foreground) 4%, transparent), color-mix(in oklab, var(--foreground) 8%, transparent));
    --accent-hover: color-mix(in oklab, var(--primary) 90%, var(--background));
    --accent-ink: var(--primary-foreground);
    --accent-soft: var(--brand-tint);
    --attention: var(--warning);
    --danger: var(--destructive);
    --ok: var(--success);
    --shadow-popover: 0 0 0 1px var(--border), var(--ui-shadow-lg);

    --s-1: .25rem;
    --s-2: .5rem;
    --s-3: .75rem;
    --s-4: 1rem;
    --s-5: 1.5rem;
    --s-6: 2rem;

    /* Corners from --radius, as runeui's: --radius itself is runeui's. --radius-scale is the
       corners' setting as a number (Sharp, Soft, Round), for plugins that multiply by it. */
    --radius-scale: 1;
    --radius-xs: max(0px, calc(var(--radius) - 6px));
    --radius-sm: var(--ui-radius-sm);
    --radius-md: var(--ui-radius-md);
    --radius-lg: var(--ui-radius-xl);
    --radius-panel: var(--ui-radius-xl);
    --radius-control: var(--ui-radius-md);
    --radius-pill: var(--ui-radius-full);
    --ease: cubic-bezier(.2, .8, .2, 1);
    --motion-fast: 120ms;
    --motion: 200ms;
    --motion-slow: 320ms;
    --motion-out: 140ms;
    --ease-in: cubic-bezier(.4, 0, 1, 1);

    --control-h: var(--ui-h);
    --control-h-sm: var(--ui-h-sm);
    --row-h: 2.5rem;
    --icon-size: 1rem;
    --main-width: 1400px;

    --text-xs: var(--ui-text-xs);
    --text-meta: var(--ui-text-xs);
    --text-ui: var(--ui-text-sm);
    --text-read: var(--ui-text-sm);
    --text-title: 1.25rem;
    --leading: 1.25rem;
    --leading-tight: 1rem;
    --weight: 400;
    --weight-strong: 500;

    /* Fizzy's, as plugins written before 4.0 read them. */
    --color-ink: var(--foreground);
    --color-ink-dark: var(--muted-foreground);
    --color-ink-medium: var(--faint-foreground);
    --color-ink-light: var(--input);
    --color-ink-lighter: var(--border);
    --color-ink-lightest: var(--muted);
    --color-ink-inverted: var(--primary-foreground);
    --color-canvas: var(--background);
    --color-link: var(--primary);
    --color-positive: var(--success);
    --color-negative: var(--destructive);
    --color-selected: var(--brand-tint-strong);
    --color-selected-light: var(--brand-tint);
    --color-hover: var(--hover);
    --focus-ring-color: color-mix(in oklab, var(--ring) 50%, transparent);
    --inline-space: 1ch;
    --inline-space-half: calc(var(--inline-space) / 2);
    --inline-space-double: calc(var(--inline-space) * 2);
    --block-space: 1rem;
    --block-space-half: calc(var(--block-space) / 2);
    --block-space-double: calc(var(--block-space) * 2);
    --text-xx-small: 0.75rem;
    --text-x-small: 0.75rem;
    --text-small: 0.875rem;
    --text-normal: 0.875rem;
    --text-medium: 1rem;
    --text-large: 1.25rem;
    --text-x-large: 1.5rem;
    --text-xx-large: 1.875rem;

    @media (max-width: 639px) {
      --text-xx-small: 0.8125rem;
      --text-x-small: 0.8125rem;
      --text-small: 0.9375rem;
      --text-normal: 0.9375rem;
      --text-medium: 1.0625rem;
    }
  }

  :root[data-radius="sharp"] { --radius-scale: .4; --radius-pill: .4em; }
  :root[data-radius="round"] { --radius-scale: 1.6; }

  @media (prefers-reduced-motion: reduce) {
    :root { --motion-fast: 1ms; --motion: 1ms; --motion-slow: 1ms; --motion-out: 1ms; }
  }
}

/* ---- rune_ui/base.css ---- */
@layer runeui.rune.base {
  * { box-sizing: border-box; }
  body {
    margin: 0; background: var(--page); color: var(--text);
    font-family: var(--font-sans); font-size: var(--text-ui); line-height: var(--leading); font-weight: var(--weight); letter-spacing: -.005em;
    -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  }
  h1, h2, h3, p, ul, ol, dl, dd, pre, figure, blockquote, fieldset { margin: 0; }
  h1 { font-size: var(--text-title); line-height: 1.75rem; font-weight: 600; letter-spacing: -.015em; }
  h2 { font-size: var(--text-read); line-height: var(--leading); font-weight: var(--weight-strong); }
  h3 { font-size: var(--text-ui); font-weight: var(--weight-strong); }
  strong, b { font-weight: var(--weight-strong); }
  a { color: var(--primary); text-underline-offset: 2px; }
  a:hover { color: var(--accent-hover); }
  ul, ol { padding-left: 1.4em; }
  code, pre, kbd, samp { font-family: var(--font-mono); font-size: var(--text-meta); line-height: 1.125rem; }
  :not(pre) > code { background: var(--layer-2); padding: 1px 5px; border-radius: var(--radius-xs); }
  pre { background: var(--layer-1); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s-3) var(--s-4); overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
  hr { border: 0; border-top: 1px solid var(--line); margin: 0; }
  img, svg, video { max-width: 100%; }
  summary { cursor: pointer; list-style: none; }
  summary::-webkit-details-marker { display: none; }
  /* runeui's own parts draw their own focus (runeui/base.css): this is everything else's. */
  :focus-visible:where(:not([data-slot], [class^="ui-"], [class*=" ui-"])) { outline: none; box-shadow: var(--ui-focus-ring); }
  [hidden] { display: none !important; }
  turbo-cable-stream-source, turbo-stream-source { display: none; }
  ::selection { background: color-mix(in srgb, var(--primary) 24%, transparent); }

  @keyframes spin { to { transform: rotate(360deg); } }
  @keyframes pulse { 50% { opacity: .3; } }
  /* The motion everything shares (--motion tokens): pop for what opens in place (menus, dialogs),
     slide for what comes in from the edge (sheets, toasts), fade for backdrops. */
  @keyframes rune-pop { from { opacity: 0; scale: .97; translate: 0 -2px; } }
  @keyframes rune-slide { from { opacity: 0; translate: 1.5rem 0; } }
  @keyframes rune-fade { from { opacity: 0; } }
}

/* ---- rune_ui/shell.css ---- */
/* What's left of rune's shell: the breadcrumb plugins draw by hand (.crumbs, the crumbs helper). */

@layer runeui.rune.components {
  .crumbs { display: flex; align-items: center; gap: var(--s-2); min-width: 0; font-weight: var(--weight-strong); }
  .crumbs a { color: var(--text-muted); text-decoration: none; font-weight: var(--weight); white-space: nowrap; }
  .crumbs a:hover { color: var(--text); }
}

/* ---- rune_ui/layout.css ---- */
/* Stacks, grids and small text utilities. Utilities sit in their own layer, above components. */

@layer runeui.rune.components {
  .stack, form { display: flex; flex-direction: column; gap: var(--s-4); }
  form.button_to { display: inline-flex; flex-direction: row; gap: 0; }

  .grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-4); align-items: start; }
  @media (max-width: 860px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }

  .catalog { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: var(--s-4); }
  .catalog .card { gap: var(--s-3); }
  .catalog .card p { flex: 1; }

  .dot-list { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-1) var(--s-2); color: var(--text-muted); }
  .dot-list > * + *::before { content: "·"; margin-right: var(--s-2); color: var(--text-faint); }

  dl.details { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: var(--s-3) var(--s-5); align-items: center; }
  dl.details dt { color: var(--text-muted); }
  dl.details dd { min-width: 0; overflow-wrap: anywhere; }
}

@layer runeui.rune.utilities {
  .muted { color: var(--text-muted); }
  .faint { color: var(--text-faint); }
  .small { font-size: var(--text-meta); line-height: var(--leading-tight); }
  .nowrap { white-space: nowrap; }
  .visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}

/* ---- rune_ui/marks.css ---- */
/* Marks: icons, avatars, status dots, badges, counts, chips, keys. */

@layer runeui.rune.components {
  .icon { width: var(--icon-size); height: var(--icon-size); flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
  .icon--down { width: .75rem; height: .75rem; transform: rotate(90deg); }

  /* letter_avatar: a coloured initial. avatar: a picture, else the initial. */
  .letter, .avatar { flex: 0 0 auto; width: 1.125rem; height: 1.125rem; border-radius: var(--radius-xs); display: grid; place-items: center; overflow: hidden; font-size: var(--text-xs); font-weight: 600; line-height: 1; color: #fff; background: var(--letter, #7b7b7b); }
  .letter--lg, .avatar--lg { width: 1.75rem; height: 1.75rem; border-radius: calc(7px * var(--radius-scale)); font-size: var(--text-read); }
  .avatar { border-radius: 50%; }
  .avatar img { width: 100%; height: 100%; object-fit: cover; }
  .avatar--md { width: 1.5rem; height: 1.5rem; font-size: var(--text-xs); }
  .avatar-stack { display: inline-flex; align-items: center; }
  .avatar-stack .avatar { box-shadow: 0 0 0 2px var(--panel); }
  .avatar-stack .avatar + .avatar { margin-left: -.25rem; }
  .letter--0 { --letter: #b23b78; } .letter--1 { --letter: #a83232; } .letter--2 { --letter: #1f7a8c; } .letter--3 { --letter: #3554c4; }
  .letter--4 { --letter: #b85a1e; } .letter--5 { --letter: #6a46b8; } .letter--6 { --letter: #2d8a4e; } .letter--7 { --letter: #8a6d1f; }
  .avatar--empty { background: transparent; border: 1px dashed var(--line-strong); color: var(--text-faint); }

  .status { flex: 0 0 auto; display: inline-block; width: .5rem; height: .5rem; border-radius: 50%; }
  .status--attention { background: var(--attention); }
  .status--unread, .status--accent { background: var(--primary); }
  .status--failed, .status--danger { background: var(--danger); }
  .status--ok { background: var(--ok); }
  .status--neutral { background: var(--text-faint); }
  .status--busy { width: .75rem; height: .75rem; border: 1.6px solid var(--line-strong); border-top-color: var(--text-muted); animation: spin .8s linear infinite; }

  /* Tones: badge(status) picks one through RuneUi.badge_tones. */
  .badge { display: inline-flex; align-items: center; gap: 5px; height: 1.25rem; padding: 0 7px; border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: var(--weight-strong); line-height: 1; white-space: nowrap; background: var(--layer-2); color: var(--text-muted); text-decoration: none; }
  .badge--ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
  .badge--danger { background: color-mix(in srgb, var(--danger) 13%, transparent); color: var(--danger); }
  .badge--attention { background: color-mix(in srgb, var(--attention) 16%, transparent); color: var(--attention); }
  .badge--accent, .badge--busy { background: color-mix(in srgb, var(--primary) 13%, transparent); color: var(--primary); }
  .badge--busy::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: pulse 1.2s ease-in-out infinite; }
  .badge--outline { background: transparent; box-shadow: inset 0 0 0 1px var(--line-strong); }

  .count { min-width: 1.125rem; padding: 0 6px; border-radius: var(--radius-pill); background: var(--attention); color: #1a1300; font-size: var(--text-xs); font-weight: 600; line-height: 1.125rem; text-align: center; }
  .count--quiet { background: var(--layer-3); color: var(--text-muted); }

  .chip { display: inline-flex; align-items: center; gap: 6px; height: var(--control-h-sm); padding: 0 var(--s-2); border-radius: var(--radius-sm); color: var(--text-muted); white-space: nowrap; }

  /* A rule; with text (separator--label), the text sits in the middle of it. */
  .separator { height: 1px; margin: 0; border: 0; background: var(--line); }
  .separator--label { display: flex; align-items: center; gap: var(--s-3); height: auto; background: none; color: var(--text-faint); font-size: var(--text-meta); }
  .separator--label::before, .separator--label::after { content: ""; flex: 1; height: 1px; background: var(--line); }

  kbd, .key { display: inline-flex; align-items: center; min-width: 1.25rem; height: 1.25rem; padding: 0 5px; border: 1px solid var(--line); border-radius: var(--radius-xs); background: var(--layer-1); color: var(--text-muted); font-family: var(--font-sans); font-size: var(--text-xs); line-height: 1; justify-content: center; }
}

/* ---- rune_ui/buttons.css ---- */
/* Buttons (from button_link, action_button, submit_button, icon_button) and menus. */

@layer runeui.rune.components {
  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex: 0 0 auto; width: fit-content;
    height: var(--control-h); padding: 0 var(--s-3); border: 1px solid transparent; border-radius: var(--radius-control);
    font: inherit; font-weight: var(--weight-strong); line-height: 1; white-space: nowrap; text-decoration: none; cursor: pointer;
    transition: background .12s, border-color .12s, color .12s, opacity .12s;
  }
  .btn .icon { width: .875rem; height: .875rem; }
  .btn--sm { height: var(--control-h-sm); padding: 0 .625rem; font-size: var(--text-meta); }
  .btn--primary { background: var(--primary); color: var(--primary-foreground); }
  .btn--primary:hover { color: var(--primary-foreground); opacity: .86; }
  .btn--accent { background: var(--primary); color: var(--accent-ink); }
  .btn--accent:hover { background: var(--accent-hover); color: var(--accent-ink); }
  .btn--secondary { background: var(--panel); border-color: var(--line-strong); color: var(--text); }
  .btn--secondary:hover { background: var(--layer-1); color: var(--text); }
  .btn--ghost { background: transparent; color: var(--text-muted); }
  .btn--ghost:hover { background: var(--hover); color: var(--text); }
  .btn--danger { background: transparent; border-color: color-mix(in srgb, var(--danger) 40%, transparent); color: var(--danger); }
  .btn--danger:hover { background: color-mix(in srgb, var(--danger) 9%, transparent); color: var(--danger); }
  .btn:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; pointer-events: none; }
  .btn[aria-busy="true"] { cursor: progress; }
  .btn[aria-busy="true"]::before { content: ""; width: .75rem; height: .75rem; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
  .btn[aria-pressed="true"] { background: var(--layer-2); color: var(--text); }

  /* A filter or picker's trigger: a quiet outline button with a chevron after its choice. */
  .pill { display: inline-flex; align-items: center; gap: 6px; max-width: 16rem; height: var(--control-h-sm); padding: 0 var(--s-2) 0 .625rem; border: 1px solid var(--line-strong); border-radius: var(--radius-control); background: var(--panel); color: var(--text); font: inherit; font-size: var(--text-meta); font-weight: var(--weight-strong); white-space: nowrap; cursor: pointer; }
  .pill:hover, .pill[aria-expanded="true"] { background: var(--layer-1); }
  .pill > :not(.icon) { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .pill .icon { width: .75rem; height: .75rem; color: var(--text-faint); }

  .icon-button { display: inline-grid; place-items: center; flex: 0 0 auto; width: var(--control-h-sm); height: var(--control-h-sm); padding: 0; border: 0; border-radius: var(--radius-control); background: none; color: var(--text-muted); text-decoration: none; cursor: pointer; }
  .icon-button:hover, .icon-button[aria-pressed="true"] { background: var(--hover); color: var(--text); }
  .icon-button.is-done { color: var(--ok); }

  .button-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }

  .menu { position: relative; display: inline-flex; }
}

/* ---- rune_ui/forms.css ---- */
/* Fields, inputs, switches, choices, segmented controls, search and filter bars. */

@layer runeui.rune.base {
  input:is([type="text"], [type="email"], [type="password"], [type="url"], [type="search"], [type="number"], [type="tel"], [type="date"], [type="datetime-local"], [type="time"], [type="month"], :not([type])), select, textarea {
    width: 100%; height: var(--control-h); padding: 0 .625rem;
    border: 1px solid var(--line-strong); border-radius: var(--radius-control); background: var(--panel); color: var(--text);
    font: inherit; transition: border-color .12s, box-shadow .12s;
  }
  /* Several lines are a box, so a box's corners: round corners make a control a pill, not a textarea. */
  textarea { height: auto; min-height: 5rem; padding: var(--s-2) .625rem; border-radius: var(--radius-lg); resize: vertical; }
  select { padding-right: 1.75rem; }
  :is(input, select, textarea):focus:where(:not([data-slot], [class^="ui-"], [class*=" ui-"])) { outline: none; border-color: color-mix(in srgb, var(--primary) 60%, var(--line-strong)); box-shadow: var(--ui-focus-ring); }
  input::placeholder, textarea::placeholder { color: var(--text-faint); }
  input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: color-mix(in srgb, var(--danger) 60%, var(--line-strong)); }
  input[type="checkbox"], input[type="radio"] { width: .9375rem; height: .9375rem; margin: 0; accent-color: var(--primary); }
  fieldset { padding: 0; border: 0; min-width: 0; }
  legend { padding: 0; font-weight: var(--weight-strong); }
  label { cursor: default; }
}

@layer runeui.rune.components {
  .field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
  .field > label, .field__label { font-weight: var(--weight-strong); }
  .field__hint { color: var(--text-faint); font-size: var(--text-meta); line-height: var(--leading-tight); }

  /* Fields side by side, one column on a narrow screen. */
  .field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: var(--s-4); }

  select.select--sm { height: var(--control-h-sm); width: auto; font-size: var(--text-meta); }
  input.input--sm { height: var(--control-h-sm); font-size: var(--text-meta); }

  .checkbox { display: inline-flex; align-items: center; gap: var(--s-2); cursor: pointer; }

  .switch { position: relative; display: inline-flex; flex: 0 0 auto; width: 2.125rem; height: 1.25rem; }
  .switch input { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
  .switch__track { position: relative; width: 100%; height: 100%; border-radius: var(--radius-pill); background: var(--layer-3); transition: background .17s var(--ease); }
  .switch__track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 1rem; height: 1rem; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgb(0 0 0 / .25); transition: transform .17s var(--ease); }
  .switch input:checked + .switch__track { background: var(--primary); }
  .switch input:checked + .switch__track::after { transform: translateX(.875rem); }
  .switch input:focus-visible + .switch__track { box-shadow: var(--ui-focus-ring); }
  .switch input:disabled + .switch__track { opacity: .45; }

  .choice { display: flex; flex-direction: column; gap: var(--s-2); padding: 0; border: 0; }

  /* rune-rows: the list of repeating rows. */

  .search { position: relative; display: flex; align-items: center; flex: 1 1 16rem; min-width: 12rem; }
  .search .icon { position: absolute; left: .625rem; color: var(--text-faint); pointer-events: none; }
  .search input { padding-left: 2rem; }

  .copy-field { display: flex; align-items: center; gap: var(--s-2); min-width: 0; }
  .copy-field code { flex: 1; min-width: 0; padding: 5px 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .copy { display: inline-flex; }
}

/* ---- rune_ui/cards.css ---- */
/* Page header, cards, folds, empty states. */

@layer runeui.rune.components {
  .page-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-3) var(--s-4); min-height: var(--control-h); }

  .card { display: flex; flex-direction: column; gap: var(--s-4); padding: var(--s-4) var(--s-5); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); }
  .card__head { display: flex; flex-direction: column; gap: 2px; }
  .card__title { font-size: var(--text-read); }
  .card__hint { color: var(--text-faint); font-size: var(--text-meta); line-height: var(--leading-tight); }
  .card__footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--s-2); }
  .card--flush { gap: 0; padding: 0; overflow: hidden; }
  .card--flush > .card__head { padding: var(--s-3) var(--s-5); border-bottom: 1px solid var(--line); }
  .card--flush > .list { padding: var(--s-1); }

  /* A card's parts beyond its head: .card__content (the body, when it needs one), .card__action
     (beside the title and hint, top right), and a rule under the head or over the footer. */
  .card__content { display: flex; flex-direction: column; gap: var(--s-3); min-width: 0; }
  .card__head:has(.card__action) { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: var(--s-3); }
  .card__head:has(.card__action) :is(.card__title, .card__hint) { grid-column: 1; }
  .card__action { grid-column: 2; grid-row: 1 / span 2; align-self: start; display: flex; align-items: center; gap: var(--s-2); }
  .card__head--bordered { padding-bottom: var(--s-3); border-bottom: 1px solid var(--line); }
  .card--sm { gap: var(--s-3); padding: var(--s-3) var(--s-4); }
  .card--flush > .card__content, .card--flush > .card__footer { padding: var(--s-3) var(--s-5); }

  .empty { display: flex; flex-direction: column; align-items: center; gap: var(--s-3); padding: var(--s-6) var(--s-5); border: 1px dashed var(--line-strong); border-radius: var(--radius-lg); color: var(--text-muted); text-align: center; }
  .empty--compact { align-items: flex-start; padding: var(--s-3) var(--s-4); border: 0; text-align: left; color: var(--text-faint); }
}

/* ---- rune_ui/lists.css ---- */
/* Lists: rows of avatar · title · muted detail · meta, grouped by day if wanted. */

@layer runeui.rune.components {
  .list { display: flex; flex-direction: column; gap: 1px; }
  .list-row { display: flex; align-items: center; gap: var(--s-3); min-height: var(--row-h); padding: 6px var(--s-3); border-radius: var(--radius-sm); color: var(--text); text-decoration: none; }
  a.list-row:hover, a.list-row:focus-visible { background: var(--hover); color: var(--text); }
  .list-row > .icon { color: var(--text-faint); }
  .list-row__title { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: var(--weight-strong); }
  .list-row__sub { flex: 1 1 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-faint); }
  .list-row__meta { flex: 0 0 auto; display: flex; align-items: center; gap: var(--s-2); color: var(--text-faint); white-space: nowrap; font-variant-numeric: tabular-nums; }

  /* A row with more to it: a picture (__media), a title over a description (__content with
     __title and __desc), and buttons at the end (__actions). */
  .list-row__media { flex: 0 0 auto; display: inline-flex; align-items: center; color: var(--text-faint); }
  .list-row__content { flex: 1 1 auto; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
  .list-row__content > .list-row__title { flex: none; }
  .list-row__desc { min-width: 0; color: var(--text-faint); font-size: var(--text-meta); line-height: var(--leading-tight); overflow-wrap: anywhere; }
  .list-row__actions { flex: 0 0 auto; display: flex; align-items: center; gap: var(--s-2); margin-left: auto; }

  [data-nav-item]:focus-visible { box-shadow: var(--ui-focus-ring); }
}

/* ---- rune_ui/settings.css ---- */
/* Settings: a heading above a card of label / control rows. */

@layer runeui.rune.components {
  /* settings_group / setting_row (plugins): runeui's card holding runeui's fields with control:,
     a rule between rows. */
  .settings-group .setting-row + .setting-row { padding-top: var(--s-3); border-top: 1px solid var(--line); }
  @media (max-width: 860px) {
    .setting-row { flex-direction: column; align-items: stretch; }
  }
}

/* ---- rune_ui/overlays.css ---- */
/* Popover menus, dialogs, sheets and tooltips. */

@layer runeui.rune.components {
  .popover-menu { display: inline-flex; }
  .popover:not(:popover-open) { display: none; }
  .popover:popover-open { animation: rune-pop var(--motion-fast) var(--ease); }

  .dialog-wrap { display: contents; }
  .dialog { width: min(32rem, calc(100vw - 2rem)); max-height: calc(100vh - 4rem); margin: 10vh auto auto; padding: 0; border: 0; border-radius: var(--radius-lg); background: var(--panel); color: var(--text); box-shadow: var(--shadow-popover); overflow: auto; }
  .dialog::backdrop { background: rgb(0 0 0 / .45); }
  .dialog[open] { animation: rune-pop var(--motion) var(--ease); }
  .dialog[open]::backdrop { animation: rune-fade var(--motion) var(--ease); }
  .dialog__title { font-size: var(--text-read); }

  .dialog__actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--s-2); }

  .sheet { width: min(28rem, 100vw); height: 100vh; max-height: none; margin: 0 0 0 auto; border-radius: var(--radius-panel) 0 0 var(--radius-panel); }
  .sheet[open] { animation: rune-slide var(--motion) var(--ease); }

  /* A tooltip on anything with data-tooltip="…" (CSS only; the title attribute stays for touch). */
  [data-tooltip] { position: relative; }
  [data-tooltip]:is(:hover, :focus-visible)::after {
    content: attr(data-tooltip); position: absolute; bottom: calc(100% + 6px); left: 50%; z-index: 40; transform: translateX(-50%);
    padding: 3px 7px; border-radius: var(--radius-xs); background: var(--text); color: var(--panel);
    font-size: var(--text-meta); font-weight: var(--weight); line-height: var(--leading-tight); white-space: nowrap; pointer-events: none;
  }
}

/* ---- rune_ui/data.css ---- */
/* Tables, tabs, alerts, skeletons and progress. */

@layer runeui.rune.components {
  .table { width: 100%; border-collapse: separate; border-spacing: 0; font-variant-numeric: tabular-nums; }
  .table :is(th, td) { padding: var(--s-2) var(--s-3); text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line); }
  .table th { height: 2.25rem; color: var(--text-muted); font-size: var(--text-meta); font-weight: var(--weight-strong); white-space: nowrap; }
  .table td { height: var(--row-h); }
  .table tbody tr:last-child td { border-bottom: 0; }
  .table tbody tr:hover td { background: var(--hover); }
  .table a:not([class]) { color: var(--text); text-decoration: none; font-weight: var(--weight-strong); }
  .table a:not([class]):hover { color: var(--primary); }
  .table .number { text-align: right; }

  .table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--panel); }

  .tabs { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-1); border-bottom: 1px solid var(--line); }
  .tabs__tab { display: inline-flex; align-items: center; gap: 6px; height: 2.25rem; padding: 0 var(--s-2); margin-bottom: -1px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--text-muted); font: inherit; text-decoration: none; cursor: pointer; }
  .tabs__tab:hover { color: var(--text); }
  .tabs__tab:is([aria-current="page"], [aria-pressed="true"], [aria-selected="true"]) { border-bottom-color: var(--text); color: var(--text); font-weight: var(--weight-strong); }

  .tabs--icons { gap: 2px; padding: 2px; border: 0; border-radius: var(--radius); background: var(--layer-2); }
  .tabs--icons .tabs__tab { height: var(--control-h-sm); padding: 0 var(--s-2); margin: 0; border: 0; border-radius: var(--radius-sm); }
  .tabs--icons .tabs__tab:is([aria-current="page"], [aria-pressed="true"], [aria-selected="true"]) { background: var(--panel); box-shadow: 0 1px 2px rgb(0 0 0 / .12); }
  .tabs--pills { gap: 2px; padding: 2px; border: 0; border-radius: var(--radius); background: var(--layer-2); width: fit-content; }
  .tabs--pills .tabs__tab { height: var(--control-h-sm); padding: 0 var(--s-3); margin: 0; border: 0; border-radius: var(--radius-sm); }
  .tabs--pills .tabs__tab:is([aria-current="page"], [aria-pressed="true"], [aria-selected="true"]) { background: var(--panel); box-shadow: 0 1px 2px rgb(0 0 0 / .12); }
  /* Plugins' hand-written tables (class data-table), which the core's old data table styled. */
  .data-table td a:not([class]) { color: var(--text); text-decoration: none; font-weight: var(--weight-strong); }
  .data-table td a:not([class]):hover { color: var(--primary); }
  .table a.row-link { color: var(--text); text-decoration: none; font-weight: var(--weight-strong); }
  .table a.row-link:hover { color: var(--primary); }

  .alert { display: flex; flex-direction: column; gap: 2px; padding: var(--s-3) var(--s-4); border: 1px solid; border-radius: var(--radius); }
  .alert__title { font-weight: var(--weight-strong); }
  .alert--danger { background: color-mix(in srgb, var(--danger) 7%, var(--panel)); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }

  .alert:has(.alert__icon) { display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: var(--s-3); }
  .alert:has(.alert__icon) :is(.alert__title, .alert__body, p, ul) { grid-column: 2; }
  .alert__icon { grid-row: 1 / span 2; margin-top: 2px; }
  .alert--danger .alert__icon { color: var(--danger); }
  .alert__body { color: var(--text-muted); }
  ul.alert__body { padding-left: 1.2em; }

  .skeleton { display: block; height: 1em; border-radius: var(--radius-xs); background: linear-gradient(90deg, var(--layer-2), var(--layer-1), var(--layer-2)); background-size: 200% 100%; animation: skeleton 1.4s ease-in-out infinite; }
  @keyframes skeleton { to { background-position: -200% 0; } }

}

/* ---- The compatibility helpers' runeui parts (RuneCompatHelper) ---- */

/* A trigger written with the caller's own class (menu's and dialog's trigger_class:) is a
   <button> now, where rune's menu had a <summary>: bare, so that class draws all of it. In
   rune's base layer, under every component rule. */
@layer runeui.rune.base {
  :is(ui-menu-trigger, ui-dialog-trigger, ui-drawer-trigger, ui-alert-dialog-trigger) > button { padding: 0; border: 0; background: none; color: inherit; font: inherit; letter-spacing: inherit; text-align: inherit; cursor: pointer; }
}

/* Unlayered from here, so these win over runeui's layers: what makes a runeui part drawn by a
   compat helper sit right among rune's classes still written by hand around it. */

/* menu(…, trigger_class:): the trigger fills the menu's box as rune's <summary> did, and shows
   it's open. */
:is(.menu, .popover-menu) > ui-menu-trigger { display: contents; }

/* card(): runeui's card at rune's measure, so it lines up with the cards still written as
   .card around it (its padding moves from the card to its parts, which is how runeui's card
   lets content run to the edges: card--flush). */
.card[data-slot="card"] { gap: var(--s-4); padding: var(--s-4) 0; border-radius: var(--radius-lg); box-shadow: none; }
.card > :is([data-slot="card-header"], [data-slot="card-content"], [data-slot="card-footer"]) { padding-inline: var(--s-5); }
.card > [data-slot="card-header"] { gap: 2px; }
.card > [data-slot="card-header"] [data-slot="card-description"] { color: var(--text-faint); font-size: var(--text-meta); line-height: var(--leading-tight); }
.card > [data-slot="card-content"] { display: flex; flex-direction: column; gap: var(--s-4); min-width: 0; }
.card--flush[data-slot="card"] { gap: 0; padding: 0; overflow: hidden; }
.card--flush > [data-slot="card-header"] { padding-block: var(--s-3); border-bottom: 1px solid var(--line); }
.card--flush > [data-slot="card-content"] { gap: 0; padding-inline: 0; }
.card--flush > [data-slot="card-content"] > .list { padding: var(--s-1); }

/* The small button's text and the icon button's ink, as rune's beside them. */
.ui-button.btn { gap: 6px; padding: 0 var(--s-3); }
.ui-button.btn--sm { padding: 0 .625rem; font-size: var(--text-meta); }
.ui-button.icon-button { color: var(--text-muted); }
.ui-button.icon-button:hover { color: var(--text); }
.ui-button.btn .icon, .ui-button.icon-button .icon { flex: 0 0 auto; }

/* badge(): a pill, as the badges and counts written by hand beside it; busy pulses. */
.badge[data-slot="badge"] { border-radius: var(--radius-pill); }
.badge--outline[data-slot="badge"] { box-shadow: none; }

/* field(): its hint as .field__hint beside it. */
.field > [data-slot="field-description"] { color: var(--text-faint); font-size: var(--text-meta); line-height: var(--leading-tight); }
.card > [data-slot="card-header"] [data-slot="card-title"] { display: flex; align-items: center; min-height: var(--control-h-sm); line-height: var(--leading); }

/* menu(): the widths the nav's and the portal's menus had, a key at the end of its row, and
   Runwell's icons in the ink runeui gives its own. */
.nav-account [data-slot="menu-content"] { min-width: 15rem; }
.portal-topbar [data-slot="menu-content"] { min-width: 14rem; }
:is(.menu, .popover-menu) .ui-item kbd { margin-inline-start: auto; }
:is(.menu, .popover-menu) .ui-item .icon { color: var(--text-muted); }
:is(.menu, .popover-menu) .ui-item .theme-toggle { display: inline-flex; }
.portal-user__label .portal-user__email { color: var(--text-faint); font-size: var(--text-meta); font-weight: var(--weight); }

/* progress_bar(): as wide as the caller's .progress says (runeui's keeps a minimum for a bar
   on its own line), and the muted track rune's bar had. */
.progress[data-slot="progress"] { flex: 0 0 auto; min-width: 0; }

/* popup_menu (PopupHelper): a <dialog class="popup"> the dialog controller opens below its
   trigger, drawn as a menu, for plugins (the meetings plugin's picker). Items are
   .popup__item > .popup__btn; the chosen one carries a check, and the one under the pointer or
   the keys the brand's tint. */
.popup {
  position: absolute; inset: calc(100% + 4px) auto auto 0; z-index: 40;
  display: none; flex-direction: column; gap: 1px;
  min-width: 12.5rem; max-width: min(22rem, calc(100vw - 1rem)); max-height: min(24rem, 70vh); overflow-y: auto;
  margin: 0; padding: 4px; border: 0; border-radius: var(--ui-radius-lg);
  background: var(--background); color: var(--foreground); box-shadow: 0 0 0 1px var(--border), var(--ui-shadow-lg);
  font-size: var(--ui-text-sm); text-align: start;
}
.popup[open] { display: flex; animation: rune-pop var(--ui-duration) var(--ui-ease); }
.popup.orient-left { inset-inline: auto 0; translate: var(--orient-offset, 0px); }
.popup.orient-right { inset-inline: 0 auto; translate: var(--orient-offset, 0px); }
.popup form { display: contents; }

.popup__title { padding: .5rem .75rem .25rem; color: var(--faint-foreground); font-size: var(--ui-text-xs); font-weight: 400; white-space: nowrap; }
.popup__title:focus-visible { box-shadow: none; }
.popup__list { display: flex; flex-direction: column; gap: 1px; width: 100%; margin: 0; padding: 0; list-style: none; }
.popup__item { position: relative; display: flex; align-items: center; width: 100%; border-radius: calc(var(--ui-radius-lg) * 0.5); }
.popup__item[aria-selected] { background: var(--muted); }
.popup__item:has(.popup__btn[disabled]) { pointer-events: none; }
.popup .popup__btn {
  display: flex; align-items: center; gap: .5rem; flex: 1 1 auto; width: 100%; min-width: 0; min-height: var(--ui-h);
  padding: 0 .75rem; border: 0; border-radius: inherit; background: none; color: var(--foreground);
  font: inherit; text-align: start; text-decoration: none; cursor: pointer;
}
.popup .popup__btn:is(:hover, :focus-visible) { background: var(--muted); color: var(--foreground); box-shadow: none; }
.popup .popup__btn[disabled] { opacity: .5; }
.popup .popup__btn .icon { color: var(--faint-foreground); }
.popup__item[aria-checked] .popup__btn { padding-right: 2rem; }
.popup__item .checked { display: none; position: absolute; right: .75rem; color: var(--muted-foreground); pointer-events: none; }
.popup__item[aria-checked="true"] .checked { display: block; }
.popup__item[aria-checked="true"] .popup__btn { font-weight: 500; }
/* The popup is a flex column that scrolls past its max height: its filter box and list keep their
/* size (a long list would otherwise squeeze the box until typing shortens the list). */
.popup input:is([type="search"], [type="text"]) { flex: none; height: var(--ui-h-sm); margin-bottom: 4px; }
.popup .popup__list { flex: none; }
.popup .popup__btn:is(:hover, :focus-visible), .popup__item[aria-selected] { background: var(--brand-tint); }
.popup .popup__btn:is(:hover, :focus-visible) .icon:not(.checked) { color: var(--primary); }
.popup__item[aria-checked="true"] .popup__btn .icon.checked { color: var(--primary); }

/* .table's column widths, one convention for every table: the column that identifies the row (the
   first, or the one marked table__grow) takes the leftover width and wraps; every other column
   fits its content, one gap apart, so narrow facts (type, status, dates) sit together. A table
   that sizes its own columns with a <colgroup> is left to it. Unlayered, so it holds on a plugin's
   ui :table given class "table" too. */
.table:not(:has(colgroup)) :is(th, td):not(:first-child) { width: 1%; white-space: nowrap; }
.table:not(:has(colgroup)):has(.table__grow) :is(th, td):first-child { width: 1%; white-space: nowrap; }
.table:not(:has(colgroup)) :is(th, td).table__grow { width: auto; white-space: normal; }
