/* ============================================================================
   Semantik Blazor UI — design system
   Ported from Semantik-chat-ui-sdk-v3 (src/index.css tokens + the Tailwind classes
   used across the SDK components): shadcn/ui token contract, assistant-ui layout.
   Colour tokens are declared per family in themes.css (status colours in base.css);
   this file only consumes them.
   ========================================================================= */

/* Blazor's built-in error banner: hidden unless the runtime sets display:block. */
#blazor-error-ui {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--card);
  color: var(--foreground);
  font-size: 0.875rem;
}

#blazor-error-ui .dismiss { cursor: pointer; position: absolute; top: 0.5rem; right: 0.9rem; }

/* ----------------------------------------------------------------------------
   Non-colour tokens.

   The palettes live in themes.css (one block per family and mode). Only the non-colour
   variables are declared below: radius, sidebar metrics and
   the font stacks. Everything else is consumed as a complete colour, e.g.
   `background: var(--background)` or
   `background: color-mix(in srgb, var(--card) 70%, transparent)`.
   ---------------------------------------------------------------------------- */

:root {
  color-scheme: light;

  /* sm- prefixed: a host shell (Blazor Blueprint) has its own --sm-sidebar-width. */
  --sm-sidebar-width: 16rem;
  --sm-sidebar-width-collapsed: 4rem;
  /* Font stacks (--font-sans, --font-heading, --font-mono) and the reading tokens are declared
     once, in typography.css. */
}

/* With an external theme the host owns --radius (external-tokens.css only gives a fallback). */
:root:not([data-sm-theme="external"]) {
  --radius: 0.625rem;             /* tighter than library default — modern product feel */
}

/* Dark mode: colour values come from themes.css; only the colour scheme is set here. */

.dark {
  color-scheme: dark;

}

/* ----------------------------------------------------------------------------
   Scope. Every rule of the SDK is either sm- prefixed or confined to the chat surface,
   :where(.sm-root, .sm-scope), so a host shell (its own design system, its own Tailwind build)
   is never restyled: unlayered rules here would beat every one of the host's layers. .sm-root is
   the SemantikChat surface; .sm-scope gives the same base to SDK parts a host renders on their
   own. :where() keeps each rule's original specificity. The document reset (box-sizing, margins,
   button fonts) is base.css, in @layer base.
   ---------------------------------------------------------------------------- */

@layer base {
  html, body { height: 100%; }
  body { min-height: 100vh; -webkit-font-smoothing: antialiased; }
}

:where(.sm-root, .sm-scope) {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

:where(.sm-root, .sm-scope) a { color: var(--primary); }

:where(.sm-root, .sm-scope) :focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }

/* Explicit rings for the controls that paint over the shared surface (filled buttons, pills,
   popover rows) or live inside a clipping container, where the UA default is invisible. Every
   other focusable element inherits the rule above. */
.sm-button:focus-visible,
.sm-button--primary:focus-visible,
.sm-button--ghost:focus-visible,
.sm-button--danger:focus-visible,
.sm-icon-button:focus-visible,
.sm-session__select:focus-visible,
.sm-suggestion:focus-visible,
.sm-marker:focus-visible,
.sm-theme-menu__item:focus-visible,
.sm-composer__send:focus-visible,
.sm-usage__trigger:focus-visible,
.sm-code__copy:focus-visible,
.sm-step__detail-toggle:focus-visible,
.ui-collapsible-trigger:focus-visible,
#blazor-error-ui .dismiss:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
/* Rows that sit inside a clipping or rounded parent keep the ring inside their own box. */
.sm-code__copy:focus-visible,
.sm-theme-menu__item:focus-visible { outline-offset: -2px; }

:where(.sm-root, .sm-scope), :where(.sm-root, .sm-scope) * { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--muted-foreground) calc(0.3 * 100%), transparent) transparent; }
:where(.sm-root, .sm-scope) ::-webkit-scrollbar { width: 8px; height: 8px; }
:where(.sm-root, .sm-scope) ::-webkit-scrollbar-track { background: transparent; }
:where(.sm-root, .sm-scope) ::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--muted-foreground) calc(0.3 * 100%), transparent); border-radius: 999px; }
:where(.sm-root, .sm-scope) ::-webkit-scrollbar-thumb:hover { background: color-mix(in srgb, var(--muted-foreground) calc(0.5 * 100%), transparent); }

/* ── Utilities (small subset used by the ported markup) ─────────────────── 
   Confined to the chat surface: the same class names in a host's Tailwind build (hidden, flex,
   text-sm…) keep their own values outside it. */

:where(.sm-root, .sm-scope) .flex { display: flex; }
:where(.sm-root, .sm-scope) .inline-flex { display: inline-flex; }
:where(.sm-root, .sm-scope) .grid { display: grid; }
:where(.sm-root, .sm-scope) .hidden { display: none; }
:where(.sm-root, .sm-scope) .relative { position: relative; }
:where(.sm-root, .sm-scope) .absolute { position: absolute; }
:where(.sm-root, .sm-scope) .items-center { align-items: center; }
:where(.sm-root, .sm-scope) .items-start { align-items: flex-start; }
:where(.sm-root, .sm-scope) .items-end { align-items: flex-end; }
:where(.sm-root, .sm-scope) .justify-between { justify-content: space-between; }
:where(.sm-root, .sm-scope) .justify-center { justify-content: center; }
:where(.sm-root, .sm-scope) .justify-end { justify-content: flex-end; }
:where(.sm-root, .sm-scope) .flex-col { flex-direction: column; }
:where(.sm-root, .sm-scope) .flex-wrap { flex-wrap: wrap; }
:where(.sm-root, .sm-scope) .flex-1 { flex: 1 1 0%; }
:where(.sm-root, .sm-scope) .shrink-0 { flex-shrink: 0; }
:where(.sm-root, .sm-scope) .min-w-0 { min-width: 0; }
:where(.sm-root, .sm-scope) .min-h-0 { min-height: 0; }
:where(.sm-root, .sm-scope) .gap-1 { gap: 0.25rem; }
:where(.sm-root, .sm-scope) .gap-2 { gap: 0.5rem; }
:where(.sm-root, .sm-scope) .gap-3 { gap: 0.75rem; }
:where(.sm-root, .sm-scope) .gap-4 { gap: 1rem; }
:where(.sm-root, .sm-scope) .w-full { width: 100%; }
:where(.sm-root, .sm-scope) .h-full { height: 100%; }
:where(.sm-root, .sm-scope) .h-screen { height: 100vh; }
:where(.sm-root, .sm-scope) .text-center { text-align: center; }
:where(.sm-root, .sm-scope) .text-right { text-align: right; }
:where(.sm-root, .sm-scope) .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
:where(.sm-root, .sm-scope) .whitespace-pre-wrap { white-space: pre-wrap; }
:where(.sm-root, .sm-scope) .break-all { word-break: break-all; }
:where(.sm-root, .sm-scope) .cursor-pointer { cursor: pointer; }
:where(.sm-root, .sm-scope) .select-none { user-select: none; }
:where(.sm-root, .sm-scope) .uppercase { text-transform: uppercase; }
:where(.sm-root, .sm-scope) .font-medium { font-weight: 500; }
:where(.sm-root, .sm-scope) .font-semibold { font-weight: 600; }
:where(.sm-root, .sm-scope) .font-bold { font-weight: 700; }
:where(.sm-root, .sm-scope) .font-mono { font-family: var(--font-mono); }
:where(.sm-root, .sm-scope) .text-xs { font-size: 0.75rem; line-height: 1.4; }
:where(.sm-root, .sm-scope) .text-sm { font-size: 0.8125rem; line-height: 1.5; }
:where(.sm-root, .sm-scope) .text-base { font-size: 1rem; }
:where(.sm-root, .sm-scope) .text-lg { font-size: 1.125rem; }
:where(.sm-root, .sm-scope) .text-2xl { font-size: 1.5rem; line-height: 1.25; }
:where(.sm-root, .sm-scope) .tracking-tight { letter-spacing: -0.015em; }
:where(.sm-root, .sm-scope) .tracking-wide { letter-spacing: 0.06em; }
:where(.sm-root, .sm-scope) .tracking-wider { letter-spacing: 0.1em; }
:where(.sm-root, .sm-scope) .leading-6 { line-height: 1.5rem; }
:where(.sm-root, .sm-scope) .leading-7 { line-height: 1.75rem; }
:where(.sm-root, .sm-scope) .mx-auto { margin-inline: auto; }
:where(.sm-root, .sm-scope) .ml-auto { margin-left: auto; }
:where(.sm-root, .sm-scope) .mt-1 { margin-top: 0.25rem; }
:where(.sm-root, .sm-scope) .mt-2 { margin-top: 0.5rem; }
:where(.sm-root, .sm-scope) .mt-4 { margin-top: 1rem; }
:where(.sm-root, .sm-scope) .mb-1 { margin-bottom: 0.25rem; }
:where(.sm-root, .sm-scope) .mb-2 { margin-bottom: 0.5rem; }
:where(.sm-root, .sm-scope) .mb-3 { margin-bottom: 0.75rem; }
:where(.sm-root, .sm-scope) .text-foreground { color: var(--foreground); }
:where(.sm-root, .sm-scope) .text-muted { color: var(--muted-foreground); }
:where(.sm-root, .sm-scope) .text-primary { color: var(--primary); }
:where(.sm-root, .sm-scope) .text-destructive { color: var(--destructive); }
:where(.sm-root, .sm-scope) .text-success { color: var(--success); }
:where(.sm-root, .sm-scope) .text-emerald { color: #10b981; }
:where(.sm-root, .sm-scope) .bg-card { background: var(--card); }
:where(.sm-root, .sm-scope) .bg-muted { background: var(--muted); }
:where(.sm-root, .sm-scope) .bg-transparent { background: transparent; }
:where(.sm-root, .sm-scope) .border { border: 1px solid var(--border); }
:where(.sm-root, .sm-scope) .border-b { border-bottom: 1px solid var(--border); }
:where(.sm-root, .sm-scope) .border-t { border-top: 1px solid var(--border); }
:where(.sm-root, .sm-scope) .rounded-md { border-radius: calc(var(--radius) - 2px); }
:where(.sm-root, .sm-scope) .rounded-lg { border-radius: var(--radius); }
:where(.sm-root, .sm-scope) .rounded-xl { border-radius: calc(var(--radius) + 4px); }
:where(.sm-root, .sm-scope) .rounded-2xl { border-radius: calc(var(--radius) + 8px); }
:where(.sm-root, .sm-scope) .rounded-3xl { border-radius: calc(var(--radius) + 14px); }
:where(.sm-root, .sm-scope) .rounded-full { border-radius: 999px; }
:where(.sm-root, .sm-scope) .shadow-sm { box-shadow: 0 1px 2px hsl(240 10% 3% / 0.16); }
:where(.sm-root, .sm-scope) .shadow-md { box-shadow: 0 8px 24px hsl(240 10% 3% / 0.22); }
:where(.sm-root, .sm-scope) .transition { transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease, opacity 150ms ease, transform 150ms ease; }
:where(.sm-root, .sm-scope) .overflow-hidden { overflow: hidden; }
:where(.sm-root, .sm-scope) .overflow-auto { overflow: auto; }
:where(.sm-root, .sm-scope) .opacity-75 { opacity: 0.75; }
:where(.sm-root, .sm-scope) .z-10 { z-index: 10; }
:where(.sm-root, .sm-scope) .z-30 { z-index: 30; }
:where(.sm-root, .sm-scope) .animate-spin { animation: sm-spin 1s linear infinite; }
:where(.sm-root, .sm-scope) .animate-bounce { animation: sm-bounce 1.1s infinite; }
:where(.sm-root, .sm-scope) .animate-ping { animation: sm-ping 1.6s cubic-bezier(0, 0, 0.2, 1) infinite; }
:where(.sm-root, .sm-scope) .animate-fade-in { animation: fadeIn 260ms ease-out both; }
:where(.sm-root, .sm-scope) .animate-activity-enter { animation: activityEnter 320ms ease-out both; }

@keyframes sm-spin { to { transform: rotate(360deg); } }
@keyframes sm-bounce { 0%, 100% { transform: translateY(-18%); } 50% { transform: translateY(0); } }
@keyframes sm-ping { 0% { transform: scale(1); opacity: 0.75; } 70%, 100% { transform: scale(2); opacity: 0; } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideIn { from { opacity: 0; transform: translateX(-20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes activityEnter { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: translateX(0); } }
/* aurora-move-1/2 removed with the aurora layers — the standard theme has no moving backdrop. */
@keyframes sm-usage-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@keyframes caret-blink { 0%, 45% { opacity: 1; } 50%, 100% { opacity: 0; } }
@keyframes skeleton-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ============================================================================
   Chat shell (SemantikChat.jsx + ChatLayout)
   ========================================================================= */

.sm-root {
  position: relative;
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--background);
  color: var(--foreground);
}
/* Inside a host shell (no built-in sidebar): fill the shell's content area, not the viewport. */
.sm-root--embedded { height: 100%; min-height: 0; }

/* The bespoke aurora background layers were removed with the theme rework: the library's
   standard theme is a flat surface, so .sm-effects and ThemeEffects.razor are gone. */

.sm-sidebar {
  position: relative;
  z-index: 20;
  display: flex;
  flex-direction: column;
  width: var(--sm-sidebar-width);
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: color-mix(in srgb, var(--card) calc(0.7 * 100%), transparent);
  backdrop-filter: blur(12px);
  transition: width 300ms ease;
}
.sm-sidebar--collapsed { width: var(--sm-sidebar-width-collapsed); }

.sm-main { position: relative; z-index: 10; display: flex; flex: 1; min-width: 0; flex-direction: column; }

/* ── Sidebar internals ─────────────────────────────────────────────────── */

.sm-sidebar__brand { display: flex; align-items: center; gap: 0.625rem; padding: 0.75rem; border-bottom: 1px solid var(--border); }
.sm-sidebar__brand-mark {
  display: flex; align-items: center; justify-content: center;
  width: 2rem; height: 2rem; flex-shrink: 0;
  border-radius: var(--radius);
  background: var(--primary); color: var(--primary-foreground);
}
.sm-sidebar__brand-copy { min-width: 0; }
.sm-sidebar__brand-title { font-size: 0.875rem; font-weight: 600; }
.sm-sidebar__brand-subtitle { font-size: 0.6875rem; color: var(--muted-foreground); }

.sm-sidebar__toolbar { display: flex; align-items: center; gap: 0.5rem; padding: 0.75rem; }
.sm-sidebar__toolbar--flush { padding-top: 0; }
.sm-sidebar__new-chat { flex: 1; }
.sm-sidebar__search {
  display: flex; align-items: center; gap: 0.5rem; flex: 1; min-width: 0;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--background) calc(0.6 * 100%), transparent);
  color: var(--muted-foreground);
}
.sm-sidebar__search input { flex: 1; min-width: 0; border: 0; background: transparent; color: var(--foreground); font-size: 0.8125rem; }
.sm-sidebar__search input:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; border-radius: calc(var(--radius) - 6px); }
.sm-sidebar__scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 0 0.5rem 0.75rem; }
.sm-sidebar__list { padding: 0.5rem; }
.sm-sidebar__group-label {
  padding: 0.5rem 0.5rem 0.25rem;
  font-size: 0.6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em;
  color: color-mix(in srgb, var(--muted-foreground) calc(0.8 * 100%), transparent);
}

.sm-session {
  position: relative; display: flex; align-items: center; gap: 0.5rem; width: 100%;
  padding: 0.5rem 0.55rem;
  border: 1px solid transparent; border-radius: var(--radius);
  background: transparent; text-align: left; cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease;
}
.sm-session:hover { background: color-mix(in srgb, var(--muted) calc(0.6 * 100%), transparent); }
.sm-session + .sm-session { margin-top: 0.125rem; }
.sm-session--active { background: color-mix(in srgb, var(--muted) calc(0.85 * 100%), transparent); border-color: var(--border); }

/* The row is a plain container so the select control and the row actions can be siblings
   (a <button> may not contain the rename input or the action buttons). This is the control
   that actually selects the session, so it carries the reset plus its own focus ring. */
.sm-session__select {
  display: flex; align-items: center; gap: 0.5rem;
  flex: 1; min-width: 0;
  padding: 0; border: 0; background: transparent; color: inherit;
  font: inherit; text-align: left; cursor: pointer;
}
.sm-session__select:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }
.sm-session__body { min-width: 0; flex: 1; }
.sm-session__title { font-size: 0.8125rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sm-session__meta { display: flex; align-items: center; gap: 0.375rem; font-size: 0.6875rem; color: var(--muted-foreground); }
.sm-session__preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sm-session__actions { display: flex; align-items: center; gap: 0.125rem; opacity: 0; transition: opacity 150ms ease; }
.sm-session:hover .sm-session__actions { opacity: 1; }
.sm-session__rename {
  flex: 1; min-width: 0;
  padding: 0.25rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 4px);
  background: var(--background);
  color: var(--foreground);
  font-size: 0.8125rem;
}
.sm-session__rename:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }

.sm-sidebar__footer { border-top: 1px solid var(--border); padding: 0.75rem; }
.sm-profile { display: flex; align-items: center; gap: 0.6rem; }
.sm-profile__avatar {
  display: flex; align-items: center; justify-content: center;
  width: 1.875rem; height: 1.875rem;
  border-radius: 999px; background: var(--muted);
  border: 1px solid var(--border); font-size: 0.75rem; font-weight: 600;
}
.sm-profile__name { font-size: 0.8125rem; font-weight: 500; }
.sm-profile__role { font-size: 0.6875rem; color: var(--muted-foreground); }

/* ── Header ───────────────────────────────────────────────────────────── */

.sm-header {
  position: sticky; top: 0; z-index: 30;
  display: flex; height: 3.5rem; flex-shrink: 0; align-items: center; justify-content: space-between;
  gap: 0.75rem; padding: 0 1rem;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--card) calc(0.8 * 100%), transparent);
  backdrop-filter: blur(12px);
}
.sm-header__left { display: flex; align-items: center; gap: 0.625rem; min-width: 0; }
.sm-header__badge {
  display: flex; align-items: center; justify-content: center;
  width: 2rem; height: 2rem; border-radius: var(--radius);
  background: color-mix(in srgb, var(--primary) calc(0.12 * 100%), transparent); color: var(--primary);
}
.sm-header__title { font-size: 1rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sm-header__subtitle { font-size: 0.6875rem; color: var(--muted-foreground); }
.sm-header__actions { display: flex; align-items: center; gap: 0.5rem; }

.sm-icon-button {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.75rem; height: 1.75rem;
  border: 1px solid transparent; border-radius: calc(var(--radius) - 2px);
  background: transparent; color: var(--muted-foreground); cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}
.sm-icon-button:hover { background: var(--muted); color: var(--foreground); }
.sm-icon-button--danger:hover { color: var(--destructive); }
.sm-icon-button--lg { width: 2.25rem; height: 2.25rem; border-color: var(--border); background: var(--card); }
.sm-icon-button--push { margin-left: auto; }

.sm-pill {
  display: inline-flex; align-items: center; gap: 0.375rem; height: 2rem; padding: 0 0.75rem;
  border: 1px solid var(--border); border-radius: 999px;
  background: color-mix(in srgb, var(--card) calc(0.85 * 100%), transparent); font-size: 0.75rem; color: var(--foreground); white-space: nowrap;
}
.sm-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  height: 2rem; padding: 0 0.9rem;
  border: 1px solid var(--border); border-radius: calc(var(--radius) - 2px);
  background: var(--card); font-size: 0.8125rem; cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease;
}
.sm-button:hover { background: var(--muted); }
.sm-button--primary { background: var(--primary); color: var(--primary-foreground); border-color: transparent; font-weight: 600; }
.sm-button--primary:hover { background: color-mix(in srgb, var(--primary) calc(0.9 * 100%), transparent); }
.sm-button--ghost { background: transparent; border-color: transparent; color: var(--muted-foreground); }
.sm-button--ghost:hover { background: var(--muted); color: var(--foreground); }
.sm-button--danger { color: var(--destructive); }
.sm-button--danger:hover { background: color-mix(in srgb, var(--destructive) calc(0.18 * 100%), transparent); }
.sm-button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Thread ───────────────────────────────────────────────────────────── */

.sm-thread { flex: 1; min-height: 0; overflow-y: auto; padding: 1.5rem 1.25rem 0.5rem; }
.sm-thread__inner { display: flex; flex-direction: column; gap: 1.25rem; max-width: 56rem; margin-inline: auto; }

.sm-row { display: flex; gap: 0.85rem; width: 100%; }
.sm-row--user { justify-content: flex-end; }
.sm-avatar {
  display: flex; align-items: center; justify-content: center;
  width: 2rem; height: 2rem; flex-shrink: 0; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--muted); color: var(--foreground);
}
.sm-avatar--assistant { background: color-mix(in srgb, var(--primary) calc(0.12 * 100%), transparent); color: var(--primary); border-color: color-mix(in srgb, var(--primary) calc(0.25 * 100%), transparent); }

.sm-message { flex: 1; min-width: 0; max-width: 48rem; }
.sm-message__head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.2rem; }
.sm-message__author { font-size: 0.8125rem; font-weight: 600; }
.sm-message__time { font-size: 0.6875rem; color: var(--muted-foreground); }
.sm-message__body { color: var(--foreground); } /* size and leading: typography.css */
.sm-message__actions { display: flex; align-items: center; gap: 0.125rem; opacity: 0; transition: opacity 150ms ease; }
.sm-message:hover .sm-message__actions { opacity: 1; }

/* One width cap, on .sm-user-col (80% of the thread, as assistant-ui and ChatGPT): capping the
   bubble again inside it shrank it to ~64% and forced wraps inside words. */
.sm-bubble-user {
  max-width: 100%; margin-left: auto; padding: 0.65rem 1rem;
  border-radius: calc(var(--radius) + 8px);
  background: var(--primary); color: var(--primary-foreground);
  box-shadow: 0 1px 2px hsl(240 10% 3% / 0.18);
}
.sm-user-meta { display: flex; align-items: center; justify-content: flex-end; gap: 0.5rem; padding: 0 0.25rem; min-height: 1.5rem; }
.sm-user-meta__time { font-size: 0.6875rem; color: var(--muted-foreground); opacity: 0; transition: opacity 150ms ease; }
.sm-row--user:hover .sm-user-meta__time { opacity: 1; }

/* The user column stacks the bubble over its meta line, and keeps the copy/delete controls at the
   bubble's trailing edge. `.sm-user-actions` mirrors `.sm-message__actions`: hidden until the row
   is hovered or holds focus, so the copy/delete buttons stay invisible but keyboard-reachable. */
.sm-user-col { display: flex; flex-direction: column; align-items: flex-end; gap: 0.25rem; max-width: 80%; margin-left: auto; }
.sm-user-actions { display: inline-flex; align-items: center; gap: 0.125rem; opacity: 0; transition: opacity 150ms ease; }
.sm-row--user:hover .sm-user-actions,
.sm-row--user:focus-within .sm-user-actions { opacity: 1; }

/* Composing placeholder (TypingDots) — a shimmer label over skeleton lines. */
.sm-pending { display: flex; flex-direction: column; gap: 0.45rem; padding: 0.35rem 0 0.5rem; }
.sm-pending__label { font-size: 0.75rem; font-weight: 500; }
.sm-pending__bars { display: flex; flex-direction: column; gap: 0.4rem; }

.sm-caret {
  display: inline-block; width: 0.5rem; height: 1.05rem; margin-left: 0.15rem;
  vertical-align: text-bottom; background: var(--primary);
  animation: caret-blink 1s steps(1) infinite;
}

/* ── Thinking ─────────────────────────────────────────────────────────────
   One quiet line when settled (marker + summary + chevron), with the reasoning notes and the
   activity steps behind it. No panel, no eyebrow, no badge pills. */

.sm-thought { margin-bottom: 0.35rem; }
.sm-thought__collapsible { display: block; }
.sm-thought .ui-collapsible-trigger {
  width: auto; max-width: 100%; gap: 0.4rem;
  margin-left: -0.35rem; padding: 0.2rem 0.45rem 0.2rem 0.3rem;
  border-radius: 999px; color: var(--muted-foreground);
  font-size: 0.75rem; font-weight: 500;
  transition: background-color 150ms ease, color 150ms ease;
}
.sm-thought .ui-collapsible-trigger:hover { background: color-mix(in srgb, var(--muted) calc(0.45 * 100%), transparent); color: var(--foreground); }
.sm-thought__marker {
  display: inline-flex; flex-shrink: 0; align-items: center; justify-content: center;
  width: 0.9rem; height: 0.9rem; color: var(--muted-foreground);
}
.sm-thought[data-state="streaming"] .sm-thought__marker { color: var(--primary); }
.sm-thought[data-state="idle"] .sm-thought__marker { color: var(--success); }
.sm-thought__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sm-thought__chevron { flex-shrink: 0; opacity: 0.5; transition: transform 220ms cubic-bezier(0.16, 1, 0.3, 1); }
.sm-thought__collapsible[data-state="open"] .sm-thought__chevron { transform: rotate(90deg); }
.sm-thought__body {
  margin: 0.2rem 0 0.35rem 0.5rem;
  padding: 0.35rem 0 0.15rem 0.7rem;
  border-left: 1px solid color-mix(in srgb, var(--border) calc(0.6 * 100%), transparent);
}

/* Steps — a flat list of marker + title lines (see ActivityRow). */
.sm-steps { display: flex; flex-direction: column; gap: 0.05rem; }
.sm-steps__label {
  padding: 0.3rem 0.35rem 0.15rem;
  font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.01em;
  color: color-mix(in srgb, var(--muted-foreground) calc(0.85 * 100%), transparent);
}

.sm-badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.1rem 0.5rem;
  border: 1px solid var(--border); border-radius: 999px;
  background: color-mix(in srgb, var(--muted) calc(0.6 * 100%), transparent);
  font-size: 0.6875rem; color: var(--muted-foreground); white-space: nowrap;
}
.sm-badge--primary { border-color: color-mix(in srgb, var(--primary) calc(0.3 * 100%), transparent); background: color-mix(in srgb, var(--primary) calc(0.12 * 100%), transparent); color: var(--primary); }
/* Status colours come from the theme's own success/warning/info/destructive tokens rather
   than hand-picked hexes, so they follow the active skin (and light/dark) automatically. */
.sm-badge--success { border-color: color-mix(in srgb, var(--success) calc(0.35 * 100%), transparent); background: color-mix(in srgb, var(--success) calc(0.12 * 100%), transparent); color: var(--success); }
.sm-badge--danger { border-color: color-mix(in srgb, var(--destructive) calc(0.45 * 100%), transparent); background: color-mix(in srgb, var(--destructive) calc(0.16 * 100%), transparent); color: var(--destructive); }
.sm-badge--warning { border-color: color-mix(in srgb, var(--warning) calc(0.4 * 100%), transparent); background: color-mix(in srgb, var(--warning) calc(0.14 * 100%), transparent); color: var(--warning); }
.sm-badge--info { border-color: color-mix(in srgb, var(--info) calc(0.4 * 100%), transparent); background: color-mix(in srgb, var(--info) calc(0.14 * 100%), transparent); color: var(--info); }

/* Reasoning notes: plain quiet prose. The thinking body already draws the rule that groups the
   notes with the steps, so this needs no box of its own. */
.sm-reasoning {
  margin: 0 0 0.6rem;
  font-size: 0.8125rem; line-height: 1.7; color: var(--muted-foreground); white-space: pre-wrap;
}
.sm-reasoning + .sm-steps { margin-top: 0.15rem; }
/* In the chronological timeline a note sits between steps: breathing room on both sides, none at the edges. */
.sm-steps--tree > .sm-reasoning { margin: 0.35rem 0 0.4rem; padding-left: 0.35rem; }
.sm-steps--tree > .sm-reasoning:first-child { margin-top: 0; }
.sm-steps--tree > .sm-reasoning:last-child { margin-bottom: 0; }

/* ── Activity steps ───────────────────────────────────────────────────────
   A step is one line: marker, title, muted meta. The marker carries the state (spinner, check,
   cross, dot), so nothing needs a border, an icon disc or a status pill. */

.sm-step-block { display: block; }
.sm-step {
  display: flex; align-items: center; gap: 0.45rem;
  padding: 0.22rem 0.35rem;
  border-radius: calc(var(--radius) - 4px);
  font-size: 0.8125rem; line-height: 1.5;
  transition: background-color 150ms ease;
}
.sm-step:hover { background: color-mix(in srgb, var(--muted) calc(0.35 * 100%), transparent); }
.sm-step__marker {
  display: inline-flex; flex-shrink: 0; align-items: center; justify-content: center;
  width: 0.85rem; height: 0.85rem;
  color: var(--muted-foreground);
}
.sm-step[data-status="running"] .sm-step__marker,
.sm-step[data-status="queued"] .sm-step__marker { color: var(--primary); }
.sm-step[data-status="completed"] .sm-step__marker { color: var(--success); }
.sm-step[data-status="failed"] .sm-step__marker,
.sm-step[data-status="blocked"] .sm-step__marker { color: var(--destructive); }
.sm-step__dot { width: 0.3rem; height: 0.3rem; border-radius: 999px; background: currentColor; opacity: 0.6; }
.sm-step__title { color: var(--foreground); }
.sm-step[data-status="completed"] .sm-step__title { color: var(--muted-foreground); }
.sm-step[data-status="failed"] .sm-step__title,
.sm-step[data-status="blocked"] .sm-step__title { color: var(--destructive); }
.sm-step__meta {
  font-size: 0.6875rem; font-weight: 400; font-variant-numeric: tabular-nums;
  color: color-mix(in srgb, var(--muted-foreground) calc(0.85 * 100%), transparent);
}
/* Plain style: "Read table · SFLIGHT, SCARR". The subjects continue the title's sentence. */
.sm-step__subjects { margin-left: -0.45rem; min-width: 0; color: var(--muted-foreground); white-space: pre-wrap; overflow-wrap: anywhere; }
.sm-step__subject[data-failed="true"] { color: var(--destructive); }
.sm-step__spacer { flex: 1; }
.sm-step__detail-toggle {
  padding: 0 0.15rem; border: 0; background: transparent;
  font-size: 0.6875rem; color: var(--muted-foreground); cursor: pointer;
  text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 2px;
  transition: color 150ms ease;
}
.sm-step__detail-toggle:hover { color: var(--foreground); }
.sm-step__detail {
  margin: 0.15rem 0.35rem 0.4rem 1.3rem;
  padding: 0.4rem 0.55rem;
  border-radius: calc(var(--radius) - 2px);
  background: color-mix(in srgb, var(--muted) calc(0.4 * 100%), transparent);
  font-family: var(--font-mono); font-size: 0.6875rem; line-height: 1.6;
  color: var(--muted-foreground); white-space: pre-wrap; word-break: break-word;
}
/* ── Markdown prose ───────────────────────────────────────────────────────
   Sizes, rhythm, headings, lists and inline code live in typography.css (the reading layer);
   only the table frame is drawn here. */

.sm-prose a { color: var(--primary); text-decoration: underline; text-underline-offset: 2px; }
.sm-prose hr { border: 0; border-top: 1px solid var(--border); }
.sm-prose table {
  width: 100%; border-collapse: collapse; overflow: hidden;
  border: 1px solid var(--border); border-radius: calc(var(--radius) + 2px);
}
.sm-prose th { border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--muted) calc(0.9 * 100%), transparent); text-align: left; }
.sm-prose td { border-top: 1px solid color-mix(in srgb, var(--border) calc(0.6 * 100%), transparent); vertical-align: top; }
.sm-prose tbody tr:hover { background: color-mix(in srgb, var(--muted) calc(0.25 * 100%), transparent); }
.sm-prose__table-wrap { overflow-x: auto; }

/* ── Code block ───────────────────────────────────────────────────────── */

.sm-code { margin: 1rem 0; overflow: hidden; border: 1px solid var(--border); border-radius: calc(var(--radius) + 4px); background: var(--muted); }
.sm-code__head {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  padding: 0.6rem 1rem; border-bottom: 1px solid var(--border);
  font-size: 0.6875rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted-foreground);
}
.sm-code__copy {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--border); border-radius: calc(var(--radius) - 2px);
  background: var(--card); color: var(--foreground);
  font-size: 0.75rem; text-transform: none; letter-spacing: normal; cursor: pointer;
  transition: background-color 150ms ease;
}
.sm-code__copy:hover { background: var(--muted); }
.sm-code pre {
  margin: 0; padding: 1rem; overflow-x: auto;
  font-family: var(--font-mono); font-size: 0.8125rem; line-height: 1.7;
  color: var(--foreground); background: color-mix(in srgb, var(--background) calc(0.35 * 100%), transparent);
}
.sm-code code { font-family: inherit; }

/* Syntax highlighting token colours live in prism-theme.css (light + dark), generated by
   tools/vendor-prism.mjs. Nothing hljs-* remains: Prism emits `token` classes instead. */

/* ── Mermaid ──────────────────────────────────────────────────────────── */

.sm-mermaid { margin: 1rem 0; overflow: hidden; border: 1px solid var(--border); border-radius: calc(var(--radius) + 4px); background: color-mix(in srgb, var(--card) calc(0.7 * 100%), transparent); }
.sm-mermaid__head {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  padding: 0.6rem 1rem; border-bottom: 1px solid var(--border);
  font-size: 0.6875rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted-foreground);
}
.sm-mermaid__canvas { padding: 1rem; display: flex; justify-content: center; min-height: 5rem; overflow-x: auto; }
.sm-mermaid__canvas svg { max-width: 100%; height: auto; }
.sm-mermaid__fallback { margin: 0; padding: 1rem; font-family: var(--font-mono); font-size: 0.75rem; color: var(--muted-foreground); white-space: pre-wrap; }
.sm-mermaid__error { padding: 0.6rem 1rem; border-top: 1px solid var(--border); font-size: 0.75rem; color: #fbbf24; }

/* ── Artifacts & content items ────────────────────────────────────────── */

.sm-artifact {
  margin: 1rem 0; overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--border) calc(0.8 * 100%), transparent); border-radius: calc(var(--radius) + 8px);
  background: color-mix(in srgb, var(--card) calc(0.8 * 100%), transparent); box-shadow: 0 1px 2px hsl(240 10% 3% / 0.16);
}
.sm-artifact__head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 0.75rem;
  padding: 0.75rem 1rem; border-bottom: 1px solid color-mix(in srgb, var(--border) calc(0.7 * 100%), transparent);
}
.sm-artifact__title { display: flex; align-items: center; gap: 0.5rem; font-size: 0.875rem; font-weight: 600; }
.sm-artifact__subtitle { font-size: 0.6875rem; color: var(--muted-foreground); }
.sm-artifact__body { padding: 0.85rem 1rem; font-size: 0.8125rem; color: var(--muted-foreground); }
.sm-artifact__actions { display: flex; align-items: center; gap: 0.375rem; }

.sm-gallery { display: grid; gap: 0.6rem; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); }
.sm-gallery__item { overflow: hidden; border: 1px solid color-mix(in srgb, var(--border) calc(0.7 * 100%), transparent); border-radius: calc(var(--radius) + 2px); background: color-mix(in srgb, var(--background) calc(0.6 * 100%), transparent); }
.sm-gallery__media { display: flex; align-items: center; justify-content: center; width: 100%; height: 7.5rem; object-fit: cover; background: var(--muted); color: var(--muted-foreground); font-size: 0.75rem; }
.sm-gallery__caption { padding: 0.5rem 0.6rem; font-size: 0.6875rem; color: var(--muted-foreground); }

.sm-card-grid { display: grid; gap: 0.6rem; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); }
.sm-card {
  padding: 0.75rem 0.85rem;
  border: 1px solid color-mix(in srgb, var(--border) calc(0.7 * 100%), transparent); border-radius: calc(var(--radius) + 2px);
  background: color-mix(in srgb, var(--background) calc(0.55 * 100%), transparent);
  transition: border-color 150ms ease, background-color 150ms ease;
}
.sm-card:hover { border-color: color-mix(in srgb, var(--primary) calc(0.35 * 100%), transparent); background: color-mix(in srgb, var(--muted) calc(0.35 * 100%), transparent); }
.sm-card__title { display: flex; align-items: center; gap: 0.4rem; font-size: 0.8125rem; font-weight: 600; color: var(--foreground); }
.sm-card__domain { display: flex; align-items: center; gap: 0.4rem; font-size: 0.6875rem; color: var(--muted-foreground); }
.sm-card__snippet { margin-top: 0.35rem; font-size: 0.75rem; line-height: 1.6; color: var(--muted-foreground); }
.sm-card a { text-decoration: none; color: inherit; }

/* ── Sources (citation group) ─────────────────────────────────────────────
   One line when collapsed: label + overlapping favicons + "+N" + chevron, using the
   avatar group. Expanding reveals slim source rows rather than a grid of cards. */

.sm-sources { margin: 0.75rem 0 0.1rem; }
.sm-sources__collapsible { display: block; }
.sm-sources .ui-collapsible-trigger {
  width: auto; max-width: 100%;
  margin-left: -0.4rem; padding: 0.2rem 0.45rem;
  border-radius: 999px; color: var(--muted-foreground);
  font-size: 0.75rem; font-weight: 500;
  transition: background-color 150ms ease, color 150ms ease;
}
.sm-sources .ui-collapsible-trigger:hover { background: color-mix(in srgb, var(--muted) calc(0.5 * 100%), transparent); color: var(--foreground); }
.sm-sources__label { white-space: nowrap; }
.sm-sources__avatars { margin-left: 0.1rem; }
.sm-sources__chevron { flex-shrink: 0; opacity: 0.55; transition: transform 220ms cubic-bezier(0.16, 1, 0.3, 1); }
.sm-sources__collapsible[data-state="open"] .sm-sources__chevron { transform: rotate(180deg); }

.sm-sources__list {
  display: flex; flex-direction: column; gap: 0.05rem;
  margin: 0.45rem 0 0; padding: 0.4rem 0 0;
  border-top: 1px solid color-mix(in srgb, var(--border) calc(0.5 * 100%), transparent);
  list-style: none;
}
.sm-source > a {
  display: flex; align-items: flex-start; gap: 0.5rem;
  padding: 0.35rem 0.45rem;
  border-radius: calc(var(--radius) - 2px);
  color: inherit; text-decoration: none;
  transition: background-color 150ms ease;
}
.sm-source > a:hover { background: color-mix(in srgb, var(--muted) calc(0.4 * 100%), transparent); }
.sm-source__index {
  flex-shrink: 0; width: 1rem; padding-top: 0.15rem;
  font-size: 0.625rem; font-variant-numeric: tabular-nums;
  color: color-mix(in srgb, var(--muted-foreground) calc(0.75 * 100%), transparent); text-align: right;
}
.sm-source__text { display: flex; flex-direction: column; min-width: 0; flex: 1; gap: 0.02rem; }
.sm-source__title {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 0.8125rem; font-weight: 500; line-height: 1.35;
  color: var(--foreground);
}
.sm-source__domain { font-size: 0.6875rem; line-height: 1.35; color: var(--muted-foreground); }
.sm-source__snippet {
  display: grid; grid-template-rows: 0fr; visibility: hidden;
  font-size: 0.75rem; line-height: 1.55; color: color-mix(in srgb, var(--muted-foreground) calc(0.9 * 100%), transparent);
  transition: grid-template-rows 220ms ease, visibility 0s linear 220ms;
}
.sm-source__snippet > span { overflow: hidden; }
.sm-source > a:hover .sm-source__snippet,
.sm-source > a:focus-visible .sm-source__snippet {
  grid-template-rows: 1fr; visibility: visible;
  transition: grid-template-rows 220ms ease, visibility 0s;
}
.sm-source__open { flex-shrink: 0; padding-top: 0.2rem; opacity: 0; color: var(--muted-foreground); transition: opacity 150ms ease; }
.sm-source > a:hover .sm-source__open,
.sm-source > a:focus-visible .sm-source__open { opacity: 1; }

/* Inline citation marker — one citation inside prose, sized to the line. */
.sm-marker {
  display: inline-flex; align-items: center; gap: 0.3rem;
  margin: 0 0.15rem; padding: 0.05rem 0.5rem 0.05rem 0.15rem;
  border: 1px solid color-mix(in srgb, var(--border) calc(0.7 * 100%), transparent); border-radius: 999px;
  background: color-mix(in srgb, var(--muted) calc(0.35 * 100%), transparent);
  font-size: 0.6875rem; color: var(--muted-foreground); text-decoration: none;
  vertical-align: middle; transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}
.sm-marker:hover { background: var(--muted); border-color: color-mix(in srgb, var(--primary) calc(0.35 * 100%), transparent); color: var(--foreground); }
.sm-marker__avatar { width: 1.15rem; height: 1.15rem; }
.sm-marker__avatar::after { border-color: transparent; }
.sm-marker__label { max-width: 12rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  .sm-sources__chevron,
  .sm-source__snippet,
  .sm-source__open { transition: none; }
}

.sm-comparison { overflow-x: auto; }
.sm-comparison table { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }
.sm-comparison th, .sm-comparison td { padding: 0.45rem 0.65rem; border: 1px solid color-mix(in srgb, var(--border) calc(0.6 * 100%), transparent); text-align: left; }
.sm-comparison thead th { background: color-mix(in srgb, var(--muted) calc(0.8 * 100%), transparent); font-weight: 600; }

.sm-chart { padding: 0.75rem 1rem 1rem; }
.sm-chart__bars { display: grid; gap: 0.55rem; }
.sm-chart__row { display: grid; grid-template-columns: 3.5rem 1fr 5.5rem; align-items: center; gap: 0.6rem; font-size: 0.75rem; }
.sm-chart__label { color: var(--muted-foreground); font-family: var(--font-mono); }
.sm-chart__track { height: 0.5rem; border-radius: 999px; background: color-mix(in srgb, var(--muted) calc(0.7 * 100%), transparent); overflow: hidden; }
.sm-chart__fill { height: 100%; border-radius: 999px; background: var(--chart-1); }
.sm-chart__value { text-align: right; color: var(--foreground); font-variant-numeric: tabular-nums; }

/* ── Approval ─────────────────────────────────────────────────────────── */

/* v4 GenericApprovalCard: a quiet bordered card; only the pending state is tinted, and the
   status is always stated in words next to its colour dot. */
.sm-approval {
  --approval-accent: hsl(38 92% 50%);
  margin: 0.75rem 0; overflow: hidden;
  border: 1px solid var(--border); border-radius: calc(var(--radius) + 6px);
  background: var(--card);
  box-shadow: 0 1px 2px hsl(240 10% 3% / 0.06);
  outline: none;
}
.sm-approval:focus-visible { box-shadow: 0 0 0 2px var(--ring); }
.sm-approval--pending { border-color: color-mix(in srgb, var(--approval-accent) 45%, var(--border)); }
.sm-approval--pending .sm-approval__head { background: color-mix(in srgb, var(--approval-accent) 7%, transparent); border-bottom: 1px solid color-mix(in srgb, var(--approval-accent) 25%, var(--border)); }
.sm-approval__head { display: flex; align-items: flex-start; gap: 0.75rem; padding: 0.8rem 1rem; }
.sm-approval__icon {
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 2rem; height: 2rem; border-radius: calc(var(--radius) - 2px);
  background: var(--muted); color: var(--muted-foreground);
}
.sm-approval--pending .sm-approval__icon { background: color-mix(in srgb, var(--approval-accent) 16%, transparent); color: var(--approval-accent); }
.sm-approval--completed .sm-approval__icon { background: color-mix(in srgb, hsl(152 60% 40%) 14%, transparent); color: hsl(152 60% 40%); }
.sm-approval__heading { flex: 1; min-width: 0; }
.sm-approval__eyebrow { font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted-foreground); }
.sm-approval__title { margin-top: 0.1rem; font-size: 0.9375rem; font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; }
.sm-approval__description { margin-top: 0.25rem; font-size: 0.8125rem; line-height: 1.55; color: var(--muted-foreground); }
.sm-approval__status { display: inline-flex; align-items: center; gap: 0.4rem; flex-shrink: 0; padding-top: 0.2rem; font-size: 0.75rem; color: var(--muted-foreground); white-space: nowrap; }
.sm-approval__dot { width: 0.5rem; height: 0.5rem; border-radius: 999px; background: var(--muted-foreground); }
.sm-approval__dot--pending, .sm-approval__dot--ambiguous { background: var(--approval-accent); }
.sm-approval__dot--resuming { background: hsl(199 89% 48%); animation: sm-pulse 1.4s ease-in-out infinite; }
.sm-approval__dot--waiting { background: hsl(199 89% 48%); }
.sm-approval__dot--completed { background: hsl(152 60% 42%); }
.sm-approval__dot--failed { background: var(--destructive); }
.sm-approval__params { margin: 0; padding: 0.25rem 1rem; }
.sm-approval__param {
  display: grid; grid-template-columns: minmax(7rem, 0.8fr) minmax(0, 2fr); gap: 0.25rem 1rem;
  padding: 0.55rem 0; border-top: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}
.sm-approval__param:first-child { border-top: 0; }
.sm-approval__param-name { font-size: 0.75rem; font-weight: 500; color: var(--muted-foreground); }
.sm-approval__param-description { display: block; margin-top: 0.1rem; font-weight: 400; }
.sm-approval__param-value { margin: 0; min-width: 0; font-size: 0.8125rem; color: var(--foreground); overflow-wrap: anywhere; }
.sm-approval__code, .sm-approval__pre {
  display: block; margin: 0; padding: 0.4rem 0.6rem;
  border: 1px solid var(--border); border-radius: calc(var(--radius) - 4px);
  background: color-mix(in srgb, var(--muted) 45%, transparent);
  font-family: var(--font-mono); font-size: 0.75rem; white-space: pre-wrap; word-break: break-all;
}
.sm-approval__pre { max-height: 16rem; overflow: auto; margin-top: 0.4rem; }
.sm-approval__more summary {
  display: inline-flex; align-items: center; gap: 0.25rem; min-height: 1.75rem;
  cursor: pointer; list-style: none; font-size: 0.75rem; font-weight: 500; color: var(--muted-foreground);
}
.sm-approval__more summary::-webkit-details-marker { display: none; }
.sm-approval__more[open] summary svg { transform: rotate(180deg); }
.sm-approval__more summary:hover { color: var(--foreground); }
.sm-approval__error { margin: 0; padding: 0.5rem 1rem; font-size: 0.8125rem; color: var(--destructive); }
.sm-approval__actions {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  padding: 0.65rem 1rem; border-top: 1px solid var(--border);
}
.sm-approval__spacer { flex: 1; }
.sm-approval__expiry { display: inline-flex; align-items: center; gap: 0.25rem; font-size: 0.6875rem; color: var(--muted-foreground); }
.sm-approval__reason {
  flex: 1 1 14rem; min-width: 10rem; height: 2rem; padding: 0 0.7rem;
  border: 1px solid var(--border); border-radius: calc(var(--radius) - 2px);
  background: var(--background); color: var(--foreground); font-size: 0.8125rem;
}
.sm-approval__reason:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }
@media (max-width: 640px) {
  .sm-approval__param { grid-template-columns: 1fr; }
  .sm-approval__actions .sm-button { flex: 1; min-height: 2.5rem; }
  .sm-approval__spacer { display: none; }
}

/* v4 ApprovalTray: every pending approval, grouped above the composer, one compact card at a time. */
.sm-approval-tray {
  max-width: 48rem; margin: 0 auto 0.5rem;
  animation: sm-rise 180ms ease-out;
}
.sm-approval-tray__head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 0.4rem; }
.sm-approval-tray__title { display: inline-flex; align-items: center; gap: 0.45rem; font-size: 0.8125rem; font-weight: 600; }
.sm-approval-tray__title svg { color: hsl(38 92% 50%); }
.sm-approval-tray__count { padding: 0.05rem 0.45rem; border-radius: 999px; background: var(--muted); font-size: 0.6875rem; font-weight: 500; color: var(--muted-foreground); }
.sm-approval-tray__nav { display: inline-flex; align-items: center; gap: 0.15rem; }
.sm-approval-tray__nav .sm-icon-button:disabled { opacity: 0.3; pointer-events: none; }
.sm-approval-tray__nav .sm-button { margin-left: 0.5rem; }
.sm-approval-tray__position { min-width: 2.5rem; text-align: center; font-size: 0.75rem; color: var(--muted-foreground); font-variant-numeric: tabular-nums; }
.sm-approval--compact { margin: 0; }
.sm-approval--compact .sm-approval__head { padding: 0.55rem 0.85rem; }
.sm-approval--compact .sm-approval__icon { width: 1.75rem; height: 1.75rem; }
.sm-approval--compact .sm-approval__title { margin-top: 0; font-size: 0.875rem; }
.sm-approval--compact .sm-approval__params { max-height: 12rem; overflow: auto; padding: 0.15rem 0.85rem; }
.sm-approval--compact .sm-approval__actions { padding: 0.5rem 0.85rem; }

/* ── Empty state ──────────────────────────────────────────────────────── */

.sm-empty {
  display: flex; flex: 1; flex-direction: column; align-items: center; justify-content: center; gap: 0.25rem;
  max-width: 48rem; margin-inline: auto; padding: 3.5rem 1.5rem; text-align: center;
}
.sm-empty__mark {
  display: flex; align-items: center; justify-content: center;
  width: 3rem; height: 3rem; margin-bottom: 1.25rem;
  border-radius: calc(var(--radius) + 10px);
  background: color-mix(in srgb, var(--primary) calc(0.12 * 100%), transparent); color: var(--primary);
}
.sm-empty__title { font-size: 1.5rem; font-weight: 600; letter-spacing: -0.015em; }
.sm-empty__body { margin-top: 0.5rem; max-width: 34rem; font-size: 0.875rem; line-height: 1.65; color: var(--muted-foreground); }
.sm-empty__suggestions { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.6rem; margin-top: 2rem; max-width: 42rem; }
.sm-suggestion {
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--border); border-radius: 999px;
  background: color-mix(in srgb, var(--muted) calc(0.5 * 100%), transparent); font-size: 0.8125rem; color: var(--foreground);
  cursor: pointer; transition: background-color 150ms ease, border-color 150ms ease, transform 150ms ease;
}
.sm-suggestion:hover { background: var(--muted); border-color: color-mix(in srgb, var(--primary) calc(0.35 * 100%), transparent); transform: translateY(-1px); }

/* ── Composer ─────────────────────────────────────────────────────────── */

.sm-composer-wrap { padding: 0.75rem 1.25rem 1.25rem; }
.sm-composer {
  max-width: 48rem; margin-inline: auto;
  border: 1px solid var(--border); border-radius: calc(var(--radius) + 14px);
  background: var(--card); box-shadow: 0 1px 2px hsl(240 10% 3% / 0.18);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.sm-composer:focus-within { border-color: color-mix(in srgb, var(--ring) calc(0.5 * 100%), transparent); box-shadow: 0 0 0 1px color-mix(in srgb, var(--ring) calc(0.2 * 100%), transparent); }
.sm-composer__input {
  width: 100%; max-height: 14rem; min-height: 2.75rem;
  padding: 0.9rem 1rem 0.5rem;
  border: 0; background: transparent; color: var(--foreground);
  font-family: inherit; font-size: 0.9375rem; line-height: 1.5rem; resize: none;
}
/* The visible focus ring for the composer is drawn by .sm-composer:focus-within, above, so the
   textarea opts out of the global :focus-visible outline (a textarea always matches it, which
   drew a square box inside the rounded pill). */
.sm-composer__input:focus,
.sm-composer__input:focus-visible { outline: none; }
.sm-composer__input::placeholder { color: var(--muted-foreground); }
.sm-composer__footer { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0 0.75rem 0.75rem; }
.sm-composer__hint { font-size: 0.6875rem; color: var(--muted-foreground); }
.sm-composer__send {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.25rem; height: 2.25rem; border: 0; border-radius: 999px;
  background: var(--primary); color: var(--primary-foreground);
  cursor: pointer; transition: opacity 150ms ease, transform 150ms ease;
}
.sm-composer__send { margin-left: auto; } /* stays at the end when the hint is visually hidden and no tools render */
.sm-composer__send:disabled { opacity: 0.45; cursor: not-allowed; }
.sm-composer__send--stop { background: var(--foreground); color: var(--background); }
.sm-composer__send:not(:disabled):hover { transform: scale(1.04); }
/* Footer tools (model picker, host controls): fill the space left of the send button. */
.sm-composer__tools { display: flex; align-items: center; justify-content: flex-start; gap: 0.25rem; flex: 1 1 auto; min-width: 0; }

/* ── Token usage panel ────────────────────────────────────────────────── */

.sm-usage { position: relative; }
.sm-usage__trigger {
  display: inline-flex; align-items: center; gap: 0.5rem; height: 2rem; padding: 0 0.75rem;
  border: 1px solid var(--border); border-radius: calc(var(--radius) - 2px);
  background: color-mix(in srgb, var(--card) calc(0.85 * 100%), transparent); font-size: 0.75rem; cursor: pointer;
}
.sm-usage__dot { width: 0.5rem; height: 0.5rem; border-radius: 999px; background: var(--primary); animation: sm-usage-pulse 1.5s ease-in-out infinite; }
.sm-usage__panel {
  position: absolute; top: calc(100% + 0.5rem); right: 0; z-index: 40; width: 21rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border); border-radius: calc(var(--radius) + 6px);
  background: var(--popover); box-shadow: 0 18px 40px hsl(240 10% 3% / 0.4);
}
/* A quiet popover (shadcn): sections split by hairlines, sentence-case headings, label/value
   rows in two columns with tabular figures. No tiles, bars or uppercase micro-labels. */
.sm-usage__stat { display: inline-flex; align-items: center; gap: 0.2rem; font-variant-numeric: tabular-nums; }
.sm-usage__stat svg { color: var(--muted-foreground); }
.sm-usage__section { padding: 0.75rem 0; border-bottom: 1px solid var(--border); }
.sm-usage__section:first-child { padding-top: 0.15rem; }
.sm-usage__head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.75rem; margin-bottom: 0.45rem; }
.sm-usage__head h2 { margin: 0; font-size: 0.8125rem; font-weight: 600; color: var(--foreground); }
.sm-usage__head span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.75rem; color: var(--muted-foreground); }
.sm-usage__stats { display: grid; grid-template-columns: 1fr 1fr; gap: 0.3rem 1.25rem; margin: 0; }
.sm-usage__row { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; font-size: 0.75rem; }
.sm-usage__row dt { color: var(--muted-foreground); }
.sm-usage__row dd { display: inline-flex; align-items: baseline; gap: 0.35rem; margin: 0; color: var(--foreground); }
.sm-usage__num { font-variant-numeric: tabular-nums; }
.sm-usage__muted { color: var(--muted-foreground); font-size: 0.6875rem; }
.sm-usage__models { display: grid; gap: 0.3rem; margin: 0; padding: 0; list-style: none; }
.sm-usage__models li { display: grid; grid-template-columns: minmax(0, 1fr) auto 2.75rem; gap: 0.75rem; align-items: baseline; font-size: 0.75rem; }
.sm-usage__models .sm-usage__muted { text-align: right; }
.sm-usage__model { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--foreground); }
.sm-usage__total { display: flex; align-items: baseline; justify-content: space-between; padding-top: 0.7rem; font-size: 0.8125rem; color: var(--muted-foreground); }
.sm-usage__total strong { font-weight: 600; color: var(--foreground); }

.sm-usage__empty { margin: 0; font-size: 0.75rem; color: var(--muted-foreground); }

/* ── Theme switcher ───────────────────────────────────────────────────── */

.sm-theme-menu {
  position: absolute; top: calc(100% + 0.5rem); right: 0; z-index: 40; width: 13rem;
  padding: 0.35rem;
  border: 1px solid var(--border); border-radius: calc(var(--radius) + 4px);
  background: var(--popover); box-shadow: 0 18px 40px hsl(240 10% 3% / 0.4);
}
.sm-theme-menu__item {
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  width: 100%; padding: 0.45rem 0.6rem;
  border: 0; border-radius: calc(var(--radius) - 2px); background: transparent;
  font-size: 0.8125rem; cursor: pointer; text-align: left;
}
.sm-theme-menu__item:hover { background: var(--muted); }
.sm-theme-menu__item--active { background: color-mix(in srgb, var(--muted) calc(0.85 * 100%), transparent); }
.sm-theme-menu__swatch { width: 0.85rem; height: 0.85rem; border-radius: 999px; border: 1px solid var(--border); background: conic-gradient(from 210deg, var(--primary), var(--ring), var(--card), var(--primary)); }
.sm-theme-menu__divider { height: 1px; margin: 0.3rem 0; background: var(--border); }

/* ============================================================================
   UI primitives (Components/Ui)
   Our own primitives, shadcn/Radix contract: a data-slot marker on every root, a ui-* hook
   class for skinning, and data-* attributes for state (data-size, data-animation,
   data-state). Animation knobs stay overridable through the --ui-shimmer-* properties.
   ========================================================================= */

/* Avatar: size-8/6/10 via data-size, inner border painted over the image. */
.ui-avatar {
  position: relative; display: flex; flex-shrink: 0; align-items: center; justify-content: center;
  width: 2rem; height: 2rem; overflow: hidden; border-radius: 999px;
  background: var(--muted); color: var(--muted-foreground);
  font-size: 0.75rem; font-weight: 600; user-select: none;
}
.ui-avatar::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  border: 1px solid var(--border); pointer-events: none;
}
.ui-avatar[data-size="sm"] { width: 1.5rem; height: 1.5rem; font-size: 0.625rem; }
.ui-avatar[data-size="lg"] { width: 2.5rem; height: 2.5rem; font-size: 0.875rem; }
.ui-avatar-image { width: 100%; height: 100%; object-fit: cover; }
.ui-avatar-fallback { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; }

/* Avatar group: half-rem overlap plus a ring in the page background colour,
   so a stack of favicons reads as separate discs on one line. */
.ui-avatar-group { display: flex; align-items: center; }
.ui-avatar-group > * + * { margin-left: -0.5rem; }
.ui-avatar-group > * {
  box-shadow: 0 0 0 2px var(--background);
  transition: transform 150ms ease;
}
.ui-avatar-group > *:hover { transform: translateY(-2px); position: relative; z-index: 1; }
.ui-avatar-group-count {
  display: flex; flex-shrink: 0; align-items: center; justify-content: center;
  min-width: 1.5rem; height: 1.5rem; padding: 0 0.3rem; border-radius: 999px;
  background: var(--muted); color: var(--muted-foreground);
  font-size: 0.625rem; font-weight: 600; font-variant-numeric: tabular-nums;
}

/* Skeleton: data-animation shimmer (default) | pulse | none. */
.ui-skeleton {
  position: relative; display: block; overflow: hidden;
  width: 100%; height: 0.75rem;
  border-radius: calc(var(--radius) - 2px); background: var(--muted);
}
.ui-skeleton[data-animation="shimmer"]::after {
  content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, var(--ui-shimmer-color, color-mix(in srgb, var(--foreground) calc(0.07 * 100%), transparent)), transparent);
  animation: ui-shimmer var(--ui-shimmer-duration, 1.6s) infinite linear;
}
.ui-skeleton[data-animation="pulse"] { animation: ui-pulse 1.8s ease-in-out infinite; }
.ui-skeleton--line { height: 0.6rem; border-radius: 999px; }
@keyframes ui-shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
@keyframes ui-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

/* Shimmer (text mode): a highlight travelling across glyphs.
   Used for the live "thinking" line instead of a spinner-only busy state. */
.ui-shimmer {
  background-image: linear-gradient(90deg,
      var(--muted-foreground) 0%, var(--muted-foreground) 38%,
      var(--foreground) 50%,
      var(--muted-foreground) 62%, var(--muted-foreground) 100%);
  background-size: 220% 100%;
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
  animation: ui-shimmer-text var(--ui-shimmer-duration, 1.6s) linear infinite;
}
@keyframes ui-shimmer-text { from { background-position: 130% 0; } to { background-position: -130% 0; } }

/* Spinner: one busy indicator for the whole app, coloured by currentColor. */
.ui-spinner {
  display: inline-flex; flex-shrink: 0; align-items: center; justify-content: center;
  color: currentColor; animation: ui-spin 0.9s linear infinite;
}
@keyframes ui-spin { to { transform: rotate(360deg); } }

/* Collapsible (Components/Ui/Collapsible*.razor): the root owns data-state; the content animates
   its height with grid rows (0fr -> 1fr), so nothing is measured in script, and it is inert while
   closed. Callers style the trigger through Class="ui-collapsible-trigger". */
.ui-collapsible-trigger {
  display: flex; align-items: center; gap: 0.5rem; width: 100%;
  padding: 0; border: 0; background: transparent; text-align: left; cursor: pointer;
}
.ui-collapsible-trigger:disabled { cursor: not-allowed; }
.ui-collapsible-content {
  display: grid; grid-template-rows: 0fr; opacity: 0;
  transition: grid-template-rows 220ms cubic-bezier(0.16, 1, 0.3, 1), opacity 160ms ease;
}
.ui-collapsible-content[data-state="open"] { grid-template-rows: 1fr; opacity: 1; }
.ui-collapsible-inner { min-height: 0; overflow: hidden; }
@media (prefers-reduced-motion: reduce) { .ui-collapsible-content { transition: none; } }

/* Every primitive animation, entrance and blinking busy indicator sits out under reduced motion. */
@media (prefers-reduced-motion: reduce) {
  .ui-spinner,
  .ui-skeleton[data-animation="pulse"],
  .ui-skeleton[data-animation="shimmer"]::after,
  :where(.sm-root, .sm-scope) .animate-activity-enter,
  :where(.sm-root, .sm-scope) .animate-fade-in,
  .sm-caret,
  .sm-pending__dots,
  .sm-usage__dot { animation: none; }
  .ui-shimmer {
    animation: none; background-image: none;
    -webkit-text-fill-color: currentColor; color: var(--muted-foreground);
  }
  .ui-avatar-group > *:hover { transform: none; }
}

/* ── Error / loading / misc ───────────────────────────────────────────── */

.sm-error {
  display: flex; align-items: center; gap: 0.5rem;
  margin: 0 auto 0.5rem; max-width: 48rem; padding: 0.45rem 0.5rem 0.45rem 0.85rem;
  border: 1px solid color-mix(in srgb, var(--destructive) 45%, var(--border)); border-radius: calc(var(--radius) + 2px);
  background: color-mix(in srgb, var(--destructive) 8%, var(--card)); font-size: 0.8125rem; color: var(--destructive);
  animation: sm-rise 180ms ease-out;
}
.sm-error__text { flex: 1; min-width: 0; color: var(--foreground); }
/* Aliases for the ported sm-* names — both resolve to the primitives above, so the
   existing markup keeps the same shimmer and spin timings. */
.sm-skeleton {
  position: relative; display: block; overflow: hidden;
  height: 0.75rem; border-radius: 999px; background: var(--muted);
}
.sm-skeleton--row { margin-bottom: 0.5rem; }
.sm-skeleton::after {
  content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--foreground) calc(0.07 * 100%), transparent), transparent);
  animation: ui-shimmer 1.6s infinite linear;
}
.sm-spinner {
  display: inline-flex; align-items: center; justify-content: center;
  color: currentColor; animation: ui-spin 0.9s linear infinite;
}
.sm-run-banner {
  display: flex; align-items: center; gap: 0.5rem;
  margin: 0 auto 0.5rem; max-width: 48rem; padding: 0.5rem 0.75rem;
  border: 1px solid color-mix(in srgb, var(--border) calc(0.7 * 100%), transparent); border-radius: calc(var(--radius) + 2px);
  background: color-mix(in srgb, var(--muted) calc(0.35 * 100%), transparent); font-size: 0.75rem; color: var(--muted-foreground);
}
.sm-live-region { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.sm-visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; }

/* ── Responsive layout ───────────────────────────────────────────────────
   Desktop (>=1281px) is untouched: every rule below applies only once the chat shell has less
   room than the sidebar plus the 56rem transcript and the usage panel need on one line. */

@media (max-width: 1280px) {
  .sm-thread { padding: 1.25rem 1rem 0.5rem; }
  .sm-thread__inner { max-width: 48rem; gap: 1.1rem; }
  .sm-usage__panel { width: 18rem; }
  .sm-theme-menu { max-width: min(13rem, calc(100vw - 2rem)); }
}

@media (max-width: 1024px) {
  /* The sidebar stops being a column and becomes an overlay drawer; its collapsed state hides it
     completely so the transcript keeps the full width. */
  .sm-sidebar {
    position: absolute; top: 0; left: 0; bottom: 0;
    width: min(var(--sm-sidebar-width), calc(100vw - 4rem));
    box-shadow: 0 18px 40px hsl(240 10% 3% / 0.4);
  }
  .sm-sidebar--collapsed { display: none; }
  .sm-thread { padding: 1rem 0.9rem 0.5rem; }
  .sm-thread__inner { max-width: 100%; }
  .sm-header { padding: 0 0.85rem; }
  .sm-composer-wrap { padding: 0.6rem 0.9rem 1rem; }
  .sm-sources { margin: 0.6rem 0 0.1rem; }
  .sm-approval__param { grid-template-columns: 7rem 1fr; }
}

@media (max-width: 768px) {
  /* The usage panel leaves its popover position and docks as a bottom sheet. */
  .sm-usage__panel {
    position: fixed; top: auto; right: 0; bottom: 0; left: 0;
    width: 100%; max-height: 70vh; overflow-y: auto;
    border-bottom-left-radius: 0; border-bottom-right-radius: 0;
  }
  .sm-header { height: 3.25rem; gap: 0.5rem; padding: 0 0.75rem; }
  .sm-header__subtitle { display: none; }
  .sm-thread { padding: 0.9rem 0.75rem 0.4rem; }
  .sm-composer-wrap { padding: 0.5rem 0.75rem 0.85rem; }
  .sm-composer { border-radius: calc(var(--radius) + 8px); }
  .sm-sources__label { white-space: normal; }
  .sm-marker__label { max-width: 8rem; }
}

@media (max-width: 560px) {
  .sm-approval__param { grid-template-columns: minmax(0, 1fr); }
  .sm-thread { padding: 0.75rem 0.6rem 0.35rem; }
  .sm-thread__inner { gap: 0.9rem; }
  .sm-approval__actions { padding: 0 0.75rem 0.75rem; }
  .sm-usage__panel { max-height: 80vh; }
  .sm-theme-menu { max-width: min(13rem, calc(100vw - 2rem)); }
}

/* Forced colours: the flattened tokens lose their contrast, so borders and state colours are
   restored from the system palette instead of the theme. */
@media (forced-colors: active) {
  :where(.sm-root, .sm-scope) :focus-visible { outline: 2px solid Highlight; outline-offset: 2px; }
  .sm-button,
  .sm-icon-button,
  .sm-session__select,
  .sm-suggestion,
  .sm-theme-menu__item,
  .sm-composer__send,
  .sm-usage__trigger,
  .sm-code__copy,
  .sm-step__detail-toggle,
  .ui-collapsible-trigger,
  #blazor-error-ui .dismiss { border: 1px solid ButtonBorder; color: ButtonText; background: ButtonFace; }
  .sm-sidebar__search input,
  .sm-session__rename,
  .sm-composer__input,
  .sm-approval__reason { border: 1px solid FieldText; color: FieldText; background: Field; }
  .sm-session--active,
  .sm-theme-menu__item--active { border-color: Highlight; color: HighlightText; background: Highlight; }
  .sm-badge,
  .sm-pill { border: 1px solid CanvasText; color: CanvasText; }
  .sm-usage__dot,
  .sm-caret { background: Highlight; }
  .sm-spinner,
  .sm-step[data-status="running"] .sm-step__marker { color: Highlight; }
  /* Forced colours repaint backgrounds, so the "…" dots paint their own system colour. */
  .sm-dots > span { forced-color-adjust: none; background: ButtonText; }
  .sm-run-indicator > span { forced-color-adjust: none; background: Highlight; }
}

/* ============================================================================
   v4 / assistant-ui surface: conversation dock, viewport, message chrome,
   session groups and menus. Consumes the same tokens as everything above, so
   light/dark and the Joule theme apply unchanged.
   ========================================================================= */

@keyframes sm-rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes sm-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.sm-conversation { position: relative; display: flex; flex: 1; min-height: 0; flex-direction: column; }
.sm-dock { position: relative; z-index: 2; padding: 0 1.25rem; }
.sm-dock .sm-composer-wrap { padding-inline: 0; }

/* Thread viewport + floating scroll-to-bottom (assistant-ui ThreadPrimitive.ScrollToBottom). */
.sm-thread-shell { position: relative; display: flex; flex: 1; min-height: 0; flex-direction: column; }
.sm-thread { scroll-behavior: auto; overscroll-behavior: contain; outline: none; }
.sm-thread__inner { min-height: 100%; padding-bottom: 1rem; }
.sm-thread__inner > .sm-empty { flex: 1; }
.sm-thread__loading { display: flex; flex-direction: column; gap: 0.6rem; max-width: 48rem; width: 100%; margin: 2rem auto; }
.sm-skeleton--bubble { width: 40%; height: 2.25rem; margin-left: auto; border-radius: calc(var(--radius) + 8px); }
.sm-skeleton--short { width: 60%; }
.sm-scroll-bottom {
  position: absolute; left: 50%; bottom: 0.75rem; z-index: 3; transform: translateX(-50%);
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.25rem; height: 2.25rem; border: 1px solid var(--border); border-radius: 999px;
  background: var(--card); color: var(--foreground); cursor: pointer;
  box-shadow: 0 6px 18px hsl(240 10% 3% / 0.18);
  animation: sm-rise 160ms ease-out;
}
.sm-scroll-bottom:hover { background: var(--muted); }
.sm-scroll-bottom:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }

/* Assistant message chrome: thinking indicator, footer meta and the hover action bar. */
.sm-thinking { display: inline-flex; align-items: center; gap: 0.6rem; min-height: 2rem; font-size: 0.875rem; }
.sm-thinking__pulse { position: relative; width: 0.6rem; height: 0.6rem; border-radius: 999px; background: var(--primary); }
.sm-thinking__pulse::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; background: var(--primary);
  animation: sm-ping 1.4s cubic-bezier(0, 0, 0.2, 1) infinite;
}
.sm-message__footer {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap;
  min-height: 2rem; margin-top: 0.35rem;
}
.sm-message__meta { display: flex; align-items: center; gap: 0.35rem 0.75rem; flex-wrap: wrap; font-size: 0.6875rem; color: var(--muted-foreground); }
.sm-row--assistant .sm-message__actions { opacity: 0; transition: opacity 150ms ease; }
.sm-row--assistant:hover .sm-message__actions,
.sm-row--assistant:focus-within .sm-message__actions,
.sm-row--assistant:last-child .sm-message__actions { opacity: 1; }
.sm-run-note {
  display: inline-flex; align-items: center; gap: 0.45rem; align-self: center;
  padding: 0.3rem 0.75rem; border: 1px solid var(--border); border-radius: 999px;
  background: var(--card); font-size: 0.75rem; color: var(--muted-foreground);
}
.sm-link-button { padding: 0; border: 0; background: none; color: var(--primary); font: inherit; font-weight: 600; cursor: pointer; }
.sm-link-button:hover { text-decoration: underline; }

/* Composer: kbd hints and the busy state. */
.sm-composer--busy { border-color: color-mix(in srgb, var(--primary) 35%, var(--border)); }
.sm-composer__hint kbd {
  display: inline-block; min-width: 1.1rem; padding: 0 0.3rem;
  border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px;
  background: var(--muted); font-family: var(--font-sans); font-size: 0.625rem; line-height: 1.1rem; text-align: center;
}
.sm-button--sm { height: 1.75rem; padding: 0 0.7rem; font-size: 0.75rem; }

/* Sidebar: grouped sections, run indicators, row menu and inline confirmations. */
.sm-sidebar__toolbar { display: flex; align-items: center; gap: 0.4rem; }
.sm-sidebar__toolbar .sm-sidebar__new-chat { flex: 1; }
.sm-sidebar__section + .sm-sidebar__section { margin-top: 0.35rem; }
.sm-sidebar__group-head { position: relative; display: flex; align-items: center; gap: 0.25rem; padding: 0.35rem 0.5rem 0.2rem; }
.sm-sidebar__group-head:hover .sm-session__actions,
.sm-sidebar__group-head:focus-within .sm-session__actions { opacity: 1; }
.sm-sidebar__group-toggle {
  display: inline-flex; align-items: center; gap: 0.35rem; flex: 1; min-width: 0;
  padding: 0.15rem 0.25rem; border: 0; border-radius: calc(var(--radius) - 4px); background: none;
  font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--muted-foreground); cursor: pointer; text-align: left;
}
.sm-sidebar__group-toggle:hover { color: var(--foreground); }
.sm-sidebar__count { margin-left: auto; font-weight: 500; letter-spacing: 0; opacity: 0.7; }
.sm-sidebar__empty { margin: 0.75rem; font-size: 0.75rem; color: var(--muted-foreground); }
.sm-sidebar__empty--group { margin: 0.1rem 0.9rem 0.4rem 1.75rem; font-style: italic; }
.sm-sidebar__list { margin: 0; padding: 0 0.4rem; list-style: none; }
.sm-session { position: relative; }
.sm-session__select { display: flex; align-items: center; gap: 0.5rem; }
.sm-session__select--icon { width: 2.5rem; height: 2.5rem; margin: 0.1rem auto; justify-content: center; border-radius: var(--radius); }
.sm-session:hover .sm-session__actions,
.sm-session:focus-within .sm-session__actions { opacity: 1; }
.sm-confirm {
  height: 1.5rem; padding: 0 0.55rem; border: 0; border-radius: calc(var(--radius) - 2px);
  background: var(--destructive); color: var(--destructive-foreground, #fff);
  font-size: 0.6875rem; font-weight: 600; cursor: pointer;
}
.sm-menu-backdrop { position: fixed; inset: 0; z-index: 40; }
.sm-menu {
  position: absolute; right: 0.4rem; top: calc(100% - 0.25rem); z-index: 41;
  min-width: 12rem; max-width: 15rem; padding: 0.3rem;
  border: 1px solid var(--border); border-radius: calc(var(--radius) + 2px);
  background: var(--popover, var(--card)); color: var(--popover-foreground, var(--foreground));
  box-shadow: 0 12px 32px hsl(240 10% 3% / 0.22);
  animation: sm-rise 120ms ease-out;
}
.sm-menu__item {
  display: flex; align-items: center; gap: 0.5rem; width: 100%;
  padding: 0.4rem 0.55rem; border: 0; border-radius: calc(var(--radius) - 4px);
  background: none; font-size: 0.8125rem; text-align: left; cursor: pointer;
}
.sm-menu__item:hover, .sm-menu__item:focus-visible { background: var(--muted); outline: none; }
.sm-menu__item--danger { color: var(--destructive); }
.sm-menu__item:is(a) { color: inherit; text-decoration: none; }
.sm-menu__item:disabled, .sm-menu__item[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }
/* The chosen option of a radio group (MenuRadioItem): a check mark at the end of the row. */
.sm-menu__item[aria-checked="true"] { font-weight: 600; }
.sm-menu__item[aria-checked="true"]::after {
  content: ""; flex: none; width: 0.3rem; height: 0.6rem; margin: 0 0.2rem 0.15rem auto;
  border: solid currentColor; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
/* MenuContent flips above its trigger when placeMenu found too little room below (the account menu already opens upward). */
.sm-menu[data-side="top"]:not(.sm-menu--account) { top: auto; bottom: calc(100% - 0.25rem); }
.sm-menu__label { padding: 0.45rem 0.55rem 0.2rem; font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted-foreground); }
.sm-menu__divider { height: 1px; margin: 0.3rem 0; background: var(--border); }

/* Composer model picker: a ghost button; its menu opens upward from the composer footer. */
.sm-model-picker-wrap { position: relative; display: inline-flex; min-width: 0; }
.sm-model-picker {
  display: inline-flex; align-items: center; gap: 0.35rem; max-width: 16rem; height: 1.75rem; padding: 0 0.5rem;
  border: 1px solid transparent; border-radius: calc(var(--radius) - 2px);
  background: transparent; color: var(--muted-foreground); font-size: 0.75rem; cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease;
}
.sm-model-picker:hover, .sm-model-picker[aria-expanded="true"] { background: var(--muted); color: var(--foreground); }
.sm-model-picker__label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sm-model-picker__menu {
  top: auto; bottom: calc(100% + 0.25rem); left: 0; right: auto;
  min-width: 16rem; max-width: min(22rem, 90vw); max-height: min(60vh, 28rem); overflow-y: auto;
}
.sm-menu.sm-model-picker__menu[data-side="top"] { top: auto; bottom: calc(100% + 0.25rem); } /* beats the generic flip above */
.sm-model-picker__menu .truncate { min-width: 0; }
.sm-model-picker__note { margin: 0; padding: 0.25rem 0.55rem 0.4rem; font-size: 0.6875rem; color: var(--muted-foreground); }
.sm-model-picker__error { margin: 0.3rem 0.55rem; font-size: 0.75rem; color: var(--destructive); }

/* Charts and sandboxed HTML artifacts. */
.sm-echart { width: 100%; height: 320px; }
.sm-artifact__frame { display: block; width: 100%; height: 420px; border: 0; border-radius: calc(var(--radius) - 2px); background: #fff; resize: vertical; }

@media (max-width: 768px) {
  .sm-dock { padding: 0 0.75rem; }
  .sm-message__actions, .sm-row--assistant .sm-message__actions { opacity: 1; }
  .sm-echart { height: 260px; }
}

@media (prefers-reduced-motion: reduce) {
  .sm-thinking__pulse::after,
  .sm-approval__dot--resuming,
  .sm-approval-tray__dot,
  .sm-approval-tray,
  .sm-scroll-bottom,
  .sm-menu,
  .sm-error { animation: none; }
}

/* Session rows use spans inside the select button (a div is not valid there): make them block so
   ellipsis applies, and never let a long title scroll the sidebar sideways. */
.sm-sidebar__scroll { overflow-x: hidden; }
.sm-session__body { display: flex; flex-direction: column; }
.sm-session__title, .sm-session__meta { display: block; }
.sm-session__meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sm-scroll-bottom { background: var(--background); }
/* ── Scoped paint for long transcripts ────────────────────────────────────
   Settled rows (not the streaming answer) skip layout and paint while off screen and remember
   their measured height (v4 1.0.33). Containment would trap a fixed overlay opened inside a row
   (expanded diagram, image lightbox), so a row with one open is excluded while it is open. */
.sm-row--settled:not(:has(.sm-mermaid--expanded, .sm-lightbox)) {
  content-visibility: auto;
  contain-intrinsic-size: auto 320px;
}

/* ── Execution hierarchy (delegated tasks) ────────────────────────────────
   A task row is a step line with a second line for the objective: marker, "Agent · Task N",
   status/duration on the right. Its tools sit under it on the same rail as other steps. */
.sm-steps--tree { gap: 0.1rem; }
.sm-steps__group + .sm-steps__group, .sm-steps__group + .sm-exec, .sm-exec + .sm-steps__group { margin-top: 0.15rem; }
.sm-steps__count { margin-left: 0.4rem; font-weight: 400; color: color-mix(in srgb, var(--muted-foreground) calc(0.75 * 100%), transparent); }
.sm-exec { display: block; }
.sm-exec__head {
  display: flex; align-items: flex-start; gap: 0.45rem; width: 100%;
  padding: 0.3rem 0.35rem; border: 0; border-radius: calc(var(--radius) - 4px);
  background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer;
  transition: background-color 150ms ease;
}
.sm-exec__head:hover { background: color-mix(in srgb, var(--muted) calc(0.35 * 100%), transparent); }
.sm-exec__head:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }
.sm-exec__marker {
  display: inline-flex; flex-shrink: 0; align-items: center; justify-content: center;
  width: 0.85rem; height: 1.2rem; color: var(--muted-foreground);
}
.sm-exec[data-status="running"] .sm-exec__marker,
.sm-exec[data-status="queued"] .sm-exec__marker,
.sm-exec[data-status="pending"] .sm-exec__marker { color: var(--primary); }
.sm-exec[data-status="completed"] .sm-exec__marker { color: var(--success); }
.sm-exec[data-status="completed_with_errors"] .sm-exec__marker,
.sm-exec[data-status="suspended"] .sm-exec__marker { color: var(--warning); }
.sm-exec[data-status="failed"] .sm-exec__marker { color: var(--destructive); }
.sm-exec__text { display: flex; flex: 1; min-width: 0; flex-direction: column; gap: 0.05rem; }
.sm-exec__title { font-size: 0.8125rem; font-weight: 500; line-height: 1.5; color: var(--foreground); overflow-wrap: anywhere; }
.sm-exec__index { font-weight: 400; color: var(--muted-foreground); }
.sm-exec__objective {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  font-size: 0.75rem; line-height: 1.45; color: var(--muted-foreground); overflow-wrap: anywhere;
}
/* Expanded, the full Objective block replaces the two-line preview. */
.sm-exec[data-state="open"] > .sm-exec__head .sm-exec__objective { display: none; }
.sm-exec__meta { font-size: 0.6875rem; color: color-mix(in srgb, var(--muted-foreground) calc(0.85 * 100%), transparent); }
.sm-exec__aside {
  display: inline-flex; flex-shrink: 0; align-items: center; gap: 0.45rem; padding-top: 0.1rem;
  font-size: 0.6875rem; font-variant-numeric: tabular-nums; color: var(--muted-foreground);
}
.sm-exec[data-status="failed"] .sm-exec__status { color: var(--destructive); }
.sm-exec[data-status="completed_with_errors"] .sm-exec__status { color: var(--warning); }
.sm-exec__chevron { opacity: 0.5; transition: transform 220ms cubic-bezier(0.16, 1, 0.3, 1); }
.sm-exec[data-state="open"] > .sm-exec__head .sm-exec__chevron { transform: rotate(90deg); }
.sm-exec__body {
  margin: 0.15rem 0 0.35rem 0.75rem; padding-left: 0.65rem;
  border-left: 1px solid color-mix(in srgb, var(--border) calc(0.6 * 100%), transparent);
}
.sm-exec__objective-block {
  margin: 0.15rem 0 0.4rem; padding: 0.45rem 0.6rem;
  border-radius: calc(var(--radius) - 2px);
  background: color-mix(in srgb, var(--muted) calc(0.4 * 100%), transparent);
  font-size: 0.75rem; line-height: 1.55;
}
.sm-exec__objective-block dt { margin-bottom: 0.15rem; font-size: 0.6875rem; color: var(--muted-foreground); }
.sm-exec__objective-block dd { margin: 0; color: var(--foreground); white-space: pre-wrap; overflow-wrap: anywhere; }
.sm-exec__empty { margin: 0.2rem 0.35rem; font-size: 0.75rem; color: var(--muted-foreground); }
@media (prefers-reduced-motion: reduce) { .sm-exec__chevron { transition: none; } }

/* ── History states ───────────────────────────────────────────────────────── */
.sm-history { display: flex; flex-direction: column; gap: 0.2rem; }
.sm-history__note { display: inline-flex; align-items: center; gap: 0.45rem; margin: 0.3rem 0.35rem; font-size: 0.75rem; color: var(--muted-foreground); }
.sm-history__note--error { color: var(--destructive); }
.sm-history__more { align-self: flex-start; margin: 0.25rem 0.35rem; font-size: 0.75rem; }
.sm-history-error {
  display: flex; align-items: flex-start; gap: 0.75rem; margin: 1.5rem 0; padding: 0.9rem 1rem;
  border: 1px solid color-mix(in srgb, var(--destructive) calc(0.3 * 100%), transparent);
  border-radius: var(--radius); background: var(--card); color: var(--destructive);
}
.sm-history-error__text { flex: 1; min-width: 0; }
.sm-history-error__title { margin: 0; font-size: 0.875rem; font-weight: 600; color: var(--foreground); }
.sm-history-error__detail { margin: 0.2rem 0 0; font-size: 0.8125rem; color: var(--muted-foreground); }
.sm-history-error .sm-button { display: inline-flex; align-items: center; gap: 0.35rem; flex-shrink: 0; }

/* ── Workspace: Details panel ─────────────────────────────────────────────── */
.sm-details { display: flex; flex-direction: column; padding: 0.25rem 0; }
.sm-details__section { display: grid; gap: 0.45rem; padding: 0.75rem 0; border-bottom: 1px solid var(--border); }
.sm-details__section:last-child { border-bottom: 0; }
.sm-details__section h2 { margin: 0; font-size: 0.8125rem; font-weight: 600; color: var(--foreground); }
.sm-details__list { display: grid; gap: 0.35rem; margin: 0; }
.sm-details__row { display: flex; align-items: baseline; justify-content: space-between; gap: 0.75rem; min-width: 0; font-size: 0.75rem; }
.sm-details__row dt { flex-shrink: 0; color: var(--muted-foreground); }
.sm-details__row dd { display: inline-flex; align-items: baseline; gap: 0.35rem; min-width: 0; margin: 0; color: var(--foreground); }
.sm-details__value { font-variant-numeric: tabular-nums; overflow-wrap: anywhere; text-align: right; }
.sm-details__id { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-mono, ui-monospace, monospace); font-size: 0.6875rem; }
.sm-details__row .sm-icon-button { align-self: center; flex-shrink: 0; }
.sm-details__muted { margin: 0; font-size: 0.6875rem; color: var(--muted-foreground); }
.sm-details__empty { margin: 1.5rem 0.25rem; font-size: 0.8125rem; color: var(--muted-foreground); text-align: center; }
