/* ==========================================================================
   Automagio – alex.css
   Nachrichten des persönlichen Assistenten Alex: Bild, Sprechblase,
   Tippanimation. Wird in html-header.php nach components.css geladen.

   Die Farben stehen als eigene Variablen direkt an .alex, damit die
   Komponente unabhängig von den Design-Tokens funktioniert und in beiden
   Modi ausreichend Kontrast hat. Werte aus tokens.css werden bevorzugt,
   falls vorhanden.
   ========================================================================== */

.alex {
    --alex-bubble-bg: #EEF1FA;
    --alex-bubble-fg: #1A1E2B;
    --alex-bubble-border: rgba(24, 30, 55, 0.10);
    --alex-meta-fg: #5B6275;
    --alex-accent: #2F4BD8;
    --alex-caret: #2F4BD8;

    display: flex;
    gap: 12px;
    align-items: flex-start;
    margin: 0 0 20px;
}

[data-theme="dark"] .alex {
    --alex-bubble-bg: #1B2030;
    --alex-bubble-fg: #E8EAF2;
    --alex-bubble-border: rgba(255, 255, 255, 0.12);
    --alex-meta-fg: #A3AAC0;
    --alex-accent: #8DA2FF;
    --alex-caret: #8DA2FF;
}

@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) .alex {
        --alex-bubble-bg: #1B2030;
        --alex-bubble-fg: #E8EAF2;
        --alex-bubble-border: rgba(255, 255, 255, 0.12);
        --alex-meta-fg: #A3AAC0;
        --alex-accent: #8DA2FF;
        --alex-caret: #8DA2FF;
    }
}

/* ---------- Bild ---------- */

.alex-avatar {
    flex: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--alex-bubble-bg);
    box-shadow: 0 0 0 2px var(--alex-bubble-border);
}

.alex-compact .alex-avatar {
    width: 34px;
    height: 34px;
}

/* ---------- Kopfzeile ---------- */

.alex-body {
    min-width: 0;
    flex: 1 1 auto;
}

.alex-meta {
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
    margin: 0 0 4px 2px;
    line-height: 1.3;
}

.alex-meta strong {
    font-size: 0.9375rem;
    color: var(--alex-bubble-fg);
}

.alex-meta span {
    font-size: 0.75rem;
    color: var(--alex-meta-fg);
}

/* ---------- Sprechblase ---------- */

.alex-bubble {
    position: relative;
    padding: 12px 16px;
    border-radius: 4px 14px 14px 14px;
    background: var(--alex-bubble-bg);
    color: var(--alex-bubble-fg);
    border: 1px solid var(--alex-bubble-border);
}

.alex-text p {
    margin: 0;
    font-size: 0.9375rem;
    line-height: 1.55;
    color: var(--alex-bubble-fg);
}

.alex-text p + p {
    margin-top: 8px;
}

.alex-compact .alex-bubble {
    padding: 10px 13px;
}

.alex-compact .alex-text p {
    font-size: 0.875rem;
}

/* Nur für Screenreader: vollständiger Text ohne Tippanimation */
.alex-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
}

/* ---------- Aktionen unter dem Text ---------- */

.alex-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

/* Während getippt wird, sind die Aktionen noch nicht da */
.alex.is-typing .alex-actions {
    opacity: 0;
    pointer-events: none;
}

.alex-actions {
    transition: opacity 180ms ease;
}

/* ---------- Tippanimation ---------- */

/* Zeilen, die noch nicht an der Reihe sind, belegen keinen Platz */
.alex.is-typing .alex-line.is-waiting {
    display: none;
}

.alex.is-typing .alex-line.is-active::after {
    content: "";
    display: inline-block;
    width: 2px;
    height: 1em;
    margin-left: 2px;
    vertical-align: -0.15em;
    background: var(--alex-caret);
    animation: alex-caret 900ms steps(1, end) infinite;
}

@keyframes alex-caret {
    0%, 45% { opacity: 1; }
    50%, 95% { opacity: 0; }
    100% { opacity: 1; }
}

/* Drei Punkte, solange Alex "überlegt" */
.alex-dots {
    display: inline-flex;
    gap: 4px;
    align-items: center;
    height: 1.55em;
}

.alex-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--alex-accent);
    opacity: 0.45;
    animation: alex-dot 1100ms ease-in-out infinite;
}

.alex-dots span:nth-child(2) { animation-delay: 160ms; }
.alex-dots span:nth-child(3) { animation-delay: 320ms; }

@keyframes alex-dot {
    0%, 100% { transform: translateY(0); opacity: 0.45; }
    40%      { transform: translateY(-3px); opacity: 1; }
}

/* Wer Animationen abgeschaltet hat, bekommt den Text sofort und vollständig */
@media (prefers-reduced-motion: reduce) {
    .alex.is-typing .alex-line.is-active::after,
    .alex-dots span {
        animation: none;
    }
}
