/**
 * AkteX Chat – Messenger-Style für Q&A
 * @since 2.30.0
 *
 * Farbschema: frisch, business-tauglich
 *   Container-BG:  #8fa4b8 (mittleres Blaugrau — Kontrast zu weißen Bubbles)
 *   Eigene Bubble:  #d4edda → sanftes Grün
 *   Andere Bubble:  #ffffff → Weiß
 *   Akzent:         #128C7E (Teal/Grün)
 *   Rückfrage:      #007bff (Blau)
 *   Text:           linksbündig (Flattersatz)
 *   Bubbles:        stark gerundet + geschwungener Tail/Haken
 */

/* ── Container ─────────────────────────────────── */
.aktex-chat {
    display: flex;
    flex-direction: column;
    max-height: 600px;
    border: 1px solid #7a8fa3;
    border-radius: 12px;
    background: #8fa4b8;
    overflow: hidden;
    position: relative;
    margin: 12px 0;
    width: 100%;
    box-sizing: border-box;
}

/* ── Messages-Bereich ──────────────────────────── */
.aktex-chat__messages {
    flex: 1 1 auto;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 16px;
    scroll-behavior: smooth;
}

/* ── System-Message (kompakter Header) ─────────── */
.aktex-chat__system-msg {
    display: flex;
    justify-content: center;
    margin: 4px 0 10px;
}

.aktex-chat__system-msg-inner {
    background: rgba(255,255,255,.85);
    border: none;
    border-radius: 16px;
    padding: 5px 14px;
    text-align: left;
    font-size: 12px;
    color: #5f6b7a;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    backdrop-filter: blur(4px);
}

.aktex-chat__system-msg-type {
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: #128C7E;
}

.aktex-chat__system-msg-meta {
    font-size: 12px;
    color: #8895a7;
}

.aktex-chat__topic {
    background: #e8f4fd;
    color: #1a6fb5;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 10px;
}

/* ── Chat-Row (Bubble + Avatar) ────────────────── */
.aktex-chat__row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 80%;
    position: relative;
}

.aktex-chat__row--left {
    align-self: flex-start;
    padding-left: 4px;   /* Platz für Tail */
}

.aktex-chat__row--right {
    align-self: flex-end;
    flex-direction: row;
    padding-right: 4px;  /* Platz für Tail */
}

/* ── Avatar ────────────────────────────────────── */
.aktex-chat__avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0,0,0,.12);
}

/* ── Bubble ────────────────────────────────────── */
.aktex-chat__bubble {
    position: relative;
    padding: 8px 12px 6px;
    border-radius: 18px;
    max-width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0,0,0,.08);
    line-height: 1.5;
    font-size: 14px;
    text-align: left;
}

/* --- Linke Bubble (andere Person) --- */
.aktex-chat__bubble--left {
    background: #fff;
    border-top-left-radius: 4px;
}

/* Tail links: geschwungener Haken */
.aktex-chat__bubble--left::before {
    content: '';
    position: absolute;
    top: 0;
    left: -8px;
    width: 12px;
    height: 16px;
    background: radial-gradient(ellipse at top right, #fff 0%, #fff 70%, transparent 71%);
}
.aktex-chat__bubble--left::after {
    content: '';
    position: absolute;
    top: 0;
    left: -10px;
    width: 12px;
    height: 20px;
    background: radial-gradient(ellipse at top right, transparent 0%, transparent 68%, #8fa4b8 69%);
    z-index: 1;
}

/* --- Rechte Bubble (eigene Nachricht) --- */
.aktex-chat__bubble--right {
    background: #d4edda;
    border-top-right-radius: 4px;
}

/* Tail rechts: geschwungener Haken */
.aktex-chat__bubble--right::before {
    content: '';
    position: absolute;
    top: 0;
    right: -8px;
    width: 12px;
    height: 16px;
    background: radial-gradient(ellipse at top left, #d4edda 0%, #d4edda 70%, transparent 71%);
}
.aktex-chat__bubble--right::after {
    content: '';
    position: absolute;
    top: 0;
    right: -10px;
    width: 12px;
    height: 20px;
    background: radial-gradient(ellipse at top left, transparent 0%, transparent 68%, #8fa4b8 69%);
    z-index: 1;
}

/* Rückfrage-Markierung */
.aktex-chat__bubble--followup {
    border-left: 3px solid #007bff;
}

.aktex-chat__followup-badge {
    display: inline-block;
    background: #e7f1ff;
    color: #0056b3;
    font-size: 10px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 3px;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: .3px;
}

/* ── Bubble-Name (nur links) ───────────────────── */
.aktex-chat__bubble-name {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 2px;
    text-align: left;
}

/* ── Bubble-Text ───────────────────────────────── */
.aktex-chat__bubble-text {
    margin: 0;
    text-align: left;
}
.aktex-chat__bubble-text p {
    margin: 0 0 4px;
    text-align: left;
}
.aktex-chat__bubble-text p:last-child {
    margin-bottom: 0;
}

/* ── Bubble-Meta (Zeitstempel) ─────────────────── */
.aktex-chat__bubble-meta {
    display: flex;
    justify-content: flex-end;
    margin-top: 2px;
}

.aktex-chat__bubble-time {
    font-size: 11px;
    color: rgba(0,0,0,.35);
}

/* ── Zitat-Block ───────────────────────────────── */
.aktex-chat__quote {
    border-left: 3px solid #128C7E;
    background: rgba(18,140,126,.06);
    padding: 4px 8px;
    margin-bottom: 6px;
    border-radius: 0 6px 6px 0;
    cursor: pointer;
    transition: background .2s;
}

.aktex-chat__quote:hover {
    background: rgba(18,140,126,.12);
}

.aktex-chat__quote-text {
    font-size: 12px;
    color: #555;
    text-align: left;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ── Reactions-Pillen ──────────────────────────── */
.aktex-chat__reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
}

.aktex-chat__reaction-pill {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: rgba(255,255,255,.5);
    border: 1px solid rgba(0,0,0,.06);
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 13px;
    cursor: pointer;
    transition: all .15s;
    line-height: 1.3;
}

.aktex-chat__reaction-pill:hover {
    background: rgba(255,255,255,.8);
}

.aktex-chat__reaction-pill--active {
    border-color: #128C7E;
    background: rgba(18,140,126,.1);
}

/* ── Hover-Aktionen ────────────────────────────── */
.aktex-chat__hover-actions {
    position: absolute;
    top: -4px;
    right: 8px;
    display: none;
    gap: 2px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,.12);
    padding: 2px;
    z-index: 5;
}

.aktex-chat__bubble--left .aktex-chat__hover-actions {
    right: auto;
    left: 8px;
}

.aktex-chat__row:hover .aktex-chat__hover-actions {
    display: flex;
}

.aktex-chat__action-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 6px;
    font-size: 14px;
    border-radius: 4px;
    line-height: 1;
    color: #666;
    transition: background .15s;
}

.aktex-chat__action-btn:hover {
    background: #edf2f7;
}

/* ── Eingabeleiste ─────────────────────────────── */
.aktex-chat__input-bar {
    background: #edf1f5;
    padding: 8px 12px;
    border-top: 1px solid #7a8fa3;
    position: relative;
}

.aktex-chat__input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.aktex-chat__textarea {
    flex: 1;
    border: 1px solid #7a8fa3;
    border-radius: 22px;
    padding: 8px 16px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    line-height: 1.4;
    max-height: 120px;
    overflow-y: auto;
    outline: none;
    background: #fff;
    transition: border-color .2s, box-shadow .2s;
    text-align: left;
}

.aktex-chat__textarea:focus {
    border-color: #128C7E;
    box-shadow: 0 0 0 2px rgba(18,140,126,.15);
}

/* ── Senden-Button ─────────────────────────────── */
.aktex-chat__send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #128C7E;
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .15s, transform .1s;
}

.aktex-chat__send-btn:hover {
    background: #0d6e63;
    transform: scale(1.05);
}

/* ── Rückfrage-Toggle ──────────────────────────── */
.aktex-chat__followup-toggle {
    cursor: pointer;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.aktex-chat__followup-toggle input {
    display: none;
}

.aktex-chat__followup-icon {
    font-size: 20px;
    opacity: .35;
    transition: opacity .15s;
}

.aktex-chat__followup-toggle input:checked + .aktex-chat__followup-icon {
    opacity: 1;
}

/* ── Emoji-Trigger ─────────────────────────────── */
.aktex-chat__emoji-trigger {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    padding: 4px;
    opacity: .4;
    transition: opacity .15s;
    flex-shrink: 0;
    line-height: 1;
}

.aktex-chat__emoji-trigger:hover {
    opacity: 1;
}

/* ── Emoji-Picker ──────────────────────────────── */
.aktex-chat__emoji-picker {
    position: absolute;
    bottom: 100%;
    right: 12px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,.15);
    padding: 8px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    z-index: 10;
    margin-bottom: 4px;
}

.aktex-chat__emoji-pick {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    transition: background .15s;
    line-height: 1;
}

.aktex-chat__emoji-pick:hover {
    background: #edf2f7;
}

/* ── Zitat-Vorschau (über Textarea) ────────────── */
.aktex-chat__quote-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #fff;
    border-left: 3px solid #128C7E;
    padding: 6px 10px;
    margin-bottom: 6px;
    border-radius: 0 8px 8px 0;
    font-size: 12px;
    color: #555;
    text-align: left;
}

.aktex-chat__quote-preview-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
}

.aktex-chat__quote-cancel {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: #999;
    padding: 0 4px;
    line-height: 1;
}

.aktex-chat__quote-cancel:hover {
    color: #333;
}

/* ── Highlight-Animation (Scroll-to-Quote) ─────── */
.aktex-chat__bubble--highlight {
    animation: aktex-chat-highlight 2s ease;
}

@keyframes aktex-chat-highlight {
    0%   { background-color: #cce5ff; }
    100% { background-color: inherit; }
}

/* ── Responsive ────────────────────────────────── */
@media (max-width: 782px) {
    .aktex-chat__row {
        max-width: 90%;
    }

    .aktex-chat__system-msg-inner {
        max-width: 95%;
    }

    .aktex-chat__emoji-picker {
        right: 4px;
    }
}
