/**
 * Aegis UX static component contracts — framework-neutral primitives.
 *
 * THE RULE THAT MAKES MOCKUPS BINDING: these classes are the single styling
 * source for the primitives below. Static catalogs / product mockups <link>
 * this file (with aegis-tokens.css first); React/Razor/Flutter counterparts
 * must render the SAME visual recipe (React components apply these classes
 * directly). A mockup styled with these classes therefore looks like the
 * shipped product by construction — fixing a recipe here fixes both.
 *
 * Consumes only aegis-tokens.css vars (--card/--border/--radius, semantic
 * --success/--warning/--destructive/--info sets incl. -subtle/-border/
 * -foreground) — light + dark come free via .dark.
 *
 * Catalog (all classes prefixed `aegis-`):
 *   .aegis-panel                          flat card/widget surface
 *   .aegis-pill    .ok|.warn|.bad|.info|.mute   dense status pill (verdicts, tiers)
 *   .aegis-gate    .ok|.wait|.miss|.none        TNA/milestone gate cell (fixed width)
 *   .aegis-stepper  > .dot/.seg (.done, .current[.warn|.bad])   deadline benchmark stepper
 *   .aegis-act                            compact one-click action button
 *   .aegis-drill-row / .aegis-drill-arrow  drillable row affordance (arrow slides in)
 *   .aegis-progress > div                 thin progress track + fill
 *   .aegis-spinner .lg                    inline busy indicator (container sets aria-busy)
 *   .aegis-skeleton                       layout-stable loading placeholder
 *
 *   Form primitives (data entry, sized for sustained reading/typing):
 *   .aegis-panel   > .head/.sub/.body      titled panel grouping fields
 *   .aegis-field   .invalid > .req/.hint/.error   label + control + hint + error slot
 *   .aegis-row     .cols-1|2|3|4           field row, collapses under 768px
 *   .aegis-actions .end                    form / workflow action bar
 *   .aegis-notice  .ok|.warn|.bad|.info|.mute    page-level state banner
 *   .aegis-insight .ok|.warn|.bad|.info|.mute .unread > .icon + .main > .tag/.headline(.open)/.meta/.body/.foot
 *                 .hue-amber|.hue-violet|.hue-teal|.hue-sky|.hue-rose|.hue-slate   category colour + icon badge
 *                                          tone-tinted card that leads somewhere (one action)
 *   .aegis-insight-rail .collapsed|.sticky > .head(.title > .icon / .count / .toggle) + .body(.sub/.toolbar/.scroll > .list/.empty) + .strip
 *                                          side column of insight cards, collapsible to a 44px strip
 *   .aegis-table-scroll > .aegis-table .compact  data grid (one scroll container)
 *   .aegis-dialog  > .head/.body/.foot     modal built on native <dialog>
 *   .aegis-toasts > .aegis-toast .ok|.warn|.bad|.info|.mute   transient feedback
 *   .aegis-btn     .primary|.danger        button recipe used by dialog footers
 *   .aegis-upload  .dragover/.disabled     drop zone
 *   .aegis-files > .aegis-file > .kind/.name/.size/.x   staged + existing file list
 *
 *   App chrome (the fixed band of chrome around a page, + its navigation):
 *   .aegis-shell   .rail|.open > .main/.foot/.scrim/.skip   fixed-chrome page shell
 *   .aegis-appbar  > .toggle/.brand/.tools    fixed 64px top bar
 *   .aegis-sidebar                            fixed 260px aside; 70px icon rail under .rail
 *   .aegis-nav     > .aegis-nav-label         navigation region + section eyebrow
 *   .aegis-nav-item  [aria-current]  > i/.label            leaf row, at any depth
 *   .aegis-nav-group > .aegis-nav-toggle[aria-expanded] + .aegis-nav-panel   nesting row
 *   .aegis-menu  .end  > .trigger[aria-expanded] > .label/.caret
 *                      + .panel > .meta/.item(.danger)/.sep     trigger + popover of actions
 *
 * Motion and pointer contract (applies to every recipe below):
 *   - Every :hover rule sits inside @media (hover: hover) and (pointer: fine).
 *     Touch browsers fake a hover on tap and leave it applied, so an ungated
 *     hover sticks. Touch feedback comes from :active instead.
 *   - Pressable controls (.aegis-btn, .aegis-act, the appbar toggle, the menu
 *     trigger) scale to 0.97 on :active, so the press registers as the finger
 *     lands. Rows (nav, menu items, table rows) do not scale; they change colour.
 *   - Only transform and opacity animate. The one exception is the desktop rail
 *     collapse (sidebar width, content margin), because the main region has to
 *     reflow and a transform cannot express that.
 *   - Curves come from --aegis-ease-* in aegis-tokens.css. Keyboard-initiated
 *     motion (the skip link) does not animate.
 *   - Form controls render at 16px on coarse pointers, or iOS zooms the page on
 *     focus and does not zoom back.
 *
 * Browser floor: the chrome recipe uses :has() (Chrome 105+, Safari 15.4+). The
 * behaviour module pairs it with `inert` (Chrome 102+, Safari 15.5+). Both are
 * baseline; everything above this line works without either.
 */

/* ── Panel — flat card surface (matches React <Card>: bg-card, border, radius) ── */
.aegis-panel {
  /* As a grid or flex item a panel may shrink below its content, so a wide
     .aegis-table-scroll inside it scrolls instead of widening the page. No
     effect in normal block flow. */
  min-width: 0;
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* ── Status pill — dense uppercase verdict/tier badge ─────────────────────── */
.aegis-pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 9.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em;
  padding: 2px 6px; border-radius: 99px; line-height: 1;
  border: 1px solid transparent;
  white-space: nowrap;
}
.aegis-pill.ok   { background: var(--success-subtle);     color: var(--success-foreground);     border-color: var(--success-border); }
.aegis-pill.warn { background: var(--warning-subtle);     color: var(--warning-foreground);     border-color: var(--warning-border); }
.aegis-pill.bad  { background: var(--destructive-subtle); color: var(--destructive-foreground); border-color: var(--destructive-border); }
.aegis-pill.info { background: var(--info-subtle);        color: var(--info-foreground);        border-color: var(--info-border); }
.aegis-pill.mute { background: var(--muted);              color: var(--muted-foreground);       border-color: var(--border); }

/* ── Gate cell — fixed-width TNA/milestone state chip (gate check grids) ──── */
.aegis-gate {
  display: inline-flex; align-items: center; justify-content: center;
  width: 54px; gap: 3px;
  font-size: 9px; font-weight: 700;
  padding: 2px 0; border-radius: 99px; line-height: 1.2;
  border: 1px solid transparent;
}
.aegis-gate.ok   { background: var(--success-subtle);     color: var(--success-foreground); }
.aegis-gate.wait { background: var(--warning-subtle);     color: var(--warning-foreground); }
.aegis-gate.miss { background: var(--destructive-subtle); color: var(--destructive-foreground); }
.aegis-gate.none { background: var(--muted);              color: var(--muted-foreground); }

/* ── Benchmark stepper — staged deadlines (e.g. PPM → PCD+7 → Ship−5) ─────
   Markup: <span class="aegis-stepper">
             <span class="dot done"></span><span class="seg done"></span>
             <span class="dot current warn"></span><span class="seg"></span>
             <span class="dot"></span>
           </span>                                                           */
.aegis-stepper { display: flex; align-items: center; gap: 0; min-width: 150px; }
.aegis-stepper .dot {
  width: 10px; height: 10px; border-radius: 99px; flex: none;
  border: 2px solid var(--border); background: var(--card);
}
.aegis-stepper .seg { height: 2px; flex: 1; min-width: 14px; background: var(--border); }
.aegis-stepper .dot.done    { background: var(--success); border-color: var(--success); }
.aegis-stepper .seg.done    { background: var(--success); }
.aegis-stepper .dot.current              { box-shadow: 0 0 0 3px var(--success-subtle); }
.aegis-stepper .dot.current.warn { background: var(--warning);     border-color: var(--warning);     box-shadow: 0 0 0 3px var(--warning-subtle); }
.aegis-stepper .dot.current.bad  { background: var(--destructive); border-color: var(--destructive); box-shadow: 0 0 0 3px var(--destructive-subtle);
                                   animation: aegis-stepper-pulse 1.6s ease infinite; }
@keyframes aegis-stepper-pulse { 50% { box-shadow: 0 0 0 5px var(--destructive-subtle); } }
@media (prefers-reduced-motion: reduce) { .aegis-stepper .dot.current.bad { animation: none; } }

/* ── One-click action button — compact inline resolve action ──────────────── */
.aegis-act {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10px; font-weight: 600;
  padding: 3px 8px; border-radius: calc(var(--radius) - 2px);
  border: 1px solid var(--border); background: var(--card); color: var(--card-foreground);
  cursor: pointer; white-space: nowrap;
  transition: transform 140ms var(--aegis-ease-out), box-shadow 140ms ease, border-color 140ms ease, color 140ms ease;
}
@media (hover: hover) and (pointer: fine) {
  .aegis-act:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 14px -6px oklch(0 0 0 / 0.25);
    border-color: var(--info); color: var(--info);
  }
}
.aegis-act:active { transform: scale(0.97); }
.aegis-act:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .aegis-act:hover, .aegis-act:active { transform: none; } }

/* ── Drillable row — cursor + hover wash + slide-in arrow ──────────────────
   CONTRACT (a11y, #19): a drill row is interactive — render it as a <button>
   (or <tr tabindex="0"> handling Enter/Space) with an accessible name. A
   clickable <div> whose only affordance appears on hover is non-conforming:
   keyboard and touch users never discover it.                               */
.aegis-drill-row { cursor: pointer; transition: background 120ms ease; }
@media (hover: hover) and (pointer: fine) {
  .aegis-drill-row:hover { background: var(--muted); }
  .aegis-drill-row:hover .aegis-drill-arrow { opacity: 1; transform: translateX(0); }
}
.aegis-drill-row:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; background: var(--muted); }
.aegis-drill-arrow {
  opacity: 0; transform: translateX(-4px);
  transition: opacity 140ms var(--aegis-ease-out), transform 140ms var(--aegis-ease-out); color: var(--info);
}
.aegis-drill-row:focus-visible .aegis-drill-arrow,
.aegis-drill-row:focus-within .aegis-drill-arrow { opacity: 1; transform: translateX(0); }
@media (prefers-reduced-motion: reduce) { .aegis-drill-arrow { transform: none; transition: opacity 140ms ease; } }

/* ── Touch hit-area extension (#21) — density stays, targets grow ──────────
   The dense recipes (act ≈22px, pill ≈18px, gate ≈16px tall) are deliberate
   for desktop dashboards, but a tap target must not equal the tiny visual
   box: WCAG floor 24px; coarse pointers (touch) get 44px. INTERACTIVE
   instances only — rendered as <button>/<a> or marked data-interactive —
   gain an invisible centered hit box. Zero visual change; clicks on the
   extension hit the control itself.                                         */
.aegis-act, .aegis-btn, .aegis-menu > .trigger,
button.aegis-pill, a.aegis-pill, .aegis-pill[data-interactive],
button.aegis-gate, a.aegis-gate, .aegis-gate[data-interactive] { position: relative; }
.aegis-act::after, .aegis-btn::after, .aegis-menu > .trigger::after,
button.aegis-pill::after, a.aegis-pill::after, .aegis-pill[data-interactive]::after,
button.aegis-gate::after, a.aegis-gate::after, .aegis-gate[data-interactive]::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: max(100%, 24px); height: max(100%, 24px);
}
@media (pointer: coarse) {
  .aegis-act::after, .aegis-btn::after, .aegis-menu > .trigger::after,
  button.aegis-pill::after, a.aegis-pill::after, .aegis-pill[data-interactive]::after,
  button.aegis-gate::after, a.aegis-gate::after, .aegis-gate[data-interactive]::after {
    width: max(100%, 44px); height: max(100%, 44px);
  }
}

/* ── Loading primitives (#20) — spinner + skeleton, aria-busy contract ─────
   Loading feedback matches the expected wait, preserves layout, and exposes
   accessible busy state: set aria-busy="true" on the loading container and
   clear it when settled. Skeletons reserve the FINAL layout (CLS guard).
   Don't flash either for near-instant (<300ms) work.                        */
.aegis-spinner {
  display: inline-block; width: 16px; height: 16px; flex: none;
  border: 2px solid var(--muted); border-top-color: var(--muted-foreground);
  border-radius: 99px;
  animation: aegis-spin 800ms linear infinite;
}
.aegis-spinner.lg { width: 24px; height: 24px; border-width: 3px; }
@keyframes aegis-spin { to { transform: rotate(360deg); } }
.aegis-skeleton {
  display: block; border-radius: calc(var(--radius) - 2px);
  background: linear-gradient(90deg, var(--muted) 25%, var(--border) 50%, var(--muted) 75%);
  background-size: 200% 100%;
  animation: aegis-shimmer 1.4s linear infinite;
  color: transparent; user-select: none;
}
@keyframes aegis-shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) {
  /* a frozen spinner reads as a frozen UI — slow it, don't stop it */
  .aegis-spinner { animation-duration: 1.6s; }
  .aegis-skeleton { animation: none; background: var(--muted); }
}

/* ── Progress — thin track + fill (readiness/conversion bars) ─────────────── */
.aegis-progress { height: 8px; border-radius: 99px; background: var(--muted); overflow: hidden; }
.aegis-progress > div { height: 100%; border-radius: 99px; }

/* ══ Form primitives ═══════════════════════════════════════════════════════
   Data-entry chrome. Sized for sustained reading and typing rather than the
   dense dashboard scale above; same rules otherwise — colour and radius from
   tokens only, so light and dark come free.                                  */

/* ── Panel header — titles a .aegis-panel that groups fields ───────────────
   Markup: <section class="aegis-panel">
             <header class="head"><i></i><h2>Title</h2></header>
             <p class="sub">optional supporting line</p>
             <div class="body">…</div>
           </section>                                                        */
.aegis-panel > .head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--muted);
  border-radius: var(--radius) var(--radius) 0 0;
}
.aegis-panel > .head h2 {
  margin: 0; font-size: 14px; font-weight: 600; line-height: 1.25;
  color: var(--card-foreground);
}
.aegis-panel > .head i { color: var(--info); }
.aegis-panel > .sub  { margin: 0; padding: 10px 14px 0; font-size: 12px; color: var(--muted-foreground); }
.aegis-panel > .body { padding: 14px; }

/* ── Field — label + consumer-owned control + hint + error slot ─────────────
   The error slot is always present, hidden while empty, and keyed via
   data-field-error so client validation targets a known hook instead of every
   page inventing its own error markup.                                       */
/* align-content: start, or a field stretched by a taller sibling in the same
   .aegis-row (one with a hint or an error line) hands the extra height to its
   control's track and the select grows taller than the inputs beside it. */
.aegis-field { display: grid; gap: 4px; align-content: start; }
.aegis-field > label { font-size: 12px; font-weight: 600; color: var(--card-foreground); }
.aegis-field > label > .req { margin-left: 2px; color: var(--destructive); }
/* Text controls only. Without the type guard a checkbox or radio inside a field
   took this whole recipe: a full-width 32px bordered box that overflowed its
   column, a solid bar when checked, a doubled focus ring (#40). Booleans keep
   their native rendering — aegis ships no boolean recipe for the static layer,
   so the consumer owns their layout (rule 5). Every input rule below repeats the
   guard: hover, coarse-pointer size, focus and invalid alike. */
.aegis-field input:not([type="checkbox"]):not([type="radio"]),
.aegis-field select,
.aegis-field textarea {
  /* border-box, or width: 100% plus padding and border runs 22px past the field
     wherever no CSS reset sets it (every Razor page; selects were fine only
     because the UA already makes them border-box). */
  box-sizing: border-box;
  width: 100%; min-height: 32px;
  padding: 6px 10px;
  border: 1px solid var(--input);
  border-radius: var(--radius);
  background: var(--background); color: var(--foreground);
  font: inherit; font-size: 13px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.aegis-field textarea { min-height: 60px; resize: vertical; }
/* The field is a grid and grid items stretch to their column, so a boolean placed
   directly in it would draw its native box in the middle of a column-wide element.
   Keep it at its own size, at the start of the column (#40). */
.aegis-field > input[type="checkbox"],
.aegis-field > input[type="radio"] { justify-self: start; }
@media (hover: hover) and (pointer: fine) {
  .aegis-field input:not([type="checkbox"]):not([type="radio"]):hover,
  .aegis-field select:hover,
  .aegis-field textarea:hover { border-color: var(--muted-foreground); }
}
/* Under 16px, iOS zooms the page when the control takes focus and never zooms
   back. Never fix that by disabling zoom in the viewport meta. */
@media (pointer: coarse) {
  .aegis-field input:not([type="checkbox"]):not([type="radio"]),
  .aegis-field select,
  .aegis-field textarea { font-size: 16px; }
}
.aegis-field input:not([type="checkbox"]):not([type="radio"]):focus-visible,
.aegis-field select:focus-visible,
.aegis-field textarea:focus-visible {
  outline: 2px solid var(--ring); outline-offset: 2px; border-color: var(--ring);
}
.aegis-field > .hint  { font-size: 11px; line-height: 1.35; color: var(--muted-foreground); }
.aegis-field > .error { font-size: 11px; line-height: 1.35; color: var(--destructive-foreground); }
.aegis-field > .error[hidden] { display: none; }
.aegis-field.invalid input:not([type="checkbox"]):not([type="radio"]),
.aegis-field.invalid select,
.aegis-field.invalid textarea { border-color: var(--destructive); }

/* ── Field row — declares intended columns, collapses on narrow viewports ─── */
.aegis-row { display: grid; gap: 14px; }
.aegis-row.cols-1 { grid-template-columns: 1fr; }
.aegis-row.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.aegis-row.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.aegis-row.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.aegis-row + .aegis-row { margin-top: 14px; }
@media (max-width: 767px) {
  .aegis-row.cols-2,
  .aegis-row.cols-3,
  .aegis-row.cols-4 { grid-template-columns: 1fr; }
}

/* ── Action bar — holds consumer-owned buttons for a form/workflow step ───── */
.aegis-actions {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.aegis-actions.end { justify-content: flex-end; }

/* ── Notice — page-level state banner (locked, read-only, needs attention) ── */
.aegis-notice {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--radius);
  background: var(--card); color: var(--card-foreground);
}
.aegis-notice > .head { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 13px; font-weight: 600; }
.aegis-notice > .meta,
.aegis-notice > .body { display: block; margin-top: 3px; font-size: 12px; line-height: 1.45; }
.aegis-notice.ok   { background: var(--success-subtle);     color: var(--success-foreground);     border-left-color: var(--success); }
.aegis-notice.warn { background: var(--warning-subtle);     color: var(--warning-foreground);     border-left-color: var(--warning); }
.aegis-notice.bad  { background: var(--destructive-subtle); color: var(--destructive-foreground); border-left-color: var(--destructive); }
.aegis-notice.info { background: var(--info-subtle);        color: var(--info-foreground);        border-left-color: var(--info); }
.aegis-notice.mute { background: var(--muted);              color: var(--muted-foreground);       border-left-color: var(--border); }

/* ── Insight card — a tone-tinted item that leads somewhere ─────────────────
   The notice recipe, turned into a list item: same subtle tone background,
   with a tone border all round and one action. Text, counts, tags and order
   all come from the consumer; the card knows no domain.

   Markup: <li class="aegis-insight bad [unread]">
             <span class="icon" aria-hidden="true"></span>
             <div class="main">
               <p class="tag">Short eyebrow<span class="unread" role="img" aria-label="Unread"></span></p>
               <h3 class="headline"><a class="open" href="…">One sentence</a></h3>
               <p class="meta">Optional facts, e.g. dates</p>
               <p class="body" title="full text">Optional, clamped to three lines</p>
               <div class="foot"><a class="aegis-act action" href="…">Review</a></div>
             </div>
           </li>

   CONTRACT (a11y): status is never colour alone — .tag carries it as text.
   The whole card is the hit area of .open (stretched ::after), so the card is
   reached by keyboard through one real link or button, never a clickable div.
   .foot sits above that overlay, so the action does not also open the card.
   An empty .icon draws a tone glyph, so Razor and static pages need no icon
   font; React fills it with a Hugeicon.                                       */
.aegis-insight {
  position: relative;
  display: flex; align-items: flex-start; gap: 10px;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card); color: var(--foreground);
}
.aegis-insight > .icon {
  display: inline-flex; align-items: center; justify-content: center;
  flex: none; width: 16px; height: 16px; margin-top: 1px;
}
.aegis-insight > .icon > svg { width: 16px; height: 16px; }
.aegis-insight > .icon:empty::before {
  content: "i";
  display: inline-flex; align-items: center; justify-content: center;
  width: 14px; height: 14px; box-sizing: border-box;
  border: 1.5px solid currentColor; border-radius: 99px;
  font-size: 9px; font-weight: 700; line-height: 1;
}
.aegis-insight.bad  > .icon:empty::before,
.aegis-insight.warn > .icon:empty::before { content: "!"; }
.aegis-insight.ok   > .icon:empty::before { content: "\2713"; }
.aegis-insight > .main { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }
.aegis-insight .tag {
  display: flex; align-items: center; gap: 6px;
  margin: 0;
  font-size: 10px; font-weight: 600; line-height: 14px;
  text-transform: uppercase; letter-spacing: 0.08em;
  overflow-wrap: anywhere;
}
.aegis-insight .tag > .unread {
  flex: none; width: 6px; height: 6px; border-radius: 99px; background: currentColor;
}
.aegis-insight .headline {
  margin: 0;
  font-size: 13px; font-weight: 600; line-height: 18px;
  color: var(--foreground);
  overflow-wrap: anywhere;
}
.aegis-insight .meta {
  margin: 0;
  font-size: 11px; font-weight: 500; line-height: 15px;
  font-variant-numeric: tabular-nums;
  color: var(--foreground);
  overflow-wrap: anywhere;
}
.aegis-insight .body {
  margin: 0;
  font-size: 12px; line-height: 17px;
  color: var(--foreground);
  overflow-wrap: anywhere;
  display: -webkit-box; -webkit-box-orient: vertical;
  -webkit-line-clamp: 3; line-clamp: 3;
  overflow: hidden;
}
.aegis-insight .foot {
  position: relative; z-index: 1;
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  margin-top: 5px;
}
/* A long action label wraps inside the card instead of widening the rail. */
.aegis-insight .foot > .action {
  max-width: 100%; height: auto; min-height: 24px;
  white-space: normal; text-align: start; text-decoration: none;
}
.aegis-insight .open {
  color: inherit; font: inherit; text-align: inherit; text-decoration: none;
  background: none; border: 0; padding: 0; margin: 0; cursor: pointer;
  outline: none;
}
.aegis-insight .open::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
}
/* Inset, because the rail's scroll container clips anything drawn outside a card. */
.aegis-insight .open:focus-visible::after { outline: 2px solid var(--ring); outline-offset: -2px; }
@media (hover: hover) and (pointer: fine) {
  .aegis-insight .open:hover { text-decoration: underline; text-underline-offset: 2px; }
}
.aegis-insight.ok   { background: var(--success-subtle);     border-color: var(--success-border); }
.aegis-insight.warn { background: var(--warning-subtle);     border-color: var(--warning-border); }
.aegis-insight.bad  { background: var(--destructive-subtle); border-color: var(--destructive-border); }
.aegis-insight.info { background: var(--info-subtle);        border-color: var(--info-border); }
.aegis-insight.mute { background: var(--muted);              border-color: var(--border); }
.aegis-insight.ok   > .icon, .aegis-insight.ok   .tag { color: var(--success-foreground); }
.aegis-insight.warn > .icon, .aegis-insight.warn .tag { color: var(--warning-foreground); }
.aegis-insight.bad  > .icon, .aegis-insight.bad  .tag { color: var(--destructive-foreground); }
.aegis-insight.info > .icon, .aegis-insight.info .tag { color: var(--info-foreground); }
.aegis-insight.mute > .icon, .aegis-insight.mute .tag { color: var(--muted-foreground); }

/* Category hues: what KIND of thing a card is, independent of its tone. A hue
   wins over the tone's colours and turns the icon into a filled 28px badge, so
   a column of mixed kinds scans by colour and glyph. The closed set comes from
   the --hue-* tokens. CONTRACT (a11y): the tag still names the kind in words;
   the hue only repeats it.
   Markup: <li class="aegis-insight warn hue-amber"> … same children …        */
.aegis-insight.hue-amber { --insight-solid: var(--hue-amber-solid); --insight-fg: var(--hue-amber-foreground); --insight-subtle: var(--hue-amber-subtle); --insight-border: var(--hue-amber-border); }
.aegis-insight.hue-violet { --insight-solid: var(--hue-violet-solid); --insight-fg: var(--hue-violet-foreground); --insight-subtle: var(--hue-violet-subtle); --insight-border: var(--hue-violet-border); }
.aegis-insight.hue-teal { --insight-solid: var(--hue-teal-solid); --insight-fg: var(--hue-teal-foreground); --insight-subtle: var(--hue-teal-subtle); --insight-border: var(--hue-teal-border); }
.aegis-insight.hue-sky { --insight-solid: var(--hue-sky-solid); --insight-fg: var(--hue-sky-foreground); --insight-subtle: var(--hue-sky-subtle); --insight-border: var(--hue-sky-border); }
.aegis-insight.hue-rose { --insight-solid: var(--hue-rose-solid); --insight-fg: var(--hue-rose-foreground); --insight-subtle: var(--hue-rose-subtle); --insight-border: var(--hue-rose-border); }
.aegis-insight.hue-slate { --insight-solid: var(--hue-slate-solid); --insight-fg: var(--hue-slate-foreground); --insight-subtle: var(--hue-slate-subtle); --insight-border: var(--hue-slate-border); }
.aegis-insight:is(.hue-amber, .hue-violet, .hue-teal, .hue-sky, .hue-rose, .hue-slate) {
  background: var(--insight-subtle); border-color: var(--insight-border);
}
.aegis-insight:is(.hue-amber, .hue-violet, .hue-teal, .hue-sky, .hue-rose, .hue-slate) .tag { color: var(--insight-fg); }
.aegis-insight:is(.hue-amber, .hue-violet, .hue-teal, .hue-sky, .hue-rose, .hue-slate) > .icon {
  width: 28px; height: 28px; margin-top: 0;
  border-radius: 99px;
  background: var(--insight-solid); color: var(--hue-on);
}

/* ── Insight rail — a side column of insight cards, collapsible to a strip ──
   Markup: <aside class="aegis-insight-rail [collapsed] [sticky]" aria-label="Title">
             <div class="head">
               <h2 class="title"><span class="icon" aria-hidden="true"></span>Title</h2>
               <span class="aegis-pill bad count">4 need attention</span>
               <button type="button" class="toggle" aria-expanded="true"
                       aria-controls="rail-body" aria-label="Collapse Title"></button>
             </div>
             <div class="body" id="rail-body">
               <p class="sub">Muted subtitle</p>
               <div class="toolbar">Optional controls, e.g. a sort select</div>
               <div class="scroll"><ul class="list" role="list">…cards…</ul></div>
               (or <p class="empty">…</p> when there are no cards)
             </div>
             <button type="button" class="strip" aria-expanded="false"
                     aria-controls="rail-body" aria-label="Expand Title">
               <span class="icon" aria-hidden="true"></span>
               <span class="aegis-pill bad">4</span>
               <span class="chevron" aria-hidden="true"></span>
             </button>
           </aside>

   .collapsed swaps the head and body for the 44px strip; the toggle and the
   strip both carry aria-expanded, and whoever toggles moves focus to the
   control that is still visible (createInsightRail in the vanilla module, or
   the React component). .sticky pins the rail under fixed chrome
   (--app-header-offset) and lets the list scroll inside it. role="list" stays
   on the <ul>: Safari drops list semantics once list-style is removed.        */
.aegis-insight-rail {
  display: flex; flex-direction: column; gap: 8px;
  min-width: 0; min-height: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card); color: var(--card-foreground);
}
.aegis-insight-rail.sticky {
  position: sticky; top: var(--app-header-offset, 0px);
  max-height: calc(100vh - var(--app-header-offset, 0px));
  max-height: calc(100dvh - var(--app-header-offset, 0px));
}
/* The pill wraps under the title rather than squeezing it, and the toggle is
   pinned to the top-right corner so it never wraps onto the pill's line. The
   icon lives inside the title, so a long title wraps with its icon. */
.aegis-insight-rail > .head {
  position: relative;
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px;
  min-width: 0;
}
.aegis-insight-rail > .head:has(> .toggle) { padding-right: 32px; }
.aegis-insight-rail > .head > .title {
  display: flex; align-items: center; gap: 8px;
  flex: 0 1 auto; min-width: 0;
  margin: 0;
  font-size: 14px; font-weight: 600; line-height: 20px;
  overflow-wrap: anywhere;
}
.aegis-insight-rail > .head > .title > .icon,
.aegis-insight-rail > .strip > .icon {
  display: inline-flex; align-items: center; justify-content: center;
  /* --info, not --primary: dark --primary falls under 3:1 on --card. */
  flex: none; width: 16px; height: 16px; color: var(--info);
}
.aegis-insight-rail > .head > .title > .icon > svg,
.aegis-insight-rail > .strip > .icon > svg { width: 16px; height: 16px; }
.aegis-insight-rail > .head > .title > .icon:empty::before,
.aegis-insight-rail > .strip > .icon:empty::before { content: "\2726"; font-size: 13px; line-height: 1; }
.aegis-insight-rail > .head > .count { flex: none; }
.aegis-insight-rail > .head > .toggle,
.aegis-insight-rail > .strip {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; background: none; color: var(--muted-foreground);
  font: inherit; cursor: pointer;
  border-radius: calc(var(--radius) - 2px);
}
.aegis-insight-rail > .head > .toggle { position: absolute; top: -2px; right: 0; width: 24px; height: 24px; }
.aegis-insight-rail > .head > .toggle > svg,
.aegis-insight-rail > .strip > .chevron > svg { width: 14px; height: 14px; }
.aegis-insight-rail > .strip > .chevron { display: inline-flex; }
.aegis-insight-rail > .head > .toggle:empty::before,
.aegis-insight-rail > .strip > .chevron:empty::before {
  content: ""; display: block; width: 6px; height: 6px; box-sizing: border-box;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
}
.aegis-insight-rail > .strip > .chevron:empty::before { transform: rotate(135deg); }
.aegis-insight-rail > .head > .toggle::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: max(100%, 24px); height: max(100%, 24px);
}
@media (pointer: coarse) {
  .aegis-insight-rail > .head > .toggle::after { width: max(100%, 44px); height: max(100%, 44px); }
}
.aegis-insight-rail > .head > .toggle:focus-visible,
.aegis-insight-rail > .strip:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
@media (hover: hover) and (pointer: fine) {
  .aegis-insight-rail > .head > .toggle:hover,
  .aegis-insight-rail > .strip:hover { background: var(--muted); color: var(--foreground); }
}
.aegis-insight-rail > .body { display: flex; flex-direction: column; gap: 10px; flex: 1; min-height: 0; }
.aegis-insight-rail > .body > .sub {
  margin: 0; font-size: 12px; line-height: 16px; color: var(--muted-foreground);
}
.aegis-insight-rail > .body > .toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0;
}
.aegis-insight-rail > .body > .scroll { flex: 1; min-height: 0; overflow-y: auto; }
.aegis-insight-rail .list {
  display: flex; flex-direction: column; gap: 8px;
  margin: 0; padding: 0; list-style: none;
}
.aegis-insight-rail > .body > .empty {
  margin: 0; padding: 16px 12px;
  border: 1px dashed var(--border); border-radius: var(--radius);
  font-size: 12px; line-height: 16px; text-align: center; color: var(--muted-foreground);
}
.aegis-insight-rail > .strip {
  flex-direction: column; gap: 8px;
  width: 44px; min-height: 44px; padding: 10px 0;
}
.aegis-insight-rail.collapsed { width: max-content; padding: 0; }
.aegis-insight-rail.collapsed > .head,
.aegis-insight-rail.collapsed > .body,
.aegis-insight-rail:not(.collapsed) > .strip { display: none; }

/* ── Data grid ──────────────────────────────────────────────────────────────
   ONE horizontal scroll container, and it is .aegis-table-scroll.

   Nesting two scroll containers is a real defect, not a style preference: a
   grid wrapped in an outer scroller *and* handed to a plugin that manages its
   own (jQuery DataTables `scrollX`) sizes the inner wrapper independently, and
   the rightmost columns overflow with no visible scrollbar. Pick one — either
   this wrapper with the plugin's own scrolling off, or the plugin's with no
   wrapper.                                                                    */
.aegis-table-scroll { overflow-x: auto; }
.aegis-table {
  width: 100%; border-collapse: collapse;
  font-size: 13px; color: var(--card-foreground);
}
.aegis-table caption { padding: 0 0 8px; font-size: 12px; color: var(--muted-foreground); text-align: left; }
.aegis-table thead th {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--muted); color: var(--muted-foreground);
  font-size: 11px; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase;
  text-align: left; white-space: nowrap;
}
.aegis-table tbody td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.aegis-table tbody tr:last-child td { border-bottom: 0; }
@media (hover: hover) and (pointer: fine) { .aegis-table tbody tr:hover { background: var(--muted); } }
.aegis-table tfoot td { padding: 8px 10px; border-top: 1px solid var(--border); font-weight: 600; }
.aegis-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.aegis-table.compact thead th,
.aegis-table.compact tbody td { padding: 4px 8px; font-size: 12px; }

/* ── Dialog — native <dialog>, so open/close needs no library ───────────────
   Markup: <dialog class="aegis-dialog">
             <header class="head"><h2>Title</h2></header>
             <div class="body">…</div>
             <footer class="foot">…buttons…</footer>
           </dialog>
   Consumer calls .showModal() / .close(); ::backdrop and Esc come free.       */
.aegis-dialog {
  width: min(92vw, 560px); padding: 0;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card); color: var(--card-foreground);
  box-shadow: 0 24px 70px -38px oklch(0 0 0 / 0.5);
}
.aegis-dialog::backdrop { background: var(--overlay, oklch(0 0 0 / 0.45)); }
.aegis-dialog > .head {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.aegis-dialog > .head h2 { margin: 0; font-size: 14px; font-weight: 600; }
.aegis-dialog > .body { padding: 16px; font-size: 13px; line-height: 1.5; }
.aegis-dialog > .foot {
  display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px;
  padding: 12px 16px; border-top: 1px solid var(--border); background: var(--muted);
  border-radius: 0 0 var(--radius) var(--radius);
}
.aegis-dialog.wide { width: min(96vw, 880px); }

/* ── Button — shared recipe so dialog footers and action bars match ────────── */
.aegis-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 32px; padding: 6px 14px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card); color: var(--card-foreground);
  font: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  transition: border-color 120ms ease, background 120ms ease, transform 160ms var(--aegis-ease-out);
}
@media (hover: hover) and (pointer: fine) { .aegis-btn:hover:not(:disabled) { border-color: var(--muted-foreground); } }
.aegis-btn:active:not(:disabled) { transform: scale(0.97); }
@media (prefers-reduced-motion: reduce) { .aegis-btn:active:not(:disabled) { transform: none; } }
.aegis-btn:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.aegis-btn:disabled { cursor: not-allowed; opacity: 0.6; }
.aegis-btn.primary { background: var(--primary); color: var(--primary-foreground); border-color: transparent; }
.aegis-btn.danger  { background: var(--destructive); color: var(--destructive-foreground); border-color: transparent; }

/* ── Toasts — transient feedback, stacked in one live region ────────────────
   The region is a polite live region so screen readers announce messages
   without stealing focus. Errors are announced assertively by the helper.     */
.aegis-toasts {
  position: fixed; inset-block-start: 16px; inset-inline-end: 16px;
  z-index: 9999;
  display: grid; gap: 8px;
  max-width: min(92vw, 380px);
  pointer-events: none;
}
.aegis-toast {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border); border-inline-start-width: 3px;
  border-radius: var(--radius);
  background: var(--card); color: var(--card-foreground);
  box-shadow: 0 10px 30px -18px oklch(0 0 0 / 0.45);
  font-size: 13px; line-height: 1.45;
  pointer-events: auto;
  animation: aegis-toast-in 140ms var(--aegis-ease-out);
}
.aegis-toast > .msg { flex: 1; }
.aegis-toast > .x {
  flex: none; padding: 0 2px; border: 0; background: none; cursor: pointer;
  color: inherit; opacity: 0.6; font-size: 14px; line-height: 1;
}
@media (hover: hover) and (pointer: fine) { .aegis-toast > .x:hover { opacity: 1; } }
.aegis-toast.ok   { background: var(--success-subtle);     color: var(--success-foreground);     border-inline-start-color: var(--success); }
.aegis-toast.warn { background: var(--warning-subtle);     color: var(--warning-foreground);     border-inline-start-color: var(--warning); }
.aegis-toast.bad  { background: var(--destructive-subtle); color: var(--destructive-foreground); border-inline-start-color: var(--destructive); }
.aegis-toast.info { background: var(--info-subtle);        color: var(--info-foreground);        border-inline-start-color: var(--info); }
.aegis-toast.mute { background: var(--muted);              color: var(--muted-foreground);       border-inline-start-color: var(--border); }
@keyframes aegis-toast-in { from { opacity: 0; transform: translateY(-6px); } }
@media (prefers-reduced-motion: reduce) { .aegis-toast { animation: none; } }

/* ── Upload drop zone ───────────────────────────────────────────────────────
   A label wrapping a visually-hidden file input, so clicking, tabbing and
   Space/Enter all work from the platform with no key handling of our own.     */
.aegis-upload {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 20px 16px;
  border: 1px dashed var(--input); border-radius: var(--radius);
  background: var(--card); color: var(--muted-foreground);
  font-size: 13px; text-align: center; cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease;
}
@media (hover: hover) and (pointer: fine) { .aegis-upload:hover { border-color: var(--muted-foreground); } }
.aegis-upload:focus-within { outline: 2px solid var(--ring); outline-offset: 2px; }
.aegis-upload > .lead { font-weight: 600; color: var(--card-foreground); }
.aegis-upload > input[type="file"] {
  /* Visually hidden, still focusable and still the real control. */
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap; border: 0;
}
.aegis-upload.dragover { border-color: var(--info); background: var(--info-subtle); color: var(--info-foreground); }
.aegis-upload.disabled { cursor: not-allowed; opacity: 0.6; }

/* ── File list — staged (not yet sent) and already-stored files ─────────────
   `.kind` is a data hook, not an icon: the design system bundles no icon font,
   so a consumer maps [data-kind] to its own set.                              */
.aegis-files { display: grid; gap: 6px; margin-top: 8px; }
.aegis-files:empty { display: none; }
.aegis-file {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card); font-size: 12px;
}
.aegis-file > .kind {
  flex: none; padding: 1px 5px; border-radius: 3px;
  background: var(--muted); color: var(--muted-foreground);
  font-size: 10px; font-weight: 700; text-transform: uppercase;
}
.aegis-file > .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aegis-file > .size { flex: none; color: var(--muted-foreground); font-variant-numeric: tabular-nums; }
.aegis-file > .x {
  flex: none; padding: 0 2px; border: 0; background: none;
  color: inherit; opacity: 0.6; font-size: 14px; line-height: 1; cursor: pointer;
}
@media (hover: hover) and (pointer: fine) { .aegis-file > .x:hover { opacity: 1; color: var(--destructive); } }
.aegis-file.staged { border-style: dashed; }
.aegis-file.bad { border-color: var(--destructive); background: var(--destructive-subtle); color: var(--destructive-foreground); }

/* ══ App chrome ════════════════════════════════════════════════════════════
   The top bar and the aside paint on the SAME surface (--sidebar*), which is
   what makes them read as one frame around the page rather than two widgets.
   Both are position:fixed; .aegis-shell owns the offsets, so the main region
   and the footer track the sidebar's width without a sibling selector.

   State lives on .aegis-shell, not on the aside: it is the only element that
   is an ancestor of both the chrome and the content.

   Reusing --sidebar* for the top bar is deliberate. Adding an --appbar* set
   would oblige the React and Flutter surfaces to mirror it, for a band that
   in every consumer so far is the same colour as the aside.               */

/* Contain fixed chrome below body portals (Sheet/Dialog use z-index: 50).
   Isolation preserves fixed positioning without transforming its containing block. */
/* 100dvh tracks the visible area as the mobile URL bar shows and hides; the
   100vh line is the fallback for browsers without dynamic viewport units. */
.aegis-shell { min-height: 100vh; min-height: 100dvh; isolation: isolate; }

/* First focusable element on the page; visible only while focused. It is
   reached by keyboard, so it appears instantly rather than animating in. */
.aegis-shell > .skip {
  position: absolute; left: 8px; top: -48px; z-index: 1100;
  padding: 8px 14px; border-radius: var(--radius);
  background: var(--card); color: var(--card-foreground);
  font-size: 13px; font-weight: 600; text-decoration: none;
}
.aegis-shell > .skip:focus-visible { top: 8px; outline: 2px solid var(--ring); outline-offset: 2px; }

/* ── Top bar ─────────────────────────────────────────────────────────────── */
.aegis-appbar {
  position: fixed; inset: 0 0 auto 0; z-index: 1000;
  display: flex; align-items: center; gap: 16px;
  /* border-box, so the 1px rule sits inside the 64px the content is offset by.
     In content-box the bar is 65px tall and overlaps the first row of content. */
  box-sizing: border-box; height: 64px; padding: 0 16px;
  background: var(--sidebar); color: var(--sidebar-foreground);
  border-bottom: 1px solid var(--sidebar-border);
}
.aegis-appbar > .brand {
  display: flex; align-items: center; gap: 10px;
  color: inherit; font-size: 18px; font-weight: 700; text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.aegis-appbar > .tools { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.aegis-appbar > .toggle {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; padding: 0;
  border: 0; border-radius: calc(var(--radius) - 2px);
  background: none; color: inherit; cursor: pointer;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  transition: transform 160ms var(--aegis-ease-out);
}
@media (hover: hover) and (pointer: fine) { .aegis-appbar > .toggle:hover { background: var(--sidebar-accent); color: var(--sidebar-accent-foreground); } }
.aegis-appbar > .toggle:active { transform: scale(0.97); }
@media (prefers-reduced-motion: reduce) { .aegis-appbar > .toggle:active { transform: none; } }
.aegis-appbar > .toggle:focus-visible { outline: 2px solid var(--sidebar-ring); outline-offset: 2px; }

/* CSS-drawn hamburger: no icon font ships here, so a control the design system
   owns must not require one. Consumers may pass their own icon class instead. */
.aegis-appbar > .toggle > .bars,
.aegis-appbar > .toggle > .bars::before,
.aegis-appbar > .toggle > .bars::after {
  display: block; width: 18px; height: 2px; border-radius: 2px; background: currentColor;
}
.aegis-appbar > .toggle > .bars { position: relative; }
.aegis-appbar > .toggle > .bars::before { content: ""; position: absolute; top: -6px; }
.aegis-appbar > .toggle > .bars::after  { content: ""; position: absolute; top: 6px; }

/* ── Aside ───────────────────────────────────────────────────────────────── */
.aegis-sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 900;
  /* border-box for the same reason as the bar: the content offsets below are the
     same 260px / 70px, so the border has to be inside the width, not added to it. */
  box-sizing: border-box; width: 260px; overflow: hidden auto; overscroll-behavior: contain;
  background: var(--sidebar); color: var(--sidebar-foreground);
  border-right: 1px solid var(--sidebar-border);
  /* width animates only for the desktop rail collapse (see the motion contract
     at the top of this file); the mobile drawer moves by transform alone. */
  transition: width 200ms var(--aegis-ease-in-out), transform 240ms var(--aegis-ease-drawer);
}
/* Only clear the bar when there is one — a shell may run without an appbar. */
.aegis-shell:has(> .aegis-appbar) .aegis-sidebar { padding-top: 64px; }
.aegis-sidebar::-webkit-scrollbar { width: 6px; }
.aegis-sidebar::-webkit-scrollbar-thumb { background: var(--sidebar-border); border-radius: 3px; }

/* ── Content offsets ─────────────────────────────────────────────────────── */
.aegis-shell > .main,
.aegis-shell > .foot { margin-left: 260px; transition: margin-left 200ms var(--aegis-ease-in-out); }
.aegis-shell:has(> .aegis-appbar) > .main { padding-top: 64px; }
.aegis-shell > .main { min-height: 100vh; min-height: 100dvh; box-sizing: border-box; }

/* The behaviour module stamps data-nav-ready once it has applied the restored
   rail preference. Until then transitions are off, so a shell that loads
   already railed does not animate open on every page load. */
.aegis-shell:not([data-nav-ready]) .aegis-sidebar,
.aegis-shell:not([data-nav-ready]) > .main,
.aegis-shell:not([data-nav-ready]) > .foot { transition: none; }

/* ── Icon rail (the persisted desktop collapse) ──────────────────────────── */
/* Scoped to the desktop rather than undone below the breakpoint. Cancelling
   these with `display: revert` instead would revert to the UA value — block —
   which reveals every collapsed panel rather than restoring the base rule. */
@media (min-width: 992px) {
  .aegis-shell.rail .aegis-sidebar { width: 70px; }
  .aegis-shell.rail > .main,
  .aegis-shell.rail > .foot { margin-left: 70px; }
  .aegis-shell.rail .aegis-nav-label,
  .aegis-shell.rail .aegis-nav-toggle > .chevron { display: none; }
  /* The expanded-panel rule further down is an equal three classes' worth of
     specificity and comes later in the file, so hiding panels in the rail has
     to out-specify it rather than merely follow it. */
  .aegis-shell.rail .aegis-nav-panel,
  .aegis-shell.rail .aegis-nav-toggle[aria-expanded="true"] + .aegis-nav-panel { display: none; }
  .aegis-shell.rail .aegis-nav-item,
  .aegis-shell.rail .aegis-nav-toggle { justify-content: center; padding-left: 0; padding-right: 0; }
  /* Visually hidden, NOT display:none — the row keeps its accessible name, and
     the title attribute the markup contract requires supplies the hover hint. */
  .aegis-shell.rail .label {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip-path: inset(50%); white-space: nowrap;
  }
}

/* ── Drawer + scrim, below the breakpoint ────────────────────────────────── */
.aegis-shell > .scrim { display: none; }
@media (max-width: 991px) {
  /* The rail is a desktop affordance; under here the aside is always a drawer,
     whether or not the persisted preference says railed. */
  .aegis-sidebar { width: 260px; transform: translateX(-100%); }
  .aegis-shell.open .aegis-sidebar { transform: translateX(0); }
  .aegis-shell > .main,
  .aegis-shell > .foot { margin-left: 0; }
  .aegis-shell.open > .scrim {
    display: block; position: fixed; inset: 0; z-index: 850; background: var(--overlay);
  }
}

/* ══ Navigation ════════════════════════════════════════════════════════════
   ONE item class and ONE group class at every depth: a level-2 disclosure is
   the same widget as a level-1 disclosure. Depth is expressed by nesting and
   indentation by descendant selectors, so arbitrary depth needs no new class
   and a filter script needs one selector per concept rather than one per level.

   Expansion is aria-expanded on the toggle, not an .open class — one source of
   truth, and the a11y state becomes load-bearing so it cannot rot. The toggle
   and its panel must therefore be ADJACENT SIBLINGS; the tag helper guarantees
   that and a test pins it.

   Active state is aria-current="page" on the leaf only; the trail of ancestor
   groups is derived with :has(). The consumer marks exactly one element, and
   the trail lights up with JavaScript disabled.                            */

.aegis-nav { padding: 10px 0; }

.aegis-nav-label {
  margin: 12px 0 4px; padding: 0 20px;
  color: var(--sidebar-foreground); opacity: 0.55;
  font-size: 10px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
}

.aegis-nav-item,
.aegis-nav-toggle {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px;
  padding: 11px 20px;
  border: 0; border-left: 3px solid transparent; background: none;
  color: inherit; font: inherit; font-size: 14px; font-weight: 500;
  text-align: left; text-decoration: none; cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease;
}
.aegis-nav-item > .icon,
.aegis-nav-toggle > .icon,
.aegis-nav-item > i,
.aegis-nav-toggle > i:first-child { flex: none; width: 20px; font-size: 15px; text-align: center; }
.aegis-nav-item > .label,
.aegis-nav-toggle > .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (hover: hover) and (pointer: fine) {
  .aegis-nav-item:hover,
  .aegis-nav-toggle:hover { background: var(--sidebar-accent); color: var(--sidebar-accent-foreground); }
}
.aegis-nav-item:focus-visible,
.aegis-nav-toggle:focus-visible { outline: 2px solid var(--sidebar-ring); outline-offset: -2px; }

.aegis-nav-item[aria-current] {
  background: var(--sidebar-accent); color: var(--sidebar-accent-foreground);
  border-left-color: var(--sidebar-primary); font-weight: 600;
}
.aegis-nav-group:has(.aegis-nav-item[aria-current]) > .aegis-nav-toggle {
  border-left-color: var(--sidebar-primary);
}

/* Chevron: CSS-drawn, for the same reason as the hamburger. */
.aegis-nav-toggle > .chevron {
  flex: none; width: 7px; height: 7px; margin-right: 3px; opacity: 0.7;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform 180ms var(--aegis-ease-in-out);
}
.aegis-nav-toggle[aria-expanded="true"] > .chevron { transform: rotate(-135deg) translate(-2px, -2px); }

/* Collapsed panels are display:none, not max-height:0 — a clipped-but-present
   panel leaves its links in the tab order and imposes a height ceiling that a
   long section silently overflows. */
.aegis-nav-panel { display: none; background: oklch(0 0 0 / 0.08); }
.aegis-nav-toggle[aria-expanded="true"] + .aegis-nav-panel {
  display: block; animation: aegis-nav-in 140ms var(--aegis-ease-out);
}
@keyframes aegis-nav-in { from { opacity: 0; transform: translateY(-4px); } }

/* Indent by depth. Three levels are defined; deeper nesting keeps level 3. */
.aegis-nav-panel > .aegis-nav-item,
.aegis-nav-panel > .aegis-nav-group > .aegis-nav-toggle { padding-left: 40px; font-size: 13px; }
.aegis-nav-panel .aegis-nav-panel > .aegis-nav-item,
.aegis-nav-panel .aegis-nav-panel > .aegis-nav-group > .aegis-nav-toggle { padding-left: 56px; }

@media (prefers-reduced-motion: reduce) {
  .aegis-sidebar,
  .aegis-shell > .main,
  .aegis-shell > .foot,
  .aegis-nav-item,
  .aegis-nav-toggle,
  .aegis-nav-toggle > .chevron { transition: none; }
  .aegis-nav-toggle[aria-expanded="true"] + .aegis-nav-panel { animation: none; }
}

/* ── Menu — a trigger that toggles a small popover of actions ─────────────────
   Presentation and mechanics only. What the items say, where they go and who
   may see them are the consumer's, per the presentation-only charter.

   Closed state is driven off the trigger's aria-expanded rather than a class,
   so a page with no JavaScript renders the menu closed instead of open, and the
   items stay out of the tab order without needing `inert`. That also makes the
   ARIA attribute the single source of truth — a class could drift from it, and
   a menu that looks closed while announcing itself open is worse than either. */
.aegis-menu { position: relative; display: inline-flex; }

.aegis-menu > .trigger {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 32px; padding: 6px 10px;
  border: 1px solid transparent; border-radius: var(--radius);
  background: none; color: inherit;
  font: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  transition: background 120ms ease, border-color 120ms ease, transform 160ms var(--aegis-ease-out);
}
/* `inherit` above, and --sidebar-accent here, so the trigger reads correctly on
   the appbar (its usual home, which is a --sidebar surface) without a second
   recipe. On a --card surface the same rule lands on the muted hover. */
@media (hover: hover) and (pointer: fine) { .aegis-menu > .trigger:hover { background: var(--sidebar-accent); color: var(--sidebar-accent-foreground); } }
.aegis-menu > .trigger:active { transform: scale(0.97); }
.aegis-menu > .trigger:focus-visible { outline: 2px solid var(--sidebar-ring); outline-offset: 2px; }
.aegis-menu > .trigger > .label {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 22ch;
}
/* CSS-drawn caret: no icon font ships here, so a control this library owns must
   not require one. A consumer may put its own icon element in instead. */
.aegis-menu > .trigger > .caret {
  flex: none; width: 8px; height: 8px; margin-left: 2px;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
  transition: transform 120ms var(--aegis-ease-in-out);
}
.aegis-menu > .trigger[aria-expanded="true"] > .caret { transform: translateY(1px) rotate(225deg); }

.aegis-menu > .panel {
  display: none;
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 1100;
  min-width: 200px; max-width: 320px; padding: 6px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card); color: var(--card-foreground);
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.18);
}
/* z-index sits above .aegis-appbar (1000) on purpose — the appbar is the menu's
   usual parent and would otherwise clip it behind the next section. */
.aegis-menu.end > .panel { left: auto; right: 0; }
.aegis-menu > .trigger[aria-expanded="true"] + .panel {
  display: block; animation: aegis-menu-in 150ms var(--aegis-ease-out);
}
@keyframes aegis-menu-in { from { opacity: 0; transform: translateY(-4px); } }

.aegis-menu > .panel > .meta {
  padding: 6px 10px 8px;
  border-bottom: 1px solid var(--border); margin-bottom: 6px;
  font-size: 12px; line-height: 1.4; color: var(--muted-foreground);
  overflow-wrap: anywhere;
}
.aegis-menu > .panel > .meta > strong {
  display: block; color: var(--card-foreground); font-size: 13px; font-weight: 600;
}

.aegis-menu > .panel > .item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 8px 10px;
  border: 0; border-radius: calc(var(--radius) - 2px);
  background: none; color: inherit;
  font: inherit; font-size: 13px; text-align: left; text-decoration: none;
  cursor: pointer;
}
@media (hover: hover) and (pointer: fine) { .aegis-menu > .panel > .item:hover { background: var(--muted); } }
.aegis-menu > .panel > .item:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; }
.aegis-menu > .panel > .item.danger { color: var(--destructive); }
.aegis-menu > .panel > .item > i {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; color: var(--muted-foreground);
}
.aegis-menu > .panel > .item.danger > i { color: inherit; }
.aegis-menu > .panel > .sep {
  height: 1px; margin: 6px 0; border: 0; background: var(--border);
}

@media (prefers-reduced-motion: reduce) {
  .aegis-menu > .trigger,
  .aegis-menu > .trigger > .caret { transition: none; }
  .aegis-menu > .trigger:active { transform: none; }
  .aegis-menu > .trigger[aria-expanded="true"] + .panel { animation: none; }
}
