/* AI Chat Widget Styles */

/* Кнопка открытия чата */
.chat-widget-trigger {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary, #1a2744) 0%, var(--primary-light, #243b6a) 100%);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px var(--primary-glow, rgba(59, 130, 246, 0.3));
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 9998;
}

.chat-widget-trigger:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 30px var(--primary-glow, rgba(59, 130, 246, 0.4));
}

.chat-widget-trigger:active {
    transform: scale(0.95);
}

/* Ответ оператора пришёл, а виджет свёрнут — подсвечиваем, где ждёт ответ. */
.chat-widget-trigger.chat-attention {
    animation: chat-attention-pulse 1.4s ease-out 4;
}

@keyframes chat-attention-pulse {
    0%   { box-shadow: 0 4px 20px var(--primary-glow, rgba(59, 130, 246, 0.3)),
                       0 0 0 0 rgba(59, 130, 246, 0.55); }
    70%  { box-shadow: 0 4px 20px var(--primary-glow, rgba(59, 130, 246, 0.3)),
                       0 0 0 16px rgba(59, 130, 246, 0); }
    100% { box-shadow: 0 4px 20px var(--primary-glow, rgba(59, 130, 246, 0.3)),
                       0 0 0 0 rgba(59, 130, 246, 0); }
}

@media (prefers-reduced-motion: reduce) {
    .chat-widget-trigger.chat-attention { animation: none; }
}

.chat-widget-trigger .chat-icon {
    font-size: 28px;
    transition: all 0.3s ease;
}

.chat-widget-trigger.active .chat-icon {
    transform: rotate(90deg);
}

/* Бейдж с непрочитанными сообщениями */
.chat-widget-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 22px;
    height: 22px;
    background: #ef4444;
    border-radius: 50%;
    color: white;
    font-size: 12px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    display: none;
}

.chat-widget-badge.visible {
    display: flex;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* Контейнер чата */
.chat-widget {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 380px;
    max-height: 520px;
    background: var(--bg-card);
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.chat-widget.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Шапка чата */
.chat-widget-header {
    background: linear-gradient(135deg, var(--primary, #1a2744) 0%, var(--primary-light, #243b6a) 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-widget-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-widget-avatar {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.chat-widget-info h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.chat-widget-status {
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-widget-status::before {
    content: '';
    width: 8px;
    height: 8px;
    background: #4ade80;
    border-radius: 50%;
    animation: online-pulse 2s infinite;
}

@keyframes online-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.chat-widget-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: background 0.2s;
}

.chat-widget-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Область сообщений */
.chat-widget-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 280px;
    max-height: 320px;
    background: var(--bg-hover);
}

/* Сообщение */
.chat-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    animation: messageIn 0.3s ease;
}

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

.chat-message.bot {
    background: var(--bg-elevated);
    color: var(--text);
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.chat-message.user {
    background: linear-gradient(135deg, var(--primary-accent, #3b82f6) 0%, #6366f1 100%);
    color: white;
    border-bottom-right-radius: 4px;
    align-self: flex-end;
}

/* Время сообщения */
.chat-message-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 6px;
    display: block;
}

/* Индикатор набора */
.chat-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: var(--bg-elevated);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.chat-typing span {
    width: 8px;
    height: 8px;
    background: #9ca3af;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

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

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        background: #9ca3af;
    }
    30% {
        transform: translateY(-8px);
        background: var(--primary-accent, #3b82f6);
    }
}

/* Переключатель режима AI ↔ поддержка.
   Без своих стилей кнопка рисовалась браузером по умолчанию — белый прямоугольник
   поверх тёмной темы. */
.chat-mode-switcher {
    padding: 8px 16px 0;
    background: var(--bg-card);
    display: flex;
    justify-content: flex-start;
}

.chat-mode-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg-elevated);
    color: var(--text-secondary, #a0a0b8);
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 500;
    line-height: 1.2;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, border-color 0.2s, transform 0.15s;
}

.chat-mode-btn:hover {
    background: var(--bg-hover);
    color: var(--text);
    border-color: var(--primary-accent, #3b82f6);
    transform: translateY(-1px);
}

.chat-mode-btn:active {
    transform: translateY(0);
}

/* Форма ввода */
.chat-widget-input {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: var(--bg-card);
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.chat-widget-input textarea {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    min-height: 42px;
    max-height: 100px;
    background: var(--bg-input);
    color: var(--text);
    transition: border-color 0.2s, box-shadow 0.2s;
}

/* iOS zooms the whole page when a focused field is under 16px. The app already
   holds form inputs at 16px for exactly this reason; the chat box was the one
   left behind. */
@media (max-width: 768px) {
    .chat-widget-input textarea { font-size: 16px; }
}

.chat-widget-input textarea:focus {
    outline: none;
    border-color: var(--primary-accent, #3b82f6);
    box-shadow: 0 0 0 3px var(--primary-glow, rgba(59, 130, 246, 0.2));
}

.chat-widget-input textarea::placeholder {
    color: #9ca3af;
}

.chat-widget-send {
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, var(--primary-accent, #3b82f6) 0%, #6366f1 100%);
    border: none;
    border-radius: 12px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.2s;
    flex-shrink: 0;
}

.chat-widget-send:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 15px var(--primary-glow, rgba(59, 130, 246, 0.3));
}

.chat-widget-send:active {
    transform: scale(0.95);
}

.chat-widget-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Быстрые ответы */
.chat-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 16px;
    background: var(--bg-card);
}

.chat-quick-reply {
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text);
}

.chat-quick-reply:hover {
    background: var(--primary-accent, #3b82f6);
    color: white;
    border-color: var(--primary-accent, #3b82f6);
}

/* Мобильная адаптация */
@media (max-width: 480px) {
    .chat-widget {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-height: 100vh;
        border-radius: 16px 16px 0 0;
    }
    
    .chat-widget.open {
        bottom: 0;
    }
    
    .chat-widget-trigger {
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
    }
    
    .chat-widget-messages {
        max-height: calc(100vh - 200px);
    }
}

/* Dark theme overrides removed — base styles use CSS vars that work for both themes */
