/* Styly chatu asistenta.
   Nejsou to scoped .razor.css: v téhle RCL se scoped styly nenačítají, takže se
   registrují v App.razor hostitele jako _content/2ndSide.Blazor.Ai/css/secondside-blazor-ai.css

   Barvy jdou výhradně z proměnných MudBlazoru (--mud-palette-*, --mud-elevation-*),
   ať okno sedí se světlým i tmavým tématem hostitele. */

.ai-chat {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    gap: 8px;
}

/* Obal seznamu zpráv — kvůli pilulce „Nové zprávy“, která plave nad ním. */
.ai-chat__feed {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.ai-chat__messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 4px 2px;
    /* Bez smooth: JS během streamu nastavuje scrollTop každých 80 ms a plynulá
       animace nikdy nedoběhla — delší odpovědi se kvůli tomu trhaly. */
    scroll-behavior: auto;
}

.ai-chat__new-messages {
    position: absolute;
    left: 50%;
    bottom: 10px;
    transform: translateX(-50%);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px 4px 8px;
    border: 0;
    border-radius: 999px;
    font: inherit;
    font-size: .78rem;
    cursor: pointer;
    color: var(--mud-palette-primary-text);
    background: var(--mud-palette-primary);
    box-shadow: var(--mud-elevation-4);
    animation: ai-message-in .16s ease-out;
}

.ai-chat__new-messages[hidden] {
    display: none;
}

.ai-chat__empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    text-align: center;
    padding: 24px 16px;
}

.ai-chat__empty .mud-typography {
    opacity: .75;
}

.ai-chat__suggestions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    margin-top: 4px;
}

/* Návrhy po odpovědi. Text místo obrysu schválně — pod hotovou odpovědí by výrazné
   chipy přetahovaly pozornost z toho, co model právě napsal. */
.ai-chat__followups {
    display: flex;
    flex-wrap: wrap;
    gap: .25rem;
    padding: .25rem .5rem .75rem;
}

/* Proužek s kontextem stránky nad vstupem. Decentní — je to informace, ne akce. */
.ai-chat__context {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px 0;
    color: var(--mud-palette-text-secondary);
    font-size: .72rem;
    min-width: 0;
}

.ai-chat__context-text {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-chat__composer {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--mud-palette-divider);
}

.ai-chat__actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
}

/* ============================================================
   Přiložený soubor: sponka, přetažení, štítek s akcemi
   ============================================================ */

.ai-chat {
    position: relative;
}

/* Přes celý panel během tažení souboru. Neviditelné InputFile nahoře soubor převezme samo. */
.ai-chat__drop {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 2px dashed var(--mud-palette-primary);
    border-radius: 8px;
    background: color-mix(in srgb, var(--mud-palette-surface) 90%, transparent);
    color: var(--mud-palette-primary);
    font-weight: 500;
}

.ai-chat__drop-input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: copy;
}

.ai-chat__attach {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    color: var(--mud-palette-action-default);
}

.ai-chat__attach:hover {
    background: var(--mud-palette-action-default-hover);
}

.ai-chat__attach-input {
    display: none;
}

.ai-chat__attachment {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.ai-chat__attachment .mud-chip {
    max-width: 100%;
}

.ai-chat__attachment-error {
    color: var(--mud-palette-error);
    font-size: .75rem;
}

.ai-message__files {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 4px;
    margin-bottom: 4px;
}

.ai-message__file {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    max-width: 100%;
    padding: 2px 8px;
    border-radius: 12px;
    background: var(--mud-palette-action-default-hover);
    font-size: .75rem;
}

.ai-message__file-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================================
   Bubliny
   ============================================================ */

.ai-message {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
}

.ai-message--user {
    align-items: flex-end;
}

.ai-message--user .ai-message__body {
    background: var(--mud-palette-primary);
    color: var(--mud-palette-primary-text);
    border-radius: 14px 14px 4px 14px;
}

.ai-message--assistant .ai-message__body {
    background: var(--mud-palette-background-gray);
    color: var(--mud-palette-text-primary);
    border-radius: 14px 14px 14px 4px;
}

.ai-message__body {
    /* Strop v znacích, ne v procentech: v širokém okně měla řádka odpovědi přes sto
       znaků a oko na dalším řádku ztrácelo začátek. Tabulky a grafy si šířku berou
       zpátky níž (.ai-message__body > .ai-visual). */
    max-width: min(92%, 78ch);
    min-width: 0;
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-wrap: anywhere;
}

.ai-message__retry {
    display: flex;
    justify-content: flex-start;
}

/* Vizualizace se z textové míry vymaňuje — graf ani tabulka nejsou text ke čtení
   po řádcích a v 78 znacích se nakreslí zbytečně malé. */
.ai-message--assistant .ai-message__body:has(.ai-visual) {
    max-width: 96%;
    width: 100%;
}

/* Čas, kopírování a hodnocení: skryté, dokud se na zprávu nenajede (nebo nedostane fokus). */
.ai-message__meta {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 0 4px;
    font-size: .7rem;
    color: var(--mud-palette-text-secondary);
    opacity: 0;
    transition: opacity .15s ease;
}

.ai-message:hover .ai-message__meta,
.ai-message:focus-within .ai-message__meta {
    opacity: 1;
}

/* Už udělené hodnocení musí být vidět i bez najetí — jinak nejde poznat,
   co jsem hodnotil a co ne. */
.ai-message__meta:has(.ai-message__rate--on) {
    opacity: 1;
}

.ai-message__meta .mud-icon-button {
    padding: 2px;
}

.ai-message__meta .mud-icon-button .mud-icon-root {
    font-size: 1rem;
    width: 1rem;
    height: 1rem;
}

.ai-message__time {
    font-variant-numeric: tabular-nums;
}

/* --- krok nástroje (řádek v podrobnostech procesu) --- */

.ai-tool-call {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 24px;
    font-size: .8rem;
    opacity: .85;
}

.ai-tool-call--running {
    opacity: 1;
}

.ai-tool-call__title {
    flex: 1 1 auto;
}

.ai-tool-call__duration {
    opacity: .6;
    font-variant-numeric: tabular-nums;
}

/* ============================================================
   Scéna — co asistent zrovna dělá
   Velká Sponka hraje stav, k ní dvě tři slova. Dřív tu stály tři řádky s týmž
   titulkem; teď nese význam animace a text je jen potvrzení. Co přesně se dělo,
   je schované pod „podrobnosti“.
   ============================================================ */

/* Pódium: měkká záře za Sponkou a stín pod ní. Stín dýchá proti pohybu těla, takže
   sponka působí, že stojí na zemi, a ne že je nalepená na pozadí. Sdílí ho scéna
   v bublině i úvodní obrazovka prázdné konverzace. */
.ai-podium {
    position: relative;
    flex: 0 0 auto;
    isolation: isolate;
}

.ai-podium::before {
    content: "";
    position: absolute;
    /* Tělo sponky je ve viewBoxu vlevo od středu (vpravo je místo na rekvizity). */
    inset: -14% -6% -10% -22%;
    z-index: -1;
    border-radius: 50%;
    background: radial-gradient(closest-side,
        color-mix(in srgb, var(--ai-stage-tint, var(--mud-palette-primary)) 26%, transparent) 0%,
        color-mix(in srgb, var(--ai-stage-tint, var(--mud-palette-primary)) 9%, transparent) 55%,
        transparent 100%);
    animation: ai-podium-glow 3.6s ease-in-out infinite;
}

.ai-podium::after {
    content: "";
    position: absolute;
    left: 12%;
    width: 70%;
    bottom: -3%;
    height: 9%;
    z-index: -1;
    border-radius: 50%;
    background: radial-gradient(closest-side, rgba(15, 23, 42, .28), transparent);
    animation: ai-podium-shadow 3.6s ease-in-out infinite;
}

@keyframes ai-podium-glow {
    0%, 100% { opacity: .75; transform: scale(.94); }
    50%      { opacity: 1; transform: scale(1.04); }
}

@keyframes ai-podium-shadow {
    0%, 100% { opacity: .9; transform: scaleX(1); }
    50%      { opacity: .55; transform: scaleX(.86); }
}

/* Úvodní obrazovka: Sponka jako hostitel, ne jako ikonka nad textem. */
.ai-chat__hero {
    width: 112px;
    margin: 10px 0 8px;
}

.ai-stage {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}

.ai-stage__row {
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0;
}

/* Velikost Sponky řídí jen tahle šířka, takže přechod do kompaktní podoby je plynulý. */
.ai-stage__mascot {
    width: 100px;
    margin: 10px 4px 8px 8px;
    transition: width .45s cubic-bezier(.2, .8, .2, 1), margin .45s cubic-bezier(.2, .8, .2, 1);
}

.ai-stage__side {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    animation: ai-stage-side-in .3s ease-out;
}

/* Popisek s přejíždějícím leskem: říká „pořád se něco děje“ bez dalšího pohyblivého prvku.
   Barvy z palety, takže lesk sedí ve světlém i tmavém tématu. */
.ai-stage__caption {
    align-self: flex-start;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -.005em;
    line-height: 1.25;
    color: var(--mud-palette-text-secondary);
    background: linear-gradient(100deg,
        var(--mud-palette-text-secondary) 0%,
        var(--mud-palette-text-secondary) 38%,
        var(--mud-palette-primary) 50%,
        var(--mud-palette-text-secondary) 62%,
        var(--mud-palette-text-secondary) 100%);
    background-size: 250% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: ai-stage-caption-in .35s cubic-bezier(.2, .8, .2, 1), ai-stage-shimmer 2.6s linear infinite;
}

@keyframes ai-stage-caption-in {
    from { opacity: 0; transform: translateY(7px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes ai-stage-shimmer {
    from { background-position: 115% 0; }
    to   { background-position: -15% 0; }
}

@keyframes ai-stage-side-in {
    from { opacity: 0; transform: translateX(-6px); }
    to   { opacity: 1; transform: translateX(0); }
}

.ai-stage__meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    min-height: 18px;
    font-size: .72rem;
    color: var(--mud-palette-text-secondary);
}

/* Tečky kroků: hotový krok tlumená, běžící plná s rozbíhajícím se kroužkem. */
.ai-stage__dots {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.ai-stage__dots-more {
    font-variant-numeric: tabular-nums;
    opacity: .7;
}

.ai-stage__dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--mud-palette-primary) 42%, transparent);
    animation: ai-stage-dot-in .3s cubic-bezier(.3, 1.5, .5, 1);
}

.ai-stage__dot--running {
    background: var(--mud-palette-primary);
    animation: ai-stage-dot-in .3s cubic-bezier(.3, 1.5, .5, 1), ai-stage-ping 1.5s ease-out .3s infinite;
}

.ai-stage__dot--error {
    background: var(--mud-palette-error);
}

@keyframes ai-stage-dot-in {
    from { transform: scale(0); }
    to   { transform: scale(1); }
}

@keyframes ai-stage-ping {
    0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--mud-palette-primary) 55%, transparent); }
    100% { box-shadow: 0 0 0 7px transparent; }
}

/* Vteřiny počítá prohlížeč: registrovaná celočíselná vlastnost se animuje lineárně
   a counter() ji vypíše. Ze serveru by to bylo překreslení a SignalR zpráva každou
   vteřinu. Prvních pár vteřin je schovaný — u rychlé odpovědi je to údaj navíc. */
@property --ai-stage-seconds {
    syntax: "<integer>";
    initial-value: 0;
    inherits: false;
}

.ai-stage__timer {
    font-variant-numeric: tabular-nums;
    counter-reset: ai-stage-seconds var(--ai-stage-seconds);
    opacity: 0;
    animation: ai-stage-count 3600s linear forwards, ai-stage-timer-in .5s ease-out 4s forwards;
}

.ai-stage__timer::after {
    content: counter(ai-stage-seconds) " s";
}

@keyframes ai-stage-count {
    to { --ai-stage-seconds: 3600; }
}

@keyframes ai-stage-timer-in {
    to { opacity: .8; }
}

.ai-stage__more {
    display: inline-flex;
    align-items: center;
    gap: 0;
    margin-left: -2px;
    padding: 0 2px;
    border: 0;
    border-radius: 6px;
    background: none;
    font: inherit;
    color: inherit;
    cursor: pointer;
    opacity: .8;
    transition: opacity .15s ease, color .15s ease;
}

.ai-stage__more:hover,
.ai-stage__more:focus-visible {
    opacity: 1;
    color: var(--mud-palette-primary);
}

.ai-stage__more .mud-icon-root {
    font-size: 1rem;
    width: 1rem;
    height: 1rem;
}

.ai-stage__details {
    animation: ai-stage-details-in .22s ease-out;
}

@keyframes ai-stage-details-in {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Kompaktní podoba: odpověď už teče (nebo právě doběhla), zbývá malá píšící Sponka
   pod textem. Popisek mizí — bublina se hýbe sama. */
.ai-stage--compact .ai-stage__mascot {
    width: 40px;
    margin: 0 2px 2px 2px;
}

.ai-stage--compact .ai-stage__side {
    display: none;
}

.ai-stage--compact .ai-podium::before {
    opacity: .6;
    animation: none;
}

/* Hotovo: záře se na okamžik rozsvítí do žluta spolu se žárovkou. */
.ai-stage--done {
    --ai-stage-tint: var(--mud-palette-warning);
}

/* Dokud je scéna v bublině sama, bublina ustoupí: Sponka stojí volně ve feedu,
   ne v šedém rámečku. Jakmile přiteče první obsah, pozadí se vrátí. */
.ai-message--assistant .ai-message__body {
    transition: background-color .3s ease;
}

.ai-message--assistant .ai-message__body:has(> .ai-stage:only-child) {
    background: transparent;
    padding-left: 0;
}

/* --- chyba --- */

.ai-stage--error {
    --ai-stage-tint: var(--mud-palette-error);
}

.ai-stage--error .ai-stage__mascot {
    width: 58px;
    margin: 4px 2px 4px 4px;
}

.ai-stage--error .ai-stage__side {
    gap: 2px;
}

.ai-stage__error-text {
    font-size: .88rem;
    line-height: 1.4;
}

.ai-stage--error .ai-message__retry .mud-button-root {
    margin-left: -6px;
}

/* Starší chyba v konverzaci: tvář zůstává, pohyb ne. Kapka má jinak průhlednost
   jen z animace, tak ji tu rozsvítíme staticky. */
.ai-stage--still .ai-clippy,
.ai-stage--still .ai-clippy *,
.ai-stage--still .ai-podium::before,
.ai-stage--still .ai-podium::after {
    animation: none !important;
}

.ai-stage--still .ai-clippy__sweat path {
    opacity: .9;
}

/* --- stopa hotového procesu ---
   Jeden tichý řádek místo rámečku: počet kroků a čas. Je to záznam, ne obsah —
   nesmí se prát s odpovědí o pozornost. */

.ai-trace {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.ai-trace__toggle {
    display: inline-flex;
    align-items: center;
    align-self: flex-start;
    gap: 4px;
    margin: -2px 0 -2px -4px;
    padding: 1px 4px;
    border: 0;
    border-radius: 6px;
    background: none;
    font: inherit;
    font-size: .72rem;
    font-variant-numeric: tabular-nums;
    color: var(--mud-palette-text-secondary);
    cursor: pointer;
    opacity: .75;
    transition: opacity .15s ease, background-color .15s ease;
}

.ai-trace__toggle:hover,
.ai-trace__toggle:focus-visible,
.ai-trace__toggle[aria-expanded="true"] {
    opacity: 1;
    background: var(--mud-palette-action-default-hover);
}

.ai-trace__clip {
    width: 14px;
    height: 14px;
    flex: 0 0 auto;
    fill: none;
    stroke: var(--mud-palette-primary);
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.ai-trace--error .ai-trace__clip {
    stroke: var(--mud-palette-error);
}

.ai-trace__toggle .mud-icon-root {
    font-size: .95rem;
    width: .95rem;
    height: .95rem;
    margin-left: -2px;
}

/* --- podrobnosti procesu: poznámky z uvažování a kroky, v pořadí --- */

.ai-process {
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin-left: 3px;
    padding: 2px 0 2px 11px;
    border-left: 2px solid color-mix(in srgb, var(--mud-palette-primary) 28%, transparent);
    font-size: .78rem;
    color: var(--mud-palette-text-secondary);
    animation: ai-stage-details-in .22s ease-out;
}

.ai-process__note {
    white-space: pre-wrap;
    font-style: italic;
    line-height: 1.45;
    padding: 2px 0;
}

/* Právě tekoucí uvažování je náhled do práce, ne obsah: jen posledních pár řádků,
   nahoře do ztracena. */
.ai-process__note--streaming {
    max-height: 5.8em;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 1.4em);
    mask-image: linear-gradient(to bottom, transparent 0, #000 1.4em);
}

@media (prefers-reduced-motion: reduce) {
    .ai-podium::before,
    .ai-podium::after,
    .ai-stage__side,
    .ai-stage__dot,
    .ai-stage__details,
    .ai-process {
        animation: none;
    }

    .ai-stage__mascot {
        transition: none;
    }

    /* Bez lesku zůstane čitelný jednobarevný popisek. Vteřiny běží dál — je to údaj,
       ne ozdoba. */
    .ai-stage__caption {
        animation: none;
        background: none;
        -webkit-text-fill-color: currentColor;
    }
}

/* --- soubor --- */

.ai-artifact {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 6px 6px 10px;
    border: 1px solid var(--mud-palette-divider);
    border-radius: 10px;
    background: var(--mud-palette-surface);
    color: var(--mud-palette-text-primary);
    min-width: 0;
}

/* Soubor z dřívější relace: karta zůstává jako stopa, ale vizuálně ustoupí. */
.ai-artifact--expired {
    opacity: .65;
}

.ai-artifact__icon {
    flex: 0 0 auto;
}

.ai-artifact__meta {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-width: 0;
}

.ai-artifact__name {
    font-size: .85rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-artifact__size {
    font-size: .75rem;
    opacity: .6;
    white-space: nowrap;
}

.ai-artifact__spinner {
    flex: 0 0 auto;
    margin: 4px;
    width: 20px !important;
    height: 20px !important;
}

/* --- markdown --- */

/* Během streamování se kreslí prostý text, takže je potřeba zachovat zalomení. */
.ai-markdown--plain {
    white-space: pre-wrap;
}

.ai-markdown {
    min-width: 0;
}

.ai-markdown > *:first-child {
    margin-top: 0;
}

.ai-markdown > *:last-child {
    margin-bottom: 0;
}

/* Tabulka v obalu s vodorovným posuvem — široká tabulka nesmí roztáhnout okno. */
.ai-markdown__table {
    overflow-x: auto;
    max-width: 100%;
    margin: 4px 0;
    border-radius: 8px;
    border: 1px solid var(--mud-palette-divider);
}

.ai-markdown table {
    border-collapse: collapse;
    width: 100%;
    font-size: .85rem;
    background: var(--mud-palette-surface);
}

.ai-markdown th,
.ai-markdown td {
    border-bottom: 1px solid var(--mud-palette-divider);
    padding: 4px 8px;
    text-align: left;
    white-space: nowrap;
}

.ai-markdown th {
    background: var(--mud-palette-background-gray);
    font-weight: 600;
}

.ai-markdown tr:last-child td {
    border-bottom: 0;
}

.ai-markdown pre {
    overflow-x: auto;
    padding: 8px;
    border-radius: 8px;
    background: var(--mud-palette-surface);
    border: 1px solid var(--mud-palette-divider);
}

.ai-markdown code {
    font-size: .85em;
}

/* Text jen pro odečítač. Knihovna nemůže spoléhat na to, že hostitel nějaký takový
   pomocník má. */
.ai-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* ============================================================
   Sponka — maskot
   Barvy jdou z MudBlazor proměnných, ať sedí s tématem aplikace.

   Nálada není jen tempo: ke každé patří i rekvizita (bublina, lupa, blok
   s tužkou, žárovka, Zzz). Uživatel tak z pohledu pozná, jestli se přemýšlí,
   čte z databáze, nebo se jen čeká na něj.

   Dlouhé nálady mají několikataktovou smyčku — sponka po chvíli změní, co dělá,
   místo aby donekonečna opakovala jeden pohyb. Procenta v keyframes proto
   odpovídají jednotlivým „hereckým“ aktům a jsou u nich komentáře.
   ============================================================ */

.ai-clippy {
    display: inline-block;
    flex: 0 0 auto;
    line-height: 0;
    vertical-align: middle;
}

.ai-clippy svg {
    width: 100%;
    height: 100%;
    overflow: visible;
}

/* Bez pevné velikosti: šířku dává rodič (scéna v bublině), poměr stran drží viewBox.
   Díky tomu jde Sponku zmenšit CSS přechodem — inline rozměr by ho přebil. */
.ai-clippy--fluid {
    display: block;
    width: 100%;
    aspect-ratio: 64 / 72;
}

.ai-clippy__wire {
    stroke: var(--mud-palette-primary);
}

/* Bělmo bílé a zornice tmavá NATVRDO, ne z palety: v tmavém režimu je
   --mud-palette-surface tmavá a --mud-palette-text-primary světlá, takže maskot
   koukal s bílými zornicemi v tmavém oku. */
.ai-clippy__eye-white {
    fill: #fff;
    stroke: var(--mud-palette-primary);
    stroke-width: 1.4;
}

.ai-clippy__pupil {
    fill: #1f2430;
    transition: transform .18s ease;
}

.ai-clippy__brow {
    stroke: var(--mud-palette-primary);
    opacity: 0;
    transition: opacity .2s ease;
}

/* Oči i rekvizity se zmenšují a natáčejí samy kolem sebe. Bez fill-box míří
   transform-origin doprostřed viewBoxu, takže se mrknutí měnilo v posun oka dolů. */
.ai-clippy__eye-white,
.ai-clippy__pupil,
.ai-clippy__brow,
.ai-clippy__thought,
.ai-clippy__lens,
.ai-clippy__note,
.ai-clippy__pencil,
.ai-clippy__bulb,
.ai-clippy__zzz,
.ai-clippy__zzz path,
.ai-clippy__sweat path,
.ai-clippy__chart,
.ai-clippy__chart-point,
.ai-clippy__doc,
.ai-clippy__doc-stamp {
    transform-box: fill-box;
    transform-origin: center;
}

/* Sloupce grafu rostou od paty, ne ze středu. */
.ai-clippy__chart-bar {
    transform-box: fill-box;
    transform-origin: 50% 100%;
}

/* --- rekvizity ---
   Všechny jsou schované; rozsvítí je teprve nálada, která je potřebuje. */

.ai-clippy__thought,
.ai-clippy__lens,
.ai-clippy__note,
.ai-clippy__bulb,
.ai-clippy__zzz,
.ai-clippy__sweat,
.ai-clippy__chart,
.ai-clippy__doc {
    opacity: 0;
}

.ai-clippy__thought > circle {
    fill: var(--mud-palette-primary);
    opacity: 0;
}

/* Lupa: sklo musí zůstat průhledné, jinak by pod ní sponka zmizela. */
.ai-clippy__lens-glass {
    fill: var(--mud-palette-primary);
    fill-opacity: .12;
    stroke: var(--mud-palette-primary);
    stroke-width: 2.4;
}

.ai-clippy__lens-grip {
    fill: none;
    stroke: var(--mud-palette-primary);
    stroke-width: 3;
}

.ai-clippy__lens-shine {
    fill: none;
    stroke: #fff;
    stroke-width: 1.6;
    opacity: .85;
}

/* Blok: papír bílý natvrdo ze stejného důvodu jako bělmo — v tmavém tématu by
   se z palety stal černý lístek s neviditelnými řádky. */
.ai-clippy__note-paper {
    fill: #fff;
    stroke: var(--mud-palette-primary);
    stroke-width: 2;
}

.ai-clippy__note-line {
    fill: none;
    stroke: #9aa3b2;
    stroke-width: 1.6;
    stroke-linecap: round;
    /* Řádek se „píše“ odkrýváním čáry; delší než nejdelší řádek, ať dojede celý. */
    stroke-dasharray: 14;
    stroke-dashoffset: 14;
}

/* Tužka schválně NENÍ v barvě sponky: v barvě drátu splývala v šipku. Žlutá se
   se žárovkou nepotká — ta patří k hotovo, tužka k psaní. */
.ai-clippy__pencil-body {
    fill: var(--mud-palette-warning);
}

/* Objímka pod gumou. Kvůli ní je i v 26 px poznat, že je to tužka, a ne šipka. */
.ai-clippy__pencil-band {
    fill: #fff;
    fill-opacity: .55;
}

.ai-clippy__pencil-tip {
    fill: #1f2430;
}

.ai-clippy__bulb-glass {
    fill: var(--mud-palette-warning);
    fill-opacity: .3;
    stroke: var(--mud-palette-warning);
    stroke-width: 2.2;
}

.ai-clippy__bulb-base,
.ai-clippy__bulb-ray {
    fill: none;
    stroke: var(--mud-palette-warning);
    stroke-width: 2.2;
}

.ai-clippy__zzz path {
    fill: none;
    stroke: var(--mud-palette-primary);
    stroke-width: 2;
    stroke-linejoin: round;
    stroke-linecap: round;
    opacity: 0;
}

.ai-clippy__sweat path {
    fill: var(--mud-palette-info);
    opacity: 0;
}

/* Tabule s grafem. Plocha bílá natvrdo jako papír bloku — v tmavém tématu by se
   z palety stala černá deska a sloupce v barvě sponky by na ní zanikly. */
.ai-clippy__chart-board {
    fill: #fff;
    stroke: var(--mud-palette-primary);
    stroke-width: 2;
}

.ai-clippy__chart-legs {
    fill: none;
    stroke: var(--mud-palette-primary);
    stroke-width: 2;
}

.ai-clippy__chart-bar {
    fill: var(--mud-palette-primary);
}

.ai-clippy__chart-bar--1 { fill-opacity: .4; }
.ai-clippy__chart-bar--2 { fill-opacity: .68; }

/* Trend ve žluté: přes sloupce v barvě sponky musí být vidět jako druhá řada. */
.ai-clippy__chart-trend {
    fill: none;
    stroke: var(--mud-palette-warning);
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 22;
    stroke-dashoffset: 22;
}

.ai-clippy__chart-point {
    fill: var(--mud-palette-warning);
    stroke: #fff;
    stroke-width: .8;
}

.ai-clippy__doc-sheet {
    fill: #fff;
    stroke: var(--mud-palette-primary);
    stroke-width: 2;
    stroke-linejoin: round;
}

.ai-clippy__doc-fold {
    fill: none;
    stroke: var(--mud-palette-primary);
    stroke-width: 1.6;
    stroke-linejoin: round;
}

.ai-clippy__doc-title {
    fill: none;
    stroke: var(--mud-palette-primary);
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-dasharray: 6;
    stroke-dashoffset: 6;
}

.ai-clippy__doc-line {
    fill: none;
    stroke: #9aa3b2;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-dasharray: 11;
    stroke-dashoffset: 11;
}

.ai-clippy__doc-stamp circle {
    fill: var(--mud-palette-success);
    stroke: #fff;
    stroke-width: 1;
}

.ai-clippy__doc-stamp path {
    fill: none;
    stroke: #fff;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Odznak nepřečtené odpovědi u maskota. Statický záměrně — je to informace,
   ne ozdoba, takže musí přežít i vypnutý pohyb. */
.ai-clippy__badge {
    fill: var(--mud-palette-error);
    stroke: var(--mud-palette-surface);
    stroke-width: 2.5;
    opacity: 0;
    transition: opacity .2s ease;
}

.ai-clippy--mascot.ai-clippy--unread .ai-clippy__badge {
    opacity: 1;
}

/* Nepřečteno: sponka se zlehka pohupuje, ať si jí uživatel v appbaru všimne. */
.ai-clippy--mascot.ai-clippy--unread .ai-clippy__body {
    animation: ai-clippy-nudge 1.6s ease-in-out infinite;
}

@keyframes ai-clippy-nudge {
    0%, 70%, 100% { transform: rotate(0deg); }
    80%           { transform: rotate(-8deg); }
    90%           { transform: rotate(8deg); }
}

.ai-clippy__body {
    transform-origin: 32px 40px;
}

/* Základní mrkání. Nálada, která má vlastní práci s víčky (klid, dřímota), si ho přebije. */
.ai-clippy__eye-white {
    animation: ai-clippy-blink 6s ease-in-out infinite;
}

@keyframes ai-clippy-blink {
    0%, 92%, 100% { transform: scaleY(1); }
    95%           { transform: scaleY(.1); }
}

/* --- klid: čeká na uživatele ---
   Skoro půlminutová smyčka, ve které se sponka postupně nudí: pohupuje se,
   rozhlédne se, protáhne, nakoukne k uživateli a nakonec usne. Smyčka se
   restartuje s každou změnou nálady, takže „usnutí“ přijde vždy až po tom,
   co uživatel doopravdy skoro půl minuty mlčí. */

.ai-clippy--idle .ai-clippy__body {
    animation: ai-clippy-idle-body 28s ease-in-out infinite;
}

.ai-clippy--idle .ai-clippy__pupil {
    animation: ai-clippy-idle-eyes 28s ease-in-out infinite;
}

.ai-clippy--idle .ai-clippy__eye-white {
    animation: ai-clippy-idle-lids 28s ease-in-out infinite;
}

.ai-clippy--idle .ai-clippy__brow {
    animation: ai-clippy-idle-brows 28s ease-in-out infinite;
}

.ai-clippy--idle .ai-clippy__zzz {
    opacity: 1;
}

.ai-clippy--idle .ai-clippy__zzz path {
    animation: ai-clippy-zzz 28s ease-out infinite;
}

/* Zpoždění posouvá celou smyčku, takže si Z vylétají po sobě a zůstávají v taktu. */
.ai-clippy--idle .ai-clippy__zzz path:nth-child(2) { animation-delay: .7s; }
.ai-clippy--idle .ai-clippy__zzz path:nth-child(3) { animation-delay: 1.4s; }

@keyframes ai-clippy-idle-body {
    /* pohupování */
    0%, 100% { transform: rotate(-1.5deg) translateY(0) scale(1, 1); }
    8%       { transform: rotate(1.5deg) translateY(0) scale(1, 1); }
    16%      { transform: rotate(-1.5deg) translateY(0) scale(1, 1); }
    24%      { transform: rotate(1.5deg) translateY(0) scale(1, 1); }
    /* rozhlédne se po místnosti */
    30%      { transform: rotate(-8deg) translateY(-1px) scale(1, 1); }
    36%      { transform: rotate(8deg) translateY(-1px) scale(1, 1); }
    41%      { transform: rotate(0deg) translateY(0) scale(1, 1); }
    /* protáhne se */
    47%      { transform: rotate(0deg) translateY(-3px) scale(.94, 1.1); }
    53%      { transform: rotate(0deg) translateY(1px) scale(1.05, .95); }
    57%      { transform: rotate(0deg) translateY(0) scale(1, 1); }
    /* nakoukne k uživateli, jestli už něco píše */
    64%      { transform: rotate(-3deg) translateY(-2px) scale(1.08, 1.08); }
    70%      { transform: rotate(3deg) translateY(-2px) scale(1.08, 1.08); }
    74%      { transform: rotate(0deg) translateY(0) scale(1, 1); }
    /* usíná */
    82%, 92% { transform: rotate(10deg) translateY(3px) scale(1, 1); }
    /* a lekne se, že pořád nic */
    95%      { transform: rotate(-4deg) translateY(-2px) scale(1.04, 1.04); }
    97%      { transform: rotate(0deg) translateY(0) scale(1, 1); }
}

@keyframes ai-clippy-idle-eyes {
    0%, 26%, 100% { transform: translate(0, 0); }
    30%           { transform: translate(-1.6px, .2px); }
    36%           { transform: translate(1.6px, .2px); }
    41%           { transform: translate(0, 0); }
    64%, 70%      { transform: translate(0, -1.2px) scaleY(1); }
    74%           { transform: translate(0, 0) scaleY(1); }
    /* zornice se zavírají s víčky */
    78%           { transform: translate(0, 1.4px) scaleY(1); }
    80%, 93%      { transform: translate(0, 1.4px) scaleY(.12); }
    95%           { transform: translate(0, 0) scaleY(1); }
    97%           { transform: translate(0, 0) scaleY(1); }
}

@keyframes ai-clippy-idle-lids {
    0%, 11%, 100% { transform: scaleY(1); }
    12.5%         { transform: scaleY(.1); }
    14%           { transform: scaleY(1); }
    44%           { transform: scaleY(1); }
    45.5%         { transform: scaleY(.1); }
    47%           { transform: scaleY(1); }
    /* zavřená očka po dobu dřímoty */
    78%           { transform: scaleY(1); }
    80%, 93%      { transform: scaleY(.12); }
    /* vykulené probuzení */
    95%           { transform: scaleY(1.12); }
    97%           { transform: scaleY(1); }
}

@keyframes ai-clippy-idle-brows {
    0%, 60%, 100% { opacity: 0; transform: translateY(0); }
    /* zvednuté obočí při nakouknutí */
    64%, 70%      { opacity: .85; transform: translateY(-1.8px); }
    74%           { opacity: 0; transform: translateY(0); }
    95%           { opacity: .85; transform: translateY(-2px); }
    97%           { opacity: 0; transform: translateY(0); }
}

@keyframes ai-clippy-zzz {
    0%, 76%   { opacity: 0; transform: translate(0, 0) scale(.6); }
    80%       { opacity: .9; transform: translate(0, -1px) scale(1); }
    90%       { opacity: .9; transform: translate(1px, -3px) scale(1.05); }
    95%, 100% { opacity: 0; transform: translate(2px, -6px) scale(1.1); }
}

/* --- poslouchá: uživatel má rozepsaný dotaz ---
   Jediná nálada, kterou spouští uživatel. Sponka se nakloní k němu, zvedne
   obočí a kouká dolů, kam se píše. */

.ai-clippy--listening .ai-clippy__body {
    animation: ai-clippy-listen 2.6s ease-in-out infinite;
}

.ai-clippy--listening .ai-clippy__pupil {
    animation: ai-clippy-listen-eyes 2.6s ease-in-out infinite;
}

.ai-clippy--listening .ai-clippy__brow {
    opacity: .85;
    transform: translateY(-1.8px);
}

@keyframes ai-clippy-listen {
    0%, 100% { transform: rotate(-4deg) translateY(0) scale(1.05); }
    50%      { transform: rotate(4deg) translateY(-1.5px) scale(1.05); }
}

@keyframes ai-clippy-listen-eyes {
    0%, 100% { transform: translate(-1px, 1.6px); }
    50%      { transform: translate(1px, 1.6px); }
}

/* --- přemýšlí ---
   Tři akty po čtyřech vteřinách: dumá ze strany na stranu, přechází sem a tam,
   a nakonec se soustředí (svraštěné obočí, zorničky krouží, bublina zmizí). */

.ai-clippy--thinking .ai-clippy__body {
    animation: ai-clippy-think-body 12s ease-in-out infinite;
}

.ai-clippy--thinking .ai-clippy__pupil {
    animation: ai-clippy-think-eyes 12s ease-in-out infinite;
}

.ai-clippy--thinking .ai-clippy__brow {
    animation: ai-clippy-think-brows 12s ease-in-out infinite;
}

.ai-clippy--thinking .ai-clippy__thought {
    animation: ai-clippy-think-bubble 12s ease-in-out infinite;
}

.ai-clippy--thinking .ai-clippy__thought > circle {
    animation: ai-clippy-thought 1.8s ease-in-out infinite;
}

.ai-clippy--thinking .ai-clippy__thought > circle:nth-child(2) { animation-delay: .25s; }
.ai-clippy--thinking .ai-clippy__thought > circle:nth-child(3) { animation-delay: .5s; }

@keyframes ai-clippy-think-body {
    /* akt 1 — dumá */
    0%, 100% { transform: rotate(-5deg) translate(0, 0) scale(1); }
    8%       { transform: rotate(5deg) translate(0, -1px) scale(1); }
    17%      { transform: rotate(-5deg) translate(0, 0) scale(1); }
    25%      { transform: rotate(4deg) translate(0, -1px) scale(1); }
    /* akt 2 — přechází */
    33%      { transform: rotate(-9deg) translate(-3px, 0) scale(1); }
    42%      { transform: rotate(9deg) translate(3px, 0) scale(1); }
    50%      { transform: rotate(-9deg) translate(-3px, 0) scale(1); }
    58%      { transform: rotate(0deg) translate(0, 0) scale(1); }
    /* akt 3 — soustředí se, až se chvěje */
    64%      { transform: rotate(-2deg) translate(0, 0) scale(1.05); }
    68%      { transform: rotate(2deg) translate(0, 0) scale(1.05); }
    72%      { transform: rotate(-2deg) translate(0, 0) scale(1.05); }
    76%      { transform: rotate(2deg) translate(0, 0) scale(1.05); }
    /* nadechnutí, než začne znovu */
    84%      { transform: rotate(0deg) translate(0, -2px) scale(1.02); }
    92%      { transform: rotate(0deg) translate(0, 0) scale(1); }
}

@keyframes ai-clippy-think-eyes {
    0%, 100% { transform: translate(-1.4px, -1.2px); }
    12%      { transform: translate(1.4px, -1.2px); }
    25%      { transform: translate(-1.4px, -1.2px); }
    33%      { transform: translate(-1.8px, 0); }
    42%      { transform: translate(1.8px, 0); }
    50%      { transform: translate(-1.8px, 0); }
    58%      { transform: translate(0, 0); }
    /* zorničky krouží dokola */
    64%      { transform: translate(0, -1.6px); }
    70%      { transform: translate(1.6px, 0); }
    76%      { transform: translate(0, 1.4px); }
    82%      { transform: translate(-1.6px, 0); }
    88%      { transform: translate(0, -1.6px); }
    94%      { transform: translate(0, 0); }
}

@keyframes ai-clippy-think-brows {
    0%, 60%, 100% { opacity: 0; transform: translateY(0); }
    66%, 86%      { opacity: .85; transform: translateY(1.8px); }
    92%           { opacity: 0; transform: translateY(0); }
}

/* Ve třetím aktu bublina zeslábne, ale nezmizí — jinak by čtyři vteřiny nebylo
   podle čeho poznat, že se pořád přemýšlí. */
@keyframes ai-clippy-think-bubble {
    0%, 58%   { opacity: 1; }
    64%, 88%  { opacity: .35; }
    95%, 100% { opacity: 1; }
}

@keyframes ai-clippy-thought {
    0%, 100% { opacity: 0; transform: translateY(2px); }
    40%      { opacity: .9; transform: translateY(0); }
}

/* --- pracuje s daty ---
   Osmivteřinová smyčka ve dvou půlkách: první prohledává lupou, druhou zapisuje
   do bloku. Přesně to, co v tu chvíli dělá nástroj na druhé straně. */

.ai-clippy--working .ai-clippy__body {
    animation: ai-clippy-work-body 8s ease-in-out infinite;
}

.ai-clippy--working .ai-clippy__pupil {
    animation: ai-clippy-work-eyes 8s ease-in-out infinite;
}

.ai-clippy--working .ai-clippy__lens {
    animation: ai-clippy-work-lens 8s ease-in-out infinite;
}

.ai-clippy--working .ai-clippy__note {
    animation: ai-clippy-work-note 8s ease-in-out infinite;
}

.ai-clippy--working .ai-clippy__note-line {
    animation: ai-clippy-work-line 8s ease-in-out infinite;
}

.ai-clippy--working .ai-clippy__note-line--2 { animation-delay: .35s; }
.ai-clippy--working .ai-clippy__note-line--3 { animation-delay: .7s; }

.ai-clippy--working .ai-clippy__pencil {
    animation: ai-clippy-scribble 1.1s ease-in-out infinite;
}

@keyframes ai-clippy-work-body {
    /* naklání se k lupě a prohledává */
    0%, 100% { transform: rotate(0deg) translate(0, 0); }
    8%       { transform: rotate(7deg) translate(1px, 0); }
    20%      { transform: rotate(3deg) translate(0, 1px); }
    32%      { transform: rotate(8deg) translate(1px, 0); }
    44%      { transform: rotate(2deg) translate(0, 0); }
    /* zapisuje — drobné pokyvování do rytmu tužky */
    56%      { transform: rotate(-2deg) translate(0, -1px); }
    64%      { transform: rotate(3deg) translate(0, 1px); }
    72%      { transform: rotate(-2deg) translate(0, -1px); }
    80%      { transform: rotate(3deg) translate(0, 1px); }
    90%      { transform: rotate(-1deg) translate(0, 0); }
}

@keyframes ai-clippy-work-eyes {
    0%, 100% { transform: translate(1.2px, .6px); }
    20%      { transform: translate(1.8px, 1.4px); }
    40%      { transform: translate(1.2px, .2px); }
    60%      { transform: translate(1.6px, 1.6px); }
    80%      { transform: translate(1.9px, 1.2px); }
}

@keyframes ai-clippy-work-lens {
    0%        { opacity: 0; transform: translate(4px, -3px) scale(.8); }
    6%        { opacity: 1; transform: translate(0, 0) scale(1); }
    14%       { opacity: 1; transform: translate(-3px, 3px) scale(1); }
    24%       { opacity: 1; transform: translate(2px, 6px) scale(1); }
    34%       { opacity: 1; transform: translate(-2px, -1px) scale(1); }
    42%       { opacity: 1; transform: translate(0, 0) scale(1.06); }
    48%       { opacity: 0; transform: translate(5px, -3px) scale(.8); }
    100%      { opacity: 0; transform: translate(5px, -3px) scale(.8); }
}

@keyframes ai-clippy-work-note {
    0%, 48%   { opacity: 0; transform: translate(3px, 3px) scale(.82); }
    56%       { opacity: 1; transform: translate(0, 0) scale(1); }
    92%       { opacity: 1; transform: translate(0, 0) scale(1); }
    98%, 100% { opacity: 0; transform: translate(3px, 3px) scale(.82); }
}

@keyframes ai-clippy-work-line {
    0%, 54%  { stroke-dashoffset: 14; }
    66%      { stroke-dashoffset: 0; }
    100%     { stroke-dashoffset: 0; }
}

@keyframes ai-clippy-scribble {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    25%      { transform: translate(-3px, 1.5px) rotate(-7deg); }
    50%      { transform: translate(1.5px, 3px) rotate(5deg); }
    75%      { transform: translate(-2px, 4.5px) rotate(-4deg); }
}

/* --- píše odpověď ---
   Blok je vidět celou dobu, řádky přibývají a tužka po nich jede. */

.ai-clippy--writing .ai-clippy__body {
    animation: ai-clippy-write-body 3s ease-in-out infinite;
}

.ai-clippy--writing .ai-clippy__pupil {
    animation: ai-clippy-write-eyes 3s ease-in-out infinite;
}

.ai-clippy--writing .ai-clippy__note {
    opacity: 1;
}

.ai-clippy--writing .ai-clippy__note-line {
    animation: ai-clippy-write-line 3s ease-in-out infinite;
}

.ai-clippy--writing .ai-clippy__note-line--2 { animation-delay: .25s; }
.ai-clippy--writing .ai-clippy__note-line--3 { animation-delay: .5s; }

.ai-clippy--writing .ai-clippy__pencil {
    animation: ai-clippy-scribble 1s ease-in-out infinite;
}

@keyframes ai-clippy-write-body {
    0%, 100% { transform: rotate(4deg) translateY(0); }
    25%      { transform: rotate(6deg) translateY(1px); }
    50%      { transform: rotate(3deg) translateY(0); }
    75%      { transform: rotate(6deg) translateY(1px); }
}

@keyframes ai-clippy-write-eyes {
    0%, 100% { transform: translate(1.2px, 1.4px); }
    50%      { transform: translate(1.9px, 1.4px); }
}

@keyframes ai-clippy-write-line {
    0%        { stroke-dashoffset: 14; }
    24%       { stroke-dashoffset: 0; }
    78%       { stroke-dashoffset: 0; }
    88%, 100% { stroke-dashoffset: 14; }
}

/* --- kreslí přehled ---
   Tabule stojí po celou dobu; v šestivteřinové smyčce na ní vyrostou sloupce, přes ně
   se natáhne trend a na jeho konci blikne bod — v tu chvíli sponka povyskočí. Pak se
   tabule smaže a kreslí se znovu. */

.ai-clippy--charting .ai-clippy__body {
    animation: ai-clippy-chart-body 6s ease-in-out infinite;
}

.ai-clippy--charting .ai-clippy__pupil {
    animation: ai-clippy-chart-eyes 6s ease-in-out infinite;
}

.ai-clippy--charting .ai-clippy__brow {
    animation: ai-clippy-chart-brows 6s ease-in-out infinite;
}

.ai-clippy--charting .ai-clippy__chart {
    opacity: 1;
    animation: ai-clippy-prop-in .4s ease-out 1;
}

.ai-clippy--charting .ai-clippy__chart-bar {
    animation: ai-clippy-chart-bar 6s cubic-bezier(.3, 1.35, .5, 1) infinite;
}

.ai-clippy--charting .ai-clippy__chart-bar--2 { animation-delay: .28s; }
.ai-clippy--charting .ai-clippy__chart-bar--3 { animation-delay: .56s; }

.ai-clippy--charting .ai-clippy__chart-trend {
    animation: ai-clippy-chart-trend 6s ease-in-out infinite;
}

.ai-clippy--charting .ai-clippy__chart-point {
    animation: ai-clippy-chart-point 6s ease-out infinite;
}

@keyframes ai-clippy-prop-in {
    from { opacity: 0; transform: translate(5px, 4px) scale(.8); }
    to   { opacity: 1; transform: translate(0, 0) scale(1); }
}

@keyframes ai-clippy-chart-body {
    0%, 100% { transform: rotate(3deg) translate(0, 0) scale(1); }
    /* sleduje, jak rostou sloupce */
    20%      { transform: rotate(6deg) translate(1px, 1px) scale(1); }
    40%      { transform: rotate(4deg) translate(0, 0) scale(1); }
    57%      { transform: rotate(6deg) translate(1px, 1px) scale(1); }
    /* bod na konci trendu — povyskočí */
    63%      { transform: rotate(0deg) translate(0, -3.5px) scale(1.06); }
    70%      { transform: rotate(4deg) translate(0, .5px) scale(.99); }
    86%      { transform: rotate(3deg) translate(0, 0) scale(1); }
}

@keyframes ai-clippy-chart-eyes {
    0%, 100% { transform: translate(1.6px, 1.7px); }
    26%      { transform: translate(1.8px, .8px); }
    58%      { transform: translate(1.9px, -.4px); }
    70%      { transform: translate(1.7px, .2px); }
    88%      { transform: translate(1.6px, 1.4px); }
}

@keyframes ai-clippy-chart-brows {
    0%, 58%, 100% { opacity: 0; transform: translateY(0); }
    63%, 80%      { opacity: .85; transform: translateY(-1.9px); }
    88%           { opacity: 0; transform: translateY(0); }
}

@keyframes ai-clippy-chart-bar {
    0%, 7%    { transform: scaleY(0); }
    26%, 86%  { transform: scaleY(1); }
    95%, 100% { transform: scaleY(0); }
}

@keyframes ai-clippy-chart-trend {
    0%, 40%   { stroke-dashoffset: 22; opacity: 1; }
    58%, 86%  { stroke-dashoffset: 0; opacity: 1; }
    94%       { stroke-dashoffset: 0; opacity: 0; }
    100%      { stroke-dashoffset: 22; opacity: 0; }
}

@keyframes ai-clippy-chart-point {
    0%, 57%   { opacity: 0; transform: scale(0); }
    63%       { opacity: 1; transform: scale(1.9); }
    69%, 86%  { opacity: 1; transform: scale(1); }
    94%, 100% { opacity: 0; transform: scale(0); }
}

/* --- skládá soubor ---
   List přiletí, zaplní se nadpisem a řádky, sponka se napřáhne a dá na něj razítko —
   a hotový list odletí nahoru. Řádky mají vlastní keyframes místo zpoždění: zpožděná
   smyčka by přetekla do dalšího kola a na novém listu by chvíli svítil starý řádek. */

.ai-clippy--reporting .ai-clippy__body {
    animation: ai-clippy-report-body 5.5s ease-in-out infinite;
}

.ai-clippy--reporting .ai-clippy__pupil {
    animation: ai-clippy-report-eyes 5.5s ease-in-out infinite;
}

.ai-clippy--reporting .ai-clippy__brow {
    animation: ai-clippy-report-brows 5.5s ease-in-out infinite;
}

.ai-clippy--reporting .ai-clippy__doc {
    animation: ai-clippy-report-sheet 5.5s ease-in-out infinite;
}

.ai-clippy--reporting .ai-clippy__doc-title {
    animation: ai-clippy-report-title 5.5s ease-in-out infinite;
}

.ai-clippy--reporting .ai-clippy__doc-line--1 { animation: ai-clippy-report-line-1 5.5s ease-in-out infinite; }
.ai-clippy--reporting .ai-clippy__doc-line--2 { animation: ai-clippy-report-line-2 5.5s ease-in-out infinite; }
.ai-clippy--reporting .ai-clippy__doc-line--3 { animation: ai-clippy-report-line-3 5.5s ease-in-out infinite; }

.ai-clippy--reporting .ai-clippy__doc-stamp {
    animation: ai-clippy-report-stamp 5.5s cubic-bezier(.3, 1.4, .5, 1) infinite;
}

@keyframes ai-clippy-report-body {
    0%, 100% { transform: rotate(4deg) translate(0, 0); }
    /* pokyvuje do rytmu přibývajících řádků */
    18%      { transform: rotate(6deg) translate(0, 1px); }
    30%      { transform: rotate(3deg) translate(0, 0); }
    42%      { transform: rotate(6deg) translate(0, 1px); }
    /* napřáhne se… */
    58%      { transform: rotate(-3deg) translate(-1px, -3.5px); }
    /* …a razítko */
    64%      { transform: rotate(10deg) translate(2px, 2px); }
    72%      { transform: rotate(3deg) translate(0, 0); }
    90%      { transform: rotate(2deg) translate(0, -1px); }
}

@keyframes ai-clippy-report-eyes {
    0%, 100% { transform: translate(1.2px, 1.3px); }
    20%      { transform: translate(1.9px, 1.1px); }
    30%      { transform: translate(1.2px, 1.5px); }
    42%      { transform: translate(1.9px, 1.5px); }
    58%      { transform: translate(1.6px, .4px); }
    64%, 80% { transform: translate(1.8px, 1.9px); }
    /* dívá se za odlétajícím listem */
    94%      { transform: translate(1.4px, -1.4px); }
}

@keyframes ai-clippy-report-brows {
    0%, 62%, 100% { opacity: 0; transform: translateY(0); }
    66%, 84%      { opacity: .85; transform: translateY(-1.9px); }
    90%           { opacity: 0; transform: translateY(0); }
}

@keyframes ai-clippy-report-sheet {
    0%        { opacity: 0; transform: translate(7px, 5px) rotate(9deg); }
    10%, 86%  { opacity: 1; transform: translate(0, 0) rotate(0deg); }
    96%, 100% { opacity: 0; transform: translate(1px, -11px) rotate(-5deg); }
}

@keyframes ai-clippy-report-title {
    0%, 12%   { stroke-dashoffset: 6; }
    19%, 100% { stroke-dashoffset: 0; }
}

@keyframes ai-clippy-report-line-1 {
    0%, 20%   { stroke-dashoffset: 11; }
    30%, 100% { stroke-dashoffset: 0; }
}

@keyframes ai-clippy-report-line-2 {
    0%, 31%   { stroke-dashoffset: 11; }
    41%, 100% { stroke-dashoffset: 0; }
}

@keyframes ai-clippy-report-line-3 {
    0%, 42%   { stroke-dashoffset: 11; }
    50%, 100% { stroke-dashoffset: 0; }
}

@keyframes ai-clippy-report-stamp {
    0%, 61%   { opacity: 0; transform: scale(0) rotate(-25deg); }
    65%       { opacity: 1; transform: scale(1.4) rotate(-8deg); }
    71%, 100% { opacity: 1; transform: scale(1) rotate(-8deg); }
}

/* --- hotovo ---
   Kývnutí a nad hlavou se rozsvítí žárovka; obojí proběhne jednou a zhasne. */

.ai-clippy--done .ai-clippy__body {
    animation: ai-clippy-nod .6s ease-out 1;
}

.ai-clippy--done .ai-clippy__brow {
    opacity: .9;
}

.ai-clippy--done .ai-clippy__bulb {
    animation: ai-clippy-bulb 1.4s ease-out 1;
}

.ai-clippy--done .ai-clippy__bulb-ray {
    animation: ai-clippy-bulb-ray .5s ease-out 2;
}

@keyframes ai-clippy-nod {
    0%   { transform: translateY(0) scale(1); }
    35%  { transform: translateY(-4px) scale(1.06); }
    70%  { transform: translateY(1px) scale(.98); }
    100% { transform: translateY(0) scale(1); }
}

@keyframes ai-clippy-bulb {
    0%   { opacity: 0; transform: translateY(5px) scale(.6); }
    22%  { opacity: 1; transform: translateY(0) scale(1.12); }
    40%  { opacity: 1; transform: translateY(0) scale(1); }
    78%  { opacity: 1; transform: translateY(0) scale(1); }
    100% { opacity: 0; transform: translateY(-3px) scale(.92); }
}

@keyframes ai-clippy-bulb-ray {
    0%, 100% { opacity: 1; }
    50%      { opacity: .25; }
}

/* --- chyba ---
   Převrácené obočí, vykulené oči a kapka potu. Sponka se nehýbe do rytmu,
   jen pomalu klesá — má to vypadat rozpačitě, ne vesele. */

.ai-clippy--error .ai-clippy__body {
    animation: ai-clippy-droop 3.4s ease-in-out infinite;
}

.ai-clippy--error .ai-clippy__wire,
.ai-clippy--error .ai-clippy__eye-white {
    stroke: var(--mud-palette-error);
}

.ai-clippy--error .ai-clippy__brow {
    opacity: .9;
    stroke: var(--mud-palette-error);
    transform: rotate(180deg);
}

.ai-clippy--error .ai-clippy__eye-white {
    animation: none;
}

.ai-clippy--error .ai-clippy__sweat {
    opacity: 1;
}

.ai-clippy--error .ai-clippy__sweat path {
    animation: ai-clippy-sweat 2.8s ease-in infinite;
}

@keyframes ai-clippy-droop {
    0%, 100% { transform: rotate(7deg) translateY(1px); }
    50%      { transform: rotate(4.5deg) translateY(-1px); }
}

@keyframes ai-clippy-sweat {
    0%, 8%    { opacity: 0; transform: translate(0, -3px) scale(.7); }
    24%       { opacity: .9; transform: translate(0, 0) scale(1); }
    56%       { opacity: .9; transform: translate(0, 4px) scale(1); }
    70%, 100% { opacity: 0; transform: translate(0, 8px) scale(.8); }
}

/* Kdo nechce pohyb, ten ho nedostane — ani u sponky. Vypíná se plošně, aby na to
   nešlo zapomenout u další přidané rekvizity; co nese informaci, se pak vrátí staticky. */
/* ---------- Další postavičky (AiMascotKind): stejné nálady a rekvizity, jiné tělo ----------
   Výplň v hlavní barvě tématu (branding instalace), obrys tmavší; obočí na barevném těle tmavé, jinak by zaniklo. */
.ai-clippy__shell {
    fill: var(--mud-palette-primary);
    stroke: color-mix(in srgb, var(--mud-palette-primary) 65%, #000);
    stroke-width: 1.4;
    stroke-linejoin: round;
}

.ai-clippy--kind-bubble .ai-clippy__brow,
.ai-clippy--kind-pencil .ai-clippy__brow,
.ai-clippy--kind-note .ai-clippy__brow,
.ai-clippy--kind-spark .ai-clippy__brow {
    stroke: #1f2430;
}

.ai-clippy--kind-bubble .ai-clippy__eye-white,
.ai-clippy--kind-pencil .ai-clippy__eye-white,
.ai-clippy--kind-spark .ai-clippy__eye-white {
    stroke: color-mix(in srgb, var(--mud-palette-primary) 65%, #000);
}

.ai-clippy__eraser { fill: #f4a3b5; stroke: #1f2430; stroke-width: 1.1; }
.ai-clippy__ferrule { fill: #c9ced6; stroke: #1f2430; stroke-width: 1.1; }
.ai-clippy__wood { fill: #f1d3a2; stroke: #1f2430; stroke-width: 1.1; stroke-linejoin: round; }
.ai-clippy__lead { fill: #1f2430; transform-box: fill-box; transform-origin: 50% 0; }

.ai-clippy__paper {
    fill: #ffe27a;
    stroke: var(--mud-palette-primary);
    stroke-width: 2.2;
    stroke-linejoin: round;
}

.ai-clippy__corner {
    fill: #f2c94c;
    stroke: var(--mud-palette-primary);
    stroke-width: 1.8;
    stroke-linejoin: round;
    transform-box: fill-box;
    transform-origin: 0 0;
}

.ai-clippy__twinkle {
    fill: var(--mud-palette-primary);
    opacity: 0;
    transform-box: fill-box;
    transform-origin: center;
}

.ai-clippy--kind-spark.ai-clippy--idle .ai-clippy__twinkle {
    animation: ai-mascot-twinkle 3.2s ease-in-out infinite;
}

.ai-clippy--kind-spark.ai-clippy--done .ai-clippy__twinkle {
    animation: ai-mascot-twinkle 1.1s ease-in-out infinite;
}

.ai-clippy--kind-spark .ai-clippy__twinkle--2 {
    animation-delay: 1.4s !important;
}

/* Jiskra při chybě pohasne. */
.ai-clippy--kind-spark.ai-clippy--error .ai-clippy__shell {
    fill: color-mix(in srgb, var(--mud-palette-primary) 35%, #8a8f98);
    transition: fill .4s ease;
}

/* Lístku se zvedá roh, když uživatel píše (a občas jen tak). */
.ai-clippy--kind-note.ai-clippy--listening .ai-clippy__corner {
    animation: ai-mascot-flap 1.2s ease-in-out infinite;
}

.ai-clippy--kind-note.ai-clippy--idle .ai-clippy__corner {
    animation: ai-mascot-flap 7s ease-in-out infinite;
}

/* Tužce se při chybě ulomí hrot. */
.ai-clippy--kind-pencil.ai-clippy--error .ai-clippy__lead {
    animation: ai-mascot-snap 3.4s ease-in infinite;
}

@keyframes ai-mascot-twinkle {
    0%, 100% { transform: scale(.4) rotate(0); opacity: .25; }
    50% { transform: scale(1) rotate(45deg); opacity: 1; }
}

@keyframes ai-mascot-flap {
    0%, 100% { transform: skewY(0); }
    50% { transform: skewY(-10deg) translateY(-1px); }
}

@keyframes ai-mascot-snap {
    0%, 25% { transform: translateY(0) rotate(0); opacity: 1; }
    45% { transform: translateY(5px) rotate(40deg); opacity: 1; }
    60%, 100% { transform: translateY(7px) rotate(60deg); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .ai-clippy,
    .ai-clippy * {
        animation: none !important;
        transition: none !important;
    }

    /* Odznak nepřečtené odpovědi je informace, ne ozdoba — ten zůstává. */
    .ai-clippy--mascot.ai-clippy--unread .ai-clippy__badge {
        opacity: 1;
    }

    /* Bez pohybu nese stav rekvizita: bublina, lupa, blok, tabule, list. */
    .ai-clippy--thinking .ai-clippy__thought,
    .ai-clippy--working .ai-clippy__lens,
    .ai-clippy--writing .ai-clippy__note,
    .ai-clippy--charting .ai-clippy__chart,
    .ai-clippy--reporting .ai-clippy__doc {
        opacity: 1;
    }

    .ai-clippy--charting .ai-clippy__chart-trend,
    .ai-clippy--reporting .ai-clippy__doc-title,
    .ai-clippy--reporting .ai-clippy__doc-line {
        stroke-dashoffset: 0;
    }

    .ai-clippy--thinking .ai-clippy__thought > circle {
        opacity: .9;
    }

    .ai-clippy--writing .ai-clippy__note-line {
        stroke-dashoffset: 0;
    }
}
/* ============================================================
   Okno asistenta
   ============================================================ */

.ai-window {
    position: fixed;
    /* Nad appbarem (1300) i nad popover vrstvou MudBlazoru (1200), aby se select
       nebo datum uvnitř okna nevykreslily pod ním. */
    z-index: 1401;
    display: flex;
    flex-direction: column;
    background: var(--mud-palette-surface);
    color: var(--mud-palette-text-primary);
    border: 1px solid var(--mud-palette-divider);
    border-radius: 14px;
    box-shadow: var(--mud-elevation-12);
    overflow: hidden;
    animation: ai-window-in .18s ease-out;
    outline: none;
}

@keyframes ai-window-in {
    from { opacity: 0; transform: translateY(8px) scale(.985); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.ai-window--floating {
    right: 24px;
    bottom: 24px;
    max-width: 100vw;
    max-height: 100vh;
}

/* Během tažení nesmí okno nic „doháněť“ animací — kurzor je pravda. */
.ai-window--dragging {
    transition: none;
    animation: none;
    user-select: none;
}

.ai-window--docked {
    top: 0;
    right: 0;
    bottom: 0;
    height: 100%;
    max-width: 60vw;
    border-radius: 0;
    border-right: 0;
    border-top: 0;
    border-bottom: 0;
    box-shadow: var(--mud-elevation-8);
}

/* Levá hrana ukotvené zásuvky: úchyt pro změnu šířky. */
.ai-window__dock-edge {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 6px;
    cursor: ew-resize;
    touch-action: none;
    z-index: 1;
}

.ai-window__dock-edge:hover {
    background: var(--mud-palette-primary);
    opacity: .35;
}

.ai-window__header {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 6px 8px 12px;
    background: var(--mud-palette-surface);
    border-bottom: 1px solid var(--mud-palette-divider);
    flex: 0 0 auto;
}

.ai-window__handle {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1 1 auto;
    min-width: 0;
    cursor: grab;
    user-select: none;
    touch-action: none;
}

.ai-window__handle:active {
    cursor: grabbing;
}

.ai-window--docked .ai-window__handle {
    cursor: default;
}

.ai-window__actions {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
}

.ai-window__title {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-width: 0;
    line-height: 1.15;
}

.ai-window__title-main {
    font-weight: 600;
    font-size: .92rem;
}

.ai-window__title-sub {
    font-size: .72rem;
    color: var(--mud-palette-text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-window__body {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 8px 10px 10px;
}

/* Úchyt pro změnu velikosti: tři čárky v pravém dolním rohu. */
.ai-window__resize {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 18px;
    height: 18px;
    cursor: nwse-resize;
    touch-action: none;
    background:
        linear-gradient(135deg, transparent 0 46%, var(--mud-palette-divider) 46% 54%, transparent 54%),
        linear-gradient(135deg, transparent 0 66%, var(--mud-palette-divider) 66% 74%, transparent 74%);
}

/* Na úzkém displeji nemá plovoucí okno smysl — přes celou obrazovku. */
@media (max-width: 720px) {
    .ai-window--floating,
    .ai-window--docked {
        /* !important i na pozici: okno si pamatuje, kam ho uživatel na desktopu
           přetáhl, a ta pozice se zapisuje inline. Bez tohohle inline styl vyhrál
           a okno na telefonu viselo mimo obrazovku nebo smrsklé do rohu. */
        inset: 0 !important;
        left: 0 !important;
        top: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: auto !important;
        height: auto !important;
        max-width: none;
        border-radius: 0;
        border: 0;
    }

    /* Ovládání, které se na desktopu ukazuje až po najetí myší, musí být na dotyku
       vidět pořád — prstem se „najet“ nedá. */
    .ai-message__meta,
    .ai-history__tool,
    .ai-visual__actions {
        opacity: 1;
    }

    /* Roztažení nemá na telefonu smysl — okno je přes celou obrazovku vždycky. */
    .ai-window--expanded.ai-window--floating {
        inset: 0 !important;
    }

    .ai-window__resize,
    .ai-window__dock-edge {
        display: none;
    }

    .ai-window__handle {
        cursor: default;
    }
}

/* ============================================================
   Historie konverzací
   ============================================================ */

.ai-history {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}

.ai-history__state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    text-align: center;
    padding: 40px 16px;
}

.ai-history__state--empty {
    opacity: .7;
}

.ai-history__alert {
    margin-bottom: 6px;
}

.ai-history__item {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
}

.ai-history__text {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-width: 0;
}

.ai-history__title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-history__date {
    font-size: .72rem;
    color: var(--mud-palette-text-secondary);
}

.ai-history__confirm {
    display: flex;
    align-items: center;
    gap: 2px;
    font-size: .78rem;
    color: var(--mud-palette-error);
    white-space: nowrap;
}

/* Zprávy přilétají zespodu, ať je poznat, že přibyly. */
.ai-message {
    animation: ai-message-in .16s ease-out;
}

@keyframes ai-message-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
    .ai-window,
    .ai-message,
    .ai-chat__new-messages {
        animation: none;
    }

    .ai-chat__messages {
        scroll-behavior: auto;
    }
}

/* --- zdroje odpovědi (D4) ---------------------------------------------------
   Pod odpovědí visí pohledy, ze kterých se čerpalo. Je to obrana proti tomu, aby
   se číslo vyložilo jako fakt z jiného modulu, než ze kterého opravdu je. */

.ai-sources {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    padding: 2px 4px 0;
    font-size: .7rem;
    color: var(--mud-palette-text-secondary);
}

.ai-sources .mud-icon-root {
    font-size: .9rem;
    width: .9rem;
    height: .9rem;
}

.ai-sources__label {
    letter-spacing: .01em;
}

/* Čísla bez opory ve výsledcích nástrojů — tichá poznámka, ne varování. */
.ai-number-check {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    padding: 2px 4px 0;
    font-size: .7rem;
    color: var(--mud-palette-text-secondary);
}

.ai-number-check .mud-icon-root {
    font-size: .9rem;
    width: .9rem;
    height: .9rem;
}

.ai-answer-notes {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 2px 4px 0;
    font-size: .7rem;
    color: var(--mud-palette-text-secondary);
}

.ai-answer-notes__item {
    display: flex;
    align-items: flex-start;
    gap: 4px;
}

.ai-answer-notes .mud-icon-root {
    flex: none;
    font-size: .9rem;
    width: .9rem;
    height: .9rem;
    color: var(--mud-palette-info);
}

.ai-number-check__value {
    padding: 0 6px;
    border-radius: 8px;
    border: 1px dashed var(--mud-palette-warning);
    font-variant-numeric: tabular-nums;
}

.ai-sources__chip {
    padding: 1px 7px;
    border: 1px solid var(--mud-palette-divider);
    border-radius: 999px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: .68rem;
    background: var(--mud-palette-background-gray);
}

.ai-sources__chip--link {
    text-decoration: none;
    cursor: pointer;
}

.ai-sources__chip--link:hover {
    text-decoration: underline;
}

.ai-sources__toggle {
    border: 0;
    background: none;
    padding: 0 2px;
    font: inherit;
    color: var(--mud-palette-primary);
    cursor: pointer;
    text-decoration: underline dotted;
}

.ai-sources__details {
    padding: 2px 4px 0;
}

.ai-sources__sql {
    margin: 4px 0 0;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid var(--mud-palette-divider);
    background: var(--mud-palette-background-gray);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: .72rem;
    line-height: 1.45;
    white-space: pre-wrap;
    overflow-x: auto;
}

/* --- vizualizace v bublině (D3) ---------------------------------------------
   Graf je SVG vyrobené na serveru; tabulka jsou data, která modelem neprošla. */

.ai-visual {
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px;
    border: 1px solid var(--mud-palette-divider);
    border-radius: 12px;
    background: var(--mud-palette-surface);
}

.ai-visual__title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-weight: 600;
    font-size: .85rem;
}

.ai-visual__actions {
    display: flex;
    align-items: center;
    gap: 0;
    opacity: .55;
    transition: opacity .15s ease;
}

.ai-visual:hover .ai-visual__actions,
.ai-visual:focus-within .ai-visual__actions {
    opacity: 1;
}

.ai-visual__actions .mud-icon-button {
    padding: 3px;
}

/* SVG přichází s pevným poměrem stran; necháme ho škálovat do šířky karty. */
.ai-visual__chart svg {
    width: 100%;
    height: auto;
    display: block;
}

.ai-visual__table-wrap {
    max-height: 420px;
    overflow: auto;
}

.ai-visual__table {
    width: 100%;
    border-collapse: collapse;
    font-size: .78rem;
    font-variant-numeric: tabular-nums;
}

.ai-visual__table th,
.ai-visual__table td {
    padding: 5px 9px;
    text-align: left;
    border-bottom: 1px solid var(--mud-palette-divider);
    white-space: nowrap;
}

/* Lepkavá hlavička: u dvou set řádků je jinak po prvním odscrollování ztracená. */
.ai-visual__table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--mud-palette-background-gray);
    font-weight: 600;
    cursor: pointer;
    user-select: none;
}

.ai-visual__table thead th .mud-icon-root {
    font-size: .8rem;
    width: .8rem;
    height: .8rem;
    vertical-align: -1px;
    margin-left: 2px;
}

.ai-visual__table tbody tr:nth-child(even) {
    background: color-mix(in srgb, var(--mud-palette-background-gray) 55%, transparent);
}

.ai-visual__table tfoot td {
    position: sticky;
    bottom: 0;
    background: var(--mud-palette-background-gray);
    font-weight: 600;
    border-top: 2px solid var(--mud-palette-divider);
    border-bottom: 0;
}

.ai-visual__num {
    text-align: right !important;
}

.ai-visual__thumb {
    display: block;
    max-width: 72px;
    max-height: 48px;
    border-radius: 4px;
    background: #ffffff;
}

.ai-visual__more {
    align-self: flex-start;
    border: 0;
    background: none;
    padding: 2px 0;
    font: inherit;
    font-size: .75rem;
    color: var(--mud-palette-primary);
    cursor: pointer;
}

.ai-visual__caption {
    margin: 0;
    font-size: .72rem;
    color: var(--mud-palette-text-secondary);
}

/* --- lišta volby modelu a hloubky (R3) --------------------------------------- */

.ai-window__tuning {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    padding: 6px 12px;
    border-bottom: 1px solid var(--mud-palette-divider);
    background: var(--mud-palette-background-gray);
    flex: 0 0 auto;
}

.ai-window__tuning-group {
    display: inline-flex;
    border: 1px solid var(--mud-palette-divider);
    border-radius: 999px;
    overflow: hidden;
    background: var(--mud-palette-surface);
}

.ai-window__tuning-button {
    border: 0;
    background: none;
    padding: 3px 11px;
    font: inherit;
    font-size: .72rem;
    color: var(--mud-palette-text-secondary);
    cursor: pointer;
    white-space: nowrap;
}

.ai-window__tuning-slot {
    display: inline-flex;
}

.ai-window__tuning-slot + .ai-window__tuning-slot {
    border-left: 1px solid var(--mud-palette-divider);
}

.ai-window__tuning-button:disabled {
    cursor: default;
    opacity: .55;
}

.ai-window__tuning-button--on {
    background: var(--mud-palette-primary);
    color: var(--mud-palette-primary-text);
    font-weight: 600;
}

/* --- opakování po chybě API (R2) --------------------------------------------- */

.ai-chat__retry {
    display: flex;
    align-items: center;
    gap: 8px;
    align-self: center;
    padding: 5px 12px;
    border-radius: 999px;
    font-size: .76rem;
    color: var(--mud-palette-text-secondary);
    background: var(--mud-palette-background-gray);
    border: 1px solid var(--mud-palette-divider);
}

/* --- historie: hledání, připnutí, přejmenování (U2) --------------------------- */

.ai-history__search {
    padding: 2px 2px 8px;
    flex: 0 0 auto;
}

.ai-history__tools {
    display: flex;
    align-items: center;
    gap: 0;
}

.ai-history__tool {
    opacity: 0;
    transition: opacity .15s ease;
    padding: 3px;
}

.ai-history__row:hover .ai-history__tool,
.ai-history__row:focus-within .ai-history__tool,
.ai-history__tool--on {
    opacity: 1;
}

.ai-history__pin-mark {
    font-size: .8rem !important;
    width: .8rem !important;
    height: .8rem !important;
    vertical-align: -1px;
    margin-right: 3px;
    color: var(--mud-palette-primary);
}

.ai-history__rename {
    width: 100%;
    padding: 3px 6px;
    font: inherit;
    font-size: .82rem;
    color: var(--mud-palette-text-primary);
    background: var(--mud-palette-surface);
    border: 1px solid var(--mud-palette-primary);
    border-radius: 6px;
    outline: none;
}

/* --- roztažené okno ----------------------------------------------------------
   Vlastní režim, ne jen větší rozměry: pozice okna se ukládá inline, takže by ji
   pouhá změna šířky nepřebila. */

.ai-window--expanded.ai-window--floating {
    inset: 3vh 3vw !important;
    width: auto !important;
    height: auto !important;
    max-width: none;
}

/* --- upřesňující otázka s volbami --- */

.ai-choices {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 6px 0;
}

.ai-choices__question {
    font-size: .88rem;
    font-weight: 500;
}

.ai-choices__options {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.ai-choices__chip {
    border: 1px solid var(--mud-palette-primary);
    border-radius: 999px;
    padding: 3px 12px;
    background: transparent;
    color: var(--mud-palette-primary);
    font: inherit;
    font-size: .82rem;
    line-height: 1.5;
    cursor: pointer;
    transition: background-color .12s ease, color .12s ease;
}

.ai-choices__chip:hover:not(:disabled),
.ai-choices__chip--on {
    background: var(--mud-palette-primary);
    color: var(--mud-palette-primary-text);
}

.ai-choices__chip:focus-visible {
    outline: 2px solid var(--mud-palette-primary);
    outline-offset: 2px;
}

/* Zodpovězeno (nebo konverzace šla dál): chipy zůstávají jako stopa, ale ustoupí. */
.ai-choices--done .ai-choices__chip {
    border-color: var(--mud-palette-divider);
    color: var(--mud-palette-text-secondary);
    cursor: default;
}

.ai-choices--done .ai-choices__chip--on {
    background: var(--mud-palette-action-disabled-background);
    color: var(--mud-palette-text-primary);
}

/* --- patička odpovědi pro správce: cena, volání, doba --- */

.ai-message__cost {
    font-size: .72rem;
    color: var(--mud-palette-text-disabled);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* --- nabídka pokračovat v nové konverzaci --- */

.ai-chat__carry-over {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 8px 0;
    padding: 6px 6px 6px 10px;
    border: 1px solid var(--mud-palette-divider);
    border-radius: 10px;
    background: var(--mud-palette-surface);
    color: var(--mud-palette-text-secondary);
    font-size: .8rem;
}

.ai-chat__carry-over > span {
    flex: 1;
}

/* --- shrnutá starší část konverzace (komprese) --- */

.ai-compaction {
    margin: 4px 0;
}

.ai-compaction__line {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 0;
    border: 0;
    background: none;
    color: var(--mud-palette-text-secondary);
    font: inherit;
    font-size: .8rem;
    cursor: pointer;
}

.ai-compaction__line::before,
.ai-compaction__line::after {
    content: "";
    flex: 1;
    border-top: 1px dashed var(--mud-palette-divider);
}

.ai-compaction__toggle {
    text-decoration: underline;
}

.ai-compaction__summary {
    margin-top: 6px;
    padding: 8px 10px;
    border-radius: 8px;
    background: var(--mud-palette-background-gray);
    color: var(--mud-palette-text-secondary);
    font-size: .85rem;
    white-space: pre-wrap;
}

/* --- návrh na zapamatování --- */

.ai-memory {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 6px 0;
    padding: 6px 10px;
    border: 1px dashed var(--mud-palette-divider);
    border-radius: 10px;
    background: var(--mud-palette-surface);
}

.ai-memory__title {
    font-weight: 600;
    margin-right: 4px;
}

.ai-memory--saved {
    border-style: solid;
    border-color: var(--mud-palette-success);
}

.ai-memory--dismissed,
.ai-memory--expired {
    opacity: .65;
}

.ai-memory__icon {
    flex: 0 0 auto;
    margin-top: 2px;
    color: var(--mud-palette-warning);
}

.ai-memory__body {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-width: 0;
    gap: 1px;
}

.ai-memory__label {
    font-size: .72rem;
    color: var(--mud-palette-text-secondary);
}

.ai-memory__text {
    font-size: .85rem;
    overflow-wrap: anywhere;
}

.ai-memory__error {
    font-size: .75rem;
    color: var(--mud-palette-error);
}

.ai-memory__actions {
    display: flex;
    flex: 0 0 auto;
    gap: 2px;
}

.ai-memory-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 4px 2px;
}

.ai-memory-panel__hint {
    color: var(--mud-palette-text-secondary);
}

.ai-memory-panel__actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-memory-panel__status {
    font-size: .78rem;
    color: var(--mud-palette-text-secondary);
}

/* ── Upravitelná tabulka pod výsledkem nástroje (AiEditableTableCard) ─────────────────────
   Staví na .ai-visual (karta, tabulka); navíc vstupy v buňkách, pole nad tabulkou a patička
   s tlačítkem přepočtu. Přepočet běží v kódu bez modelu. */

.ai-message--assistant .ai-message__body:has(.ai-edit) {
    max-width: 96%;
    width: 100%;
}

.ai-edit__readonly {
    font-weight: 400;
    font-size: .72rem;
    color: var(--mud-palette-text-secondary);
}

.ai-edit__fields {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
}

.ai-edit__field {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: .78rem;
}

.ai-edit__field-label {
    color: var(--mud-palette-text-secondary);
}

.ai-edit__suffix {
    color: var(--mud-palette-text-secondary);
}

.ai-edit__input {
    width: 72px;
    padding: 2px 6px;
    border: 1px solid var(--mud-palette-lines-inputs);
    border-radius: 6px;
    background: var(--mud-palette-surface);
    color: var(--mud-palette-text-primary);
    font: inherit;
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.ai-edit__input:focus {
    outline: none;
    border-color: var(--mud-palette-primary);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--mud-palette-primary) 25%, transparent);
}

.ai-edit__input:disabled {
    opacity: .6;
}

.ai-edit__input--field {
    width: 110px;
    text-align: left;
}

/* Přepsaná hodnota je vidět na první pohled — před přepočtem i po něm v popisu dotazu. */
.ai-edit__input--changed {
    border-color: var(--mud-palette-primary);
    background: color-mix(in srgb, var(--mud-palette-primary) 10%, var(--mud-palette-surface));
    font-weight: 600;
}

.ai-edit__input--invalid {
    border-color: var(--mud-palette-error);
    background: color-mix(in srgb, var(--mud-palette-error) 10%, var(--mud-palette-surface));
}

.ai-edit__table td {
    vertical-align: middle;
}

.ai-edit__table thead th {
    cursor: default;
}

.ai-edit__row--highlight td {
    background: color-mix(in srgb, var(--mud-palette-warning) 12%, transparent);
}

.ai-edit__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
}

.ai-edit__actions {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
}

.ai-edit__error {
    color: var(--mud-palette-error);
}

@media (max-width: 600px) {
    .ai-edit__input {
        width: 60px;
    }

    .ai-edit__actions {
        width: 100%;
        justify-content: flex-end;
    }
}
