/* ========================================================
   Стили встраиваемого виджета Телфин AI-Ассистента
   Фирменный дизайн-код Телфин:
   - Оранжевая палитра (#ff7826, #ea600f)
   - Точное соответствие официальному макету окна чата
   - Шапка с гамбургером, центрированным заголовком и крестиком
   - Серая плашка автоответа с аватаром-силуэтом и датой
   - Нижняя панель с кнопкой "Задать вопрос" и формой ввода
   ======================================================== */

:root {
    /* Фирменная оранжевая палитра Телфин */
    --tw-primary: #ff7826;
    --tw-primary-hover: #ea600f;
    --tw-primary-active: #d94e02;
    --tw-primary-light: #fff4ed;
    --tw-primary-subtle: #fff9f5;
    --tw-primary-border: #fed7aa;
    --tw-primary-gradient: linear-gradient(135deg, #ff8533 0%, #ff6b18 55%, #f25200 100%);
    --tw-primary-gradient-hover: linear-gradient(135deg, #ff7a24 0%, #ea5c0a 55%, #df4500 100%);

    /* Палитра сообщений и подвала как на скриншоте Телфин */
    --tw-bubble-bg: #eff1f4;
    --tw-footer-bg: #f3f5f9;
    --tw-footer-border: #eef1f6;
    --tw-avatar-bg: #dde2e8;
    --tw-avatar-icon: #788694;
    --tw-date-color: #8c9aa8;
    --tw-time-color: #8c9aa8;

    /* Нейтральные тона */
    --tw-bg: #ffffff;
    --tw-text: #1c2530;
    --tw-text-muted: #64748b;
    --tw-border: #e2e8f0;
    --tw-border-light: #f1f5f9;

    /* Статусы */
    --tw-success: #10b981;
    --tw-success-hover: #059669;
    --tw-danger: #ef4444;

    /* Тени и скругления */
    --tw-shadow: 0 16px 40px rgba(0, 0, 0, 0.16), 0 4px 14px rgba(255, 120, 38, 0.1);
    --tw-radius: 20px;
    --tw-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ========================================================
   Кнопка-лаунчер (Круглая оранжевая кнопка с анимацией)
   ======================================================== */
.tw-launcher {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 62px;
    height: 62px;
    border-radius: 50%;
    background: var(--tw-primary-gradient);
    box-shadow: 0 8px 24px rgba(255, 107, 24, 0.42), 0 2px 6px rgba(0, 0, 0, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 999990;
    transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.25s ease;
    border: none;
    outline: none;
}

.tw-launcher:hover {
    transform: scale(1.08);
    box-shadow: 0 12px 30px rgba(255, 107, 24, 0.58), 0 4px 10px rgba(0, 0, 0, 0.12);
}

.tw-launcher:active {
    transform: scale(0.96);
}

/* Фирменная пульсирующая волна концентрических кругов Телфин */
.tw-launcher::before {
    content: '';
    position: absolute;
    top: -12px;
    left: -12px;
    right: -12px;
    bottom: -12px;
    border-radius: 50%;
    border: 1.5px solid rgba(254, 215, 170, 0.75);
    animation: twTelphinPulse 2.8s infinite cubic-bezier(0.25, 1, 0.5, 1);
    pointer-events: none;
}

.tw-launcher::after {
    content: '';
    position: absolute;
    top: -22px;
    left: -22px;
    right: -22px;
    bottom: -22px;
    border-radius: 50%;
    border: 1.5px solid rgba(255, 120, 38, 0.22);
    animation: twTelphinPulse 2.8s infinite cubic-bezier(0.25, 1, 0.5, 1) 0.7s;
    pointer-events: none;
}

@keyframes twTelphinPulse {
    0% {
        transform: scale(0.92);
        opacity: 0.95;
    }
    50% {
        transform: scale(1.15);
        opacity: 0.4;
    }
    100% {
        transform: scale(1.35);
        opacity: 0;
    }
}

.tw-launcher.tw-open::before,
.tw-launcher.tw-open::after {
    display: none;
}

/* Контейнер иконок кнопки для плавного морфинга */
.tw-launcher-icon-wrap {
    position: relative;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.tw-launcher svg {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: opacity 0.28s cubic-bezier(0.4, 0, 0.2, 1), transform 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
}

/* 1. Фирменная иконка чата (два диалоговых пузыря Телфин) - видна по умолчанию */
.tw-launcher svg.tw-icon-chat {
    width: 44px;
    height: 44px;
    opacity: 1;
    transform: translate(-50%, -50%) scale(1) rotate(0deg);
}

/* 2. Иконка трех точек (•••) - скрыта по умолчанию, появляется при наведении */
.tw-launcher svg.tw-icon-dots {
    width: 28px;
    height: 28px;
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.4) rotate(-25deg);
}

.tw-launcher svg.tw-icon-dots circle {
    transform-box: fill-box;
    transform-origin: center;
}

/* 3. Иконка закрытия (крестик) - скрыта по умолчанию */
.tw-launcher svg.tw-icon-close {
    width: 25px;
    height: 25px;
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.4) rotate(-90deg);
}

/* --- АНИМАЦИЯ ТРАНСФОРМАЦИИ ПРИ НАВЕДЕНИИ (:hover) --- */
.tw-launcher:hover:not(.tw-open) svg.tw-icon-chat {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.45) rotate(25deg);
}

.tw-launcher:hover:not(.tw-open) svg.tw-icon-dots {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1) rotate(0deg);
}

.tw-launcher:hover:not(.tw-open) svg.tw-icon-dots circle:nth-child(1) {
    animation: twDotPulse 1.2s infinite ease-in-out 0s;
}
.tw-launcher:hover:not(.tw-open) svg.tw-icon-dots circle:nth-child(2) {
    animation: twDotPulse 1.2s infinite ease-in-out 0.18s;
}
.tw-launcher:hover:not(.tw-open) svg.tw-icon-dots circle:nth-child(3) {
    animation: twDotPulse 1.2s infinite ease-in-out 0.36s;
}

@keyframes twDotPulse {
    0%, 100% {
        transform: scale(1);
        opacity: 0.9;
    }
    50% {
        transform: scale(1.28);
        opacity: 1;
    }
}

/* --- СОСТОЯНИЕ КОГДА ОКНО ЧАТА ОТКРЫТО (.tw-open) --- */
.tw-launcher.tw-open svg.tw-icon-chat {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.3) rotate(-90deg);
}

.tw-launcher.tw-open svg.tw-icon-dots {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.3);
}

.tw-launcher.tw-open svg.tw-icon-close {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1) rotate(0deg);
}

/* Индикатор онлайна (скрыт для 100% соответствия официальному дизайну кнопки) */
.tw-badge-pulse {
    display: none;
}

/* ========================================================
   Окно чата (Точный макет окна со скриншота)
   ======================================================== */
.tw-window {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 370px;
    height: 560px;
    max-height: calc(100vh - 110px);
    max-width: calc(100vw - 32px);
    background-color: var(--tw-bg);
    border-radius: var(--tw-radius);
    box-shadow: var(--tw-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 999991;
    font-family: var(--tw-font);
    font-size: 14px;
    color: var(--tw-text);
    transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.25s;
    opacity: 0;
    visibility: hidden;
    transform: translateY(16px) scale(0.96);
}

.tw-window.tw-visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Шапка чата: оранжевая плашка, гамбургер слева, заголовок по центру, крестик справа */
.tw-header {
    background: var(--tw-primary);
    color: #ffffff;
    height: 54px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(255, 120, 38, 0.2);
}

.tw-header-title {
    font-size: 16.5px;
    font-weight: 700;
    color: #ffffff;
    text-align: center;
    flex: 1;
    letter-spacing: -0.2px;
}

.tw-header-btn-menu,
.tw-header-btn-close {
    background: transparent;
    border: none;
    color: #ffffff;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: background-color 0.15s ease, opacity 0.15s ease;
    padding: 0;
}

.tw-header-btn-menu:hover,
.tw-header-btn-close:hover {
    background: rgba(255, 255, 255, 0.18);
}

/* ========================================================
   Контекстная плашка текущей страницы ЛК ВАТС
   ======================================================== */
.tw-context-bar {
    background: #fff9f5;
    border-bottom: 1px solid #fed7aa;
    padding: 6px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    color: #475569;
    flex-shrink: 0;
    transition: background-color 0.2s ease;
}

.tw-context-info {
    display: flex;
    align-items: center;
    gap: 6px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.tw-context-icon {
    font-size: 14px;
    flex-shrink: 0;
}

.tw-context-label {
    color: #94a3b8;
    font-size: 11px;
    font-weight: 500;
    flex-shrink: 0;
}

.tw-context-name {
    font-weight: 600;
    color: #c2410c;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tw-context-help-btn {
    background: #ffffff;
    border: 1px solid #fdba74;
    color: #ea580c;
    border-radius: 12px;
    padding: 3px 9px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.15s ease;
    box-shadow: 0 1px 3px rgba(234, 88, 12, 0.08);
}

.tw-context-help-btn:hover {
    background: #ffedd5;
    border-color: #ea580c;
    color: #c2410c;
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(234, 88, 12, 0.16);
}

.tw-context-help-btn:active {
    transform: translateY(0);
}

/* ========================================================
   Выпадающее меню (по кнопке ☰) для выбора разделов АТС
   ======================================================== */
.tw-menu-panel {
    position: absolute;
    top: 54px;
    left: 0;
    right: 0;
    background: #ffffff;
    border-bottom: 2px solid var(--tw-primary);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.12);
    padding: 14px 16px;
    z-index: 20;
    display: none;
    animation: twSlideDown 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.tw-menu-panel.tw-menu-open {
    display: block;
}

@keyframes twSlideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.tw-menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    font-weight: 700;
    color: var(--tw-primary);
    margin-bottom: 10px;
}

.tw-menu-close-btn {
    background: none;
    border: none;
    font-size: 16px;
    color: #8c9aa8;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
}

.tw-menu-close-btn:hover {
    background: #f1f5f9;
    color: #1e293b;
}

.tw-menu-section {
    margin-bottom: 12px;
}

.tw-menu-label {
    display: block;
    font-size: 11.5px;
    color: #64748b;
    margin-bottom: 5px;
    font-weight: 500;
}

.tw-menu-select {
    width: 100%;
    padding: 7px 10px;
    border: 1.5px solid #fed7aa;
    border-radius: 8px;
    font-size: 13px;
    color: #1e293b;
    outline: none;
    background: #fffaf5;
    cursor: pointer;
}

.tw-menu-select:focus {
    border-color: var(--tw-primary);
    box-shadow: 0 0 0 2px rgba(255, 120, 38, 0.2);
}

.tw-menu-actions {
    display: flex;
    gap: 8px;
}

.tw-menu-btn {
    flex: 1;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    color: #475569;
    transition: all 0.15s ease;
}

.tw-menu-btn:hover {
    background: #f1f5f9;
    color: #1e293b;
}

.tw-menu-btn-clear:hover {
    background: #fef2f2;
    color: #ef4444;
    border-color: #fecaca;
}

/* ========================================================
   Тело чата
   ======================================================== */
.tw-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px 16px 20px 16px;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Разделитель даты (по центру вверху) */
.tw-date-divider {
    text-align: center;
    font-size: 12px;
    color: var(--tw-date-color);
    margin: 4px 0 10px 0;
    font-weight: 500;
    letter-spacing: 0.2px;
}

/* Контейнер списка сообщений */
#tw-messages-list {
    display: flex;
    flex-direction: column;
    gap: 18px;
    width: 100%;
}

/* Быстрые подсказки */
.tw-chips-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 6px;
    margin-bottom: 6px;
}

.tw-chip {
    background: #ffffff;
    border: 1.5px solid var(--tw-primary-border);
    color: #c2410c;
    border-radius: 16px;
    padding: 7px 13px;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.35;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    box-shadow: 0 1px 3px rgba(255, 120, 38, 0.08);
}

.tw-chip:hover {
    background: var(--tw-primary);
    color: #ffffff;
    border-color: var(--tw-primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(255, 120, 38, 0.3);
}

/* ========================================================
   Сообщения чата
   ======================================================== */
.tw-msg {
    display: flex;
    flex-direction: column;
    max-width: 90%;
    line-height: 1.48;
    animation: twFadeIn 0.2s ease;
}

@keyframes twFadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Сообщение ассистента */
.tw-msg-assistant {
    align-self: flex-start;
    align-items: flex-start;
    max-width: 88%;
    margin-right: auto;
}

.tw-msg-assistant-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin-bottom: 2px;
}

/* Круглая серая иконка аватара-силуэта слева внизу */
.tw-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--tw-avatar-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.tw-msg-avatar svg {
    width: 16px;
    height: 16px;
}

/* Бабл ассистента со скруглением и серым фоном */
.tw-msg-assistant .tw-msg-bubble {
    background: var(--tw-bubble-bg);
    color: var(--tw-text);
    border-radius: 20px 20px 20px 6px;
    padding: 13px 16px;
    font-size: 13.5px;
    line-height: 1.45;
    border: none;
    box-shadow: none;
    word-break: break-word;
    overflow-wrap: anywhere;
}

/* Жирный заголовок "Автоответ" внутри бабла */
.tw-bubble-header {
    font-size: 14.5px;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 7px;
}

/* Время под сообщением */
.tw-msg-time {
    font-size: 11px;
    color: var(--tw-time-color);
    margin-top: 4px;
    margin-left: 36px; /* выравнивание по левому краю бабла (28px аватар + 8px gap) */
}

/* Сообщение пользователя */
.tw-msg-user {
    align-self: flex-end;
    align-items: flex-end;
    max-width: 85%;
    margin-left: auto;
}

.tw-msg-user .tw-msg-bubble {
    background: var(--tw-primary-gradient);
    color: #ffffff;
    border-radius: 20px 20px 6px 20px;
    padding: 11px 16px;
    font-size: 13.5px;
    box-shadow: 0 3px 10px rgba(255, 107, 24, 0.25);
    word-break: break-word;
    overflow-wrap: anywhere;
    width: fit-content;
}

.tw-msg-user .tw-msg-time {
    margin-left: 0;
    align-self: flex-end;
    margin-right: 4px;
    margin-top: 4px;
}

/* Форматирование внутри сообщений */
.tw-msg-bubble p {
    margin: 0 0 8px 0;
}

.tw-msg-bubble p:last-child {
    margin: 0;
}

.tw-msg-bubble ul, .tw-msg-bubble ol {
    margin: 4px 0 6px 0;
    padding-left: 20px;
}

.tw-msg-bubble li {
    margin-bottom: 3px;
}

.tw-msg-bubble b, .tw-msg-bubble strong {
    font-weight: 600;
}

.tw-msg-bubble code {
    background: #e2e8f0;
    border-radius: 4px;
    padding: 1px 5px;
    font-family: monospace;
    font-size: 12px;
    color: #c2410c;
}

/* Ссылки */
.tw-link {
    color: var(--tw-primary) !important;
    text-decoration: underline;
    font-weight: 600;
    word-break: break-all;
}

.tw-link:hover {
    color: var(--tw-primary-hover) !important;
}

/* ========================================================
   Кнопки аудиозаписей звонков
   ======================================================== */
.tw-record-action-group {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 6px 0;
    vertical-align: middle;
}

.tw-btn-download {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--tw-primary-gradient);
    color: #ffffff !important;
    border: none;
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none !important;
    box-shadow: 0 2px 6px rgba(255, 107, 24, 0.3);
}

.tw-btn-download:hover {
    background: var(--tw-primary-gradient-hover);
    box-shadow: 0 4px 12px rgba(255, 107, 24, 0.45);
    transform: translateY(-1px);
}

.tw-btn-download:disabled {
    opacity: 0.75;
    cursor: wait;
}

.tw-btn-copy-url {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #f8fafc;
    color: #334155;
    border: 1px solid var(--tw-border);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.tw-btn-copy-url:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

.tw-btn-copy-url.tw-copied {
    background: #ecfdf5;
    color: #047857;
    border-color: #6ee7b7;
    font-weight: 600;
}

/* ========================================================
   Карточка подтверждения действия в АТС (Draft Action Card)
   ======================================================== */
.tw-draft-card {
    background: #fffbf8;
    border: 1.5px solid var(--tw-primary-border);
    border-left: 4px solid var(--tw-primary);
    border-radius: 12px;
    padding: 14px;
    margin: 4px 0 6px 0;
    width: 100%;
    box-sizing: border-box;
    align-self: stretch;
    box-shadow: 0 4px 14px rgba(255, 120, 38, 0.1);
}

.tw-draft-title {
    font-size: 13px;
    font-weight: 700;
    color: #c2410c;
    margin-bottom: 7px;
}

.tw-draft-content {
    font-size: 13px;
    color: #1e293b;
    line-height: 1.45;
    margin-bottom: 12px;
}

.tw-draft-actions {
    display: flex;
    gap: 8px;
}

.tw-btn-confirm {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: #ffffff;
    border: none;
    border-radius: 8px;
    padding: 7px 15px;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(16, 185, 129, 0.28);
    transition: all 0.15s ease;
}

.tw-btn-confirm:hover {
    background: #047857;
    transform: translateY(-1px);
}

.tw-btn-cancel {
    background: #f8fafc;
    color: #475569;
    border: 1px solid var(--tw-border);
    border-radius: 8px;
    padding: 7px 15px;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.tw-btn-cancel:hover {
    background: #f1f5f9;
}

/* ========================================================
   Индикатор набора текста
   ======================================================== */
.tw-typing {
    display: none;
    align-self: flex-start;
    background: var(--tw-bubble-bg);
    padding: 10px 16px;
    border-radius: 16px 16px 16px 4px;
    margin-left: 36px;
    margin-top: 4px;
    margin-bottom: 4px;
}

.tw-typing span {
    display: inline-block;
    width: 6px;
    height: 6px;
    background-color: var(--tw-primary);
    border-radius: 50%;
    margin: 0 2px;
    animation: twTypingBounce 1.4s infinite both;
}

.tw-typing span:nth-child(1) { animation-delay: 0s; }
.tw-typing span:nth-child(2) { animation-delay: 0.2s; }
.tw-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes twTypingBounce {
    0%, 80%, 100% { transform: scale(0); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* ========================================================
   Подвал чата (Адаптивное поле ввода и кнопки)
   ======================================================== */
.tw-footer {
    position: relative;
    min-height: 56px;
    height: auto;
    background: var(--tw-footer-bg);
    border-top: 1px solid var(--tw-footer-border);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 10px 14px 10px 16px;
    border-radius: 0 0 20px 20px;
    flex-shrink: 0;
    box-sizing: border-box;
    transition: background-color 0.2s ease;
}

/* Кнопка "Задать вопрос" (по центру, оранжевая) как на скриншоте */
.tw-btn-ask {
    display: none !important;
}

/* Форма ввода (адаптивная по высоте) */
.tw-input-bar {
    position: relative;
    display: flex;
    align-items: flex-end;
    width: 100%;
    min-height: 36px;
    animation: twFadeIn 0.2s ease;
}

.tw-input {
    width: 100%;
    min-height: 24px;
    max-height: 125px;
    box-sizing: border-box;
    padding: 6px 68px 6px 2px;
    background: transparent;
    border: none;
    outline: none;
    resize: none;
    font-size: 14px;
    line-height: 1.45;
    font-family: inherit;
    color: #1e293b;
    overflow-y: hidden;
    vertical-align: bottom;
}

.tw-input::placeholder {
    color: #8c9aa8;
    opacity: 1;
}

.tw-input:focus {
    outline: none;
    border: none;
    box-shadow: none;
}

/* Стилизация скроллбара поля ввода */
.tw-input::-webkit-scrollbar {
    width: 5px;
}

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

.tw-input::-webkit-scrollbar-thumb {
    background: #c8c8ca;
    border-radius: 4px;
}

.tw-input::-webkit-scrollbar-thumb:hover {
    background: #9fa6b2;
}

/* Кнопки действий справа от поля ввода */
.tw-input-actions {
    position: absolute;
    right: 4px;
    bottom: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
    z-index: 2;
}

.tw-emoji-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: transparent;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #8c9aa8;
    transition: color 0.15s ease, transform 0.15s ease;
    flex-shrink: 0;
    padding: 0;
}

.tw-emoji-btn:hover {
    color: var(--tw-primary);
    transform: scale(1.12);
}

.tw-emoji-btn:active {
    transform: scale(0.92);
}

.tw-send-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: transparent;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.15s ease, opacity 0.15s ease;
    flex-shrink: 0;
    padding: 0;
}

.tw-send-btn:hover {
    transform: scale(1.15);
}

.tw-send-btn:active {
    transform: scale(0.92);
}

.tw-send-btn svg {
    width: 20px;
    height: 20px;
    fill: var(--tw-primary);
}

/* Всплывающее окно эмодзи */
.tw-emoji-picker {
    position: absolute;
    bottom: calc(100% + 8px);
    right: 14px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    border-radius: 12px;
    padding: 8px 10px;
    display: none;
    grid-template-columns: repeat(5, 32px);
    gap: 4px;
    z-index: 30;
    animation: twFadeIn 0.15s ease;
}

.tw-emoji-picker.tw-open {
    display: grid;
}

.tw-emoji-item {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 6px;
    font-size: 18px;
    cursor: pointer;
    transition: background 0.15s, transform 0.15s;
    padding: 0;
}

.tw-emoji-item:hover {
    background: #f1f5f9;
    transform: scale(1.18);
}

/* Мобильная адаптация */
@media (max-width: 480px) {
    .tw-window {
        bottom: 0;
        right: 0;
        width: 100vw;
        height: 100vh;
        max-height: 100vh;
        max-width: 100vw;
        border-radius: 0;
    }
    .tw-footer {
        border-radius: 0;
    }
    .tw-launcher {
        bottom: 16px;
        right: 16px;
    }
}

/* ========================================================
   Голосовой режим и WebSocket Realtime звонок Телфин
   ======================================================== */

.tw-header-btn-call {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: #ffffff;
    font-size: 11.5px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 14px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: all 0.2s ease;
    margin-right: auto;
    margin-left: 8px;
}

.tw-header-btn-call:hover {
    background: rgba(255, 255, 255, 0.35);
    transform: translateY(-1px);
}

.tw-mic-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #f1f5f9;
    color: var(--tw-primary);
    border: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.tw-mic-btn:hover {
    background: var(--tw-primary-light);
    color: var(--tw-primary-hover);
    border-color: var(--tw-primary-border);
    transform: scale(1.06);
}

.tw-mic-btn.active {
    background: var(--tw-primary);
    color: #ffffff;
    border-color: var(--tw-primary);
    box-shadow: 0 0 12px rgba(255, 120, 38, 0.5);
    animation: twMicPulse 1.5s infinite;
}

@keyframes twMicPulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 120, 38, 0.7); }
    70% { transform: scale(1.08); box-shadow: 0 0 0 8px rgba(255, 120, 38, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 120, 38, 0); }
}

/* Оверлей голосового звонка */
.tw-voice-overlay {
    position: absolute;
    top: 56px;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98) 0%, rgba(255, 248, 242, 0.98) 100%);
    backdrop-filter: blur(8px);
    z-index: 1000;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px 20px;
    animation: twFadeIn 0.25s ease;
    border-bottom-left-radius: var(--tw-radius);
    border-bottom-right-radius: var(--tw-radius);
}

.tw-voice-overlay.active {
    display: flex;
}

.tw-voice-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    width: 100%;
    max-width: 320px;
}

.tw-voice-avatar-wrap {
    position: relative;
    width: 90px;
    height: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}

.tw-voice-pulse {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: rgba(255, 120, 38, 0.2);
    animation: twVoicePulseRing 2s infinite ease-out;
    pointer-events: none;
}

@keyframes twVoicePulseRing {
    0% { transform: scale(0.9); opacity: 0.9; }
    50% { transform: scale(1.35); opacity: 0.3; }
    100% { transform: scale(1.6); opacity: 0; }
}

.tw-voice-avatar {
    width: 76px;
    height: 76px;
    border-radius: 50%;
    background: var(--tw-primary-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(255, 120, 38, 0.35);
    z-index: 2;
    transition: transform 0.2s ease;
}

.tw-voice-avatar.speaking {
    transform: scale(1.06);
    box-shadow: 0 10px 30px rgba(255, 120, 38, 0.55);
}

.tw-voice-title {
    font-size: 17px;
    font-weight: 700;
    color: var(--tw-text);
    margin-bottom: 6px;
}

.tw-voice-status {
    font-size: 13px;
    color: var(--tw-primary-hover);
    font-weight: 600;
    margin-bottom: 14px;
    padding: 4px 14px;
    border-radius: 12px;
    background: var(--tw-primary-light);
    display: inline-block;
    transition: all 0.2s ease;
}

.tw-voice-status.listening {
    color: #059669;
    background: #ecfdf5;
}

.tw-voice-status.speaking {
    color: #ea580c;
    background: #fff7ed;
}

.tw-voice-status.calling {
    color: #2563eb;
    background: #eff6ff;
}

/* Анимированная аудиоволна */
.tw-voice-waves {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 28px;
    margin-bottom: 16px;
}

.tw-voice-waves span {
    width: 4px;
    height: 8px;
    background: var(--tw-primary);
    border-radius: 2px;
    transition: height 0.15s ease;
}

.tw-voice-waves.speaking span {
    animation: twVoiceWaveBar 1s infinite ease-in-out;
}

.tw-voice-waves.speaking span:nth-child(1) { animation-delay: 0.1s; }
.tw-voice-waves.speaking span:nth-child(2) { animation-delay: 0.25s; }
.tw-voice-waves.speaking span:nth-child(3) { animation-delay: 0.4s; }
.tw-voice-waves.speaking span:nth-child(4) { animation-delay: 0.2s; }
.tw-voice-waves.speaking span:nth-child(5) { animation-delay: 0.35s; }

@keyframes twVoiceWaveBar {
    0%, 100% { height: 6px; }
    50% { height: 26px; }
}

.tw-voice-subtitles {
    font-size: 13px;
    line-height: 1.5;
    color: var(--tw-text-muted);
    background: #ffffff;
    border: 1px solid var(--tw-border);
    border-radius: 12px;
    padding: 12px 14px;
    width: 100%;
    min-height: 56px;
    max-height: 90px;
    overflow-y: auto;
    margin-bottom: 20px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.tw-voice-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

.tw-voice-btn-mute {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    color: #475569;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tw-voice-btn-mute:hover {
    background: #e2e8f0;
}

.tw-voice-btn-mute.muted {
    background: #fee2e2;
    color: #ef4444;
    border-color: #fca5a5;
}

.tw-voice-btn-hangup {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: #ef4444;
    border: none;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(239, 68, 68, 0.4);
    transition: all 0.2s ease;
}

.tw-voice-btn-hangup:hover {
    background: #dc2626;
    transform: scale(1.08);
    box-shadow: 0 6px 18px rgba(220, 38, 38, 0.55);
}

.tw-voice-btn-hangup:active {
    transform: scale(0.95);
}

