/* Base styles, component classes and motion for the design system (§8.7).
   Tokens live in tokens.css; this file consumes them. Anything rendered by a
   Jinja2 macro in components/_macros.html gets its shared look from here so
   markup never re-invents it ad hoc. */

body {
  background-color: var(--surface-0);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

/* § user request: pages kept scrolling past their own content boundary on
   persistent wheel/trackpad input (the browser's default rubber-band
   overscroll, chained up to the document since the app shell's own inner
   `#main`/sidebar `<nav>` scroll regions — h-screen overflow-hidden — don't
   by themselves stop the OS-level bounce physics on `html`/`body`). This is
   the document-level half of the fix; the inner scroll regions themselves
   carry Tailwind's `overscroll-y-contain` utility directly in the layout
   templates. */
html, body {
  overscroll-behavior: none;
}

/* Visible focus indicator required by WCAG 2.1 AA keyboard navigation (§8.7);
   never remove without an equivalent replacement. */
:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

[x-cloak] {
  display: none !important;
}

/* The [hidden] attribute is this app's one show/hide mechanism (app.js's
   data-toggle / data-range-toggle handlers, the tab controller, dropdown
   panels). Its UA rule is only `display: none` at specificity 0,0,1, so ANY
   Tailwind display utility on the same element — `flex`, `grid`,
   `inline-flex` — silently wins on source order and the element stays
   visible while the attribute flips uselessly. Promote it here, same
   reasoning (and same fix) as [x-cloak] above. */
[hidden] {
  display: none !important;
}

/* § user-reported bug (companion to app.js's modal scroll lock): a modal
   panel tall enough to scroll internally would, on reaching either end,
   chain the remaining wheel delta to the page behind it — which is the
   scroll that made the background stop repainting.

   The JS lock is the primary fix; this is the belt to its braces, and it
   also covers the brief window before app.js has run. Applied by ROLE so
   every dialog gets it without touching a dozen templates, and scoped to
   the inner panel because that is the only part with `overflow-y: auto`. */
[role="dialog"][aria-modal="true"] [data-modal-panel],
[role="dialog"][aria-modal="true"] .card {
  overscroll-behavior: contain;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  background: var(--brand-strong);
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
}

.skip-link:focus {
  left: 0.5rem;
  top: 0.5rem;
}

/* Subtle scrollbars that match both themes. */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* ---------- App shell ---------- */

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

/* Below lg the sidebar becomes an off-canvas drawer; .is-open slides it in. */
@media (max-width: 1023.98px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform var(--dur-base) var(--ease-out);
    box-shadow: var(--shadow-pop);
  }

  .sidebar.is-open {
    transform: translateX(0);
  }
}

/* At lg+ the same toggle collapses the sidebar to an icon-only rail instead
   of sliding it off-canvas — a persistent desktop preference (localStorage,
   applied pre-paint by sidebar-init.js), independent of the mobile drawer's
   .is-open (which has no effect at this width). */
@media (min-width: 1024px) {
  .sidebar {
    transition: width var(--dur-base) var(--ease-out);
  }

  .sidebar.is-collapsed {
    width: var(--sidebar-w-collapsed);
  }

  .sidebar.is-collapsed .sidebar-hide-collapsed {
    display: none;
  }

  .sidebar.is-collapsed .nav-item {
    justify-content: center;
  }

  .sidebar.is-collapsed .nav-item .flex-1,
  .sidebar.is-collapsed .nav-group-label {
    display: none;
  }
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--overlay);
}

.topbar {
  height: var(--topbar-h);
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.nav-group-label {
  padding: 14px 18px 5px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 1px 10px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
  transition: background-color var(--dur-fast) ease, color var(--dur-fast) ease;
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-item.is-active {
  background: rgb(var(--brand-rgb) / 0.14);
  color: var(--brand-text);
  font-weight: 700;
}

.nav-item[aria-disabled="true"] {
  opacity: 0.45;
  pointer-events: none;
}

/* ---------- Components ---------- */

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

.btn {
  transition:
    background-color var(--dur-fast) ease,
    border-color var(--dur-fast) ease,
    color var(--dur-fast) ease,
    transform var(--dur-fast) ease;
}

.btn:active {
  transform: scale(0.97);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 10.5px;
  font-weight: 700;
  width: fit-content;
  white-space: nowrap;
}

.pill-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.icon-tile {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: var(--radius-md);
}

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: 700;
  flex-shrink: 0;
  background: rgb(var(--brand-rgb) / 0.16);
  color: var(--brand-text);
}

.input {
  background: var(--surface-2);
  /* WCAG 1.4.11: a form control's boundary is the only thing that makes
     the control perceivable, so it needs 3:1 against the surface — the
     decorative --border hairline measured 1.21:1 (dark) / 1.08:1 (light).
     Dividers and card edges keep --border; only interactive boundaries
     use the stronger token. */
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--text);
  transition: border-color var(--dur-fast) ease;
}

.input:focus-within,
.input:focus {
  border-color: var(--brand);
}

.input::placeholder {
  color: var(--text-subtle);
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 14px;
  min-height: 44px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  transition: color var(--dur-fast) ease, border-color var(--dur-fast) ease;
}

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

.tab.tab-active {
  color: var(--brand-text);
  border-bottom-color: var(--brand);
  font-weight: 700;
}

/* Cross-fade on tab switch — same [hidden]-toggle-retriggers-animation
   mechanism as .dropdown-panel below (app.js just flips [hidden]). */
[data-tab-panel]:not([hidden]) {
  animation: tab-panel-fade var(--dur-fast) var(--ease-out);
}

@keyframes tab-panel-fade {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.toast {
  border-left: 3px solid var(--border);
  box-shadow: var(--shadow-pop);
  animation: toast-in var(--dur-base) var(--ease-out);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(16px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.toast-success {
  border-left-color: var(--success);
}

.toast-success .toast-icon {
  color: var(--success-text);
}

.toast-danger {
  border-left-color: var(--danger);
}

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

.toast-warning {
  border-left-color: var(--warning);
}

.toast-warning .toast-icon {
  color: var(--warning-text);
}

.toast-info {
  border-left-color: var(--info);
}

.toast-info .toast-icon {
  color: var(--info-text);
}

/* ---------- Rich text content (§ rich text editor) ----------------------
   Tailwind's preflight strips list-style/margins/heading weight, so the
   sanitized HTML from ui.rich_text() needs its own minimal typography —
   scoped to this class only, never applied globally. */
.rich-text-content {
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text);
}

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

.rich-text-content > :last-child {
  margin-bottom: 0;
}

.rich-text-content p {
  margin: 0.6em 0;
}

.rich-text-content ul,
.rich-text-content ol {
  margin: 0.6em 0;
  padding-left: 1.5em;
}

.rich-text-content ul {
  list-style: disc;
}

.rich-text-content ol {
  list-style: decimal;
}

.rich-text-content h3,
.rich-text-content h4 {
  margin: 0.8em 0 0.3em;
  font-weight: 700;
  color: var(--text);
}

.rich-text-content h3 {
  font-size: 1.05em;
}

.rich-text-content h4 {
  font-size: 1em;
}

.rich-text-content blockquote {
  margin: 0.6em 0;
  padding-left: 0.9em;
  border-left: 3px solid var(--border);
  color: var(--text-muted);
}

.rich-text-content a {
  color: var(--brand-text);
  text-decoration: underline;
}

.rich-text-content code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 0.1em 0.35em;
}

.rich-text-content pre {
  margin: 0.6em 0;
  padding: 0.7em 0.9em;
  background: var(--surface-2);
  border-radius: var(--radius-md);
  overflow-x: auto;
}

.rich-text-content pre code {
  background: none;
  padding: 0;
}

/* ---------- Rich text editor (Quill snow theme re-skin) -----------------
   Quill's snow theme is light-only by default; this app is dark-by-default
   (§6.1), so every snow-theme surface needs a token override rather than
   the stock look. Scoped to .rich-text-editor-wrap so it never leaks into
   an unrelated third-party Quill instance elsewhere (there isn't one, but
   scoping cheaply keeps this self-contained). */
.rich-text-editor-wrap .ql-toolbar.ql-snow {
  border-color: var(--border);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  background: var(--surface-2);
}

.rich-text-editor-wrap .ql-container.ql-snow {
  border-color: var(--border);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  font-family: var(--font-sans);
  font-size: 13.5px;
  /* Quill's stock .ql-container is `height: 100%`. Every richtext field
     lives in the master form's CSS grid (_details.html's
     grid-cols-1/sm:grid-cols-2), where a percentage height resolves
     against the GRID ROW — sized from the label+toolbar, not the editor —
     so the 120px-min .ql-editor overflowed its own container and painted
     on top of the next row's labels/inputs (real bug, reported live with
     screenshots). Sizing to content is what makes the row grow instead. */
  height: auto;
}

/* Belt-and-braces for the same class of bug: the wrapper is a normal
   block that must never spill outside its grid cell. */
.rich-text-editor-wrap {
  min-width: 0;
  overflow: visible;
}

.rich-text-editor-wrap .ql-editor {
  min-height: 120px;
  color: var(--text);
  background: var(--surface-1);
}

.rich-text-editor-wrap .ql-editor.ql-blank::before {
  color: var(--text-subtle);
  font-style: normal;
}

.rich-text-editor-wrap .ql-snow .ql-stroke {
  stroke: var(--text-muted);
}

.rich-text-editor-wrap .ql-snow .ql-fill {
  fill: var(--text-muted);
}

.rich-text-editor-wrap .ql-snow .ql-picker {
  color: var(--text-muted);
}

.rich-text-editor-wrap .ql-snow .ql-picker-options {
  background: var(--surface-1);
  border-color: var(--border);
}

.rich-text-editor-wrap .ql-toolbar.ql-snow button:hover,
.rich-text-editor-wrap .ql-toolbar.ql-snow button.ql-active,
.rich-text-editor-wrap .ql-toolbar.ql-snow .ql-picker-label:hover {
  color: var(--brand-text);
}

.rich-text-editor-wrap .ql-toolbar.ql-snow button:hover .ql-stroke,
.rich-text-editor-wrap .ql-toolbar.ql-snow button.ql-active .ql-stroke {
  stroke: var(--brand-text);
}

.rich-text-editor-wrap .ql-toolbar.ql-snow button:hover .ql-fill,
.rich-text-editor-wrap .ql-toolbar.ql-snow button.ql-active .ql-fill {
  fill: var(--brand-text);
}

.rich-text-editor-wrap .ql-snow .ql-tooltip {
  background: var(--surface-1);
  border-color: var(--border);
  color: var(--text);
  box-shadow: var(--shadow-pop);
}

.rich-text-editor-wrap .ql-snow .ql-tooltip input[type="text"] {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

/* ---------- Responsive table -> stacked cards below md (§8.7) ---------- */

@media (max-width: 767.98px) {
  .responsive-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .responsive-table,
  .responsive-table tbody,
  .responsive-table tr,
  .responsive-table td {
    display: block;
    width: 100%;
  }

  .responsive-table tr {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 10px 14px;
    margin-bottom: 10px;
  }

  .responsive-table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 0;
    border: 0;
  }

  .responsive-table td::before {
    content: attr(data-label);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
  }

  .responsive-table td[data-label=""]::before {
    content: none;
  }
}

/* ---------- Motion ---------- */

/* Skeleton shimmer — a sweep of light across placeholder blocks. */
.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--surface-2);
  border-radius: var(--radius-md);
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(
    90deg,
    transparent,
    rgb(255 255 255 / 0.06),
    transparent
  );
  animation: skeleton-sweep 1.4s infinite;
}

:root[data-theme="light"] .skeleton::after {
  background: linear-gradient(
    90deg,
    transparent,
    rgb(35 39 66 / 0.07),
    transparent
  );
}

@keyframes skeleton-sweep {
  100% {
    transform: translateX(100%);
  }
}

/* Identity/landing backdrop: a soft brand glow over the app background. */
.auth-bg {
  background:
    radial-gradient(600px 320px at 85% -5%, rgb(var(--brand-rgb) / 0.10), transparent 70%),
    radial-gradient(500px 300px at 0% 100%, rgb(var(--purple-rgb) / 0.07), transparent 70%),
    var(--surface-0);
}

.hover-lift {
  transition: transform var(--dur-fast) ease, box-shadow var(--dur-fast) ease;
}

.hover-lift:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-pop);
}

/* One-shot entrance for page content and HTMX-swapped fragments. */
.page-enter {
  animation: page-enter var(--dur-base) var(--ease-out);
}

/* Staggered entrance (hero sections): both fill modes matter — backwards so
   the element is invisible before its delayed start. */
.stagger-1 { animation-delay: 60ms; animation-fill-mode: backwards; }
.stagger-2 { animation-delay: 140ms; animation-fill-mode: backwards; }
.stagger-3 { animation-delay: 220ms; animation-fill-mode: backwards; }
.stagger-4 { animation-delay: 300ms; animation-fill-mode: backwards; }

@keyframes page-enter {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- Notification bell / panel (§10) ---------- */

.notif-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  line-height: 16px;
  text-align: center;
  animation: badge-pop var(--dur-fast) var(--ease-out);
}

@keyframes badge-pop {
  from {
    opacity: 0;
    transform: scale(0.5);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Shown/hidden via the [hidden] attribute (data-toggle, app.js) — the
   animation re-triggers each time display flips from none, no JS needed. */
.dropdown-panel:not([hidden]) {
  animation: dropdown-in var(--dur-fast) var(--ease-out);
  transform-origin: top right;
}

@keyframes dropdown-in {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.notif-row {
  transition: background-color var(--dur-fast) ease;
}

/* HTMX request indicator plumbing (§8.7 hx-indicator). */
.htmx-indicator {
  display: none;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  display: block;
}

/* ---------- Backlog drag-and-drop (§ user request) ---------- */
/* The row being dragged (Product Backlog only, native HTML5 DnD via the
   Order column's handle — see app.js). Color alone never carries the
   state here (§8.7) — opacity/border/background all shift together. */
.is-dragging {
  opacity: 0.5;
}

/* Valid drop target: dropping here sets this row as the dragged item's new
   parent. */
.is-drop-target {
  background-color: rgb(var(--brand-rgb) / 0.12);
  outline: 2px solid var(--brand);
  outline-offset: -2px;
}

/* Hovering a row that would self-parent or create a cycle — refused
   client-side before ever reaching the server. */
.is-drop-invalid {
  background-color: rgb(var(--danger-rgb) / 0.1);
  outline: 2px dashed var(--danger);
  outline-offset: -2px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Query assistant (§ user request) — the floating project-scoped chat widget.
   Every colour is a token, so light and dark are both covered with no
   theme-specific overrides. */
/* § user request (corrected — the first pass had this backwards): 30%
   opacity while CLOSED, so the bubble stays unobtrusive on the page; full
   opacity once the panel is OPEN, since it's then the visual anchor for
   the visible popup. Back to 30% the moment it closes again (any way) or
   on reload. `#assistant-panel` precedes `.assistant-fab` in the DOM
   (_bubble.html), so the sibling selector below reacts directly to the
   panel's [hidden] attribute — no JS state needed, can't drift out of
   sync with however the panel actually got closed. */
.assistant-fab {
  opacity: 0.3;
  transition: transform var(--dur-fast) var(--ease-out),
              background-color var(--dur-fast) ease,
              opacity var(--dur-fast) ease;
}

.assistant-fab:hover {
  transform: translateY(-2px);
  opacity: 0.6;
}

.assistant-panel:not([hidden]) ~ .assistant-fab {
  opacity: 1;
}

.assistant-panel:not([hidden]) {
  animation: assistant-in var(--dur-fast) var(--ease-out);
  transform-origin: bottom right;
}

@keyframes assistant-in {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }
}

/* Suggestion chip. Uses --border-strong (not the decorative --border) because
   it IS the control's own boundary — WCAG 1.4.11 non-text contrast. */
.assistant-chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0.25rem 0.625rem;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
  text-align: left;
  transition: background-color var(--dur-fast) ease, border-color var(--dur-fast) ease;
}

.assistant-chip:hover {
  background: rgb(var(--brand-rgb) / 0.14);
  border-color: var(--brand);
  color: var(--brand-text);
}

/* § user request: Person-group chips are disabled until a person is picked
   in the Persona selector (app.js toggles the native `disabled` attribute
   on change) — style the state so it reads as genuinely inert, including
   suppressing the hover highlight above. */
.assistant-chip:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.assistant-chip:disabled:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
  color: var(--text);
}

/* =====================================================================
   Loaders & preloaders (§ user request, §8.7 loading state)
   ---------------------------------------------------------------------
   One visual language for every "working on it" moment: the brand teal,
   round stroke caps, and the same easing as the rest of the app. All of
   it is CSS + inline SVG — no library, no sprite, nothing extra to
   download — and every size is driven by a single custom property, so
   the same markup scales from a 14px button glyph to a full-screen
   overlay on any device.

   Motion is transform/opacity ONLY (compositor-friendly: no layout or
   paint per frame), so a loader never competes for the main thread with
   the work it is waiting on. Reduced-motion overrides close this block.
   ===================================================================== */

/* ---------- 1. Page progress bar ----------
   Shown for full-page navigations and for every HTMX request.
   Indeterminate: it eases toward ~90% while the server works, then
   completes and fades. Fixed to the top, above everything, never
   interactive. */
.page-progress {
  position: fixed;
  inset-inline: 0;
  top: 0;
  height: 3px;
  z-index: 100;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--dur-base) ease;
}

.page-progress.is-active {
  opacity: 1;
}

.page-progress__bar {
  position: relative;
  height: 100%;
  width: 0;
  border-start-end-radius: 3px;
  border-end-end-radius: 3px;
  background: linear-gradient(
    90deg,
    var(--brand-stronger),
    var(--brand),
    var(--brand-text)
  );
  box-shadow:
    0 0 10px rgb(var(--brand-rgb) / 0.75),
    0 0 3px rgb(var(--brand-rgb) / 0.9);
  transition: width var(--dur-base) cubic-bezier(0.22, 1, 0.36, 1);
}

/* Leading edge: a brighter comet head, so progress still reads on a very
   thin bar and does not rely on the gradient alone. */
.page-progress__bar::after {
  content: "";
  position: absolute;
  inset-block: 0;
  inset-inline-end: 0;
  width: 90px;
  border-start-end-radius: 3px;
  border-end-end-radius: 3px;
  background: linear-gradient(90deg, transparent, rgb(255 255 255 / 0.55));
}

/* ---------- 2. Ring spinner ----------
   Three concentric arcs turning at different speeds, the middle one in
   reverse. Sized by --spinner-size (default 24px). */
.spinner {
  display: inline-block;
  width: var(--spinner-size, 24px);
  height: var(--spinner-size, 24px);
  flex: none;
  vertical-align: middle;
  color: var(--brand-text);
}

.spinner__ring {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  transform-origin: 50% 50%;
  animation: spinner-turn 1.4s linear infinite;
}

.spinner__ring--outer {
  stroke-width: 4;
  stroke-dasharray: 66 132;
  opacity: 0.95;
}

.spinner__ring--mid {
  stroke-width: 4;
  stroke-dasharray: 34 84;
  opacity: 0.6;
  animation-duration: 1s;
  animation-direction: reverse;
}

.spinner__ring--inner {
  stroke-width: 3.5;
  stroke-dasharray: 14 30;
  opacity: 0.4;
  animation-duration: 0.7s;
}

@keyframes spinner-turn {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- 3. Brand overlay preloader ----------
   For a genuinely blocking wait. The product mark flips on its Y axis (a
   real 3D transform, hence the perspective on its parent) inside a
   turning ring. Covers its nearest positioned ancestor, or the viewport
   with the --fixed modifier. */
.loader-overlay {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1.5rem;
  text-align: center;
  /* Opaque first, translucent second: a browser without color-mix() drops
     the second declaration and keeps a solid scrim, which still hides the
     content behind it. Never the other way round — an unsupported value
     there would leave the overlay fully transparent. */
  background: var(--surface-0);
  background: color-mix(in srgb, var(--surface-0) 82%, transparent);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.loader-overlay--fixed {
  position: fixed;
}

.loader-overlay__mark {
  position: relative;
  display: grid;
  place-items: center;
  width: 84px;
  height: 84px;
  perspective: 220px;
}

.loader-overlay__face {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: var(--radius-lg);
  background: rgb(var(--brand-rgb) / 0.16);
  color: var(--brand-text);
  font-size: 24px;
  animation: loader-flip 2.4s cubic-bezier(0.65, 0, 0.35, 1) infinite;
}

.loader-overlay__ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  color: var(--brand-text);
}

.loader-overlay__label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

@keyframes loader-flip {
  0%,
  15% {
    transform: rotateY(0deg);
  }
  50%,
  65% {
    transform: rotateY(180deg);
  }
  100% {
    transform: rotateY(360deg);
  }
}

/* ---------- 4. Success checkmark shield ----------
   The confirmation counterpart to the loaders above: the shield outline
   draws itself, then the check strokes in. Both are stroke-dash
   animations, so they stay crisp at any size. */
.success-check {
  display: inline-block;
  width: var(--check-size, 72px);
  height: var(--check-size, 72px);
  color: var(--success-text);
}

.success-check__shield,
.success-check__mark {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.success-check__shield {
  stroke-width: 3.5;
  stroke-dasharray: 150;
  stroke-dashoffset: 150;
  animation: check-draw 0.7s ease forwards;
}

.success-check__mark {
  stroke-width: 4;
  stroke-dasharray: 30;
  stroke-dashoffset: 30;
  animation: check-draw 0.4s 0.55s ease forwards;
}

@keyframes check-draw {
  to {
    stroke-dashoffset: 0;
  }
}

/* ---------- 5. Search pulse ----------
   Expanding arcs — the "scanning for something" shape, for a wait that is
   a lookup rather than a load. */
.search-pulse {
  display: inline-block;
  width: var(--pulse-size, 40px);
  height: var(--pulse-size, 40px);
  color: var(--brand-text);
}

.search-pulse__wave {
  fill: none;
  stroke: currentColor;
  stroke-width: 4;
  stroke-linecap: round;
  transform-origin: 50% 85%;
  opacity: 0;
  animation: pulse-out 1.8s ease-out infinite;
}

.search-pulse__wave:nth-of-type(2) {
  animation-delay: 0.3s;
}

.search-pulse__wave:nth-of-type(3) {
  animation-delay: 0.6s;
}

.search-pulse__dot {
  fill: currentColor;
}

@keyframes pulse-out {
  0% {
    opacity: 0;
    transform: scale(0.35);
  }
  35% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: scale(1);
  }
}

/* ---------- 6. Busy buttons ----------
   A form mid-submit shows its submit button working and refuses a second
   submit (see app.js) — the double-submit guard is as much about not
   creating the same record twice as it is about feedback. The button is
   never given `disabled`: that drops its own name/value from the POST,
   which several forms here depend on (the assistant's chips, for one). */
.btn[aria-busy="true"] {
  position: relative;
  pointer-events: none;
}

.btn[aria-busy="true"] > * {
  visibility: hidden;
}

.btn[aria-busy="true"]::after {
  content: "";
  position: absolute;
  width: 1.15em;
  height: 1.15em;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  animation: spinner-turn 0.65s linear infinite;
}

/* ---------- Reduced motion ----------
   The global reset earlier in this file stops every animation after one
   iteration — right for decoration, wrong for a loader, which would
   freeze and then convey nothing at all. These keep saying "still
   working" with a slow opacity breath instead: no rotation, no scaling,
   nothing vestibular. `!important` is needed only to override that
   same-strength global reset. */
@media (prefers-reduced-motion: reduce) {
  .spinner__ring,
  .search-pulse__wave,
  .loader-overlay__face,
  .btn[aria-busy="true"]::after {
    animation: loader-breathe 1.6s ease-in-out infinite !important;
    transform: none !important;
  }

  .success-check__shield,
  .success-check__mark {
    stroke-dashoffset: 0 !important;
    animation: none !important;
  }

  .page-progress__bar {
    transition: none !important;
  }
}

@keyframes loader-breathe {
  0%,
  100% {
    opacity: 0.35;
  }
  50% {
    opacity: 1;
  }
}
