/* BahnDeutsch — Expert live chat widget. RTL-first, glassmorphism, theme-aware. */

.bd-ec-modal {
    position: fixed;
    inset: 0;
    z-index: 100002;
    display: none;
    direction: rtl;
    font-family: inherit;
}
.bd-ec-modal.is-open { display: block; }

.bd-ec-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(8, 14, 26, 0.34);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    opacity: 0;
    animation: bdEcFade 0.2s ease forwards;
}

.bd-ec-panel {
    position: absolute;
    inset-inline-end: 20px;
    bottom: 24px;
    width: min(94vw, 386px);
    height: min(76vh, 620px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(246, 249, 255, 0.94));
    box-shadow: 0 30px 70px rgba(9, 21, 44, 0.36);
    backdrop-filter: blur(20px) saturate(150%);
    -webkit-backdrop-filter: blur(20px) saturate(150%);
    color: #14203a;
    transform-origin: bottom left;
    animation: bdEcPop 0.26s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes bdEcFade { to { opacity: 1; } }
@keyframes bdEcPop {
    from { opacity: 0; transform: translateY(16px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- header ---------- */
.bd-ec-head {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 14px 16px;
    background: linear-gradient(135deg, #1f8f7a 0%, #1d6ce0 100%);
    color: #fff;
    flex: 0 0 auto;
}
.bd-ec-head-avatar {
    position: relative;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.22);
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}
.bd-ec-head-avatar svg { width: 24px; height: 24px; color: #fff; }
.bd-ec-status-dot {
    position: absolute;
    inset-inline-start: -1px;
    bottom: -1px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #3ddc84;
    border: 2px solid #1f8f7a;
    box-shadow: 0 0 0 0 rgba(61, 220, 132, 0.7);
    animation: bdEcPulse 2.2s infinite;
}
@keyframes bdEcPulse {
    0%   { box-shadow: 0 0 0 0 rgba(61, 220, 132, 0.6); }
    70%  { box-shadow: 0 0 0 7px rgba(61, 220, 132, 0); }
    100% { box-shadow: 0 0 0 0 rgba(61, 220, 132, 0); }
}
.bd-ec-head-copy { display: flex; flex-direction: column; line-height: 1.35; min-width: 0; flex: 1 1 auto; }
.bd-ec-head-copy strong { font-size: 15px; font-weight: 800; }
.bd-ec-head-sub { font-size: 11.5px; opacity: 0.86; }
.bd-ec-head-actions { display: flex; gap: 4px; flex: 0 0 auto; }
.bd-ec-icon-btn {
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s ease;
}
.bd-ec-icon-btn:hover { background: rgba(255, 255, 255, 0.32); }

/* ---------- message list ---------- */
.bd-ec-list {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px 14px 8px;
    display: flex;
    flex-direction: column;
    gap: 9px;
    scroll-behavior: smooth;
    background:
        radial-gradient(1200px 240px at 100% 0%, rgba(31, 143, 122, 0.06), transparent 60%),
        radial-gradient(1200px 240px at 0% 100%, rgba(29, 108, 224, 0.06), transparent 60%);
}
.bd-ec-list::-webkit-scrollbar { width: 7px; }
.bd-ec-list::-webkit-scrollbar-thumb { background: rgba(20, 40, 70, 0.18); border-radius: 8px; }

/* greeting */
.bd-ec-greeting {
    text-align: center;
    padding: 22px 16px 8px;
    color: #33455f;
    margin: auto 0;
}
.bd-ec-avatar-lg {
    width: 58px;
    height: 58px;
    margin: 0 auto 12px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1f8f7a, #1d6ce0);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}
.bd-ec-avatar-lg svg { width: 30px; height: 30px; }
.bd-ec-greeting-title { font-weight: 800; font-size: 15px; color: #16223b; }
.bd-ec-greeting-text { font-size: 13px; line-height: 1.7; margin-top: 6px; }

/* day separator */
.bd-ec-daysep { text-align: center; margin: 6px 0; }
.bd-ec-daysep span {
    font-size: 11px;
    color: #5b6b86;
    background: rgba(20, 40, 70, 0.07);
    padding: 3px 12px;
    border-radius: 999px;
}

/* rows / bubbles */
.bd-ec-row {
    display: flex;
    align-items: flex-end;
    gap: 7px;
    max-width: 84%;
    animation: bdEcRise 0.22s ease both;
}
.bd-ec-row.bd-ec-out { align-self: flex-start; }               /* user → right in RTL */
.bd-ec-row.bd-ec-in  { align-self: flex-end; flex-direction: row-reverse; } /* expert → left, avatar outer */
@keyframes bdEcRise { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: translateY(0); } }

.bd-ec-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1f8f7a, #1d6ce0);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}
.bd-ec-avatar svg { width: 16px; height: 16px; }

.bd-ec-bubble-group { display: flex; flex-direction: column; min-width: 0; }
.bd-ec-bubble {
    padding: 9px 13px;
    font-size: 13.5px;
    line-height: 1.68;
    white-space: pre-wrap;
    word-break: break-word;
    border-radius: 16px;
}
.bd-ec-out .bd-ec-bubble {
    background: linear-gradient(135deg, #1f8f7a, #1d6ce0);
    color: #fff;
    border-top-right-radius: 5px;
}
.bd-ec-in .bd-ec-bubble {
    background: #fff;
    color: #17233d;
    border: 1px solid rgba(20, 40, 70, 0.08);
    border-top-left-radius: 5px;
}
.bd-ec-author {
    margin: 0 4px 3px;
    font-size: 10.5px;
    font-weight: 700;
    color: #1f8f7a;
}
.bd-ec-meta {
    display: flex;
    gap: 5px;
    align-items: center;
    margin-top: 3px;
    padding: 0 4px;
    font-size: 10.5px;
    color: #7d8aa1;
}
.bd-ec-out .bd-ec-meta { justify-content: flex-start; }
.bd-ec-in .bd-ec-meta { justify-content: flex-end; }
.bd-ec-tick { font-size: 10px; color: #1f8f7a; }

/* ---------- login gate ---------- */
.bd-ec-gate {
    flex: 1 1 auto;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 24px;
    text-align: center;
    color: #33455f;
    font-size: 13.5px;
}
.bd-ec-gate-cta {
    display: inline-block;
    padding: 10px 22px;
    border-radius: 12px;
    background: linear-gradient(135deg, #1f8f7a, #1d6ce0);
    color: #fff;
    font-weight: 700;
    text-decoration: none;
}

/* ---------- composer ---------- */
.bd-ec-composer {
    flex: 0 0 auto;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    border-top: 1px solid rgba(20, 40, 70, 0.09);
    background: rgba(255, 255, 255, 0.6);
}
.bd-ec-name-row { margin-bottom: 8px; }
.bd-ec-name {
    width: 100%;
    height: 38px;
    border: 1px solid rgba(20, 40, 70, 0.14);
    border-radius: 11px;
    padding: 0 12px;
    font-size: 13px;
    font-family: inherit;
    background: #fff;
    color: #17233d;
    box-sizing: border-box;
}
.bd-ec-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}
.bd-ec-textarea {
    flex: 1 1 auto;
    resize: none;
    min-height: 44px;
    max-height: 120px;
    border: 1px solid rgba(20, 40, 70, 0.14);
    border-radius: 14px;
    padding: 12px 14px;
    font-size: 13.5px;
    line-height: 1.55;
    font-family: inherit;
    background: #fff;
    color: #17233d;
    box-sizing: border-box;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.bd-ec-textarea:focus {
    outline: none;
    border-color: rgba(31, 143, 122, 0.6);
    box-shadow: 0 0 0 3px rgba(31, 143, 122, 0.14);
}
.bd-ec-send {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, #1f8f7a, #1d6ce0);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 16px rgba(29, 108, 224, 0.34);
    transition: transform 0.12s ease, opacity 0.12s ease;
}
.bd-ec-send svg { width: 20px; height: 20px; transform: scaleX(-1); }
.bd-ec-send:hover { transform: translateY(-1px) scale(1.04); }
.bd-ec-send:disabled { opacity: 0.55; cursor: default; transform: none; }
.bd-ec-status { min-height: 15px; margin-top: 6px; font-size: 11.5px; color: #5b6b86; padding: 0 4px; }
.bd-ec-status.is-error { color: #c23a5c; }
.bd-ec-status.is-warn { color: #b8791f; }

/* ---------- mobile ---------- */
@media (max-width: 640px) {
    .bd-ec-panel {
        inset: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
        border: 0;
        animation: bdEcSlide 0.26s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    }
    @keyframes bdEcSlide { from { transform: translateY(100%); } to { transform: translateY(0); } }
}

@media (prefers-reduced-motion: reduce) {
    .bd-ec-panel, .bd-ec-backdrop, .bd-ec-row { animation: none !important; }
    .bd-ec-status-dot { animation: none !important; }
}
