/* ========================================
   LOCALCHAT - CSS STYLES
   Browser-based LLM Chat POC
   Standalone - No external dependencies
   ======================================== */

/* ========================================
   DESIGN SYSTEM - CSS VARIABLES
   ======================================== */
:root,
:is(.studio, [data-appearance-scope="studio"]),
[data-appearance-scope="assistant"] {
    /* Typography */
    --font-interface: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-reading: 'Atkinson Hyperlegible', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-code: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    --font-ui: var(--font-interface);
    --font-content: var(--font-reading);

    /* Flat light palette */
    --surface-canvas: #f5f3ed;
    --surface-default: #ffffff;
    --surface-muted: #f2f1ec;
    --surface-strong: #e4e0d6;
    --ink-primary: #16191d;
    --ink-secondary: #3a4048;
    --ink-muted: #5c646e;
    --line-default: #e4e0d6;
    --lime-default: #0b7a55;
    --lime-strong: #085c3f;
    --lime-on: #ffffff;
    --lime-strong-on: var(--lime-on);
    --focus-ring: #0b7a55;
}

:root,
:is(.studio, [data-appearance-scope="studio"]),
[data-appearance-scope="assistant"] {

    /* Compatibility aliases for existing components */
    --bg-base: var(--surface-canvas);
    --bg-elevated: var(--surface-default);
    --bg-subtle: var(--surface-muted);
    --bg-accent: var(--surface-strong);
    --bg-hover: var(--surface-muted);
    --text-primary: var(--ink-primary);
    --text-secondary: var(--ink-secondary);
    --text-muted: var(--ink-muted);
    --text-inverse: var(--lime-on);
    --code-text: #3a4048;
    --code-block-bg: var(--surface-muted);
    --code-inline-bg: var(--code-block-bg);
    --accent-primary: var(--lime-default);
    --accent-hover: var(--lime-strong);
    --accent-on: var(--lime-on);
    --accent-hover-on: var(--lime-strong-on);
    --accent-muted: color-mix(in srgb, var(--lime-default) 16%, transparent);
    --success: #2f7d18;
    --success-muted: rgba(47, 125, 24, 0.12);
    --error: #b42318;
    --error-muted: rgba(180, 35, 24, 0.12);
    --error-on: #ffffff;
    --activity-live: #d97706;
    --info: var(--lime-strong);
    --info-muted: color-mix(in srgb, var(--lime-default) 12%, transparent);
    --border-subtle: rgba(16, 18, 14, 0.08);
    --border-default: var(--line-default);
    --border-strong: #aeb8a6;
    --border-focus: var(--focus-ring);
    --shadow-sm: 0 1px 2px rgba(16, 18, 14, 0.12);
    --shadow-md: 0 6px 18px rgba(16, 18, 14, 0.14);
    --shadow-lg: 0 12px 30px rgba(16, 18, 14, 0.16);
    --shadow-xl: 0 22px 48px rgba(16, 18, 14, 0.2);
}

:root {

    /* Spacing */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;

    /* Radius */
    --radius-sm: 8px;
    --radius-md: 11px;
    --radius-lg: 16px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* Neutral elevation */
    --shadow-sm: 0 1px 2px rgba(16, 18, 14, 0.12);
    --shadow-md: 0 6px 18px rgba(16, 18, 14, 0.14);
    --shadow-lg: 0 12px 30px rgba(16, 18, 14, 0.16);
    --shadow-xl: 0 22px 48px rgba(16, 18, 14, 0.2);

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 200ms ease;
    --transition-slow: 300ms ease;

    /* Layout */
    --sidebar-width: 280px;
    --topbar-height: 56px;
    --statusbar-height: 32px;
    --input-area-min: 80px;
    --vv-top: 0px;
    --vv-bottom: 0px;
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);

    /* Message formatting */
    --message-em-color: var(--text-secondary);
    --message-underline-color: var(--text-secondary);
    --message-quote-color: var(--lime-strong);
}

:root[data-color-mode='dark'],
:root[data-studio-color-mode='dark'] :is(.studio, [data-appearance-scope="studio"]),
:root[data-assistant-color-mode='dark'] [data-appearance-scope="assistant"] {
    --surface-canvas: #0a0c09;
    --surface-default: #121510;
    --surface-muted: #1b2018;
    --surface-strong: #293025;
    --ink-primary: #f7f8f4;
    --ink-secondary: #b9c0b4;
    --ink-muted: #8d9787;
    --line-default: #343c30;
    --lime-default: #a3e635;
    --lime-strong: #bef264;
    --lime-on: #0a0c09;
    --focus-ring: #a3e635;
    --code-text: #bef264;
    --accent-muted: color-mix(in srgb, var(--lime-default) 16%, transparent);
    --success: #86d74c;
    --success-muted: rgba(134, 215, 76, 0.14);
    --error: #ff7b72;
    --error-muted: rgba(255, 123, 114, 0.14);
    --error-on: #0a0c09;
    --activity-live: #f59e0b;
    --info: var(--lime-strong);
    --info-muted: color-mix(in srgb, var(--lime-default) 12%, transparent);
    --border-subtle: rgba(247, 248, 244, 0.07);
    --border-strong: #4c5746;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.34);
    --shadow-lg: 0 12px 30px rgba(0, 0, 0, 0.4);
    --shadow-xl: 0 22px 48px rgba(0, 0, 0, 0.46);
}

:root[data-color-mode='light'][data-surface-scheme='warm'],
:root[data-studio-color-mode='light'][data-studio-surface-scheme='warm'] :is(.studio, [data-appearance-scope="studio"]),
:root[data-assistant-color-mode='light'][data-assistant-surface-scheme='warm'] [data-appearance-scope="assistant"] {
    --surface-canvas: #fbf7ef;
    --surface-default: #fffdf8;
    --surface-muted: #f1e8d8;
    --surface-strong: #e6d8c1;
    --ink-primary: #1d1912;
    --ink-secondary: #5c5245;
    --ink-muted: #7c6f5e;
    --line-default: #d9cbb5;
    --border-strong: #bdab90;
}

:root[data-color-mode='light'][data-surface-scheme='cool'],
:root[data-studio-color-mode='light'][data-studio-surface-scheme='cool'] :is(.studio, [data-appearance-scope="studio"]),
:root[data-assistant-color-mode='light'][data-assistant-surface-scheme='cool'] [data-appearance-scope="assistant"] {
    --surface-canvas: #f3f7fa;
    --surface-default: #ffffff;
    --surface-muted: #e7eef3;
    --surface-strong: #d8e3eb;
    --ink-primary: #111820;
    --ink-secondary: #465766;
    --ink-muted: #677887;
    --line-default: #c9d7e1;
    --border-strong: #a9bdca;
}

:root[data-color-mode='light'][data-surface-scheme='gray'],
:root[data-studio-color-mode='light'][data-studio-surface-scheme='gray'] :is(.studio, [data-appearance-scope="studio"]),
:root[data-assistant-color-mode='light'][data-assistant-surface-scheme='gray'] [data-appearance-scope="assistant"] {
    --surface-canvas: #f5f5f5;
    --surface-default: #ffffff;
    --surface-muted: #ebebeb;
    --surface-strong: #dddddd;
    --ink-primary: #151515;
    --ink-secondary: #505050;
    --ink-muted: #737373;
    --line-default: #cecece;
    --border-strong: #adadad;
}

:root[data-color-mode='dark'][data-surface-scheme='slate'],
:root[data-studio-color-mode='dark'][data-studio-surface-scheme='slate'] :is(.studio, [data-appearance-scope="studio"]),
:root[data-assistant-color-mode='dark'][data-assistant-surface-scheme='slate'] [data-appearance-scope="assistant"] {
    --surface-canvas: #0d1117;
    --surface-default: #151b23;
    --surface-muted: #1d2630;
    --surface-strong: #2b3744;
    --ink-primary: #f4f7fa;
    --ink-secondary: #bdc7d2;
    --ink-muted: #8f9dab;
    --line-default: #364452;
    --border-strong: #526476;
}

:root[data-color-mode='dark'][data-surface-scheme='graphite'],
:root[data-studio-color-mode='dark'][data-studio-surface-scheme='graphite'] :is(.studio, [data-appearance-scope="studio"]),
:root[data-assistant-color-mode='dark'][data-assistant-surface-scheme='graphite'] [data-appearance-scope="assistant"] {
    --surface-canvas: #101010;
    --surface-default: #181818;
    --surface-muted: #242424;
    --surface-strong: #303030;
    --ink-primary: #f5f5f5;
    --ink-secondary: #c1c1c1;
    --ink-muted: #929292;
    --line-default: #3a3a3a;
    --border-strong: #575757;
}

:root[data-color-mode='dark'][data-surface-scheme='aubergine'],
:root[data-studio-color-mode='dark'][data-studio-surface-scheme='aubergine'] :is(.studio, [data-appearance-scope="studio"]),
:root[data-assistant-color-mode='dark'][data-assistant-surface-scheme='aubergine'] [data-appearance-scope="assistant"] {
    --surface-canvas: #120f16;
    --surface-default: #1b1621;
    --surface-muted: #271f2f;
    --surface-strong: #382c42;
    --ink-primary: #faf5ff;
    --ink-secondary: #d0c2d8;
    --ink-muted: #9f8faa;
    --line-default: #493a54;
    --border-strong: #665174;
}

:root[data-color-mode='light'][data-accent-preset='forest'],
:root[data-studio-color-mode='light'][data-studio-accent-preset='forest'] :is(.studio, [data-appearance-scope="studio"]),
:root[data-assistant-color-mode='light'][data-assistant-accent-preset='forest'] [data-appearance-scope="assistant"] {
    --lime-default: #0b7a55;
    --lime-strong: #085c3f;
    --lime-on: #ffffff;
    --focus-ring: #0b7a55;
    --code-text: #085c3f;
}

:root[data-color-mode='light'][data-accent-preset='cobalt'],
:root[data-studio-color-mode='light'][data-studio-accent-preset='cobalt'] :is(.studio, [data-appearance-scope="studio"]),
:root[data-assistant-color-mode='light'][data-assistant-accent-preset='cobalt'] [data-appearance-scope="assistant"] {
    --lime-default: #2563eb;
    --lime-strong: #1d4ed8;
    --lime-on: #ffffff;
    --focus-ring: #2563eb;
    --code-text: #1d4ed8;
}

:root[data-color-mode='light'][data-accent-preset='violet'],
:root[data-studio-color-mode='light'][data-studio-accent-preset='violet'] :is(.studio, [data-appearance-scope="studio"]),
:root[data-assistant-color-mode='light'][data-assistant-accent-preset='violet'] [data-appearance-scope="assistant"] {
    --lime-default: #7c3aed;
    --lime-strong: #6d28d9;
    --lime-on: #ffffff;
    --focus-ring: #7c3aed;
    --code-text: #6d28d9;
}

:root[data-color-mode='light'][data-accent-preset='rose'],
:root[data-studio-color-mode='light'][data-studio-accent-preset='rose'] :is(.studio, [data-appearance-scope="studio"]),
:root[data-assistant-color-mode='light'][data-assistant-accent-preset='rose'] [data-appearance-scope="assistant"] {
    --lime-default: #e11d48;
    --lime-strong: #be123c;
    --lime-on: #ffffff;
    --focus-ring: #e11d48;
    --code-text: #be123c;
}

:root[data-color-mode='light'][data-accent-preset='amber'],
:root[data-studio-color-mode='light'][data-studio-accent-preset='amber'] :is(.studio, [data-appearance-scope="studio"]),
:root[data-assistant-color-mode='light'][data-assistant-accent-preset='amber'] [data-appearance-scope="assistant"] {
    --lime-default: #b45309;
    --lime-strong: #92400e;
    --lime-on: #ffffff;
    --focus-ring: #b45309;
    --code-text: #92400e;
}

:root[data-color-mode='light'][data-accent-preset='lime'],
:root[data-studio-color-mode='light'][data-studio-accent-preset='lime'] :is(.studio, [data-appearance-scope="studio"]),
:root[data-assistant-color-mode='light'][data-assistant-accent-preset='lime'] [data-appearance-scope="assistant"] {
    --lime-default: #65a30d;
    --lime-strong: #4d7c0f;
    --lime-on: #10120e;
    --lime-strong-on: #ffffff;
    --focus-ring: #65a30d;
    --code-text: #4d7c0f;
}

:root[data-color-mode='light'][data-accent-preset='custom'],
:root[data-studio-color-mode='light'][data-studio-accent-preset='custom'] :is(.studio, [data-appearance-scope="studio"]),
:root[data-assistant-color-mode='light'][data-assistant-accent-preset='custom'] [data-appearance-scope="assistant"] {
    --lime-default: color-mix(in srgb, var(--accent-custom, #2563eb) 42%, #10120e);
    --lime-strong: color-mix(in srgb, var(--accent-custom, #2563eb) 32%, #10120e);
    --lime-on: #ffffff;
    --focus-ring: var(--lime-default);
    --code-text: var(--lime-strong);
}

:root[data-color-mode='dark'][data-accent-preset='cyan'],
:root[data-studio-color-mode='dark'][data-studio-accent-preset='cyan'] :is(.studio, [data-appearance-scope="studio"]),
:root[data-assistant-color-mode='dark'][data-assistant-accent-preset='cyan'] [data-appearance-scope="assistant"] {
    --lime-default: #22d3ee;
    --lime-strong: #67e8f9;
    --lime-on: #071418;
    --focus-ring: #22d3ee;
    --code-text: #67e8f9;
}

:root[data-color-mode='dark'][data-accent-preset='violet'],
:root[data-studio-color-mode='dark'][data-studio-accent-preset='violet'] :is(.studio, [data-appearance-scope="studio"]),
:root[data-assistant-color-mode='dark'][data-assistant-accent-preset='violet'] [data-appearance-scope="assistant"] {
    --lime-default: #a78bfa;
    --lime-strong: #c4b5fd;
    --lime-on: #140d26;
    --focus-ring: #a78bfa;
    --code-text: #c4b5fd;
}

:root[data-color-mode='dark'][data-accent-preset='rose'],
:root[data-studio-color-mode='dark'][data-studio-accent-preset='rose'] :is(.studio, [data-appearance-scope="studio"]),
:root[data-assistant-color-mode='dark'][data-assistant-accent-preset='rose'] [data-appearance-scope="assistant"] {
    --lime-default: #fb7185;
    --lime-strong: #fda4af;
    --lime-on: #21080d;
    --focus-ring: #fb7185;
    --code-text: #fda4af;
}

:root[data-color-mode='dark'][data-accent-preset='amber'],
:root[data-studio-color-mode='dark'][data-studio-accent-preset='amber'] :is(.studio, [data-appearance-scope="studio"]),
:root[data-assistant-color-mode='dark'][data-assistant-accent-preset='amber'] [data-appearance-scope="assistant"] {
    --lime-default: #fbbf24;
    --lime-strong: #fcd34d;
    --lime-on: #1b1200;
    --focus-ring: #fbbf24;
    --code-text: #fcd34d;
}

:root[data-color-mode='dark'][data-accent-preset='custom'],
:root[data-studio-color-mode='dark'][data-studio-accent-preset='custom'] :is(.studio, [data-appearance-scope="studio"]),
:root[data-assistant-color-mode='dark'][data-assistant-accent-preset='custom'] [data-appearance-scope="assistant"] {
    --lime-default: color-mix(in srgb, var(--accent-custom, #a3e635) 50%, #ffffff);
    --lime-strong: color-mix(in srgb, var(--accent-custom, #a3e635) 35%, #ffffff);
    --lime-on: #0a0c09;
    --focus-ring: var(--lime-default);
    --code-text: var(--lime-strong);
}

:root[data-interface-font='dm-sans'], :root[data-studio-interface-font='dm-sans'] :is(.studio, [data-appearance-scope="studio"]),
:root[data-assistant-interface-font='dm-sans'] [data-appearance-scope="assistant"] { --font-interface: 'DM Sans', sans-serif; }
:root[data-interface-font='atkinson'], :root[data-studio-interface-font='atkinson'] :is(.studio, [data-appearance-scope="studio"]),
:root[data-assistant-interface-font='atkinson'] [data-appearance-scope="assistant"] { --font-interface: 'Atkinson Hyperlegible', sans-serif; }
:root[data-interface-font='inter'], :root[data-studio-interface-font='inter'] :is(.studio, [data-appearance-scope="studio"]),
:root[data-assistant-interface-font='inter'] [data-appearance-scope="assistant"] { --font-interface: 'Inter', sans-serif; }
:root[data-interface-font='sora'], :root[data-studio-interface-font='sora'] :is(.studio, [data-appearance-scope="studio"]),
:root[data-assistant-interface-font='sora'] [data-appearance-scope="assistant"] { --font-interface: 'Sora', sans-serif; }
:root[data-interface-font='space-grotesk'], :root[data-studio-interface-font='space-grotesk'] :is(.studio, [data-appearance-scope="studio"]),
:root[data-assistant-interface-font='space-grotesk'] [data-appearance-scope="assistant"] { --font-interface: 'Space Grotesk', sans-serif; }
:root[data-interface-font='instrument-sans'], :root[data-studio-interface-font='instrument-sans'] :is(.studio, [data-appearance-scope="studio"]),
:root[data-assistant-interface-font='instrument-sans'] [data-appearance-scope="assistant"] { --font-interface: 'Instrument Sans', sans-serif; }
:root[data-interface-font='system'], :root[data-studio-interface-font='system'] :is(.studio, [data-appearance-scope="studio"]),
:root[data-assistant-interface-font='system'] [data-appearance-scope="assistant"] { --font-interface: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }

:root[data-reading-font='dm-sans'], :root[data-assistant-message-font='dm-sans'] [data-appearance-scope="assistant"] { --font-reading: 'DM Sans', sans-serif; }
:root[data-reading-font='manrope'], :root[data-assistant-message-font='manrope'] [data-appearance-scope="assistant"] { --font-reading: 'Manrope', sans-serif; }
:root[data-reading-font='inter'], :root[data-assistant-message-font='inter'] [data-appearance-scope="assistant"] { --font-reading: 'Inter', sans-serif; }
:root[data-reading-font='sora'], :root[data-assistant-message-font='sora'] [data-appearance-scope="assistant"] { --font-reading: 'Sora', sans-serif; }
:root[data-reading-font='space-grotesk'], :root[data-assistant-message-font='space-grotesk'] [data-appearance-scope="assistant"] { --font-reading: 'Space Grotesk', sans-serif; }
:root[data-reading-font='instrument-sans'], :root[data-assistant-message-font='instrument-sans'] [data-appearance-scope="assistant"] { --font-reading: 'Instrument Sans', sans-serif; }
:root[data-reading-font='system'], :root[data-assistant-message-font='system'] [data-appearance-scope="assistant"] { --font-reading: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }

:is(.studio, [data-appearance-scope="studio"]) { --font-reading: var(--font-interface); }
/* A Studio-scoped element outside the Studio page (the Settings preview card)
 * reads the same Studio tokens; .studio itself sets these in prompt-editor.css. */
[data-appearance-scope="studio"] {
    --accent-custom: var(--studio-accent-custom, #245fa8);
    color: var(--ink-primary);
    color-scheme: light;
    font-family: var(--font-interface);
}
:root[data-studio-color-mode='dark'] [data-appearance-scope="studio"] { color-scheme: dark; }
:root[data-assistant-message-font='atkinson'] [data-appearance-scope="assistant"] { --font-reading: 'Atkinson Hyperlegible', sans-serif; }
[data-appearance-scope="assistant"] {
    --accent-custom: var(--assistant-accent-custom, #245fa8);
    --font-v2-display: var(--font-interface);
    --font-v2-prose: var(--font-reading);
    --font-v2-body: var(--font-reading);
    --studio-editor-bg: var(--surface-default);
    --studio-assistant-bg: var(--surface-muted);
    --studio-header-bg: var(--surface-strong);
    --studio-panel-bg: var(--surface-muted);
    --studio-section-bg: var(--surface-muted);
    --studio-accent: var(--lime-default);
    --studio-border: var(--line-default);
    --message-em-color: var(--ink-secondary);
    --message-underline-color: var(--ink-secondary);
    --message-quote-color: var(--lime-strong);
    color: var(--ink-primary);
    color-scheme: light;
    font-family: var(--font-interface);
}
:root[data-assistant-color-mode='dark'] [data-appearance-scope="assistant"] { color-scheme: dark; }
.assistant-panel #studioConversation { font-family: var(--font-reading); }
.studio :is(#studioDocument, #studioPreviewDocument) { font-family: var(--font-interface); }

:root[data-studio-color-mode='light'][data-studio-surface-scheme='studio'] :is(.studio, [data-appearance-scope="studio"]),
:root[data-assistant-color-mode='light'][data-assistant-surface-scheme='studio'] [data-appearance-scope="assistant"] {
  --surface-canvas: #f4f7fb;
  --surface-default: #ffffff;
  --surface-muted: #e8eef5;
  --surface-strong: #dce5ef;
  --ink-primary: #172638;
  --ink-secondary: #42556b;
  --ink-muted: #5d7086;
  --line-default: #c6d2df;
  --border-strong: #a9bdca;
  --studio-header-bg: #17283d;
}
:root[data-studio-color-mode='dark'][data-studio-surface-scheme='studio'] :is(.studio, [data-appearance-scope="studio"]),
:root[data-assistant-color-mode='dark'][data-assistant-surface-scheme='studio'] [data-appearance-scope="assistant"] {
  --surface-canvas: #192331;
  --surface-default: #111b28;
  --surface-muted: #25303f;
  --surface-strong: #303f51;
  --ink-primary: #edf3fa;
  --ink-secondary: #bac9da;
  --ink-muted: #95a9bf;
  --line-default: #415165;
  --border-strong: #526476;
  --studio-header-bg: #0d1622;
}
:root[data-studio-color-mode='light'][data-studio-accent-preset='studio'] :is(.studio, [data-appearance-scope="studio"]),
:root[data-assistant-color-mode='light'][data-assistant-accent-preset='studio'] [data-appearance-scope="assistant"] {
  --lime-default: #245fa8;
  --lime-strong: #194b87;
  --lime-on: #ffffff;
  --focus-ring: var(--lime-default);
  --code-text: var(--lime-strong);
}
:root[data-studio-color-mode='dark'][data-studio-accent-preset='studio'] :is(.studio, [data-appearance-scope="studio"]),
:root[data-assistant-color-mode='dark'][data-assistant-accent-preset='studio'] [data-appearance-scope="assistant"] {
  --lime-default: #83c5f4;
  --lime-strong: #b0dbfa;
  --lime-on: #111b28;
  --focus-ring: var(--lime-default);
  --code-text: var(--lime-strong);
}

/* Assistant edit events have their own hue, separate from the accent: green by
 * default, orchid where the accent itself is green (forest, lime) so the event
 * never matches it. Every value keeps WCAG AA text contrast on that mode's surfaces. */
[data-appearance-scope="assistant"] { --edit-event: #18703f; }
:root[data-assistant-color-mode='dark'] [data-appearance-scope="assistant"] { --edit-event: #8ad6a2; }
:root[data-assistant-color-mode='light'][data-assistant-accent-preset='forest'] [data-appearance-scope="assistant"],
:root[data-assistant-color-mode='light'][data-assistant-accent-preset='lime'] [data-appearance-scope="assistant"] { --edit-event: #7b3aa8; }
:root[data-assistant-color-mode='dark'][data-assistant-accent-preset='forest'] [data-appearance-scope="assistant"],
:root[data-assistant-color-mode='dark'][data-assistant-accent-preset='lime'] [data-appearance-scope="assistant"] { --edit-event: #d4a8f0; }

/* Cached responsive values are replaced by the normalized Settings sheet. */
body { --chat-font-scale: var(--boot-desktop-interface-scale, 1.0714285714); --chat-interface-font-scale: var(--chat-font-scale); --chat-transcript-font-size: var(--boot-desktop-transcript-size, 16px); }
:is(.studio, [data-appearance-scope="studio"]) { --chat-font-scale: var(--boot-studio-desktop-interface-scale, 1.0714285714); --chat-interface-font-scale: var(--chat-font-scale); --studio-editor-font-size: var(--boot-studio-desktop-editor-size, 14px); --studio-editor-margin-step: var(--boot-studio-desktop-editor-margin-none, 0); }
@media (min-width:1051px) {
    .studio[data-sources-open="true"][data-assistant-open="false"] { --studio-editor-margin-step: var(--boot-studio-desktop-editor-margin-sources, -1); }
    .studio[data-sources-open="false"][data-assistant-open="true"] { --studio-editor-margin-step: var(--boot-studio-desktop-editor-margin-assistant, -1); }
    .studio[data-sources-open="true"][data-assistant-open="true"] { --studio-editor-margin-step: var(--boot-studio-desktop-editor-margin-both, -2); }
}
[data-appearance-scope="assistant"] { --chat-font-scale: var(--boot-assistant-desktop-interface-scale, 1.0714285714); --chat-interface-font-scale: var(--chat-font-scale); --assistant-message-font-size: var(--boot-assistant-desktop-message-size, 12.5px); }
.assistant-panel #studioConversation { font-size: var(--assistant-message-font-size); }
@media (max-width: 768px) {
    body { --chat-font-scale: var(--boot-mobile-interface-scale, 1.0714285714); --chat-transcript-font-size: var(--boot-mobile-transcript-size, 16px); }
    :is(.studio, [data-appearance-scope="studio"]) { --chat-font-scale: var(--boot-studio-mobile-interface-scale, 1.0714285714); --studio-editor-font-size: var(--boot-studio-mobile-editor-size, 14px); --studio-editor-margin-step: var(--boot-studio-mobile-editor-margin, 0); }
    [data-appearance-scope="assistant"] { --chat-font-scale: var(--boot-assistant-mobile-interface-scale, 1.0714285714); --assistant-message-font-size: var(--boot-assistant-mobile-message-size, 13px); }
}

/* ========================================
   RESET & BASE
   ======================================== */
*, *::before, *::after {
    box-sizing: border-box;
}

/* Mobile touch UX: remove tap highlight flash and accidental text-selection chrome. */
* {
    -webkit-tap-highlight-color: transparent;
}

input, textarea, [contenteditable="true"] {
    -webkit-user-select: text;
    user-select: text;
}

/* Allow selecting rendered chat text while keeping controls non-selectable. */
.message-text,
.message-text * {
    -webkit-user-select: text;
    user-select: text;
    -webkit-touch-callout: default;
}

/* Keep mobile tap UX for controls/badges without globally disabling text selection. */
button,
[role="button"],
.menu-toggle-btn,
.open-library-btn,
.chat-item,
.endpoint-trigger,
.endpoint-item,
.endpoint-add-btn,
.status-clickable,
.settings-tab,
.message-action,
.model-picker-trigger,
.model-picker-item,
.model-picker-fav,
.model-picker-clear,
.model-filter-tag,
.model-filter-checkbox,
.model-filter-icon-btn,
.endpoint-card,
.endpoint-card-edit,
.endpoint-form-back {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
}

.app-root {
    position: fixed;
    inset: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

body {
    height: calc(var(--vh, 1vh) * 100);
}

html.keyboard-open,
body.keyboard-open {
    height: calc(var(--vh, 1vh) * 100);
    overflow: hidden;
    overscroll-behavior: none;
}

html.keyboard-open {
    position: fixed;
    width: 100%;
}

body.keyboard-open {
    position: fixed;
    width: 100%;
    overflow: hidden;
}

body.keyboard-open .top-bar,
body.keyboard-open .status-bar,
body.keyboard-open .main-layout {
    transition: none !important;
}


body {
    font-family: var(--font-ui);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    /* Match top-bar background so wide-screen gutters don't look like a different "page" */
    background: var(--bg-elevated);
    -webkit-font-smoothing: antialiased;
}

/* Scrollbars */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--bg-accent) transparent;
}

*::-webkit-scrollbar {
    width: 7.5px;
    height: 7.5px;
}

*::-webkit-scrollbar-track {
    background: transparent;
}

*::-webkit-scrollbar-thumb {
    background: var(--bg-accent);
    border-radius: 999px;
    border: 2.25px solid transparent;
    background-clip: content-box;
}

*::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
    background-clip: content-box;
}

/* One scrollbar for every side panel: Chat's conversation list and Boost pane, Studio's Workspace rail and Assistant.
 * The thumb comes from each panel's own ink so it reads on any surface (--bg-accent equals Studio's rail surfaces). */
:is(.chat-list, .v2-boost-pane, .v2-memory-sidebar, .studio-current-workspace-pane, #studioRail-recent, #studioConversation, #studioThreadList) {
    --sidebar-scrollbar-thumb: color-mix(in srgb, var(--ink-primary) 18%, transparent);
    scrollbar-width: thin;
    scrollbar-color: var(--sidebar-scrollbar-thumb) transparent;
}

:is(.chat-list, .v2-boost-pane, .v2-memory-sidebar, .studio-current-workspace-pane, #studioRail-recent, #studioConversation, #studioThreadList)::-webkit-scrollbar-thumb {
    background: var(--sidebar-scrollbar-thumb);
    background-clip: content-box;
}

:is(.chat-list, .v2-boost-pane, .v2-memory-sidebar, .studio-current-workspace-pane, #studioRail-recent, #studioConversation, #studioThreadList)::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
    background-clip: content-box;
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

input, textarea {
    font-family: inherit;
    font-size: inherit;
}

.message-text {
    font-family: var(--font-content);
}

.message-role {
    display: none;
}

/* ========================================
   TOP BAR
   ======================================== */
.settings-header-actions {
    display: flex;
    min-width: 0;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
}
/* Appearance, Models and Admin: one in-page nav of surfaces at the top of the panel. */
.settings-subnav.model-picker-tabs {
    display: flex;
    max-width: 420px;
    margin: 0 0 16px;
    padding: 0;
}
.settings-subnav .model-picker-tab {
    flex: 1 1 0;
}
.settings-subnav .model-picker-tab[hidden],
.settings-subpanel[hidden] {
    display: none;
}
.settings-subnav .model-picker-tab:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: -3px;
}
.settings-subpanel {
    display: grid;
    min-width: 0;
    align-content: start;
    gap: 10px;
}
.settings-subpanel-note {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.75rem;
    line-height: 1.45;
}
/* Admin policy controls. */
.admin-option-group {
    min-width: 0;
}
.admin-studio-version {
    display: grid;
    max-width: 32rem;
    gap: var(--space-2);
    margin: var(--space-5) 0;
}
.admin-option-title {
    margin: 0 0 var(--space-2);
}
.admin-option-check {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    color: var(--text-primary);
    font-size: 0.85rem;
    line-height: 1.4;
    cursor: pointer;
}
.admin-option-check input {
    flex: 0 0 auto;
    width: 17px;
    height: 17px;
    margin: 1px 0 0;
    accent-color: var(--accent-primary);
}
.admin-option-check input:disabled {
    opacity: 0.7;
    cursor: default;
}
.admin-option-check:has(input:disabled) {
    color: var(--text-muted);
    cursor: default;
}
.admin-option-field-label {
    margin-top: var(--space-4);
}
.admin-options-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: var(--space-2);
    margin-top: var(--space-5);
}
.admin-media-account-lookup {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--space-2);
    margin-top: var(--space-3);
}
.admin-media-account-lookup button {
    white-space: nowrap;
}
#adminMediaAccountEditor {
    margin-top: var(--space-4);
    padding-top: var(--space-3);
    border-top: 1px solid var(--border-subtle);
}
.admin-media-account-identity {
    margin: 0;
    overflow: hidden;
    color: var(--text-primary);
    font-size: 0.82rem;
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
}
@media (max-width: 560px) {
    .admin-media-account-lookup {
        grid-template-columns: 1fr;
    }
}
.admin-site-status {
    min-height: 1.2em;
    margin: var(--space-3) 0 0;
    color: var(--text-secondary);
    font-size: 0.8rem;
    line-height: 1.4;
}
.admin-site-status[data-tone="error"] {
    color: var(--error);
}
.admin-site-status[data-tone="success"] {
    color: var(--success);
}
/* Admin -> Access: four compact lists; one dialog edits the chosen row. */
.admin-access-view {
    gap: var(--space-3);
}
.admin-access-view .settings-subpanel-note {
    margin-top: -2px;
}
.admin-access-head {
    display: flex;
    min-height: 32px;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    color: var(--text-muted);
    font-size: 0.75rem;
}
.admin-access-head .btn-secondary {
    min-height: 32px;
    padding: 4px 12px;
    font-size: 0.78rem;
}
.admin-access-toolbar {
    display: grid;
    grid-template-columns: minmax(9.5rem, 11rem) minmax(0, 1fr) auto;
    align-items: stretch;
    gap: var(--space-2);
}
.admin-access-toolbar .setting-input {
    min-height: 38px;
    padding: 7px 10px;
    font-size: 0.8125rem;
}
.admin-access-toolbar .btn-secondary {
    min-height: 38px;
    padding: 6px 14px;
}
.admin-access-list {
    display: grid;
    margin: 0;
    padding: 0;
    border-top: 1px solid var(--border-subtle);
    border-bottom: 1px solid var(--border-subtle);
    list-style: none;
}
.admin-access-list > li + li {
    border-top: 1px solid var(--border-subtle);
}
.admin-access-row-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
}
.admin-access-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto 16px;
    grid-template-areas:
        "title badge chevron"
        "meta badge chevron";
    align-items: center;
    gap: 3px var(--space-3);
    width: 100%;
    min-height: 54px;
    padding: 8px 6px 8px 10px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--text-primary);
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.admin-access-row:is(:hover, :focus-visible) {
    background: color-mix(in srgb, var(--accent-primary) 7%, transparent);
    outline: none;
}
.admin-access-row:focus-visible {
    box-shadow: inset 0 0 0 2px var(--accent-primary);
}
.admin-access-row-title {
    display: flex;
    grid-area: title;
    min-width: 0;
    align-items: center;
    gap: 8px;
}
.admin-access-row-title strong {
    min-width: 0;
    overflow: hidden;
    flex: 0 1 auto;
    font-size: 0.85rem;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.admin-access-row-detail,
.admin-access-row-meta {
    min-width: 0;
    overflow: hidden;
    color: var(--text-muted);
    font-size: 0.74rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}
/* The sign-in detail yields first, so a narrow row keeps the account name. */
.admin-access-row-detail {
    flex: 1 1 0;
}
.admin-access-row-meta {
    grid-area: meta;
    color: var(--text-secondary);
}
.admin-access-tag {
    flex: none;
    padding: 0 6px;
    border: 1px solid var(--border-subtle);
    border-radius: 4px;
    color: var(--text-muted);
    font-size: 0.64rem;
    font-weight: 650;
    line-height: 1.6;
}
.admin-access-tag[data-tone="error"] {
    border-color: color-mix(in srgb, var(--error) 45%, transparent);
    color: var(--error);
}
.admin-access-badge {
    grid-area: badge;
    padding: 2px 9px;
    border: 1px solid var(--border-subtle);
    border-radius: 999px;
    color: var(--text-secondary);
    font-size: 0.7rem;
    font-weight: 600;
    white-space: nowrap;
}
.admin-access-row > svg {
    grid-area: chevron;
    width: 16px;
    height: 16px;
    color: var(--text-muted);
}
.admin-access-availability {
    display: inline-flex;
    min-width: 7.5rem;
    min-height: 34px;
    align-items: center;
    justify-content: center;
    gap: 7px;
    margin-right: 8px;
    padding: 5px 9px;
    border: 1px solid var(--border-subtle);
    border-radius: 999px;
    background: transparent;
    color: var(--text-secondary);
    font: inherit;
    font-size: 0.7rem;
    font-weight: 650;
    cursor: pointer;
}
.admin-access-availability::before {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
    content: "";
}
.admin-access-availability[data-available="true"] {
    border-color: color-mix(in srgb, var(--success) 45%, var(--border-subtle));
    color: var(--success);
}
.admin-access-availability:is(:hover, :focus-visible) {
    border-color: currentColor;
    outline: none;
}
.admin-access-availability:focus-visible {
    box-shadow: 0 0 0 2px color-mix(in srgb, currentColor 30%, transparent);
}
.admin-access-availability:disabled {
    cursor: wait;
    opacity: 0.55;
}
.admin-access-empty {
    margin: 0;
    padding: 18px 10px;
    border-top: 1px solid var(--border-subtle);
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-muted);
    font-size: 0.78rem;
    text-align: center;
}
.admin-access-empty[data-tone="error"] {
    color: var(--error);
}
.admin-access-view > .admin-access-empty + .btn-secondary {
    justify-self: center;
}
.admin-access-dialog {
    width: min(540px, calc(100vw - 24px));
    max-width: none;
    max-height: calc(100dvh - 24px);
}
.admin-access-dialog > form {
    display: contents;
}
.admin-access-panel.is-provider-editor > :not(.admin-access-provider-page) {
    display: none;
}
.admin-access-provider-page,
.admin-access-provider-page > form {
    display: grid;
    min-width: 0;
}
.admin-access-provider-header {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    padding: 0 0 14px;
    border-bottom: 1px solid var(--border-subtle);
}
.admin-access-provider-header h2 {
    min-width: 0;
    margin: 0;
    overflow: hidden;
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.admin-access-provider-back {
    min-height: 34px;
}
.admin-access-editor-body {
    display: grid;
    min-height: 0;
    align-content: start;
    gap: 14px;
}
.admin-access-dialog .admin-access-editor-body {
    padding: 16px 18px 18px;
}
.admin-access-provider-page .admin-access-editor-body {
    padding: 16px 0 18px;
}
.admin-access-provider-footer {
    position: sticky;
    z-index: 2;
    bottom: 0;
    display: flex;
    min-height: 58px;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 11px 0;
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-elevated);
}
.admin-access-provider-footer .admin-access-delete {
    margin-right: auto;
    color: var(--error);
}
.admin-access-provider-footer button:disabled {
    cursor: default;
    opacity: 0.45;
}
.admin-access-field {
    display: grid;
    min-width: 0;
    align-content: start;
    gap: 6px;
}
.admin-access-field[hidden] {
    display: none;
}
.admin-access-editor :is(.admin-access-field > .setting-label, .admin-access-checks > legend) {
    margin: 0;
    padding: 0;
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 650;
}
.admin-access-editor .setting-input {
    min-height: 38px;
    padding: 7px 10px;
    border-color: var(--border-subtle);
    border-radius: 6px;
    font-size: 0.8125rem;
}
.admin-access-editor .setting-hint {
    margin: 0;
    font-size: 0.72rem;
    line-height: 1.4;
}
.admin-access-pair {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 11rem);
    align-items: start;
    gap: 12px;
}
.admin-access-checks {
    display: grid;
    min-width: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 16px;
    margin: 0;
    padding: 0;
    border: 0;
}
.admin-access-checks > legend {
    margin-bottom: 8px;
}
.admin-access-checks > .setting-hint {
    grid-column: 1 / -1;
}
.admin-access-dialog-tabs {
    display: grid;
    min-width: 0;
    gap: 10px;
}
.admin-access-dialog-tablist {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-bottom: 1px solid var(--border-subtle);
}
.admin-access-dialog-tab {
    min-height: 34px;
    padding: 5px 10px;
    border: 0;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: var(--text-muted);
    font: 650 0.78rem/1.3 var(--font-ui);
    cursor: pointer;
}
.admin-access-dialog-tab[aria-selected="true"] {
    border-bottom-color: var(--accent-primary);
    color: var(--text-primary);
}
.admin-access-dialog-tab:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: -2px;
}
.admin-access-dialog-tabpanel {
    min-width: 0;
}
.admin-access-dialog-tabpanel > .admin-access-scroll-checks > legend {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
}
.admin-access-scroll-checks {
    max-height: min(280px, 35dvh);
    overflow: auto;
    padding: 9px 10px;
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
}
.admin-access-scroll-checks > legend {
    padding: 0 4px;
}
.admin-access-model-access,
.admin-access-model-chooser {
    display: grid;
    min-width: 0;
    gap: 8px;
}
.admin-access-model-chooser > .setting-input {
    width: 100%;
}
.admin-access-model-columns {
    display: grid;
    min-width: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}
.admin-access-model-column {
    min-width: 0;
    overflow: hidden;
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
}
.admin-access-model-column h3 {
    margin: 0;
    padding: 7px 9px;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    font-size: 0.72rem;
    font-weight: 650;
}
.admin-access-model-column ul {
    display: grid;
    max-height: min(230px, 30dvh);
    margin: 0;
    padding: 0;
    overflow: auto;
    list-style: none;
}
.admin-access-provider-page .admin-access-model-column ul {
    max-height: min(340px, 40dvh);
}
.admin-access-model-column li + li {
    border-top: 1px solid var(--border-subtle);
}
.admin-access-model-choice {
    display: grid;
    width: 100%;
    min-width: 0;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    padding: 7px 8px;
    border: 0;
    background: transparent;
    color: var(--text-primary);
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.admin-access-model-choice:is(:hover, :focus-visible) {
    background: color-mix(in srgb, var(--accent-primary) 8%, transparent);
    outline: none;
}
.admin-access-model-choice > span:first-child {
    display: grid;
    min-width: 0;
    gap: 1px;
}
.admin-access-model-choice strong,
.admin-access-model-choice small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.admin-access-model-choice strong {
    font-size: 0.76rem;
    font-weight: 600;
}
.admin-access-model-choice small {
    color: var(--text-muted);
    font-size: 0.66rem;
}
.admin-access-model-choice small.admin-access-model-choice-price {
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    line-height: 1.25;
    white-space: normal;
}
.admin-access-model-choice-mark {
    color: var(--accent-primary);
    font-size: 1rem;
    line-height: 1;
}
.admin-access-model-empty {
    padding: 12px 8px;
    color: var(--text-muted);
    font-size: 0.72rem;
    text-align: center;
}
.admin-access-facts {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    gap: 6px 14px;
    margin: 0;
    padding: 10px 12px;
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    background: var(--bg-subtle);
    font-size: 0.8rem;
}
.admin-access-facts dt {
    color: var(--text-muted);
}
.admin-access-facts dd {
    min-width: 0;
    margin: 0;
    color: var(--text-primary);
    overflow-wrap: anywhere;
}
.admin-access-models {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: 8px 10px 8px 12px;
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.8rem;
}
.admin-access-models .btn-secondary {
    min-height: 30px;
    padding: 4px 12px;
    font-size: 0.76rem;
}
.admin-access-dialog-status {
    margin: 0;
    padding: 8px 10px;
    border-radius: 6px;
    background: var(--error-muted);
    color: var(--error);
    font-size: 0.8rem;
    line-height: 1.4;
}
.admin-access-dialog-status[hidden] {
    display: none;
}
.admin-access-invite-result {
    display: grid;
    min-width: 0;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    background: var(--bg-subtle);
}
.admin-access-invite-result[hidden] {
    display: none;
}
.admin-access-invite-result .setting-input {
    width: 100%;
}
.admin-access-invite-result .admin-access-copy {
    justify-self: start;
}
@media (max-width: 560px) {
    .admin-access-toolbar {
        grid-template-columns: minmax(0, 1fr) auto;
    }
    .admin-access-toolbar > .sandcat-select {
        grid-column: 1 / -1;
    }
    .admin-access-pair,
    .admin-access-checks {
        grid-template-columns: minmax(0, 1fr);
    }
    .admin-access-row-item .admin-access-row {
        grid-template-columns: minmax(0, 1fr) 16px;
        grid-template-areas:
            "title chevron"
            "meta chevron"
            "badge chevron";
    }
    .admin-access-row-item .admin-access-badge {
        justify-self: start;
    }
    .admin-access-dialog .admin-access-editor-body {
        padding: 14px 14px 16px;
    }
    .admin-access-provider-footer {
        bottom: 0;
    }
    .admin-access-model-columns {
        grid-template-columns: minmax(0, 1fr);
    }
    .admin-access-model-column ul {
        max-height: 150px;
    }
}
/* The preview card wears its surface's own scope (Chat by default,
 * data-appearance-scope for Assistant and Studio), so it shows that surface's
 * colours, Interface font and this screen's text size while nothing else moves. */
.appearance-specimen {
    display: grid;
    gap: 6px;
    padding: 12px 14px;
    border: 1px solid var(--line-default);
    border-radius: var(--radius-md);
    background: var(--surface-default);
    color: var(--ink-primary);
    font-family: var(--font-interface);
}
.appearance-specimen-label {
    color: var(--ink-muted);
    font-size: 0.75rem;
}
/* The text size arrives through --specimen-text-size: these sizes are already
 * final, and the Interface scaling pass only rewrites literal font sizes. */
.appearance-specimen-text {
    margin: 0;
    font-family: var(--specimen-text-font);
    font-size: var(--specimen-text-size);
    line-height: 1.5;
}
.appearance-specimen[data-specimen="chat"] {
    --specimen-text-font: var(--font-reading);
    --specimen-text-size: var(--chat-transcript-font-size);
}
.appearance-specimen[data-specimen="assistant"] {
    --specimen-text-font: var(--font-reading);
    --specimen-text-size: var(--assistant-message-font-size);
}
.appearance-specimen[data-specimen="studio"] {
    --specimen-text-font: var(--font-interface);
    --specimen-text-size: var(--studio-editor-font-size);
}
.appearance-specimen-accent {
    justify-self: start;
    padding: 3px 9px;
    border-radius: 4px;
    background: var(--lime-default);
    color: var(--lime-on);
    font-size: 0.75rem;
    font-weight: 600;
}
.appearance-mode-settings {
    min-width: 0;
    border: 0;
    padding: 0;
}
.appearance-mode-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 7px;
}
.appearance-mode-card {
    min-width: 0;
    padding: 11px;
    overflow: hidden;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: var(--surface-default);
    color: var(--text-primary);
    cursor: pointer;
}
.appearance-mode-card.is-active {
    border-color: var(--accent-primary);
    box-shadow: inset 0 0 0 2px var(--accent-primary);
}
.appearance-mode-select {
    display: grid;
    width: 100%;
    grid-template-columns: minmax(0, 1fr) 24px;
    align-items: center;
    gap: 8px;
    margin: 0 0 10px;
    padding: 0 0 9px;
    border: 0;
    border-bottom: 1px solid var(--border-default);
    background: transparent;
    color: var(--text-primary);
    text-align: left;
}
.appearance-mode-select > span:first-child,
.appearance-mode-select strong,
.appearance-mode-select small {
    display: block;
    min-width: 0;
}
.appearance-mode-select strong {
    font-size: 0.875rem;
    font-weight: 700;
}
.appearance-mode-select small {
    margin-top: 2px;
    color: var(--text-muted);
    font-size: 0.64rem;
}
.appearance-mode-select:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 3px;
}
.appearance-mode-check {
    display: grid;
    width: 22px;
    height: 22px;
    place-items: center;
    border: 1px solid var(--border-default);
    border-radius: 50%;
    color: var(--accent-primary);
    opacity: 0;
}
.appearance-mode-card.is-active .appearance-mode-check {
    opacity: 1;
}
.appearance-mode-card .setting-label {
    margin: 9px 0 5px;
    padding: 0;
    color: var(--text-muted);
    font-size: 0.75rem;
}
.appearance-accent-row {
    display: grid;
    grid-template-columns: 16px minmax(0, 1fr) 42px;
    align-items: center;
    gap: 8px;
}
.appearance-accent-preview {
    width: 16px;
    height: 16px;
    border: 1px solid color-mix(in srgb, currentColor 24%, transparent);
    border-radius: 50%;
    background: var(--appearance-custom-preview);
}
.appearance-accent-row[data-mode='light'][data-accent='cobalt'] .appearance-accent-preview { background: #2563eb; }
.appearance-accent-row[data-mode='light'][data-accent='forest'] .appearance-accent-preview { background: #0b7a55; }
.appearance-accent-row[data-mode='light'][data-accent='violet'] .appearance-accent-preview { background: #7c3aed; }
.appearance-accent-row[data-mode='light'][data-accent='rose'] .appearance-accent-preview { background: #e11d48; }
.appearance-accent-row[data-mode='light'][data-accent='amber'] .appearance-accent-preview { background: #b45309; }
.appearance-accent-row[data-mode='light'][data-accent='lime'] .appearance-accent-preview { background: #65a30d; }
.appearance-accent-row[data-mode='dark'][data-accent='lime'] .appearance-accent-preview { background: #a3e635; }
.appearance-accent-row[data-mode='dark'][data-accent='cyan'] .appearance-accent-preview { background: #22d3ee; }
.appearance-accent-row[data-mode='dark'][data-accent='violet'] .appearance-accent-preview { background: #a78bfa; }
.appearance-accent-row[data-mode='dark'][data-accent='rose'] .appearance-accent-preview { background: #fb7185; }
.appearance-accent-row[data-mode='dark'][data-accent='amber'] .appearance-accent-preview { background: #fbbf24; }
.appearance-accent-row[data-mode='light'][data-accent='studio'] .appearance-accent-preview { background: #245fa8; }
.appearance-accent-row[data-mode='dark'][data-accent='studio'] .appearance-accent-preview { background: #83c5f4; }
.appearance-color-picker {
    width: 42px;
    height: 38px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: var(--surface-default);
    cursor: pointer;
    padding: 3px;
}
.appearance-color-picker:disabled {
    cursor: default;
    opacity: 0.4;
}
.appearance-color-picker:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
}
.appearance-family-settings {
    min-width: 0;
    border: 0;
    padding: 0;
}
.appearance-family-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}
.appearance-family-grid section {
    min-width: 0;
}
.appearance-family-grid > section:only-child {
    grid-column: 1 / -1;
}
.appearance-family-grid h3 {
    margin: 0 0 8px;
    color: var(--text-secondary);
    font-family: var(--font-interface);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.appearance-font-options {
    display: grid;
    gap: 6px;
}
.appearance-font-option {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: baseline;
    gap: 12px;
    width: 100%;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: var(--surface-default);
    color: var(--text-primary);
    cursor: pointer;
    padding: 9px 10px;
    text-align: left;
}
.appearance-font-option:hover {
    border-color: var(--border-strong);
    background: var(--surface-muted);
}
.appearance-font-option[aria-pressed='true'] {
    border-color: var(--lime-strong);
    background: var(--accent-muted);
}
.appearance-font-option:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
}
.appearance-font-option strong {
    min-width: 0;
    font-size: 0.875rem;
    font-weight: 700;
}
.appearance-font-option span {
    color: var(--text-muted);
    font-family: var(--font-interface);
    font-size: 0.6875rem;
}
.appearance-font-option[data-font-preview='dm-sans'] strong { font-family: 'DM Sans', sans-serif; }
.appearance-font-option[data-font-preview='manrope'] strong { font-family: 'Manrope', sans-serif; }
.appearance-font-option[data-font-preview='atkinson'] strong { font-family: 'Atkinson Hyperlegible', sans-serif; }
.appearance-font-option[data-font-preview='inter'] strong { font-family: 'Inter', sans-serif; }
.appearance-font-option[data-font-preview='sora'] strong { font-family: 'Sora', sans-serif; }
.appearance-font-option[data-font-preview='space-grotesk'] strong { font-family: 'Space Grotesk', sans-serif; }
.appearance-font-option[data-font-preview='instrument-sans'] strong { font-family: 'Instrument Sans', sans-serif; }
.appearance-font-option[data-font-preview='system'] strong { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
.appearance-font-settings {
    min-width: 0;
    border: 0;
    padding: 0;
}
.appearance-font-settings .setting-label {
    padding: 0;
}
.appearance-font-grid {
    display: grid;
    grid-template-columns: minmax(92px, 1fr) repeat(2, 82px);
    align-items: center;
    gap: 8px 12px;
}
.appearance-font-device {
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    text-align: center;
}
.appearance-font-kind {
    color: var(--text-secondary);
    font-size: 0.8125rem;
}
.appearance-font-input {
    min-width: 0;
    padding: var(--space-2);
    text-align: center;
}
.appearance-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 14px;
}
.appearance-reset {
    min-width: 132px;
}
.studio-toolbar-settings {
    display: grid;
    min-width: 0;
    gap: 8px;
    border: 0;
    padding: 0;
}
.studio-toolbar-settings > .setting-hint {
    margin: -2px 0 2px;
}
.studio-toolbar-settings-list {
    display: grid;
    gap: 5px;
}
.studio-toolbar-setting-row {
    display: grid;
    grid-template-columns: 24px minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 6px;
    min-width: 0;
    padding: 6px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: var(--surface-default);
}
.studio-toolbar-setting-row[data-visible='false'] {
    background: var(--surface-muted);
}
.studio-toolbar-setting-icon {
    display: grid;
    width: 24px;
    height: 24px;
    place-items: center;
    color: var(--text-secondary);
}
.studio-toolbar-setting-icon svg {
    width: 18px;
    height: 18px;
}
.studio-toolbar-setting-copy {
    display: grid;
    min-width: 0;
    gap: 1px;
}
.studio-toolbar-setting-copy strong {
    overflow: hidden;
    color: var(--text-primary);
    font-size: .8125rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.studio-toolbar-setting-copy small {
    color: var(--text-muted);
    font-size: .6875rem;
}
.studio-toolbar-setting-order {
    display: flex;
    gap: 2px;
}
.studio-toolbar-setting-move {
    display: grid;
    width: 26px;
    min-width: 26px;
    height: 26px;
    place-items: center;
    padding: 0;
    border: 1px solid var(--border-default);
    border-radius: 5px;
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
}
.studio-toolbar-setting-move:not(:disabled):is(:hover, :focus-visible) {
    border-color: var(--border-strong);
    background: var(--surface-muted);
}
.studio-toolbar-setting-move:disabled {
    opacity: .35;
}
.studio-toolbar-setting-toggle {
    min-width: 112px;
    min-height: 28px;
    padding: 4px 8px;
    font-size: .72rem;
}
.studio-toolbar-settings-reset {
    justify-self: end;
    min-height: 30px;
}
@media (max-width: 480px) {
    .studio-toolbar-setting-row {
        grid-template-columns: 24px minmax(0, 1fr) auto;
    }
    .studio-toolbar-setting-icon {
        grid-column: 1;
        grid-row: 1 / span 2;
    }
    .studio-toolbar-setting-copy {
        grid-column: 2;
        grid-row: 1;
    }
    .studio-toolbar-setting-order {
        grid-column: 2;
        grid-row: 2;
    }
    .studio-toolbar-setting-toggle {
        grid-column: 3;
        grid-row: 1 / span 2;
        min-width: 104px;
    }
}
@media (max-width: 480px) {
    .appearance-mode-grid,
    .appearance-family-grid {
        grid-template-columns: 1fr;
    }
    .appearance-font-grid {
        grid-template-columns: minmax(86px, 1fr) repeat(2, 72px);
        gap: 8px;
    }
}
.chat-sidebar-resizer {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 8px;
    z-index: 42;
    cursor: col-resize;
    touch-action: none;
    background: transparent;
    outline: none;
}
/* The right panel's edge continues through its fixed-footer segment. */
.chat-sidebar-resizer[data-side="right"] {
    top: var(--topbar-height);
    z-index: 101;
}
.chat-sidebar-resizer[hidden] { display: none; }
.chat-sidebar-resizer::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 1px;
    background: transparent;
    transform: translateX(-50%);
    pointer-events: none;
}
/* One 4px highlight weight for every panel divider in Chat and Studio. */
.chat-sidebar-resizer:hover::before,
.chat-sidebar-resizer:focus-visible::before,
.chat-sidebar-resizer.is-dragging::before {
    width: 4px;
    background: var(--accent-primary);
}
body.chat-sidebar-dragging { cursor: col-resize; user-select: none; }

.top-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-height);
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.top-bar-inner {
    /* Allow the layout to shrink below 1280px without causing horizontal overflow */
    width: 100%;
    max-width: 1280px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 calc(var(--space-2) + var(--safe-right)) 0 calc(var(--space-2) + var(--safe-left));
}

/* Wide screen: constrain chrome to readable width */

.top-bar-left {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--space-1);
}


/* Menu Toggle Button */
.menu-toggle-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    /* Paint only: animating `all` also animated its size across breakpoints. */
    transition: background var(--transition-fast), border-color var(--transition-fast);
    flex-shrink: 0;
}

.menu-toggle-btn:hover {
    background: var(--bg-hover);
}

.menu-toggle-btn svg {
    width: 22px;
    height: 22px;
}

.app-version {
    position: absolute;
    z-index: 2;
    top: 6px;
    left: 15px;
    transform: translateX(-50%);
    color: var(--studio-accent, var(--lime-strong));
    font-family: var(--font-interface);
    font-size: 0.325rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.04em;
    line-height: 1;
    white-space: nowrap;
    text-shadow: 0 1px 1px var(--bg-elevated);
    pointer-events: none;
}

body.ui-version-v2.guest-workspace.v2-no-chat .app-version {
    left: 14px;
}

@media (max-width: 768px) {
    body.ui-version-v2 .app-version {
        left: 18px;
    }

    body.ui-version-v2.guest-workspace.v2-no-chat .app-version {
        left: 14px;
    }
}

/* Powered-by tagline: empty state (below "Select a chat...") and in-chat (top of messages) */
.powered-by-tagline {
    font-size: 10px;
    color: var(--text-muted);
    opacity: 0.75;
}

.powered-by-tagline-in-chat {
    flex-shrink: 0;
    padding: 0;
    margin-bottom: 0;
    text-align: center;
}

.powered-by-tagline-in-chat.powered-by-tagline-in-chat-with-header {
    margin-bottom: calc(-1 * var(--space-2));
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.app-title-anchor {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 0;
    min-width: 0;
}

.debug-status {
    font-size: 10px;
    color: var(--text-muted);
    opacity: 0.8;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-title {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--text-primary);
}

a.app-title {
    text-decoration: none;
    border-radius: var(--radius-sm);
}

a.app-title:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 4px;
}

.app-title-text {
    font-size: 1.2rem;
    font-weight: 600;
}


body.ui-version-v2 .top-bar {
    box-shadow: 0 1px 0 color-mix(in srgb, var(--accent-primary) 28%, transparent);
}

.shell-opening-title {
    font-size: 1rem;
    font-weight: 300;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 260px;
}

.shell-opening-title:empty {
    display: none;
}

.shell-opening-title::before {
    content: "/";
    margin-right: var(--space-2);
    opacity: 0.4;
}

/* Endpoint Selector */
.endpoint-selector {
    position: relative;
}

.endpoint-trigger {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    background: var(--bg-subtle);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: all var(--transition-fast);
}

.endpoint-trigger:hover {
    background: var(--bg-hover);
    border-color: var(--border-strong);
}

.endpoint-name {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.endpoint-arrow {
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    transition: transform var(--transition-fast);
}

.endpoint-selector.open .endpoint-arrow {
    transform: rotate(180deg);
}

.endpoint-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    min-width: 220px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all var(--transition-fast);
    z-index: 200;
}

.endpoint-selector.open .endpoint-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.endpoint-list {
    padding: var(--space-2);
    max-height: 300px;
    overflow-y: auto;
}

.endpoint-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.endpoint-item:hover {
    background: var(--bg-hover);
}

.endpoint-item.active {
    background: var(--accent-muted);
}

.endpoint-item-disabled {
    opacity: 0.58;
    cursor: default;
}

.endpoint-item-disabled:hover {
    background: transparent;
}

.endpoint-item-name {
    font-weight: 500;
}

.endpoint-item-model {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.endpoint-item-check {
    width: 16px;
    height: 16px;
    color: var(--accent-primary);
    opacity: 0;
}

.endpoint-item.active .endpoint-item-check {
    opacity: 1;
}

.endpoint-add-btn {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    width: 100%;
    padding: var(--space-3);
    border-top: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    font-size: 0.875rem;
    transition: all var(--transition-fast);
}

.endpoint-add-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.endpoint-add-btn svg {
    width: 18px;
    height: 18px;
}


/* ========================================
   MAIN LAYOUT
   ======================================== */
.main-layout {
    position: absolute;
    top: var(--topbar-height);
    left: 50%;
    height: calc(100% - var(--topbar-height) - var(--statusbar-height));
    display: flex;
    /* Desktop: cap at 1280px, but shrink with the viewport instead of staying fixed */
    width: 100%;
    max-width: 1280px;
    transform: translateX(-50%);
    overflow: hidden;
}

/* ========================================
   SIDEBAR
   ======================================== */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-elevated);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    transition: transform var(--transition-normal);
    overflow: hidden;
    flex-shrink: 0;
}

/* Desktop: the column is reserved or released in one frame by the negative
 * margin, while only the painted panel travels. The panel keeps its full width
 * and is clipped by the layout, so the slide is never an animated geometry
 * change and the transcript reflows exactly once per toggle. */
@media (min-width: 769px) {
    .sidebar {
        position: relative;
        z-index: 1;
    }
    .sidebar.collapsed {
        margin-right: calc(var(--sidebar-width) * -1);
        transform: translateX(-100%);
        visibility: hidden;
        transition: transform var(--transition-normal), visibility 0s linear 200ms;
    }
}
@media (min-width: 769px) and (prefers-reduced-motion: reduce) {
    .sidebar,
    .sidebar.collapsed {
        transition: none;
    }
}

.sidebar-header {
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
}

.open-library-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    width: 100%;
    padding: var(--space-3);
    background: var(--accent-primary);
    color: var(--accent-on);
    font-weight: 500;
    border-radius: var(--radius-md);
    transition: background var(--transition-fast);
}

.open-library-btn:hover {
    background: var(--accent-hover);
    color: var(--accent-hover-on);
}


.chat-list {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: none;
    touch-action: pan-y;
    padding: 4px var(--space-2);
}


.chat-list-empty {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.chat-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 6px 8px;
    border-radius: 3px;
    cursor: pointer;
    transition: background var(--transition-fast);
    margin-bottom: 2px;
}

.chat-item-ungrouped {
    min-height: 44px;
    gap: 6px;
    margin: 1px 0;
    padding: 4px 5px;
}

.chat-item-manuscript-link {
    display: flex;
    min-width: 0;
    flex: 1;
    align-self: stretch;
    align-items: center;
    gap: 6px;
    color: inherit;
    text-decoration: none;
}

.chat-item-portrait {
    display: grid;
    box-sizing: border-box;
    width: 28px;
    min-width: 28px;
    max-width: 28px;
    height: 28px;
    min-height: 28px;
    max-height: 28px;
    aspect-ratio: 1;
    flex: 0 0 28px;
    place-items: center;
    overflow: hidden;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    color: var(--text-muted);
    font-size: 0.67rem;
    font-weight: 700;
}

.chat-item-portrait img {
    display: block;
    width: 100%;
    min-width: 100%;
    max-width: 100%;
    height: 100%;
    min-height: 100%;
    max-height: 100%;
    object-fit: cover;
    object-position: 50% 25%;
}

.chat-item-ungrouped-copy {
    display: grid;
    align-content: center;
    gap: 1px;
    overflow: hidden;
    white-space: nowrap;
}

.chat-item-character {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 2px;
    overflow: hidden;
    color: var(--text-secondary);
    font-size: 0.72rem;
    font-weight: 650;
    line-height: 1.15;
}

.chat-item-character-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-item-ungrouped-copy .chat-item-title {
    display: block;
    min-width: 0;
    overflow: hidden;
    color: var(--text-muted);
    font-size: 0.65rem;
    font-weight: 450;
    line-height: 1.15;
    text-overflow: ellipsis;
}

.chat-item-relative-time {
    flex: 0 0 auto;
    margin-left: 0;
    font-size: 0.6rem;
    font-variant-numeric: tabular-nums;
}

/* Width is fixed so the title column keeps its room. Height fills the row's content
 * box (44px min-height less the 4px vertical padding and 1px borders), so the larger
 * target and dots never grow the row. The 1px translate is visual only: it moves the
 * button into the row's right padding without changing layout. */
.chat-item-menu-button {
    display: grid;
    flex: 0 0 18px;
    width: 18px;
    height: 34px;
    place-items: center;
    padding: 0;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    transform: translateX(1px);
}

.chat-item-menu-dots {
    display: grid;
    gap: 3px;
    place-items: center;
}

.chat-item-menu-dots i {
    display: block;
    width: 3.5px;
    height: 3.5px;
    border-radius: 50%;
    background: currentColor;
}

.chat-item-menu-button:hover,
.chat-item-menu-button[aria-expanded="true"] {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.chat-item-menu.sandcat-menu {
    position: absolute;
    z-index: 40;
    top: calc(100% - 2px);
    right: 3px;
    width: min(216px, calc(100% - 6px));
}

/* No room below the row: open upward (placed by placeChatItemMenu in app.js). */
.chat-item-menu.sandcat-menu.is-above {
    top: auto;
    bottom: calc(100% - 2px);
}


@media (hover: hover) {
    .chat-item:hover:not(.active) {
        background: var(--bg-hover);
    }
}

.chat-item.active {
    background: var(--accent-muted);
}

.chat-item-icon {
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.chat-item.active .chat-item-icon {
    color: var(--accent-primary);
}

.chat-item-content {
    flex: 1;
    min-width: 0;
}

.chat-item-title {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-subtitle {
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
}

.chat-item-subtitle:empty {
    display: none;
}

.chat-item-date {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-left: auto;
}

.chat-item-generation {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 24px;
    min-width: 24px;
    color: var(--text-muted);
}
.activity-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    min-width: 12px;
    height: 14px;
    font: bold .88rem/1 system-ui, sans-serif;
}

@keyframes activity-pulse {
    50% {
        opacity: 0.58;
        transform: scale(0.86);
    }
}

.activity-dot,
.activity-mark[data-live="true"],
body.ui-version-v2 .message-flight-indicator > span,
body.ui-version-v2 .v2-story-outcome-mark[data-live="true"],
.studio #studioAIStatus[data-live="true"]::before {
    display: inline-block;
    width: 11px;
    min-width: 11px;
    height: 11px;
    flex: 0 0 11px;
    border: 0;
    border-radius: 50%;
    background: var(--activity-live);
    transform-origin: center;
}

.activity-dot,
.activity-mark[data-live="true"],
body.ui-version-v2 .message-flight-indicator > span,
body.ui-version-v2 .v2-story-outcome-mark[data-live="true"],
.studio #studioAIStatus[data-live="true"]::before {
    animation: activity-pulse 1.35s ease-in-out infinite;
}



.chat-item-generation[hidden] {
    display: none;
}

.chat-item-prompt,
.chat-item-delete {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    opacity: 0;
    transition: all var(--transition-fast);
}

.chat-item:hover .chat-item-prompt,
.chat-item:hover .chat-item-delete {
    opacity: 1;
}

@media (max-width: 768px) {
    .chat-item-prompt,
    .chat-item-delete {
        opacity: 0.6;
    }
}

.chat-item-prompt:hover {
    background: var(--accent-muted);
    color: var(--accent-primary);
}

.chat-item-delete:hover {
    background: var(--error-muted);
    color: var(--error);
}

.chat-item-prompt svg,
.chat-item-delete svg {
    width: 14px;
    height: 14px;
}

.sidebar-footer {
    padding: var(--space-3);
    border-top: 1px solid var(--border-subtle);
}

.sidebar-toggle-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    transition: all var(--transition-fast);
}

.sidebar-toggle-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sidebar-toggle-btn svg {
    width: 18px;
    height: 18px;
}

/* ========================================
   CHAT AREA
   ======================================== */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    min-height: 0;
    /* Flex item: allow shrinking so the RHS doesn't force horizontal overflow */
    min-width: 0;
    height: 100%;
    overscroll-behavior: contain;
}

/* Active Chat */
.chat-active {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
    position: relative;
    height: 100%;
}

.payloads-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.manager-toolbar {
    display: flex;
    justify-content: flex-end;
    margin: 8px 0 10px;
}

.manager-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.manager-item {
    background: var(--bg-subtle);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: 12px;
}

.manager-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}

.manager-main {
    min-width: 0;
    flex: 1;
}

.manager-title {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.manager-sub {
    margin-top: 3px;
    font-size: 0.74rem;
    color: var(--text-muted);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.manager-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.manager-editor {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-subtle);
}

.manager-field-label {
    display: block;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.manager-editor .setting-textarea,
.manager-editor .setting-input {
    margin-bottom: 8px;
}

.manager-editor-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

.payload-action-btn {
    border: 1px solid var(--border-default);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    padding: 5px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-family: var(--font-ui);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.payload-action-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.payload-action-btn:last-child:hover {
    background: var(--error-muted);
    color: var(--error);
    border-color: var(--error-muted);
}

.greeting-selector {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 0 var(--space-4) var(--space-2);
    font-size: 0.75rem;
    color: var(--text-muted);
}

.greeting-selector button {
    border: none;
    background: var(--bg-subtle);
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.greeting-selector button:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.greeting-selector-label {
    min-width: 3em;
    text-align: center;
}

/* Messages Container */
.messages-container {
    position: relative;
    overflow-y: auto;
    /* OpenCatTurnFlow is the sole transcript anchor during live layout changes. */
    overflow-anchor: none;
    padding: var(--space-4) calc(var(--space-4) + var(--safe-right)) var(--space-4) calc(var(--space-4) + var(--safe-left));
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    min-height: 0;
    padding-bottom: var(--space-4);
    overscroll-behavior: none;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
}

.messages-container::after {
    content: '';
    display: block;
    height: calc(var(--input-area-min) - 18px);
    flex-shrink: 0;
}

.messages-container.is-empty {
    padding: 0;
    overflow: hidden;
}

/* Chat Header (character name, author) */
.chat-header {
    text-align: center;
    padding: var(--space-4) var(--space-4) var(--space-2);
    margin-bottom: var(--space-2);
}

.chat-header-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-1);
}

.chat-header-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Message Bubbles */
.message {
    display: flex;
    gap: var(--space-3);
    max-width: 85%;
}

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message.assistant {
    align-self: flex-start;
}

.message-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
    width: 100%;
}

.message-meta-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    margin-top: 0;
    padding-top: 0;
    min-height: 22px;
}

.message-meta-actions {
    display: flex;
    align-items: center;
    gap: 1px;
}

.message-meta-row .message-action {
    width: 22px;
    height: 22px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 0;
    box-shadow: none;
}

.message-meta-row .message-action:hover {
    background: transparent;
    color: var(--text-primary);
}

.message-meta-row .message-action:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

.message-meta-row .message-action svg {
    width: 15px;
    height: 15px;
}

.message-meta-row .message-endpoint-model {
    font-size: 0.7rem;
    color: var(--text-muted);
}


.generation-receipt {
    max-width: 100%;
    color: var(--text-muted);
}

.generation-receipt-summary {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 7px;
    cursor: pointer;
    list-style: none;
}

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

.generation-receipt-summary-text {
    min-width: 0;
    overflow: hidden;
    color: var(--text-secondary);
    font: 500 0.64rem/1.3 var(--font-ui);
    text-overflow: ellipsis;
    white-space: nowrap;
}
.message-model-step-icon {
    display: none;
}

/* Turn activity: one summary line over the turn's steps. */
.message-model-turn-summary {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 6px;
    padding: 2px 0;
    border: 0;
    background: none;
    color: var(--text-muted);
    font: 500 0.64rem/1.3 var(--font-ui);
    text-align: left;
    cursor: pointer;
}

.message-model-turn-boost-icon {
    display: inline-grid;
    width: 12px;
    height: 12px;
    flex: 0 0 12px;
    margin-right: 4px;
    place-items: center;
    color: var(--text-muted);
}

.message-model-turn-boost-icon[hidden],
.message-model-turn-boosts[hidden] {
    display: none;
}

.message-model-turn-boost-icon svg {
    width: 100%;
    height: 100%;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.message-model-turn-boosts {
    margin: 3px 0 5px;
    color: var(--text-muted);
    font-size: 0.64rem;
}

.message-model-turn-boosts-heading {
    margin: 0 0 2px;
    color: var(--text-secondary);
    font-weight: 600;
}

.message-model-turn-boosts ul {
    display: flex;
    flex-direction: column;
    gap: 1px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.message-model-turn-boosts li {
    display: flex;
    min-width: 0;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 1px 12px;
}

.message-model-turn-boosts li strong {
    color: var(--text-secondary);
    font-weight: 600;
}

.message-model-turn-boost-states {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 2px 8px;
}

.message-model-turn-body[hidden],
.message-model-turn-totals[hidden] {
    display: none;
}

.message-model-turn-totals {
    margin: 4px 0 0;
    color: var(--text-muted);
    font-size: 0.62rem;
}

.generation-receipt-details {
    max-width: min(680px, 100%);
    margin: 4px 0 0;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-subtle);
    color: var(--text-secondary);
    font: 400 0.65rem/1.5 var(--font-code);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.message-generation-metadata {
    align-self: flex-end;
}

.message-generation-metadata .generation-receipt-summary {
    justify-content: flex-end;
    min-height: 28px;
}

.message-generation-metadata .generation-receipt-summary-text {
    text-align: right;
}


.message-meta {
    margin-top: 2px;
    text-align: right;
}

.message-model,
.message-endpoint-model {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: var(--bg-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.message-avatar svg {
    width: 18px;
    height: 18px;
    color: var(--text-secondary);
}

.message.user .message-avatar {
    background: var(--accent-muted);
}

.message.user .message-avatar svg {
    color: var(--accent-primary);
}

.message-content {
    position: relative;
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-lg);
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
}

/* Thinking block (collapsible, before message text) */
.message-thinking {
    margin-bottom: var(--space-2);
}

.message-thinking-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    width: 100%;
    padding: var(--space-1) 0;
    font-size: 0.75rem;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    transition: color var(--transition-fast);
}

.message-thinking-toggle:hover {
    color: var(--text-secondary);
}

.message-thinking-toggle::after {
    content: '';
    flex: 1;
}

.message-thinking-label {
    flex-shrink: 0;
}

.message-thinking-label-stream {
    display: inline-flex;
    gap: 0.01em;
    letter-spacing: 0.01em;
    align-items: baseline;
}


.message-thinking-toggle.collapsed::before {
    content: '▶';
    font-size: 0.6rem;
    margin-right: 4px;
    opacity: 0.7;
}

.message-thinking-toggle:not(.collapsed)::before {
    content: '▼';
    font-size: 0.6rem;
    margin-right: 4px;
    opacity: 0.7;
}

.message-thinking-body {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    padding: var(--space-2);
    margin-top: var(--space-1);
    background: var(--bg-subtle);
    border-radius: var(--radius-sm);
}

.message-thinking[data-live="true"] .message-thinking-body {
    display: block;
    max-height: 4em;
    overflow: hidden;
}

.message-thinking[data-live="true"].thinking-expanded .message-thinking-body {
    max-height: none;
    overflow: visible;
}

.turn-generation-chip {
    position: absolute;
    left: 50%;
    bottom: 6px;
    z-index: 24;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    transform: translateX(-50%);
    padding: 7px 11px;
    border: 1px solid var(--border-default);
    border-radius: 999px;
    background: var(--surface-default);
    color: var(--text-secondary);
    box-shadow: var(--shadow-sm);
    font: 600 0.68rem/1 var(--font-ui);
    letter-spacing: 0.03em;
    cursor: pointer;
}

.turn-generation-chip[hidden] { display: none; }

.turn-generation-chip span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--info);
    box-shadow: 0 0 0 3px var(--info-muted);
    animation: none;
}



/* Debug: raw/formatted toggle – icon only */
.message-debug-toggle {
    position: absolute;
    top: var(--space-2);
    right: var(--space-2);
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    background: var(--bg-subtle);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    cursor: pointer;
    z-index: 1;
    transition: color var(--transition-fast), background var(--transition-fast);
}

.message-debug-toggle .message-debug-icon,
.message-debug-toggle svg {
    width: 14px;
    height: 14px;
}

.message-debug-toggle:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.message-text-raw {
    margin-top: calc(-1 * var(--space-2));
}

.message-text-raw pre {
    margin: 0;
    padding: 0;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.8rem;
    line-height: 1.5;
    color: var(--text-secondary);
    font-family: var(--font-code);
}

.message.user .message-content {
    background: var(--accent-muted);
    border-color: transparent;
}

/* Message text: SillyTavern-style formatting (markdown → em, strong, u, blockquote, code, etc.) */
.message-text {
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.6;
}

/* Paragraphs: compact spacing (6px between blocks; was 10px) */
.message-text p,
.message-text .message-text p {
    margin-top: 0;
    margin-bottom: 0;
}

.message-text p:last-child,
.message-text > *:last-child {
    margin-bottom: 0;
}

/* Italics: distinct color like ST --SmartThemeEmColor */
.message-text i,
.message-text em {
    color: var(--message-em-color);
    font-style: italic;
}

.message-text u {
    color: var(--message-underline-color);
    text-decoration: underline;
}

.message-text q {
    color: inherit;
}

/* Disable browser's default quote marks on <q> - we keep original quotes in content */
.message-text q::before,
.message-text q::after {
    content: none;
}

/* ST parity: italics/underline inside quotes inherit quote color */
.message-text q i,
.message-text q em {
    color: inherit;
}

.message-text q u {
    color: inherit;
}

.message-text strong,
.message-text b,
.message-text h1,
.message-text h2,
.message-text h3 {
    font-weight: bold;
}


/* Blockquote: ST uses 10px padding-left, 30% black bg */
.message-text blockquote {
    border-left: 3px solid var(--message-quote-color);
    padding-left: 10px;
    padding-right: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin: 0;
    margin-left: 0;
    background-color: rgba(0, 0, 0, 0.3);
    color: inherit;
}

.message-text blockquote p {
    margin: 0;
    line-height: 1.35;
}

/* Space between blockquotes and between blockquote and adjacent p */
.message-text blockquote + blockquote,
.message-text p + blockquote,
.message-text blockquote + p {
    margin-top: 0;
}


.message-text code {
    background: var(--code-inline-bg);
    color: var(--code-text);
    padding: 0.125em 0.375em;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    font-family: var(--font-code);
    font-size: 0.875em;
}

/* ST parity: horizontal rules */
.message-text hr {
    background: var(--border-default);
    margin: 5px 0;
    height: 1px;
    border: 0;
    opacity: 0.4;
}


.message-text pre {
    background: var(--code-block-bg);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: var(--space-3);
    overflow-x: auto;
    margin: 0;
}

.message-text pre code {
    display: block;
    background: none;
    padding: 0;
}

.message-text ul,
.message-text ol {
    margin-top: 0;
    margin-bottom: 0;
    padding-left: 1.5em;
}

.message-text li {
    margin-bottom: 0;
}

.message-text table {
    border-collapse: collapse;
    margin-bottom: 0;
}

.message-text th,
.message-text td {
    border: 1px solid var(--border-subtle);
    padding: 0.25em 0.5em;
}

.message-text a {
    color: var(--accent-primary);
}

.message-text img {
    max-width: 100%;
    height: auto;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: var(--space-3) var(--space-4);
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

/* In-message streaming loader (inside assistant bubble) */
.message-stream-loader {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: var(--space-2) 0;
    min-height: 24px;
}

.message-stream-loader span {
    width: 6px;
    height: 6px;
    background: var(--accent-primary);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.message-stream-loader span:nth-child(2) {
    animation-delay: 0.2s;
}

.message-stream-loader span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* Scroll to Bottom Button */
.composer-rail-badge {
    position: absolute;
    bottom: 6px;
    height: 22px;
    padding: 0 16px;
    border: 1px solid var(--lime-strong);
    border-radius: var(--radius-full);
    background: var(--lime-default);
    color: var(--lime-on);
    box-shadow: none;
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    font: 650 0.625rem/1 var(--font-ui);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    transition: border-color var(--transition-fast), background var(--transition-fast), color var(--transition-fast);
    z-index: 24;
    touch-action: manipulation;
}

.scroll-bottom-btn {
    left: 50%;
    min-width: 132px;
    transform: translateX(-50%);
}

.composer-boost-badge {
    right: 0;
    min-width: 0;
    padding-inline: 6px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--text-secondary);
    box-shadow: none;
    backdrop-filter: none;
    letter-spacing: 0.06em;
    display: none;
}

body.ui-version-v2 .composer-boost-badge {
    display: flex;
}

.composer-rail-badge:hover,
.composer-rail-badge:focus-visible {
    border-color: var(--lime-strong);
    background: var(--lime-strong);
    color: var(--lime-strong-on);
}
.composer-boost-badge:is(:hover, :focus-visible) {
    border-color: transparent;
    background: transparent;
    color: var(--text-primary);
}

.composer-boost-badge:focus-visible {
    outline: none;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.composer-boost-label {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

.composer-boost-core {
    height: 18px;
    padding-inline: 4px;
    border: 1px solid color-mix(in srgb, var(--ink-primary) 14%, transparent);
    border-radius: 3px;
    background: color-mix(in srgb, var(--ink-primary) 10%, transparent);
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-variant-numeric: tabular-nums;
}

.composer-boost-core.is-zero {
    padding-inline: 0;
    border-width: 0;
    border-color: transparent;
    background: transparent;
}

.composer-boost-badge .composer-boost-icon {
    width: 14px;
    height: 14px;
    color: #facc15;
    flex: none;
    fill: currentColor;
    stroke: #171a1f;
    stroke-width: 2px;
    stroke-linecap: round;
    stroke-linejoin: round;
    paint-order: stroke fill;
}
.scroll-bottom-btn.is-generating {
    border-color: var(--border-default);
    background: var(--surface-muted);
    color: var(--text-secondary);
}
.scroll-bottom-btn.is-generating:hover,
.scroll-bottom-btn.is-generating:focus-visible {
    border-color: var(--border-strong);
    background: var(--surface-strong);
    color: var(--text-primary);
}



.scroll-bottom-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.composer-rail-badge svg {
    width: 16px;
    height: 16px;
}

.scroll-bottom-label,
.composer-boost-label {
    white-space: nowrap;
}

/* ========================================
   PREVIEW RAIL
   ======================================== */
.preview-rail {
    position: absolute;
    top: 8px;
    left: var(--space-4);
    right: calc(var(--space-4) + var(--safe-right));
    z-index: 6;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    pointer-events: none;
}

.preview-rail[hidden] {
    display: none;
}

.preview-rail-badge,
.test-chat-restart,
.preview-rail-edit {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    padding: 1px 10px;
    border: 0;
    border-radius: 999px;
    background: rgba(88, 96, 108, .96);
    color: #fff;
    font: 650 .64rem/1.45 var(--font-interface);
    letter-spacing: .03em;
    white-space: nowrap;
    pointer-events: auto;
}

.preview-rail-badge,
.preview-rail-edit {
    text-transform: uppercase;
}

.preview-rail-badge {
    background: var(--accent-primary);
    color: var(--accent-on);
}

/* The rail's actions stay on the right without intercepting clicks between controls. */
.preview-rail-actions {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
    pointer-events: none;
}

.preview-rail-edit,
.test-chat-restart {
    cursor: pointer;
}

.test-chat-restart {
    justify-content: center;
    padding: 1px 8px;
}

.test-chat-restart svg {
    width: 13px;
    height: 13px;
    flex: none;
}

.preview-rail-edit:is(:hover, :focus-visible),
.test-chat-restart:is(:hover, :focus-visible) {
    background: rgba(70, 78, 90, .98);
}

/* The Playtest freshness note floats centred between the mode and the exit,
 * so it never shifts either control and never shifts the transcript. */
.test-chat-note {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    max-width: min(60%, 520px);
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 1px 10px;
    border-radius: 999px;
    background: rgba(88, 96, 108, .96);
    color: #fff;
    font: 600 .64rem/1.45 var(--font-interface);
    letter-spacing: .02em;
    white-space: nowrap;
    pointer-events: none;
}

.test-chat-note[hidden] {
    display: none;
}

.test-chat-note[data-tone="updated"] {
    background: var(--accent-primary);
    color: var(--accent-on);
}

.test-chat-note[data-tone="stale"] {
    background: rgba(132, 92, 22, .96);
}

/* The rail floats over the transcript's first line, so keep that line clear. */
.chat-active.has-test-chat .messages-container {
    padding-top: calc(var(--space-4) + 26px);
}

/* The same fade as Studio's rail: a canvas-coloured gradient under the rail's pills, plain paint
 * with no backdrop filter. Each surface reveals it once text can pass under the rail. */
:is(.chat-active.has-test-chat, .mr-preview-dock)::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 46px;
    z-index: 5;
    pointer-events: none;
    opacity: 0;
    transition: opacity 120ms ease-out;
    background: linear-gradient(to bottom,
        color-mix(in srgb, var(--surface-canvas) 94%, transparent) 0,
        color-mix(in srgb, var(--surface-canvas) 90%, transparent) 56%,
        color-mix(in srgb, var(--surface-canvas) 45%, transparent) 82%,
        transparent 100%);
}

.chat-active.has-test-chat.transcript-scrolled::before,
.mr-preview-dock.is-scrolled::before {
    opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
    :is(.chat-active.has-test-chat, .mr-preview-dock)::before {
        transition: none;
    }
}

@media (max-width: 600px) {
    .preview-rail {
        top: 5px;
    }
    .preview-rail-badge,
    .preview-rail-edit,
    .test-chat-note {
        padding: 1px 8px;
        font-size: .6rem;
    }
    /* Keep the centred note inside the gap between the mode pill and the two action pills. */
    .test-chat-note {
        max-width: calc(100% - 244px);
    }
}

/* ========================================
   INPUT AREA
   ======================================== */
.input-area {
    padding: 6px var(--space-4) 10px;
    background: var(--bg-base);
    border-top: 1px solid var(--border-subtle);
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    transform: none;
    z-index: 20;
    padding-left: calc(var(--space-4) + var(--safe-left));
    padding-right: calc(var(--space-4) + var(--safe-right));
}

@media (max-width: 1280px) {
    .input-area {
        width: 100%;
        left: 0;
        transform: none;
    }
}


.composer-control-rail {
    position: relative;
    width: 100%;
    height: 0;
    margin: 0 auto;
}

.composer-control-rail.turn-generation-visible,
.composer-control-rail.scroll-bottom-visible {
    height: 28px;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: flex-end;
    gap: var(--space-2);
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    padding: 1px 2px;
    align-items: center;
    transition: border-color var(--transition-fast);
}



.input-wrapper:focus-within {
    border-color: var(--accent-primary);
}

.input-wrapper textarea {
    flex: 1;
    min-width: 0;
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    resize: none;
    padding: 1px 6px;
    max-height: 200px;
    line-height: 1.2;
    overflow-x: hidden;
    overflow-y: hidden;
    overscroll-behavior: contain;
    scrollbar-color: color-mix(in srgb, var(--accent-primary) 42%, transparent) transparent;
    scrollbar-width: thin;
}

.input-wrapper textarea::-webkit-scrollbar {
    width: 3px;
}

.input-wrapper textarea::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: color-mix(in srgb, var(--accent-primary) 42%, transparent);
}

.input-wrapper textarea::-webkit-scrollbar-track {
    background: transparent;
}

.input-wrapper textarea::placeholder {
    color: var(--text-muted);
}

.send-btn, .stop-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.send-btn {
    background: var(--accent-primary);
    color: var(--accent-on);
}

.send-btn:hover:not(:disabled) {
    background: var(--accent-hover);
    color: var(--accent-hover-on);
}

.send-btn:disabled {
    background: var(--bg-accent);
    color: var(--text-muted);
    cursor: not-allowed;
}

.send-btn svg, .stop-btn svg {
    width: 16px;
    height: 16px;
}

.stop-btn {
    background: var(--error);
    color: var(--error-on);
}

.stop-btn:hover {
    background: var(--error);
}

/* ========================================
   STATUS BAR
   ======================================== */
.status-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--statusbar-height);
    background: var(--bg-elevated);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 calc(var(--space-4) - 8px);
    font-size: 0.75rem;
    z-index: 100;
}

/* The fixed footer owns exactly --statusbar-height; no decorative surface may
   extend upward over the workspace. */
.status-bar::before {
    content: none;
}

.status-bar-inner {
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 calc(var(--space-4) + var(--safe-right) - 8px) 0 calc(var(--space-4) + var(--safe-left) - 8px);
}

.status-left, .status-right {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.status-context-control {
    display: none;
}

.status-right {
    min-width: 0;
}

/* Let trigger wrappers shrink so inner text can truncate */
.status-right .status-clickable {
    min-width: 0;
    overflow: hidden;
    display: inline-flex;
    max-width: 100%;
}

#statusModel,
#statusEndpoint {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#statusEndpoint {
    max-width: 120px;
}
.status-model-control {
    position: relative;
    min-width: 0;
}

.status-model-trigger {
    align-items: center;
    gap: 4px;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
}

.status-model-trigger.is-model-action,
body.ui-version-v2 .status-model-trigger.is-model-action {
    min-height: 22px;
    padding: 2px 8px;
    border: 1px solid color-mix(in srgb, var(--accent-primary) 70%, var(--border-default) 30%);
    border-radius: 999px;
    background: color-mix(in srgb, var(--accent-primary) 10%, transparent);
    color: var(--accent-primary);
    font-weight: 650;
    line-height: 1;
}

.status-model-trigger.is-model-action:hover,
.status-model-trigger.is-model-action:focus-visible,
body.ui-version-v2 .status-model-trigger.is-model-action:hover,
body.ui-version-v2 .status-model-trigger.is-model-action:focus-visible {
    border-color: var(--accent-primary);
    background: color-mix(in srgb, var(--accent-primary) 16%, transparent);
    color: var(--accent-primary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
}

.status-dot.ready {
    background: var(--success);
}

.status-dot.streaming {
    background: var(--info);
    box-shadow: 0 0 0 3px var(--info-muted);
    animation: pulse 1s infinite;
}

.status-dot.error {
    background: var(--error);
}

.status-dot.guest {
    background: var(--accent, var(--info));
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.status-text {
    color: var(--text-secondary);
}

.status-right {
    color: var(--text-muted);
}

.status-sep {
    opacity: 0.5;
}

.status-clickable {
    cursor: pointer;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
}

.status-clickable:hover {
    background: var(--bg-hover);
}

/* ========================================
   MODALS
   ======================================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.78);
    backdrop-filter: none;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
    overflow: auto;
    padding: calc(var(--space-4) + var(--safe-top)) var(--space-4) calc(var(--space-4) + var(--safe-bottom));
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Age gate */
.age-gate-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 24px;
}
.age-gate-overlay.active {
    display: flex;
}
.age-gate-modal {
    width: 100%;
    max-width: 420px;
    background: var(--surface-default);
    color: var(--text-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-xl);
}
.age-gate-modal h2 {
    margin: 0 0 8px;
    font-size: 1.25rem;
}
.age-gate-modal p {
    margin: 0 0 20px;
    color: var(--text-secondary);
}
.age-gate-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}
.age-gate-btn {
    border: 0;
    border-radius: 10px;
    padding: 10px 14px;
    font-weight: 600;
    cursor: pointer;
}
.age-gate-btn.confirm {
    background: var(--lime-default);
    color: var(--lime-on);
}
.age-gate-btn.exit {
    background: var(--surface-strong);
    color: var(--text-primary);
}
@media (max-width: 480px) {
    .age-gate-modal {
        padding: 20px;
    }
    .age-gate-actions {
        flex-direction: column;
    }
    .age-gate-btn {
        width: 100%;
    }
}

/* Removed: was causing modals to jump to top on input focus */
/* body.keyboard-open .modal-overlay.active { align-items: flex-start; } */

.modal-content {
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-xl);
    width: 90%;
    max-width: 500px;
    max-height: calc(100% - var(--space-4));
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: scale(0.95) translateY(-10px);
    transition: transform var(--transition-normal);
}

.modal-overlay.active .modal-content {
    transform: scale(1) translateY(0);
}

.guest-account-prompt {
    margin: auto;
    padding: 0;
    max-height: calc(100dvh - 2rem);
    color: var(--text-primary);
    transform: none;
}

.guest-account-prompt:not([open]) {
    display: none;
}

.guest-account-prompt::backdrop {
    background: rgba(0, 0, 0, 0.85);
}

.ask-dialog-list {
    margin: var(--space-2) 0 0;
    padding-inline-start: 1.4em;
    list-style: disc;
    overflow-wrap: anywhere;
}

/* askDialog's opt-in checkbox sits one gap from its label and a gap below the question. */
.setting-label.ask-dialog-check {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
}

.chat-rename-dialog > form {
    display: contents;
}

.chat-rename-error {
    color: var(--error);
}

.settings-modal {
    --settings-label-size: calc(0.9rem * var(--chat-font-scale, 1));
    --settings-detail-size: calc(0.8rem * var(--chat-font-scale, 1));
    /* Only the body/panels scroll; focus must not move the fixed shell. */
    overflow: clip;
    width: min(92vw, 880px);
    max-width: 880px;
    height: min(88vh, 840px);
}

@media (max-width: 768px) {

    #settingsModal .settings-modal {
        position: fixed;
        inset: 0;
        width: 100vw;
        max-width: none;
        height: 100dvh;
        max-height: none;
        border: none;
        border-radius: 0;
        transform: none;
        transition: none;
    }

    #settingsModal .modal-header {
        padding-top: calc(var(--space-4) + var(--safe-top));
        padding-right: calc(var(--space-5) + var(--safe-right));
        padding-left: calc(var(--space-5) + var(--safe-left));
    }

    #settingsModal .modal-body {
        padding-right: calc(var(--space-5) + var(--safe-right));
        padding-left: calc(var(--space-5) + var(--safe-left));
    }

    #settingsModal .modal-footer {
        padding-right: calc(var(--space-5) + var(--safe-right));
        padding-bottom: calc(var(--space-4) + var(--safe-bottom));
        padding-left: calc(var(--space-5) + var(--safe-left));
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border-subtle);
}

.modal-header h2 {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 600;
}

.modal-close,
.model-picker-modal-close {
    display: flex;
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    font: 750 32px/1 system-ui, sans-serif;
    transition: color var(--transition-fast);
}

.modal-close:hover,
.modal-close:focus-visible,
.model-picker-modal-close:hover,
.model-picker-modal-close:focus-visible {
    background: transparent;
    color: var(--accent-primary);
    outline: none;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-5);
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-subtle);
}

.modal-footer[hidden] {
    display: none;
}

#chatDeleteDialog .modal-footer {
    gap: var(--space-2);
}

.modal-footer-right {
    display: flex;
    gap: var(--space-2);
}

.modal-description {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-4);
    line-height: 1.5;
}

.label-hint {
    font-weight: 400;
    color: var(--text-muted);
}

/* Settings Tabs */
.settings-tabs {
    display: flex;
    gap: var(--space-1);
    overflow-x: auto;
    scrollbar-width: thin;
    margin-bottom: var(--space-5);
    background: var(--bg-subtle);
    border-radius: var(--radius-md);
    padding: var(--space-1);
}

.settings-tab {
    flex: 0 0 auto;
    padding: var(--space-2) var(--space-3);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

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

.settings-tab.active {
    background: var(--bg-elevated);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

.settings-panel {
    display: none;
}

.settings-panel.active {
    display: block;
}


/* Setting Groups */
.setting-group {
    margin-bottom: var(--space-5);
}

.setting-group:last-child {
    margin-bottom: 0;
}

.setting-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    background: var(--bg-subtle);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
}

.setting-value {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.module-settings-intro {
    margin: 0 0 var(--space-4);
    color: var(--text-secondary);
    font-size: 0.84rem;
    line-height: 1.5;
}

.module-settings-list {
    display: grid;
    gap: var(--space-2);
}

.module-setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-3);
    background: var(--bg-subtle);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
}

.module-setting-row-optional {
    border-color: color-mix(in srgb, var(--accent-primary) 45%, var(--border-default));
}

.module-setting-copy {
    min-width: 0;
}

.module-setting-copy strong,
.module-setting-copy small {
    display: block;
}

.module-setting-copy strong {
    color: var(--text-primary);
    font-size: 0.86rem;
    font-weight: 600;
}

.module-setting-copy small {
    margin-top: 3px;
    color: var(--text-muted);
    font-size: 0.75rem;
    line-height: 1.4;
}

.module-setting-lock,
.module-setting-toggle {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    gap: 7px;
    color: var(--text-secondary);
    font-size: 0.76rem;
    white-space: nowrap;
}

.module-setting-lock input,
.module-setting-toggle input {
    width: 17px;
    height: 17px;
    margin: 0;
    accent-color: var(--accent-primary);
}

.module-setting-lock input:disabled {
    opacity: 0.7;
}

.module-setting-toggle {
    cursor: pointer;
}

.module-setting-budget {
    margin-top: var(--space-5);
}

.module-setting-model {
    margin-top: var(--space-5);
}

.module-model-controls {
    display: flex;
    align-items: stretch;
    gap: var(--space-2);
}

.module-model-controls .model-picker {
    min-width: 0;
}

.module-model-default {
    flex: 0 0 auto;
    white-space: nowrap;
}

.model-routing-settings-list {
    display: grid;
    gap: var(--space-3);
}

.model-routing-setting {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(190px, 0.9fr);
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-4);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: var(--bg-subtle);
}

.model-routing-picker {
    display: flex;
    min-width: 0;
    min-height: 38px;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    padding: 8px 10px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    background: var(--bg-base);
    color: var(--text-primary);
    cursor: pointer;
}

.model-routing-picker span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.model-routing-controls {
    display: flex;
    min-width: 0;
    align-items: stretch;
    gap: var(--space-2);
}

.model-routing-controls .model-picker {
    min-width: 0;
}

.model-routing-controls .model-picker-trigger {
    min-height: 38px;
}

.model-routing-picker:hover,
.model-routing-picker:focus-visible {
    border-color: var(--accent-primary);
    background: var(--bg-hover);
}

@media (max-width: 520px) {
    .module-setting-row {
        align-items: flex-start;
        gap: var(--space-2);
    }

    .module-setting-lock,
    .module-setting-toggle {
        padding-top: 1px;
    }

    .module-model-controls {
        align-items: stretch;
        flex-direction: column;
    }

    .model-routing-setting {
        grid-template-columns: 1fr;
        gap: var(--space-3);
    }

    .model-routing-controls {
        flex-direction: column;
    }
}

.setting-input, .setting-textarea {
    width: 100%;
    background: var(--bg-subtle);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: var(--space-3);
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

.setting-input:focus, .setting-textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
    background: var(--bg-base);
}

.setting-textarea {
    resize: vertical;
    min-height: 80px;
}

.setting-hint {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: var(--space-1);
}

/* Settings -> Assistant: two account-wide authoring defaults. */
.authoring-instructions-input {
    min-height: 132px;
    font-family: var(--font-ui);
    font-size: 0.82rem;
    line-height: 1.5;
}

.authoring-instructions-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    margin-top: var(--space-2);
}

.authoring-instructions-meta .setting-hint {
    margin-top: 0;
}

.authoring-instructions-reset {
    flex: 0 0 auto;
    padding: 5px 10px;
    font-size: 0.75rem;
}

.authoring-instructions-unavailable {
    margin: 0 0 var(--space-3);
}

#settingsModal .modal-header h2 {
    font-size: 1.25rem;
}

#settingsModal .settings-tab,
#settingsModal .setting-label,
#settingsModal .module-setting-copy strong {
    font-size: var(--settings-label-size);
}

#settingsModal .setting-hint,
#settingsModal .settings-subpanel-note,
#settingsModal .module-settings-intro,
#settingsModal .module-setting-copy small,
#settingsModal .module-setting-lock,
#settingsModal .module-setting-toggle {
    font-size: var(--settings-detail-size);
}

@media (prefers-reduced-motion: reduce) {
    .activity-dot,
    .activity-mark[data-live="true"],
    body.ui-version-v2 .message-flight-indicator > span,
    body.ui-version-v2 .v2-story-outcome-mark[data-live="true"],
    .studio #studioAIStatus[data-live="true"]::before {
        animation: none;
    }
}

.input-with-toggle {
    position: relative;
}

.input-with-toggle .setting-input {
    padding-right: 40px;
}

.api-key-input {
    -webkit-text-security: disc;
}

.api-key-input.api-key-visible {
    -webkit-text-security: none;
}

.toggle-visibility {
    position: absolute;
    right: var(--space-2);
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.toggle-visibility:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.toggle-visibility svg {
    width: 18px;
    height: 18px;
}

/* Native selects retain their value/form contract; Sandcat renders the visible
   trigger and listbox so every menu follows the active interface palette. */
.setting-select {
    min-height: 38px;
}



/* A preset owns its destination, so the URL reads as a locked value. */
#endpointEditUrl[readonly] {
    background: var(--bg-base);
    color: var(--text-secondary);
    cursor: default;
}

#endpointPresetSelect {
    min-width: 0;
    max-width: 100%;
    text-overflow: ellipsis;
}

#endpointUrlHint[hidden],
#endpointTypeHint[hidden] {
    display: none;
}

.model-picker {
    position: relative;
    flex: 1;
    max-width: 420px;
}

.model-picker-trigger {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    background: var(--bg-subtle);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: var(--space-1) var(--space-2);
    font-size: 0.75rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: border-color var(--transition-fast), background var(--transition-fast);
}

.model-picker-trigger:hover {
    background: var(--bg-hover);
}

.model-picker.open .model-picker-trigger {
    border-color: var(--accent-primary);
}

.model-picker-arrow {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.model-picker-list {
    max-height: 260px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.model-picker-section {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.model-picker-section + .model-picker-section {
    margin-top: 10px;
}

.model-picker-section-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.model-picker-group {
    margin: 0;
    padding: 5px var(--space-2);
    border-radius: 3px;
    background: var(--text-primary);
    color: var(--bg-base);
    font-size: 0.84rem;
    font-weight: 700;
    line-height: 1.25;
}

:root[data-color-mode='dark'] .model-picker-group {
    background: var(--bg-accent);
    color: var(--text-primary);
}


.model-picker-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    column-gap: var(--space-2);
    row-gap: 2px;
    align-items: center;
    padding: 6px var(--space-2);
    border-radius: 3px;
    font-size: 0.8rem;
    cursor: pointer;
    color: var(--text-primary);
}

.model-picker-item:hover {
    background: var(--bg-hover);
}

.model-picker-item.is-selected {
    background: color-mix(in srgb, var(--accent-primary) 13%, var(--bg-subtle) 87%);
    box-shadow: inset 0 0 0 2px var(--accent-primary);
}

.model-picker-choice {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-row: 1;
    gap: 2px;
    min-width: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: start;
    cursor: inherit;
}

.model-picker-choice:focus-visible {
    outline: 1px solid var(--accent-primary);
    outline-offset: -1px;
}

.model-picker-item .model-picker-sub {
    font-size: 0.7rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.model-picker-item .model-picker-sub:has(.model-picker-meta) {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-2);
}

.model-picker-item .model-picker-sub > span:first-child {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.model-picker-meta {
    flex-shrink: 0;
    color: var(--text-secondary);
    font-size: 0.66rem;
}

.model-picker-meta-warning {
    color: var(--error);
}

.model-picker-item.model-picker-item-disabled {
    cursor: not-allowed;
    opacity: 0.52;
}

.model-picker-item.model-picker-item-disabled:hover {
    background: transparent;
}

.model-picker-title {
    display: flex;
    align-items: center;
    gap: 5px;
}

.model-picker-title-text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.model-picker-unavailable-icon {
    display: grid;
    width: 14px;
    height: 14px;
    flex: 0 0 14px;
    place-items: center;
    box-sizing: border-box;
    border: 1px solid currentColor;
    border-radius: 50%;
    font-size: 0.6rem;
    font-weight: 800;
    line-height: 1;
}


.model-picker-fav,
.model-picker-clear {
    grid-row: 1;
    display: grid;
    width: 32px;
    min-width: 32px;
    height: 32px;
    place-items: center;
    align-self: center;
    padding: 0;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    font-size: 1.05rem;
    line-height: 1;
    cursor: pointer;
}
.model-picker-clear {
    font-size: 1.2rem;
}

.model-picker-clear:hover {
    color: var(--error);
    background: var(--error-muted);
}

.model-picker-fav:hover {
    color: var(--lime-strong);
    background: var(--accent-muted);
}

.model-picker-fav.active {
    color: var(--lime-strong);
}

.model-picker-compact {
    max-width: 100%;
}

.model-picker-overlay {
    display: none;
    background: rgba(0, 0, 0, 0.58);
    backdrop-filter: none;
    z-index: 1200;
}

.model-picker-overlay.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.model-picker-modal {
    position: relative;
    width: min(1040px, 94vw);
    height: min(760px, calc(100dvh - 48px));
    max-height: calc(100dvh - 48px);
    overflow: hidden;
    border: 1px solid var(--border-subtle);
    border-radius: 16px;
    background: var(--bg-elevated);
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
}

.model-picker-modal-header {
    min-height: 62px;
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px 8px 18px;
    border-bottom: 1px solid var(--border-subtle);
}


.model-picker-header-leading {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 10px;
}

.model-picker-header-leading > div {
    min-width: 0;
}

.model-picker-header-actions {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 4px;
    margin-left: 12px;
}

.model-picker-generation-toggle {
    display: inline-flex;
    min-height: 32px;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 0 11px;
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
}

.model-picker-generation-toggle[hidden] {
    display: none;
}

.model-picker-generation-toggle svg {
    width: 16px;
    height: 16px;
    flex: 0 0 auto;
}

.model-picker-generation-toggle:hover {
    border-color: var(--border-default);
    color: var(--text-primary);
}

.model-picker-generation-toggle:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
    color: var(--text-primary);
}

.model-picker-generation-toggle[aria-expanded="true"] {
    border-color: color-mix(in srgb, var(--accent-primary) 55%, var(--border-subtle) 45%);
    background: var(--accent-muted);
    color: var(--accent-primary);
}

.model-picker-header-copy {
    min-width: 0;
}

.model-picker-selection-row {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 8px;
}

.model-picker-back {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    border: 1px solid var(--border-subtle);
    border-radius: 50%;
    background: var(--bg-subtle);
    color: var(--text-secondary);
    font-size: 1rem;
}

.model-picker-back:hover,
.model-picker-back:focus-visible {
    color: var(--accent-primary);
    outline: none;
}

.model-picker-modal-title {
    font-weight: 600;
    font-size: 1rem;
}

.model-picker-selection {
    display: block;
    min-width: 0;
    flex: 1 1 auto;
    margin-top: 2px;
    overflow: hidden;
    color: var(--text-muted);
    font-size: 0.7rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.model-picker-selection[hidden] {
    display: none;
}

/* Credits for included models; provider USD is named separately so the two
 * units never read as the same price. */
.model-picker-rate-summary {
    min-width: 0;
    flex: 0 1 auto;
    color: var(--text-secondary);
    font-size: 0.7rem;
    overflow-wrap: anywhere;
    white-space: normal;
}

.model-picker-rate-summary[hidden] {
    display: none;
}

.model-picker-rate-summary[data-kind='provider'] {
    color: var(--text-muted);
}

/* The current model use is chosen in the phone header; desktop keeps the
 * always-visible consumer rail instead. */
.model-picker-role-picker {
    display: none;
    min-width: 0;
}

.model-picker-role-picker[hidden] {
    display: none;
}

.model-picker-apply-all {
    grid-row: 1;
    min-height: 28px;
    padding: 3px 8px;
    border: 1px solid currentColor;
    border-radius: var(--radius-sm);
    background: var(--bg-base);
    color: var(--accent-primary);
    font-size: 0.74rem;
    line-height: 1.2;
    font-weight: 650;
    cursor: pointer;
}

.model-picker-apply-all:hover:not(:disabled),
.model-picker-apply-all:focus-visible {
    color: var(--text-primary);
    text-decoration: underline;
}

.model-picker-apply-all:disabled {
    background: transparent;
    border-color: var(--border-default);
    color: var(--text-muted);
    cursor: default;
}

@container model-editor (max-width: 500px) {
    .model-picker-apply-all {
        grid-column: 1;
        grid-row: 2;
        justify-self: start;
    }
}


.model-configuration-body {
    display: grid;
    min-height: 0;
    flex: 1;
    overflow: hidden;
    grid-template-columns: 250px minmax(0, 1fr);
}

.model-picker-modal > .busy-region,
.model-picker-confirm {
    position: absolute;
    inset: 62px 0 0;
    z-index: 8;
}

.model-picker-modal > .busy-region {
    --busy-surface: var(--bg-elevated);
}

.model-picker-confirm[hidden] {
    display: none;
}

.model-picker-confirm {
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(5, 8, 9, 0.76);
    backdrop-filter: blur(3px);
}

.model-picker-confirm > section {
    width: min(430px, 100%);
    border: 1px solid color-mix(in srgb, var(--accent-primary) 44%, var(--border-default) 56%);
    border-radius: 10px;
    padding: 20px;
    background: var(--bg-elevated);
    box-shadow: var(--shadow-xl);
}

.model-picker-confirm h3 {
    margin: 0 0 8px;
    color: var(--text-primary);
    font-size: 1rem;
}

.model-picker-confirm p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.8rem;
    line-height: 1.5;
}

.model-picker-confirm > section > div {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 18px;
}

.model-picker-confirm button {
    min-height: 36px;
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    padding: 7px 12px;
    background: var(--bg-subtle);
    color: var(--text-secondary);
}

.model-picker-confirm .model-picker-confirm-discard {
    border-color: color-mix(in srgb, var(--error) 65%, var(--border-default) 35%);
    color: var(--error);
}

.model-routing-dashboard,
.model-picker-editor,
.model-picker-catalog,
.model-provider-manager {
    min-width: 0;
    min-height: 0;
}

.model-routing-dashboard {
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow-y: auto;
    padding: 18px 14px;
    border-right: 1px solid var(--border-subtle);
    background: color-mix(in srgb, var(--bg-subtle) 48%, transparent 52%);
    overscroll-behavior: contain;
}


.model-routing-cards {
    display: grid;
    gap: 9px;
}

.model-routing-card {
    display: grid;
    width: 100%;
    gap: 3px;
    justify-items: start;
    padding: 12px;
    border: 1px solid var(--border-subtle);
    border-radius: 4px;
    background: color-mix(in srgb, var(--bg-elevated) 72%, transparent 28%);
    color: var(--text-primary);
    text-align: left;
    cursor: pointer;
}

.model-routing-card:hover:not(.is-selected) {
    border-color: var(--border-default);
}


.model-routing-card:focus-visible {
    border-color: color-mix(in srgb, var(--accent-primary) 45%, var(--border-default) 55%);
}

.model-routing-card.is-selected {
    border-width: 2px;
    border-color: color-mix(in srgb, var(--accent-primary) 72%, var(--border-default) 28%);
    padding: 11px;
    background: color-mix(in srgb, var(--accent-muted) 45%, var(--bg-subtle) 55%);
    box-shadow: none;
}

.model-routing-card.is-dirty {
    border-color: color-mix(in srgb, var(--accent-primary) 58%, var(--border-default) 42%);
}

.model-routing-card.has-error {
    border-color: color-mix(in srgb, var(--error) 64%, var(--border-default) 36%);
}

.model-routing-card-status {
    color: var(--text-muted);
    font-size: 0.68rem;
    font-weight: 600;
}

.model-routing-card.is-dirty .model-routing-card-status {
    color: var(--error);
}

.model-routing-card.has-error .model-routing-card-status {
    color: var(--error);
    font-weight: 400;
}

.model-routing-card:disabled {
    opacity: 0.52;
    cursor: not-allowed;
}


.model-routing-card-title {
    font-size: 0.83rem;
}

.model-routing-card-route {
    max-width: 100%;
    overflow: hidden;
    color: var(--accent-primary);
    font-size: 0.74rem;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}


.model-picker-tabs {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 36px;
    flex: 0 0 auto;
    align-items: stretch;
    padding: 0 16px;
    border-bottom: 1px solid var(--border-subtle);
}

.model-picker-tabs[hidden] {
    display: none;
}

.model-picker-tablist {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    min-width: 0;
    align-items: stretch;
}

.model-picker-tab {
    min-width: 0;
    min-height: 40px;
    padding: 0 8px;
    border: 0;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 600;
    text-align: center;
    cursor: pointer;
}

.model-picker-tab:hover,
.model-picker-tab:focus-visible {
    color: var(--text-primary);
    outline: none;
}

.model-picker-tab[aria-selected="true"] {
    border-bottom-color: var(--accent-primary);
    color: var(--accent-primary);
}

.model-picker-catalog-refresh {
    display: grid;
    width: 36px;
    min-height: 40px;
    justify-self: end;
    place-items: center;
    border: 0;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
}

.model-picker-catalog-refresh:hover,
.model-picker-catalog-refresh:focus-visible {
    color: var(--text-primary);
    outline: none;
}

.model-picker-catalog-refresh:disabled {
    cursor: wait;
    opacity: 0.65;
}

.model-picker-catalog-refresh svg {
    width: 17px;
    height: 17px;
}

.model-picker-editor {
    container-type: inline-size;
    container-name: model-editor;
    display: flex;
    overflow: hidden;
    flex-direction: column;
}

.model-picker-error {
    min-height: 0;
    flex: 0 0 auto;
    margin: 0;
    padding: 8px 16px;
    border-bottom: 1px solid color-mix(in srgb, var(--error) 30%, var(--border-subtle) 70%);
    background: color-mix(in srgb, var(--error) 8%, var(--bg-elevated) 92%);
    color: var(--error);
    font-size: 0.74rem;
    line-height: 1.4;
}

.model-picker-error:empty {
    display: none;
}

.model-picker-catalog {
    display: flex;
    min-height: 0;
    flex: 1 1 auto;
    container-type: inline-size;
    container-name: model-catalog;
    overflow: hidden;
    flex-direction: column;
    gap: 10px;
    padding: 16px;
}

.model-picker-catalog[hidden] {
    display: none;
}

.model-picker-modal-search input {
    flex: 1;
    min-width: 0;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    background: var(--bg-subtle);
    color: var(--text-primary);
    font-size: 0.85rem;
}

.model-picker-modal-search input:focus,
.model-picker-modal-search input:focus-visible {
    border-color: var(--accent-primary);
    outline: none;
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent-primary) 18%, transparent);
    caret-color: var(--accent-primary);
}

.model-picker-modal-search {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: var(--space-2);
}


.model-picker-modal-list {
    display: flex;
    min-height: 0;
    flex: 1;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
    padding-right: 4px;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.model-picker-empty {
    padding: 18px 10px;
    color: var(--text-muted);
    font-size: 0.78rem;
    text-align: center;
}

.model-picker-catalog-status {
    flex: 0 0 auto;
    max-height: 6rem;
    overflow: auto;
    overflow-wrap: anywhere;
    color: var(--error);
    font-size: 0.74rem;
    line-height: 1.4;
    text-align: end;
}

.model-picker-catalog-status:not(:empty) {
    padding: 6px calc(16px + var(--safe-right)) calc(8px + var(--safe-bottom)) calc(16px + var(--safe-left));
}

.model-picker-catalog-status p {
    margin: 0;
}

.model-picker-catalog-status[data-syncing] {
    color: var(--text-muted);
}

.model-picker-catalog-status > .v2-action-spinner {
    margin-inline-end: 6px;
}

.model-picker-generation {
    min-width: 0;
    min-height: 0;
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    -webkit-overflow-scrolling: touch;
}

.model-picker-generation-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.model-picker-settings-route {
    min-width: 0;
    margin: 0;
    color: var(--text-muted);
    font-size: 0.72rem;
}

.model-picker-settings-route strong {
    color: var(--text-primary);
    font-weight: 650;
}

.model-picker-generation-groups {
    display: grid;
    gap: 10px;
    margin-top: 10px;
}

.model-picker-generation-group {
    min-width: 0;
    margin: 0;
    padding: 10px;
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    background: color-mix(in srgb, var(--bg-subtle) 56%, transparent 44%);
}

.model-picker-generation-group[hidden] {
    display: none;
}

.model-picker-generation-group legend {
    padding: 0 5px;
    color: var(--text-secondary);
    font-size: 0.66rem;
    font-weight: 650;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.model-picker-generation-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
}

.model-picker-generation-grid label {
    display: grid;
    min-width: 0;
    gap: 4px;
    color: var(--text-muted);
    font-size: 0.66rem;
}

.model-picker-generation-field {
    display: grid;
    grid-column: 1 / -1;
    min-width: 0;
    gap: 4px;
}

.model-picker-generation-field > label {
    display: block;
}

.model-picker-number-control {
    display: grid;
    min-width: 0;
    grid-template-columns: 76px minmax(0, 1fr);
    align-items: center;
    gap: 6px;
}

.model-picker-number-presets {
    display: flex;
    min-width: 0;
    flex-wrap: nowrap;
    gap: 4px;
    font-size: 0.66rem;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: none;
}

.model-picker-number-presets::-webkit-scrollbar {
    display: none;
}

.model-picker-number-presets button {
    min-width: 30px;
    min-height: 30px;
    flex: 0 0 auto;
    padding: 3px 4px;
    border: 1px solid var(--border-subtle);
    border-radius: 999px;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    cursor: pointer;
}

.model-picker-number-presets button:hover,
.model-picker-number-presets button:focus-visible,
.model-picker-number-presets button[aria-pressed="true"] {
    border-color: color-mix(in srgb, var(--accent-primary) 62%, var(--border-subtle));
    background: color-mix(in srgb, var(--accent-primary) 12%, transparent);
    color: var(--text-primary);
}

.model-picker-number-presets button:focus-visible {
    outline: 1px solid var(--accent-primary);
    outline-offset: 1px;
}

.model-picker-generation-grid [hidden] {
    display: none;
}

.model-picker-generation-grid input,
.model-picker-generation-grid select {
    width: 100%;
    min-width: 0;
    height: 34px;
    padding: 5px 8px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    background: var(--bg-subtle);
    color: var(--text-primary);
    font: inherit;
}

.model-picker-generation-grid input:focus,
.model-picker-generation-grid select:focus {
    border-color: var(--accent-primary);
    outline: none;
}

.model-picker-generation-grid :disabled {
    opacity: 0.42;
    cursor: not-allowed;
}


/* A selection the endpoint does not offer: kept, never replaced, and flagged
 * wherever the choice is shown. */
.model-picker-trigger.is-model-unavailable,
.model-picker.is-model-unavailable .model-picker-trigger {
    border-color: var(--error);
    color: var(--error);
}

.model-picker-selection.is-model-unavailable {
    color: var(--error);
}

.model-picker-item.is-unavailable {
    background: transparent;
    color: var(--error);
    cursor: not-allowed;
    box-shadow: none;
}

.model-picker-item.is-unavailable.is-selected {
    background: color-mix(in srgb, var(--accent-primary) 13%, var(--bg-subtle) 87%);
    box-shadow: inset 0 0 0 2px var(--accent-primary);
}

/* A route whose endpoint no longer offers its model reads as failed wherever
 * the route is displayed, not only inside the model picker. */
.status-model-trigger.is-model-unavailable,
.model-routing-card.is-model-unavailable .model-routing-card-route {
    color: var(--error);
}

/* The route and the phase a running step reports, shown when expanded. */
.message-model-step-live,
.message-model-step-progress {
    margin: 0 0 6px;
    color: var(--text-secondary);
    font-size: 0.7rem;
    line-height: 1.45;
}


.model-picker-generation-reset {
    flex: 0 0 auto;
    padding: 3px 0;
    border: 0;
    background: transparent;
    color: var(--accent-primary);
    font-size: 0.66rem;
    cursor: pointer;
}


.model-picker-endpoint-select {
    position: relative;
    min-width: 0;
}

.model-picker-endpoint-trigger {
    display: flex;
    width: 100%;
    min-width: 0;
    height: 38px;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 7px 10px;
    border: 1px solid var(--border-subtle);
    border-radius: 7px;
    background: var(--bg-subtle);
    color: var(--text-primary);
    font-size: 0.74rem;
    font-weight: 500;
    letter-spacing: normal;
    text-align: left;
    text-transform: none;
    cursor: pointer;
}

.model-picker-endpoint-trigger span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.model-picker-endpoint-trigger svg {
    width: 16px;
    height: 16px;
    flex: 0 0 auto;
    transition: transform var(--transition-fast);
}

.model-picker-endpoint-select.is-open .model-picker-endpoint-trigger svg {
    transform: rotate(180deg);
}

.model-picker-endpoint-trigger:hover,
.model-picker-endpoint-trigger:focus-visible,
.model-picker-endpoint-select.is-open .model-picker-endpoint-trigger {
    border-color: var(--accent-primary);
}


.model-picker-endpoint-trigger:disabled {
    opacity: 0.62;
    cursor: default;
}

.model-picker-endpoint-options {
    position: fixed;
    inset: auto;
    display: grid;
    max-height: min(240px, 42vh);
    overflow-y: auto;
    overscroll-behavior: contain;
}


.model-picker-catalog-controls {
    display: grid;
    min-width: 0;
    flex: 0 0 auto;
    grid-template-columns: minmax(0, 1fr) minmax(120px, 34%);
    gap: 10px;
    align-items: stretch;
}

.model-picker-catalog-controls[hidden] {
    display: none;
}

.model-picker-catalog-controls > .model-picker-modal-search,
.model-picker-catalog-controls > .model-picker-catalog-endpoint-filter {
    min-width: 0;
}

.model-picker-catalog-controls .model-picker-modal-search input,
.model-picker-catalog-controls .model-picker-endpoint-trigger {
    height: 38px;
}

.model-picker-openrouter-controls {
    min-width: 0;
    padding: 4px 0;
}

.model-picker-openrouter-controls[hidden] {
    display: none;
}

.model-picker-openrouter-toolbar,
.model-picker-catalog-sort {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 2px;
    font-size: 0.7rem;
}

.model-picker-openrouter-toolbar .model-picker-endpoint-select {
    width: auto;
    min-width: 0;
}

.model-picker-openrouter-toolbar .model-picker-endpoint-trigger {
    height: 28px;
    gap: 4px;
    padding: 4px;
    font: inherit;
}

.model-picker-openrouter-toolbar .model-picker-endpoint-trigger svg {
    width: 12px;
    height: 12px;
}


.model-picker-filter-fields input {
    min-width: 0;
    padding: 4px 6px;
    border: 1px solid var(--border-subtle);
    border-radius: 4px;
    background: var(--bg-subtle);
    color: var(--text-primary);
    font: inherit;
}

.model-picker-catalog-action {
    height: 28px;
    padding: 4px 6px;
    border: 1px solid var(--border-subtle);
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 0.7rem;
    white-space: nowrap;
}

.model-picker-catalog-action:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 1px;
}

.model-picker-sort-direction,
.model-picker-filter-settings-toggle {
    display: inline-flex;
    width: 24px;
    flex: 0 0 24px;
    align-items: center;
    justify-content: center;
    padding: 3px;
}

.model-picker-sort-direction svg {
    width: 14px;
    height: 14px;
}

.model-picker-sort-direction[data-direction="asc"] svg {
    transform: rotate(180deg);
}

.model-picker-filter-settings-toggle {
    margin-inline-start: auto;
}

.model-picker-filter-settings-toggle svg {
    width: 16px;
    height: 16px;
}

.model-picker-filter-settings-toggle[aria-expanded="true"] {
    border-color: var(--accent-primary);
    background: var(--accent-muted);
    color: var(--accent-primary);
}

.model-picker-catalog-action[aria-pressed="true"] {
    border-color: var(--accent-primary);
    background: var(--accent-muted);
    color: var(--accent-primary);
}

.model-picker-filter-fields input:disabled {
    border-color: var(--border-subtle);
    background: transparent;
    color: var(--text-muted);
    opacity: 0.45;
    cursor: not-allowed;
}

.model-picker-filter-settings {
    margin-top: 7px;
    color: var(--text-muted);
    font-size: 0.7rem;
}

.model-picker-filter-settings[hidden] {
    display: none;
}

.model-picker-filter-fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 8px;
}

.model-picker-filter-fields label {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 4px;
}

.model-picker-filter-settings p {
    margin: 6px 0 0;
    font-size: 0.65rem;
}

.model-picker-subgroup {
    margin: 6px 0 0;
    padding: 4px var(--space-2);
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-primary);
    font-size: 0.75rem;
    font-weight: 650;
}

@media (min-width: 769px) {
    @container model-editor (min-width: 600px) {
        .model-picker-generation-grid {
            grid-template-columns: repeat(3, minmax(0, 1fr));
            align-items: start;
        }

        .model-picker-request-grid {
            grid-template-columns: repeat(6, minmax(0, 1fr));
        }

        .model-picker-request-grid > label {
            grid-column: span 2;
        }

        .model-picker-request-grid > .model-picker-generation-field {
            grid-column: span 3;
        }

        .model-picker-request-grid .model-picker-number-presets {
            flex-wrap: wrap;
            overflow: visible;
        }
    }

}

.model-picker-modal-search[hidden] {
    display: none;
}

/* A side trip out of model uses, never a fourth consumer. Kept outside the
 * editor and the unsaved-changes row so Save stays the bottom-most action. */
.model-picker-providers {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-elevated);
}

.model-picker-providers[hidden] {
    display: none;
}

.model-picker-manage-providers {
    min-height: 32px;
    padding: 5px 12px;
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.74rem;
    font-weight: 600;
}

.model-picker-manage-providers:hover,
.model-picker-manage-providers:focus-visible {
    border-color: var(--accent-primary);
    color: var(--text-primary);
    outline: none;
}

.model-picker-manage-providers:disabled {
    cursor: default;
    opacity: 0.5;
}


.model-picker-actions {
    display: flex;
    min-height: 60px;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 11px 16px;
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-elevated);
}

.model-picker-actions[hidden] {
    display: none;
}

.model-picker-actions p {
    min-width: 0;
    flex: 1;
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.74rem;
    line-height: 1.35;
}

.model-picker-actions p.is-unsaved,
.model-picker-actions p.is-error {
    color: var(--error);
}

.model-picker-action-buttons {
    display: flex;
    flex: 0 0 auto;
    justify-content: flex-end;
    gap: 8px;
}

.model-picker-actions button {
    min-height: 34px;
    padding: 6px 12px;
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    background: var(--bg-subtle);
    color: var(--text-secondary);
    font-size: 0.74rem;
}

.model-picker-actions button:hover,
.model-picker-actions button:focus-visible {
    border-color: var(--accent-primary);
    color: var(--text-primary);
    outline: none;
}

.model-picker-actions .model-picker-save,
.model-picker-confirm .model-picker-save {
    border-color: color-mix(in srgb, var(--accent-primary) 66%, var(--border-default) 34%);
    background: var(--accent-muted);
    color: var(--accent-primary);
    font-weight: 650;
}

.model-picker-actions button:disabled,
.model-picker-confirm button:disabled {
    opacity: 0.5;
}

@media (min-width: 769px) {
    .model-picker-modal .model-routing-dashboard[aria-hidden="true"],
    .model-picker-modal .model-picker-editor[aria-hidden="true"],
    .model-picker-modal .model-provider-manager[aria-hidden="true"] {
        display: none;
    }
}

@media (max-width: 768px) {
    #settingsModal,
    #characterCatalogModal,
    .model-picker-overlay {
        display: flex;
        align-items: stretch;
        justify-content: stretch;
        overflow: hidden;
        padding: 0;
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: opacity var(--transition-normal), visibility 0s linear 200ms;
    }

    #settingsModal.active,
    #characterCatalogModal.active,
    .model-picker-overlay.active {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
        transition: opacity var(--transition-normal), visibility 0s linear 0s;
    }


    .model-picker-modal {
        position: fixed;
        inset: 0;
        width: 100vw;
        max-width: none;
        height: 100dvh;
        max-height: 100dvh;
        border: none;
        border-radius: 0;
    }

    .model-picker-modal-header {
        min-height: calc(57px + var(--safe-top));
        padding-top: calc(6px + var(--safe-top));
        padding-right: calc(11px + var(--safe-right));
        padding-bottom: 6px;
        padding-left: calc(11px + var(--safe-left));
    }

    .model-picker-header-actions {
        margin-left: 8px;
    }

    .model-picker-generation-toggle {
        min-height: 36px;
    }


    .model-picker-modal > .busy-region,
    .model-picker-confirm {
        top: calc(57px + var(--safe-top));
    }

    .model-configuration-body {
        position: relative;
        display: block;
        overflow: clip;
        contain: layout paint;
    }

    .model-routing-dashboard,
    .model-picker-editor,
    .model-provider-manager {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
        transition: transform 180ms ease;
        will-change: transform;
    }

    .model-routing-dashboard {
        padding: 14px calc(12px + var(--safe-right)) calc(14px + var(--safe-bottom)) calc(12px + var(--safe-left));
        border-right: 0;
    }

    .model-provider-manager {
        padding-right: calc(12px + var(--safe-right));
        padding-bottom: calc(18px + var(--safe-bottom));
        padding-left: calc(12px + var(--safe-left));
    }

    .model-picker-catalog {
        padding: 14px calc(12px + var(--safe-right)) 12px calc(12px + var(--safe-left));
    }

    .model-picker-tabs {
        padding: 0 calc(12px + var(--safe-right)) 0 calc(12px + var(--safe-left));
    }

    .model-picker-role-picker {
        display: block;
        width: 100%;
    }

    .model-picker-role-picker[hidden] {
        display: none;
    }

    .model-picker-modal.has-role-picker .model-picker-header-copy {
        flex: 1 1 auto;
    }

    .model-picker-modal.has-role-picker .model-picker-modal-title {
        position: absolute;
        width: 1px;
        height: 1px;
        margin: -1px;
        padding: 0;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }

    .model-picker-role-picker .sandcat-select-trigger {
        height: 30px;
        min-height: 30px;
        padding: 3px 8px;
        border-radius: 6px;
        font-size: 0.78rem;
        font-weight: 600;
    }

    .model-picker-role-picker .sandcat-select-trigger svg {
        width: 16px;
        height: 16px;
    }

    .model-picker-providers {
        padding: 6px calc(12px + var(--safe-right)) calc(6px + var(--safe-bottom)) calc(12px + var(--safe-left));
    }

    .model-picker-modal.has-unsaved-changes .model-picker-providers {
        padding-bottom: 6px;
    }

    .model-picker-manage-providers {
        min-height: 40px;
    }

    .model-picker-generation {
        padding: 14px calc(12px + var(--safe-right)) 14px calc(12px + var(--safe-left));
        scrollbar-gutter: auto;
    }

    .model-picker-actions {
        padding-right: calc(12px + var(--safe-right));
        padding-bottom: calc(10px + var(--safe-bottom));
        padding-left: calc(12px + var(--safe-left));
    }

    .model-picker-actions {
        align-items: stretch;
        flex-direction: column;
        gap: 7px;
    }

    .model-picker-action-buttons {
        width: 100%;
    }

    .model-picker-action-buttons button {
        flex: 1;
    }

    .model-picker-modal[data-view="consumers"] .model-routing-dashboard,
    .model-picker-modal:not([data-view="consumers"]) .model-picker-editor {
        transform: translateX(0);
    }

    .model-picker-modal[data-view="consumers"] .model-picker-editor {
        transform: translateX(100%);
    }

    .model-picker-modal:not([data-view="consumers"]) .model-routing-dashboard {
        transform: translateX(-100%);
    }

    .model-picker-modal .model-routing-dashboard[aria-hidden="true"],
    .model-picker-modal .model-picker-editor[aria-hidden="true"],
    .model-picker-modal .model-provider-manager[aria-hidden="true"] {
        pointer-events: none;
    }

    .model-routing-card {
        padding: 13px;
    }
}

@media (max-width: 520px) {
    .model-picker-generation-toggle {
        width: 36px;
        min-width: 36px;
        height: 36px;
        padding: 0;
        border-color: transparent;
        border-radius: 50%;
    }

    .model-picker-generation-toggle-label {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .model-routing-dashboard,
    .model-picker-editor,
    .model-provider-manager {
        transition: none;
    }

    #settingsModal,
    .model-picker-overlay {
        transition: none;
    }
}

.model-reset-btn {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-subtle);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.model-reset-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.model-reset-btn svg {
    width: 14px;
    height: 14px;
}

/* Provider onboarding inside Models & generation */
.model-provider-manager {
    grid-column: 1 / -1;
    overflow-y: auto;
    padding: 20px;
    overscroll-behavior: contain;
}

.model-provider-manager[hidden],
#endpointListView[hidden],
#endpointFormView[hidden] {
    display: none;
}

#endpointListView,
#endpointFormView {
    width: min(720px, 100%);
    margin: 0 auto;
}

.model-provider-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-5);
}


.model-provider-heading p {
    max-width: 590px;
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.8rem;
    line-height: 1.5;
}

.provider-list-group {
    display: grid;
    gap: var(--space-2);
}

.provider-list-group + .provider-list-group {
    margin-top: var(--space-5);
}

.provider-list-group h4 {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 650;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.managed-api-refresh-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    background: var(--bg-subtle);
    transition: all var(--transition-fast);
}

.managed-api-refresh-btn:hover:not(:disabled) {
    color: var(--text-primary);
    border-color: var(--border-default);
    background: var(--bg-hover);
}

.managed-api-refresh-btn:disabled {
    opacity: 0.55;
    cursor: default;
}

.managed-api-refresh-btn svg {
    width: 16px;
    height: 16px;
}

.endpoints-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
}

.endpoints-list-empty {
    padding: var(--space-6);
    text-align: center;
    color: var(--text-muted);
    background: var(--bg-subtle);
    border-radius: var(--radius-md);
}

.endpoint-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    background: var(--bg-subtle);
}

.endpoint-card-managed {
    background: color-mix(in srgb, var(--bg-subtle) 72%, transparent 28%);
}

.endpoint-card-disabled {
    opacity: 0.62;
}

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

.endpoint-card-name {
    font-weight: 500;
}

.endpoint-card-heading {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: var(--space-2);
}

.endpoint-card-kind {
    flex: 0 0 auto;
    padding: 2px 6px;
    border: 1px solid var(--border-subtle);
    border-radius: 999px;
    color: var(--text-muted);
    font-size: 0.62rem;
    font-weight: 650;
}

.endpoint-card-details {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.endpoint-card-edit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.endpoint-card-edit:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.endpoint-card-edit svg {
    width: 16px;
    height: 16px;
}

.endpoint-card-edit--managed {
    cursor: default;
}

.endpoint-card-edit--managed:hover {
    color: var(--text-muted);
    background: transparent;
}

.add-endpoint-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3);
    border: 1px dashed var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.875rem;
    width: 100%;
    transition: all var(--transition-fast);
}

.add-endpoint-btn:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background: var(--accent-muted);
}

.add-endpoint-btn svg {
    width: 18px;
    height: 18px;
}

.endpoint-form-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
}

.endpoint-form-back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: all var(--transition-fast);
    cursor: pointer;
}

.endpoint-form-back:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.endpoint-form-back svg {
    width: 18px;
    height: 18px;
}

.endpoint-form-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.endpoint-form-heading-copy {
    display: grid;
    min-width: 0;
    gap: 2px;
}

.endpoint-form-heading-copy small {
    color: var(--text-muted);
    font-size: 0.72rem;
    line-height: 1.35;
}

.endpoint-form-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-top: var(--space-5);
    padding-top: var(--space-4);
    border-top: 1px solid var(--border-subtle);
}

.endpoint-form-actions-right {
    display: flex;
    gap: var(--space-2);
    margin-left: auto;
}

.endpoint-capabilities {
    margin-top: var(--space-4);
    padding-top: var(--space-3);
    border-top: 1px solid var(--border-subtle);
}

.endpoint-capabilities > summary {
    margin-bottom: var(--space-2);
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
}

.endpoint-capability-limits,
.endpoint-capability-options {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-2);
    margin-top: var(--space-3);
}

.endpoint-capability-options label {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--text-secondary);
    font-size: 0.8rem;
}

@media (max-width: 520px) {
    .endpoint-capability-limits,
    .endpoint-capability-options {
        grid-template-columns: 1fr;
    }

    .endpoint-form-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .endpoint-form-actions-right {
        margin-left: 0;
    }

    .endpoint-form-actions-right > button {
        flex: 1;
    }
}

/* Buttons */
.btn-primary, .btn-secondary, .btn-danger {
    padding: var(--space-2) var(--space-4);
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.btn-primary {
    background: var(--accent-primary);
    color: var(--accent-on);
}

.btn-primary:hover {
    background: var(--accent-hover);
    color: var(--accent-hover-on);
}

.btn-secondary {
    background: var(--bg-subtle);
    color: var(--text-secondary);
    border: 1px solid var(--border-default);
}

.btn-secondary:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-danger {
    background: var(--error);
    color: var(--error-on);
}

.btn-danger:hover {
    background: var(--error);
}

/* ========================================
   TOAST NOTIFICATIONS
   One transient card that rises in at the bottom right, just above the fixed
   footer and over the composer, stacks upward and leaves by itself. The host
   takes no layout space and ignores pointer events; only a card can be
   clicked, so nothing underneath is blocked.
   ======================================== */
.toast-container {
    position: fixed;
    bottom: calc(var(--statusbar-height) + var(--safe-bottom) + 8px);
    right: calc(12px + var(--safe-right));
    z-index: 12000;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    width: min(360px, calc(100vw - 24px - var(--safe-left) - var(--safe-right)));
    pointer-events: none;
}
/* The nested provider page owns a sticky action row. Keep transient cards above
   it so a just-saved provider cannot cover the next provider's Save control. */
body:has(#adminAccessProviderEditor) .toast-container {
    bottom: calc(var(--statusbar-height) + var(--safe-bottom) + 132px);
}
/* The grid row animates 0fr <-> 1fr, so a card opens and closes its own slot
   and the cards above it glide instead of jumping. */
.toast {
    display: grid;
    grid-template-rows: 1fr;
    --toast-surface: var(--text-primary);
    --toast-ink: var(--bg-elevated);
    --toast-accent: var(--toast-ink);
}
.toast.success {
    --toast-accent: var(--success);
}
.toast.error {
    --toast-accent: var(--error);
}
.toast-slot {
    min-height: 0;
    overflow: hidden;
}
.toast-card {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-top: 6px;
    padding: 10px 7px 10px 14px;
    border-radius: var(--radius-sm);
    background: var(--toast-surface);
    color: var(--toast-ink);
    transform-origin: bottom right;
    pointer-events: auto;
}
.toast-icon {
    flex: 0 0 16px;
    width: 16px;
    height: 16px;
    margin-top: 2px;
    color: color-mix(in srgb, var(--toast-ink) 63%, var(--toast-accent));
}
.toast-message {
    flex: 1;
    min-width: 0;
    max-height: 8.7em;
    overflow-y: auto;
    overscroll-behavior: contain;
    font: 450 0.8125rem/1.45 var(--font-ui);
    white-space: normal;
    word-break: break-word;
}
.toast .toast-action {
    flex: 0 0 auto;
    min-height: 24px;
    margin: 0;
    padding: 2px 7px;
    border: 1px solid color-mix(in srgb, var(--toast-ink) 42%, transparent);
    border-radius: 4px;
    background: transparent;
    color: inherit;
    font: 650 0.72rem/1.2 var(--font-ui);
    cursor: pointer;
}
.toast .toast-action:is(:hover, :focus-visible) {
    border-color: currentColor;
    outline: none;
}
.toast .toast-dismiss {
    display: grid;
    place-items: center;
    flex: 0 0 24px;
    width: 24px;
    height: 24px;
    min-height: 24px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 3px;
    background: transparent;
    color: color-mix(in srgb, var(--toast-ink) 72%, transparent);
    font: inherit;
    font-size: 1rem;
    cursor: pointer;
}
.toast .toast-dismiss:hover {
    color: var(--toast-ink);
}
.toast-dismiss:focus-visible {
    outline: 2px solid var(--toast-ink);
    outline-offset: -2px;
}
@keyframes toast-open {
    from { grid-template-rows: 0fr; }
}
@keyframes toast-card-in {
    from { opacity: 0; transform: translateY(16px) scale(0.96); }
    72% { opacity: 1; transform: translateY(-2px) scale(1); }
}
@keyframes toast-close {
    to { grid-template-rows: 0fr; }
}
@keyframes toast-card-out {
    to { opacity: 0; transform: translateY(9px) scale(0.97); }
}
.toast.is-entering {
    animation: toast-open 300ms cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
.toast.is-entering .toast-card {
    animation: toast-card-in 300ms cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
.toast.is-leaving {
    animation: toast-close 200ms ease-in both;
}
.toast.is-leaving .toast-card {
    animation: toast-card-out 160ms ease-in both;
}
@media (prefers-reduced-motion: reduce) {
    .toast.is-entering,
    .toast.is-entering .toast-card,
    .toast.is-leaving,
    .toast.is-leaving .toast-card {
        animation-duration: 1ms;
    }
}

/* ========================================
   RESPONSIVE
   ======================================== */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 300px;
        --topbar-height: 44px;
        --statusbar-height: 30px;
    }

    .main-layout {
        left: 0;
        width: 100%;
        transform: none;
    }

    .top-bar-inner,
    .status-bar-inner {
        width: 100%;
        padding: 0 calc(var(--space-3) + var(--safe-right)) 0 calc(var(--space-3) + var(--safe-left));
    }

    .sidebar {
        position: fixed;
        top: var(--topbar-height);
        left: 0;
        bottom: var(--statusbar-height);
        z-index: 50;
        margin-left: 0;
        transform: translateX(-100%);
        transition: transform var(--transition-normal);
    }

    .sidebar.collapsed {
        margin-left: 0;
        transform: translateX(-100%);
    }

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

    .message {
        max-width: 95%;
    }

    #modelSelector {
        display: none !important;
    }

    .top-bar-inner {
        gap: var(--space-2);
    }

    .app-title-text {
        display: none;
    }

    .shell-opening-title {
        max-width: 180px;
        font-size: 0.95rem;
    }

    .shell-opening-title::before {
        display: none;
    }

    .input-wrapper {
        gap: var(--space-1);
        padding: 0 1px;
    }


    #messageInput,
    .input-wrapper textarea {
        font-size: calc(18px - 2pt) !important;
    }

    .send-btn,
    .stop-btn {
        transform: scale(1.15);
        transform-origin: center;
    }

    .status-bar {
        cursor: pointer;
    }

    .settings-tabs {
        margin: 0 0 var(--space-4);
        padding: 2px;
        gap: 6px;
        overflow-x: auto;
        overflow-y: hidden;
        background: transparent;
        border-radius: 0;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .settings-tabs::-webkit-scrollbar {
        display: none;
    }

    .settings-tab {
        flex: 0 0 auto;
        min-width: max-content;
        white-space: nowrap;
        padding: 8px 12px;
        border: 1px solid var(--border-default);
        border-radius: 999px;
        background: var(--bg-subtle);
        font-size: 0.8rem;
    }

    .settings-tab.active {
        background: var(--accent-muted);
        border-color: var(--accent-primary);
        color: var(--accent-primary);
        box-shadow: none;
    }

    .manager-row {
        flex-direction: column;
        align-items: stretch;
    }

    .manager-actions,
    .manager-editor-actions {
        justify-content: stretch;
    }

    .manager-actions .payload-action-btn,
    .manager-editor-actions .payload-action-btn {
        flex: 1;
    }

    /* Clamp model/endpoint width on mobile so they truncate with ellipsis */
    #statusModel {
        max-width: min(120px, 35vw);
    }
    #statusEndpoint {
        max-width: min(120px, 35vw);
    }
}


/* Sidebar overlay for mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    top: var(--topbar-height);
    bottom: var(--statusbar-height);
    background: rgba(0, 0, 0, 0.5);
    z-index: 49;
}

.sidebar-overlay.active {
    display: block;
}

@media (min-width: 769px) {
    .sidebar-overlay {
        display: none !important;
    }
}

/* iOS Safari auto-zooms focused inputs below 16px; keep editable fields at 16px on touch iOS.
 * This is the floor for the composer, so it is 1.5pt rather than the 2pt phones otherwise
 * get below 18px. */
@supports (-webkit-touch-callout: none) {
    @media (hover: none) and (pointer: coarse) {
        #messageInput,
        .input-wrapper textarea {
            font-size: 16px !important;
        }

        .setting-input,
        .setting-textarea {
            font-size: 16px !important;
        }
    }
}

/* Button activation must not leave a browser focus outline or inset ring. */
button:focus,
button:focus-visible {
    outline: none;
}


/* One actionable route from an unavailable model to the existing Models workspace. */
.model-guidance-artifact {
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr);
    gap: 10px;
    width: min(100%, 540px);
    padding: 13px 14px;
    border: 1px solid color-mix(in srgb, var(--accent-primary) 34%, var(--border-subtle));
    border-inline-start: 3px solid var(--accent-primary);
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--accent-muted) 58%, var(--surface-default) 42%);
    color: var(--ink-primary);
    font-family: var(--font-interface);
    text-align: start;
}

.model-guidance-artifact[data-kind="error"] {
    border-color: color-mix(in srgb, var(--error) 34%, var(--border-subtle));
    border-inline-start-color: var(--error);
    background: var(--error-muted);
}

.model-guidance-icon {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent-muted);
    color: var(--accent-primary);
}

.model-guidance-artifact[data-kind="error"] .model-guidance-icon {
    background: color-mix(in srgb, var(--error) 12%, transparent);
    color: var(--error);
}

.model-guidance-icon svg {
    width: 17px;
    height: 17px;
}

.model-guidance-body {
    min-width: 0;
}

.model-guidance-title {
    display: block;
    font-size: calc(0.72rem + 1pt);
    line-height: 1.35;
}

.model-guidance-detail {
    margin: 3px 0 7px;
    color: var(--ink-secondary);
    font-size: calc(0.66rem + 1pt);
    line-height: 1.45;
    overflow-wrap: anywhere;
}

button.model-guidance-action {
    min-height: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--accent-primary);
    font: 650 calc(0.66rem + 1pt)/1.4 var(--font-interface);
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
}

button.model-guidance-action:is(:hover, :focus-visible) {
    background: transparent;
    color: var(--accent-hover);
}

.chat-entry-account > .chat-model-guidance {
    margin: 16px auto 0;
    pointer-events: auto;
}

.messages-container > .chat-model-guidance,
#studioConversation > .model-guidance-artifact {
    margin: 12px auto;
}

body.ui-version-v2 .message-response-recovery-content {
    flex: 1 1 260px;
    min-width: 0;
}

body.ui-version-v2 .message-response-recovery .model-guidance-artifact {
    width: 100%;
    padding: 0;
    border: 0;
    background: transparent;
}

body.ui-version-v2 .message-response-recovery .model-guidance-icon {
    width: 26px;
    height: 26px;
}

/* Failed attempts are system state, not character prose. */
body.ui-version-v2 .message-response-recovery {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    gap: 6px 10px;
    margin: 8px 0 2px;
    padding: 9px 10px;
    border: 1px solid color-mix(in srgb, var(--error) 34%, var(--border-subtle));
    border-inline-start: 3px solid var(--error);
    border-radius: var(--radius-sm);
    background: var(--error-muted);
    font-family: var(--font-interface);
}

body.ui-version-v2 .message-response-recovery[data-tone="warning"] {
    border-color: color-mix(in srgb, var(--activity-live) 34%, var(--border-subtle));
    border-inline-start-color: var(--activity-live);
    background: color-mix(in srgb, var(--activity-live) 12%, transparent);
}

body.ui-version-v2 .message-response-recovery-reason {
    flex: 1 1 220px;
    min-width: 0;
    margin: 0;
    color: var(--ink-primary);
    font-size: calc(0.68rem + 1pt);
    line-height: 1.45;
    overflow-wrap: anywhere;
}

body.ui-version-v2 :is(.message-response-recovery-retry, .message-response-recovery-delete) {
    flex: 0 0 26px;
    width: 26px;
    min-width: 26px;
    height: 26px;
    min-height: 26px;
    padding: 3px;
}

body.ui-version-v2 .message-response-recovery button:disabled,
body.ui-version-v2 .message-response-recovery button:disabled:hover {
    background: transparent;
    color: var(--ink-muted);
    opacity: 0.6;
    cursor: default;
}

@media (max-width: 560px) {
    body.ui-version-v2 .message-response-recovery {
        gap: 8px;
    }

    body.ui-version-v2 .message-response-recovery-reason {
        flex-basis: 100%;
    }
}

.cloud-save-status {
    position: relative;
    display: inline-flex;
    flex: 0 0 24px;
    color: var(--text-muted);
}
.cloud-save-status[hidden] { display: none; }
.cloud-save-trigger {
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    padding: 5px;
    border: 0;
    background: transparent;
    color: inherit;
    box-shadow: none;
    cursor: pointer;
}
.cloud-save-trigger svg { width: 14px; height: 14px; }
.cloud-save-status[data-state="saved"] .cloud-save-cross,
.cloud-save-status:not([data-state="saved"]) .cloud-save-check { display: none; }
.cloud-save-trigger:hover { color: var(--text-primary); }
.cloud-save-trigger:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: -2px;
}
.cloud-save-status[data-state="saving"] .cloud-save-trigger { opacity: 0.65; }
.cloud-save-status:is([data-state="error"], [data-state="paused"]) { color: var(--error); }
.cloud-save-announcement {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
}
.cloud-save-details {
    position: fixed;
    inset: auto auto calc(var(--statusbar-height) + 7px + env(safe-area-inset-bottom, 0px)) calc(8px + env(safe-area-inset-left, 0px));
    width: min(360px, calc(100vw - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
    font: 0.8125rem/1.4 var(--font-interface);
}
.cloud-save-details p { margin: 6px 11px; }
.cloud-save-actions { display: flex; flex-direction: column; }
.cloud-save-actions:not(:empty) { margin-top: 10px; }


/* ========================================
   Activity Admin (Settings → Activity, hosted admins)
   ======================================== */
/* Dense by design: an operator view of many small tables, one view at a time. */
.activity-admin {
    min-width: 0;
    font-size: 0.75rem;
}
.activity-admin-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px 8px;
    margin-bottom: 6px;
}
.activity-admin-toolbar .sandcat-select {
    width: 8.5rem;
}
.activity-admin-toolbar .sandcat-select-trigger {
    min-height: 28px;
    padding: 3px 6px 3px 8px;
    gap: 6px;
    font-size: 0.75rem;
}
.activity-admin-toolbar .sandcat-select-trigger svg {
    width: 14px;
    height: 14px;
}
.activity-admin-toolbar .btn-secondary {
    min-height: 28px;
    padding: 2px 10px;
    font-size: 0.75rem;
}
.activity-admin-meta {
    margin-left: auto;
    font-size: 0.6875rem;
    color: var(--text-secondary);
}
.activity-admin-tabs.model-picker-tabs {
    display: flex;
    gap: 2px;
    padding: 0;
    margin-bottom: 8px;
    overflow-x: auto;
    scrollbar-width: none;
}
.activity-admin-tabs.model-picker-tabs[hidden] {
    display: none;
}
.activity-admin-tabs .model-picker-tab {
    flex: 0 0 auto;
    min-height: 28px;
    padding: 0 10px;
    font-size: 0.75rem;
    white-space: nowrap;
}
.activity-admin-report {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
}
.activity-admin-status {
    margin: 0;
    padding: 8px 10px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
}
.worker-admin-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
    gap: 8px;
}
.worker-admin-stat {
    display: grid;
    gap: 2px;
    min-width: 0;
    padding: 8px 10px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    background: var(--surface-default);
}
.worker-admin-stat-label,
.worker-admin-stat small {
    color: var(--text-secondary);
    font-size: 0.6875rem;
}
.worker-admin-stat strong {
    font-size: 1rem;
    font-variant-numeric: tabular-nums;
}
.worker-state-online {
    color: var(--success);
    font-weight: 700;
}
.worker-state-offline {
    color: var(--text-muted);
}
.activity-admin-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr));
    gap: 8px;
}
.activity-admin-metric {
    display: grid;
    gap: 2px;
    min-width: 0;
    padding: 9px 10px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    background: var(--surface-default);
}
.activity-admin-metric-label,
.activity-admin-metric small {
    color: var(--text-secondary);
    font-size: 0.6875rem;
}
.activity-admin-metric strong {
    font-size: 1.125rem;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}
.activity-admin-metric-online strong,
.activity-admin-online {
    color: var(--success);
    font-weight: 700;
}
.activity-admin-detail-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}
.activity-admin-detail-actions .btn-secondary {
    min-height: 28px;
    padding: 2px 10px;
    font-size: 0.75rem;
}
.activity-admin-session-link {
    appearance: none;
    padding: 0;
    border: 0;
    background: none;
    color: var(--accent-primary);
    font: inherit;
    font-family: var(--font-code);
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.activity-admin-session-link:hover {
    color: var(--accent-hover);
}
.activity-admin-note {
    margin: 0;
    color: var(--text-secondary);
}
.activity-admin-section {
    min-width: 0;
}
.activity-admin-heading {
    margin: 0 0 4px;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-secondary);
}
.activity-admin-pair {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
    gap: 10px;
    min-width: 0;
}
.activity-admin-scroll {
    max-width: 100%;
    overflow-x: auto;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
}
.activity-admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.75rem;
    line-height: 1.3;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}
.activity-admin-table th,
.activity-admin-table td {
    padding: 3px 8px;
    text-align: left;
    white-space: nowrap;
    border-bottom: 1px solid var(--border-subtle);
}
.activity-admin-table th {
    position: sticky;
    top: 0;
    font-size: 0.625rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-secondary);
    background: var(--bg-subtle);
}
.activity-admin-table tbody tr:last-child td {
    border-bottom: 0;
}
.activity-admin-table tbody tr:hover td {
    background: var(--bg-subtle);
}
.activity-admin-table .activity-admin-num {
    text-align: right;
}
.activity-admin-table .activity-admin-clip {
    max-width: 16rem;
    overflow: hidden;
    text-overflow: ellipsis;
}
.activity-admin-table .activity-admin-mono {
    font-family: var(--font-code);
    font-size: 0.6875rem;
}
.activity-admin-empty {
    margin: 0;
    color: var(--text-secondary);
    font-style: italic;
}
.activity-admin-bar-cell {
    display: block;
    width: 6rem;
    height: 6px;
    border-radius: var(--radius-full);
    background: var(--bg-subtle);
    overflow: hidden;
}
.activity-admin-bar {
    display: block;
    height: 100%;
    border-radius: var(--radius-full);
    background: var(--accent-primary);
}
@media (max-width: 480px) {
    .activity-admin-meta {
        flex-basis: 100%;
        margin-left: 0;
    }
}

/* Curio Inventory and exchange */
.composer-add-control {
    position: absolute;
    left: 0;
    bottom: 6px;
    width: 22px;
    height: 22px;
    z-index: 25;
}
.composer-add-trigger {
    position: relative;
    width: 22px;
    height: 22px;
    padding: 0;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-full);
    background: var(--surface-muted);
    color: var(--text-secondary);
    display: grid;
    place-items: center;
}
.composer-add-trigger::before {
    content: '';
    position: absolute;
    inset: -3px;
}
.composer-add-trigger svg {
    width: 14px;
    height: 14px;
}
.composer-add-trigger:is(:hover, :focus-visible),
.composer-add-control.is-open .composer-add-trigger {
    border-color: var(--accent-primary);
    background: var(--surface-strong);
    color: var(--text-primary);
}
@media (max-width: 768px) {
    .composer-add-control,
    .composer-add-trigger {
        width: 18px;
        height: 18px;
    }
    .composer-add-trigger::before {
        inset: -5px;
    }
    .composer-add-trigger svg {
        width: 12px;
        height: 12px;
    }
}
.composer-add-count {
    min-width: 20px;
    height: 20px;
    margin-left: auto;
    padding-inline: 6px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-full);
    background: var(--surface-strong);
    color: var(--text-primary);
    font: 700 0.6875rem/18px var(--font-ui);
    font-variant-numeric: tabular-nums;
    text-align: center;
}
body .composer-add-menu.sandcat-menu {
    position: absolute;
    left: 0;
    right: auto;
    bottom: calc(100% + 8px);
    width: 160px;
    z-index: 100;
}
.curio-composer-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 0 6px;
}
.curio-composer-chips[hidden] {
    display: none;
}
.curio-composer-chip,
.message-curio-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    max-width: 100%;
    padding: 4px 8px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-full);
    background: var(--surface-muted);
    color: var(--text-primary);
    font: 600 0.72rem/1.2 var(--font-ui);
}
.curio-composer-chip {
    padding-block: 2px;
}
.curio-composer-chip > span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.curio-composer-chip button {
    width: 22px;
    height: 22px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    font: 700 1.2rem/1 var(--font-ui);
}
.curio-composer-chip button:is(:hover, :focus-visible) {
    background: var(--surface-strong);
    color: var(--text-primary);
}
@media (min-width: 769px) {
    .curio-composer-chips {
        margin-top: -34px;
        padding: 3px 104px 3px 28px;
    }
    .composer-control-rail:is(.turn-generation-visible, .scroll-bottom-visible) + .curio-composer-chips {
        padding-right: calc(50% + 72px);
    }
}
@media (max-width: 768px) {
    .curio-composer-chip {
        padding: 1px 7px;
        font-size: calc(0.72rem - 1pt);
    }
}
.message-curio-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}
.message-curio-chip::before {
    content: "◇";
    color: var(--accent-primary);
}
.message-curio-exchange {
    --curio-state: var(--accent-primary);
    position: relative;
    margin: 16px 0 4px;
    padding: 14px 0 12px 20px;
    border: 0;
    border-top: 1px solid color-mix(in srgb, var(--curio-state) 58%, var(--border-default));
    border-bottom: 1px solid var(--border-default);
    border-radius: 0;
    background: transparent;
}
.message-curio-exchange::before {
    content: "";
    position: absolute;
    top: 16px;
    left: 2px;
    width: 8px;
    height: 8px;
    border: 1px solid var(--curio-state);
    background: var(--surface-default);
    transform: rotate(45deg);
}
.message-curio-exchange::after {
    content: "";
    position: absolute;
    top: 31px;
    bottom: 14px;
    left: 6px;
    width: 1px;
    background: var(--border-subtle);
}
.message-curio-exchange:is(.is-accepted, .is-transferred) {
    --curio-state: var(--success);
}
.message-curio-exchange.is-rejected {
    --curio-state: var(--text-muted);
}
.message-curio-exchange.is-inactive {
    --curio-state: var(--text-muted);
}
.message-curio-exchange.is-inactive :is(.message-curio-purpose, .message-curio-description, .message-curio-footer) {
    color: var(--text-muted);
}
.message-curio-exchange.is-inactive .message-curio-action,
.message-curio-exchange.is-inactive .message-curio-action:hover {
    border-color: var(--border-default);
    background: var(--surface-strong);
    color: var(--text-muted);
    cursor: not-allowed;
    opacity: 0.72;
}

.message-curio-heading {
    display: grid;
    gap: 4px;
}
.message-curio-heading > span {
    color: var(--curio-state);
    font: 700 0.65rem/1.2 var(--font-ui);
    letter-spacing: 0.11em;
    text-transform: uppercase;
}
.message-curio-heading h3 {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 8px;
    margin: 0;
    color: var(--text-primary);
    font: 680 1.02rem/1.28 var(--font-ui);
    letter-spacing: -0.012em;
}
.message-curio-glyph {
    display: inline-grid;
    color: var(--curio-state);
}
.message-curio-glyph svg {
    width: 17px;
    height: 17px;
}
.message-curio-category {
    color: var(--text-muted);
    font: 600 0.62rem/1.2 var(--font-ui);
    font-style: normal;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.message-curio-purpose {
    max-width: 62ch;
    margin: 8px 0 0;
    color: var(--text-primary);
    font: 600 0.88rem/1.45 var(--font-ui);
}
.message-curio-description {
    max-width: 62ch;
    margin: 6px 0 12px;
    color: var(--text-secondary);
    font: 450 0.9rem/1.55 var(--font-content);
}
.message-curio-footer {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border-subtle);
}
.message-curio-footer details {
    min-width: 0;
    flex: 1 1 18rem;
    margin: 0;
}
.message-curio-footer summary {
    width: fit-content;
    color: var(--text-secondary);
    cursor: pointer;
    font: 650 0.72rem/1.35 var(--font-ui);
    letter-spacing: 0.02em;
}
.message-curio-content {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-subtle);
}
.message-curio-actions {
    display: flex;
    flex: 0 0 auto;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0;
}
.message-curio-feedback {
    margin: 8px 0 0;
    color: var(--text-secondary);
    font: 600 0.75rem/1.4 var(--font-ui);
}
.message-curio-feedback.is-error {
    color: var(--error);
}
.message-curio-event,
.message-playtest-event {
    position: relative;
    flex-shrink: 0;
    display: grid;
    grid-template-columns: minmax(24px, 1fr) auto minmax(24px, 1fr);
    align-items: center;
    gap: 12px;
    width: min(680px, calc(100% - 36px));
    margin: 0 auto 16px;
    color: var(--success);
}
.message-curio-event > span,
.message-playtest-event > span {
    height: 1px;
    background: color-mix(in srgb, currentColor 52%, transparent);
}
.message-curio-event p,
.message-playtest-event p {
    min-width: 0;
    max-width: min(520px, 70vw);
    margin: 0;
    overflow-wrap: anywhere;
    color: var(--text-secondary);
    font: 650 0.72rem/1.4 var(--font-ui);
    letter-spacing: 0.025em;
    text-align: center;
}
.message-playtest-event {
    color: var(--error);
}
.message-playtest-event p {
    color: var(--error);
    font-size: 0.78rem;
    font-weight: 750;
    letter-spacing: 0.045em;
}
.message-curio-event.is-rejected {
    color: var(--text-muted);
}
.message-curio-event.is-rejected p {
    color: var(--text-muted);
}

.curio-inventory-dialog {
    width: min(1040px, 94vw);
    max-width: none;
    height: min(700px, calc(100dvh - 48px));
    max-height: calc(100dvh - 48px);
    border-color: var(--border-subtle);
    border-radius: 16px;
}
.curio-inventory-header {
    display: flex;
    min-height: 62px;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 10px 8px 18px;
    border-bottom: 1px solid var(--border-subtle);
}
.curio-inventory-header-leading {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 10px;
}
.curio-inventory-header-copy {
    display: grid;
    min-width: 0;
    gap: 2px;
}
.curio-inventory-header h2 {
    margin: 0;
    font: 600 1rem/1.25 var(--font-ui);
}
.curio-inventory-meta {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 8px;
}
.curio-inventory-intro {
    overflow: hidden;
    color: var(--text-muted);
    font: 450 0.7rem/1.3 var(--font-ui);
    text-overflow: ellipsis;
    white-space: nowrap;
}
.curio-context-only-tag {
    flex: 0 0 auto;
    padding: 3px 7px;
    border: 1px solid color-mix(in srgb, var(--activity-live) 62%, var(--border-default));
    border-radius: var(--radius-full);
    background: color-mix(in srgb, var(--activity-live) 12%, transparent);
    color: var(--text-primary);
    font: 700 0.6rem/1.2 var(--font-ui);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
.curio-context-only-tag[hidden],
.curio-inventory-row-state[hidden],
.curio-inventory-detail-record[hidden] {
    display: none;
}
.curio-inventory-back {
    display: none;
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    place-items: center;
    padding: 0;
    border: 1px solid var(--border-subtle);
    border-radius: 50%;
    background: var(--bg-subtle);
    color: var(--text-secondary);
    font: 600 1rem/1 var(--font-ui);
}
.curio-inventory-back:hover,
.curio-inventory-back:focus-visible {
    color: var(--accent-primary);
    outline: none;
}
.curio-inventory-browser {
    display: grid;
    min-height: 0;
    flex: 1 1 auto;
    overflow: hidden;
    grid-template-columns: 320px minmax(0, 1fr);
}
.curio-inventory-master,
.curio-inventory-detail {
    min-width: 0;
    min-height: 0;
}
.curio-inventory-master {
    overflow-y: auto;
    padding: 8px;
    border-right: 1px solid var(--border-subtle);
    background: color-mix(in srgb, var(--bg-subtle) 48%, transparent 52%);
    overscroll-behavior: contain;
}
.curio-inventory-list {
    display: grid;
    gap: 2px;
}
.curio-inventory-item {
    min-width: 0;
}
.curio-inventory-open {
    display: grid;
    width: 100%;
    min-width: 0;
    min-height: 48px;
    grid-template-columns: 28px minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    padding: 5px 7px;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    color: var(--text-primary);
    text-align: left;
    transition: border-color var(--transition-fast), background var(--transition-fast);
}
@media (hover: hover) {
    .curio-inventory-item:not(.is-selected) .curio-inventory-open:hover {
        background: var(--bg-hover);
    }
}
.curio-inventory-open:focus-visible {
    border-color: var(--focus-ring);
    outline: none;
}
.curio-inventory-item.is-selected .curio-inventory-open {
    border-color: color-mix(in srgb, var(--accent-primary) 62%, var(--border-subtle));
    background: var(--accent-muted);
}
.curio-inventory-icon {
    display: grid;
    width: 28px;
    height: 28px;
    flex: 0 0 28px;
    place-items: center;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    background: var(--surface-strong);
    color: var(--accent-primary);
}
.curio-inventory-icon svg {
    width: 16px;
    height: 16px;
}
.curio-inventory-copy {
    display: grid;
    min-width: 0;
    align-content: center;
    gap: 1px;
}
.curio-inventory-copy strong,
.curio-inventory-copy > span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.curio-inventory-copy strong {
    font: 600 0.78rem/1.2 var(--font-ui);
    letter-spacing: -0.006em;
}
.curio-inventory-copy > span {
    color: var(--text-muted);
    font: 450 0.68rem/1.2 var(--font-ui);
}
.curio-inventory-row-state {
    color: var(--accent-primary);
    font: 700 0.56rem/1.2 var(--font-ui);
    letter-spacing: 0.055em;
    text-transform: uppercase;
}
.curio-inventory-empty,
.curio-inventory-loading {
    margin: 0;
    padding: 14px 10px;
    color: var(--text-secondary);
    font-size: 0.78rem;
}
.curio-inventory-detail {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-elevated);
}
.curio-inventory-detail-empty {
    display: grid;
    margin: auto;
    padding: 24px;
    color: var(--text-muted);
    text-align: center;
}
.curio-inventory-detail-empty strong {
    color: var(--text-secondary);
    font: 600 0.88rem/1.35 var(--font-ui);
}
.curio-inventory-detail-empty span {
    margin-top: 3px;
    font: 450 0.75rem/1.4 var(--font-ui);
}
.curio-inventory-detail-record {
    display: flex;
    min-height: 0;
    height: 100%;
    flex: 1 1 auto;
    flex-direction: column;
}
.curio-inventory-detail-scroll {
    min-height: 0;
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 28px 30px;
    overscroll-behavior: contain;
}
.curio-detail-identity {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    align-items: start;
    gap: 14px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-subtle);
}
.curio-detail-identity > .curio-inventory-icon {
    width: 48px;
    height: 48px;
}
.curio-detail-identity > .curio-inventory-icon svg {
    width: 25px;
    height: 25px;
}
.curio-detail-heading {
    display: grid;
    min-width: 0;
    gap: 3px;
}
.curio-detail-heading > span {
    color: var(--accent-primary);
    font: 700 0.625rem/1.2 var(--font-ui);
    letter-spacing: 0.1em;
    text-transform: uppercase;
}
.curio-detail-heading h3 {
    margin: 0;
    color: var(--text-primary);
    font: 650 1.25rem/1.25 var(--font-ui);
    letter-spacing: -0.015em;
}
.curio-detail-purpose {
    margin: 4px 0 0;
    color: var(--text-primary);
    font: 600 0.92rem/1.45 var(--font-ui);
}
.curio-detail-description {
    margin: 18px 0 0;
    color: var(--text-secondary);
    font: 450 0.9rem/1.6 var(--font-content);
}
.curio-detail-payload {
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid var(--border-subtle);
}
.curio-detail-payload > summary {
    width: fit-content;
    color: var(--text-secondary);
    cursor: pointer;
    font: 650 0.72rem/1.35 var(--font-ui);
    letter-spacing: 0.02em;
}
.curio-detail-content {
    margin-top: 12px;
    color: var(--text-primary);
    font: 450 0.86rem/1.6 var(--font-content);
}
.curio-detail-provenance {
    margin: 18px 0 0;
    color: var(--text-muted);
    font: 450 0.72rem/1.4 var(--font-ui);
}
.curio-detail-content > :first-child {
    margin-top: 0;
}
.curio-detail-content > :last-child {
    margin-bottom: 0;
}
.curio-detail-content .curio-inventory-loading {
    padding: 0;
}
.curio-detail-error {
    margin: 0;
    color: var(--error);
}
.curio-detail-actions {
    display: flex;
    flex: 0 0 auto;
    justify-content: flex-end;
    gap: 8px;
    padding: 14px 18px;
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-subtle);
}
.curio-detail-actions .btn {
    min-width: 92px;
}
@media (max-width: 768px) {
    #curioInventoryModal {
        align-items: stretch;
        justify-content: stretch;
        overflow: hidden;
        padding: 0;
    }
    .curio-inventory-dialog {
        position: fixed;
        inset: 0;
        width: 100vw;
        max-width: none;
        height: 100dvh;
        max-height: 100dvh;
        border: 0;
        border-radius: 0;
        transform: none;
    }
    .modal-overlay.active .curio-inventory-dialog {
        transform: none;
    }
    .curio-inventory-header {
        min-height: calc(57px + var(--safe-top));
        padding-top: calc(6px + var(--safe-top));
        padding-right: calc(11px + var(--safe-right));
        padding-bottom: 6px;
        padding-left: calc(11px + var(--safe-left));
    }
    .curio-inventory-back:not([hidden]) {
        display: grid;
    }
    .curio-inventory-browser {
        position: relative;
        display: block;
        overflow: clip;
        contain: layout paint;
    }
    .curio-inventory-master,
    .curio-inventory-detail {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
        transition: transform 180ms ease;
        will-change: transform;
    }
    .curio-inventory-master {
        padding: 8px calc(8px + var(--safe-right)) calc(8px + var(--safe-bottom)) calc(8px + var(--safe-left));
        border-right: 0;
    }
    .curio-inventory-dialog[data-view="list"] .curio-inventory-master,
    .curio-inventory-dialog[data-view="detail"] .curio-inventory-detail {
        transform: translateX(0);
    }
    .curio-inventory-dialog[data-view="list"] .curio-inventory-detail {
        transform: translateX(100%);
    }
    .curio-inventory-dialog[data-view="detail"] .curio-inventory-master {
        transform: translateX(-100%);
    }
    .curio-inventory-dialog[data-view="list"] .curio-inventory-detail,
    .curio-inventory-dialog[data-view="detail"] .curio-inventory-master {
        pointer-events: none;
    }
    .curio-inventory-open {
        min-height: 50px;
    }
    .curio-inventory-detail-scroll {
        padding: 22px calc(18px + var(--safe-right)) 22px calc(18px + var(--safe-left));
    }
    .curio-detail-identity {
        grid-template-columns: 42px minmax(0, 1fr);
        gap: 12px;
        padding-bottom: 18px;
    }
    .curio-detail-identity > .curio-inventory-icon {
        width: 42px;
        height: 42px;
    }
    .curio-detail-heading h3 {
        font-size: 1.08rem;
    }
    .curio-detail-actions {
        padding-right: calc(12px + var(--safe-right));
        padding-bottom: calc(12px + var(--safe-bottom));
        padding-left: calc(12px + var(--safe-left));
    }
    .curio-detail-actions .btn {
        min-height: 42px;
        flex: 1 1 0;
    }
}
@media (prefers-reduced-motion: reduce) {
    .curio-inventory-master,
    .curio-inventory-detail {
        transition: none;
    }
}
@media (max-width: 560px) {
    .message-curio-footer {
        flex-direction: column;
    }
    .message-curio-footer details {
        width: 100%;
        flex: 0 1 auto;
    }
    .message-curio-actions {
        width: 100%;
    }
    .message-curio-actions .btn {
        flex: 1 1 auto;
    }
    .message-curio-event,
    .message-playtest-event {
        grid-template-columns: minmax(16px, 1fr) auto minmax(16px, 1fr);
        gap: 8px;
        width: calc(100% - 20px);
        margin-bottom: 12px;
    }
    .message-curio-event p,
    .message-playtest-event p {
        font-size: 0.68rem;
        letter-spacing: 0.02em;
    }
}

.image-attachment-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 0 8px;
}
.image-attachment-strip[hidden] {
    display: none;
}
.image-attachment-chip {
    display: inline-flex;
    max-width: min(220px, 100%);
    align-items: center;
    gap: 7px;
    padding: 4px 6px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    background: var(--surface-muted);
    color: var(--text-primary);
    font: 600 0.72rem/1.2 var(--font-ui);
}
.image-attachment-chip.image-attachment-uploading {
    min-height: 44px;
    border-style: dashed;
    color: var(--text-secondary);
}
.image-attachment-uploading .v2-action-spinner {
    width: 14px;
    height: 14px;
    flex: none;
    border-width: 2px;
}
.image-attachment-chip img {
    width: 34px;
    height: 34px;
    flex: none;
    border-radius: 3px;
    object-fit: cover;
}
.image-attachment-chip > span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
body.ui-version-v2 .image-attachment-chip button {
    display: inline-flex;
    width: 32px;
    height: 32px;
    flex: none;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    border: 0;
    border-radius: 50%;
    padding: 0;
    background: transparent;
    color: var(--text-secondary);
    font: 700 1.35rem/1 var(--font-ui);
    cursor: pointer;
}
body.ui-version-v2 .image-attachment-chip button:is(:hover, :focus-visible) {
    background: var(--surface-strong);
    color: var(--text-primary);
}
.message-image-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}
.message-image-attachments a {
    display: block;
    max-width: min(260px, 100%);
}
.message-image-attachments img {
    display: block;
    max-width: 100%;
    max-height: 260px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    object-fit: contain;
}
.message-image-tombstones {
    display: grid;
    gap: 4px;
    margin-top: 10px;
    color: var(--text-secondary);
    font: 0.8rem/1.35 var(--font-ui);
}
.message-image-tombstones span {
    padding-left: 10px;
    border-left: 2px solid var(--border-default);
}

/* The admin audit is a read-only document: message boundaries, exact text and
 * dashed per-request artifacts, matching Studio's assembled-prompt vocabulary. */
.assistant-prompt-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 18px;
    margin-bottom: 12px;
}
.assistant-prompt-controls .setting-label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}
.assistant-prompt-controls .admin-option-check { margin: 0; }
.assistant-prompt-controls [hidden] { display: none; }
.assistant-prompt-preview { min-width: 0; }
.assistant-prompt-message,
.assistant-prompt-tools {
    margin-top: 20px;
    padding-top: 12px;
    border-top: 1px solid var(--border-default);
}
.assistant-prompt-message-heading {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 8px;
    margin: 0 0 12px;
    font: 600 0.95rem/1.4 var(--font-ui);
}
.assistant-prompt-role {
    color: var(--text-secondary);
    font: 600 0.7rem/1.4 var(--font-ui);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.assistant-prompt-section { margin: 0 0 14px; }
.assistant-prompt-section > summary {
    cursor: pointer;
    color: var(--text-primary);
    font: 600 0.85rem/1.4 var(--font-ui);
}
.assistant-prompt-text,
.assistant-prompt-prefix {
    margin: 8px 0 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    color: var(--text-primary);
    font: 400 0.85rem/1.6 var(--font-ui);
}
.assistant-prompt-prefix { color: var(--text-secondary); margin-bottom: 8px; }
.assistant-prompt-artifact {
    margin: 8px 0;
    padding: 10px 12px;
    border: 1px dashed var(--border-default);
    border-radius: var(--radius-sm);
    background: var(--surface-muted);
    color: var(--text-secondary);
    font: 400 0.82rem/1.5 var(--font-ui);
}
.assistant-prompt-artifact > strong { color: var(--text-primary); }
.assistant-prompt-artifact > p { margin: 4px 0 0; }
.assistant-prompt-preference { margin: 12px 0; }
.assistant-prompt-tools > h3 { font: 600 0.95rem/1.4 var(--font-ui); }
.assistant-prompt-tools .assistant-prompt-text { font-family: var(--font-mono, monospace); font-size: 0.75rem; }
