/* design/chat.css */

/* Базовый контейнер чата (десктоп по умолчанию) */
#chat-window {
    position: fixed;
    bottom: 60px;
    right: 40px;
    z-index: 1000;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

/* Иконка чата (свернутое состояние) */
#chat-window .chat-icon {
    font-size: 36px;
    -webkit-text-stroke: 0.5px black;
    text-shadow: 0 0 1px black;
}

/* Пульсирующий текст (если используется) */
.pulsating-text {
    font-size: 24px;
    font-weight: bold;
    color: #ff3b3b;
    animation: pulse-text 1.5s infinite alternate;
}

@keyframes pulse-text {
    0% {
        transform: scale(1);
        opacity: 0.7;
    }
    100% {
        transform: scale(1.1);
        opacity: 1;
    }
}

/* Свернутая круглая плашка */
#chat-window .chat-minimized {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 70px;
    height: 70px;
    background: linear-gradient(45deg, #007bff, #00c6ff);
    color: #fff;
    border-radius: 50%;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
    font-size: 30px;
    position: relative;
    animation: pulse-icon 2s infinite;
}

@keyframes pulse-icon {
    0% {
        box-shadow: 0 0 0 0 rgba(0, 123, 255, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(0, 123, 255, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(0, 123, 255, 0);
    }
}

/* Call-to-action текст под кружком */
#chat-window .chat-call-to-action {
    position: absolute;
    bottom: -28px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 12px;
    font-weight: bold;
    color: #007bff;
    background: #fff;
    padding: 2px 6px;
    border-radius: 3px;
    white-space: nowrap;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* Развернутое состояние: окно чата (десктоп) */
#chat-window.active {
    width: 360px;
    height: 500px;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    cursor: default;
}

/* При активном состоянии скрываем свернутую плашку */
#chat-window.active .chat-minimized {
    display: none;
}

/* Содержимое активного окна */
#chat-window .chat-content {
    display: none;
    height: 100%;
    flex-direction: column;
}

#chat-window.active .chat-content {
    display: flex;
}

/* Шапка чата */
.chat-header {
    background: #007bff;
    color: #fff;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
}

/* Заголовок */
.chat-title {
    font-size: 18px;
    font-weight: bold;
}

/* Кнопка сворачивания (иконка "×") */
.chat-toggle {
    cursor: pointer;
    font-size: 24px;
}

/* Основной фон окна чата и область сообщений */
.chat-body {
    padding: 15px;
    flex: 1;
    overflow-y: auto;
    background: #e5ddd5; /* как в Telegram/WhatsApp */
}

/* Контейнер сообщений */
.chat-messages {
    position: relative;
}

/* Стили сообщений */
.chat-message {
    margin: 10px;
    padding: 10px 15px;
    border-radius: 20px;
    max-width: 70%;
    clear: both;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
}

/* Сообщения ассистента (влево) */
.chat-message.assistant {
    background-color: #fff;
    border: 1px solid #ccc;
    float: left;
}

/* Сообщения пользователя (вправо) */
.chat-message.user {
    background-color: #dcf8c6;
    border: 1px solid #b2d8b2;
    float: right;
}

/* Для корректного очищения float */
.chat-messages::after {
    content: "";
    display: table;
    clear: both;
}

/* Область ввода сообщений */
.chat-input {
    display: flex;
    align-items: center;
    border-top: 1px solid #ccc;
    padding: 10px;
    background: #fff;
}

/* Поле ввода (десктоп) */
.chat-input input,
.chat-input textarea {
    flex: 1;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
    outline: none;
}

/* Кнопка отправки – треугольный значок */
.send-button {
    width: 40px;
    height: 40px;
    margin-left: 8px;
    background: linear-gradient(135deg, #007bff, #00c6ff);
    border: none;
    outline: none;
    -webkit-clip-path: polygon(20% 0%, 100% 50%, 20% 100%, 0% 50%);
    clip-path: polygon(20% 0%, 100% 50%, 20% 100%, 0% 50%);
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    cursor: pointer;
}

.send-button:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}

/* Кнопка "Оформить заказ" */
.order-button {
    background-color: #007bff;
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 5px 10px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.3s;
}

.order-button:hover {
    background-color: #005bb5;
}

/* Кнопка "Админ в чат" (если используется) */
.admin-takeover-button {
    background-color: #ff5722;
    color: #fff;
    border: none;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.admin-takeover-button:hover {
    background-color: #e64a19;
}

/* ===========================
   МОБИЛЬНАЯ АДАПТАЦИЯ
   =========================== */

/* Мобильный виджет не используется — JS всегда берёт #chat-window */
#chat-window-mobile {
    display: none !important;
}

@media only screen and (max-width: 768px) {

    /* Свернутое состояние чата — маленький круг справа снизу */
    #chat-window {
        position: fixed;
        right: 25px;
        bottom: 25px;
        left: auto;
        width: 70px;
        height: 70px;
        border-radius: 50%;
        z-index: 1000;
        cursor: pointer;
        transition: all 0.3s ease;
        box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
    }

    #chat-window .chat-minimized {
        width: 70px;
        height: 70px;
        font-size: 30px;
    }

    /* Развернутое состояние — полный экран */
    #chat-window.active {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
        box-shadow: none;
        transition: none;
        z-index: 65100;
    }

    #chat-window.active .chat-content {
        display: flex;
        flex-direction: column;
        height: 100%;
    }

    /* Шапка чата на мобиле */
    #chat-window.active .chat-header {
        padding: 10px;
        font-size: 16px;
        border-radius: 0;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    /* Кнопки в шапке на мобиле */
    #chat-window.active .chat-header .chat-controls {
        display: flex;
        gap: 6px;
        align-items: center;
        flex-shrink: 0;
    }

    #chat-window.active .chat-header .chat-btn {
        width: 32px;
        height: 32px;
        font-size: 16px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Область сообщений — занимает всё свободное место */
    #chat-window.active .chat-body {
        padding: 10px;
        overflow-y: auto;
        background: #e5ddd5;
        flex: 1;
        min-height: 0;
    }

    /* Область ввода на мобиле */
    #chat-window.active .chat-input {
        padding: 8px;
        padding-bottom: max(8px, env(safe-area-inset-bottom, 8px));
        border-top: 1px solid #ccc;
        background: #fff;
        flex-shrink: 0;
    }

    #chat-window.active .chat-input input,
    #chat-window.active .chat-input textarea {
        width: 100%;
        margin: 0;
        padding: 10px;
        border: 1px solid #ccc;
        border-radius: 4px;
        font-size: 14px;
        box-sizing: border-box;
    }

    /* Кнопка отправки на мобилках — чуть больше и с анимацией */
    .send-button {
        width: 45px;
        height: 45px;
        margin-left: 8px;
        background: linear-gradient(135deg, #007bff, #00c6ff);
        border: none;
        outline: none;
        -webkit-clip-path: polygon(20% 0%, 100% 50%, 20% 100%, 0% 50%);
        clip-path: polygon(20% 0%, 100% 50%, 20% 100%, 0% 50%);
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
        animation: pulseMobile 2s infinite;
        transition: transform 0.3s ease, box-shadow 0.3s ease;
    }

    .send-button:hover {
        transform: scale(1.08);
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
    }

    @keyframes pulseMobile {
        0% {
            box-shadow: 0 0 0 0 rgba(0, 123, 255, 0.7);
        }
        70% {
            box-shadow: 0 0 0 8px rgba(0, 123, 255, 0);
        }
        100% {
            box-shadow: 0 0 0 0 rgba(0, 123, 255, 0);
        }
    }
}
/* ========== МЕДИА-КНОПКИ (ДЕСКТОП) ========== */
.chat-input {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    background: #fff;
    border-top: 1px solid #e0e0e0;
}

.media-btn {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    font-size: 18px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.media-btn:hover {
    background: #f5f5f5;
    border-color: #20b2aa;
}

.media-btn:active {
    transform: scale(0.95);
}

/* Когда идёт запись голоса */
.media-btn.recording {
    background: #ff4444;
    border-color: #ff4444;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(255, 68, 68, 0.7);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(255, 68, 68, 0);
    }
}

#chat-message {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    outline: none;
}

#chat-message:focus {
    border-color: #20b2aa;
}

.send-button {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    background: #20b2aa url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="white" viewBox="0 0 16 16"><path d="M15.854.146a.5.5 0 0 1 .11.54l-5.819 14.547a.75.75 0 0 1-1.329.124l-3.178-4.995L.643 7.184a.75.75 0 0 1 .124-1.33L15.314.037a.5.5 0 0 1 .54.11ZM6.636 10.07l2.761 4.338L14.13 2.576 6.636 10.07Zm6.787-8.201L1.591 6.602l4.339 2.76 7.494-7.493Z"/></svg>') no-repeat center;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.send-button:hover {
    background-color: #1a9a93;
}

.send-button:active {
    transform: scale(0.95);
}

/* ========== МЕДИА-КНОПКИ (МОБИЛЬНАЯ ВЕРСИЯ) ========== */
.chat-input-mobile {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px;
    background: #fff;
    border-top: 1px solid #e0e0e0;
}

.media-btn-mobile {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.media-btn-mobile:hover {
    background: #f5f5f5;
    border-color: #20b2aa;
}

.media-btn-mobile:active {
    transform: scale(0.95);
}

.media-btn-mobile.recording {
    background: #ff4444;
    border-color: #ff4444;
    animation: pulse 1s infinite;
}

#chat-message-mobile {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    outline: none;
}

#chat-message-mobile:focus {
    border-color: #20b2aa;
}

.send-button-mobile {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    background: #20b2aa url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="white" viewBox="0 0 16 16"><path d="M15.854.146a.5.5 0 0 1 .11.54l-5.819 14.547a.75.75 0 0 1-1.329.124l-3.178-4.995L.643 7.184a.75.75 0 0 1 .124-1.33L15.314.037a.5.5 0 0 1 .54.11ZM6.636 10.07l2.761 4.338L14.13 2.576 6.636 10.07Zm6.787-8.201L1.591 6.602l4.339 2.76 7.494-7.493Z"/></svg>') no-repeat center;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.send-button-mobile:hover {
    background-color: #1a9a93;
}

.send-button-mobile:active {
    transform: scale(0.95);
}

/* ========== СТИЛИ ДЛЯ ПРЕВЬЮ ИЗОБРАЖЕНИЙ ========== */
.chat-messages img,
.chat-messages-mobile img {
    max-width: 100%;
    max-height: 200px;
    border-radius: 8px;
    margin: 4px 0;
    cursor: pointer;
}

/* Индикатор загрузки */
.loading-indicator {
    display: inline-block;
    padding: 8px 12px;
    background: #f0f0f0;
    border-radius: 6px;
    color: #666;
    font-size: 13px;
}

.loading-indicator::after {
    content: '...';
    animation: dots 1.5s infinite;
}

@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}
/* Плавное появление/исчезновение кнопок */
#voice-btn, #chat-send {
    transition: opacity 0.2s ease, transform 0.2s ease;
}

#voice-btn[style*="display: none"],
#chat-send[style*="display: none"] {
    opacity: 0;
    transform: scale(0.8);
    pointer-events: none;
}

#voice-btn[style*="display: block"],
#chat-send[style*="display: block"] {
    opacity: 1;
    transform: scale(1);
}

/* ========== ДОПОЛНИТЕЛЬНЫЕ СТИЛИ ДЛЯ НОВЫХ ФУНКЦИЙ ========== */

/* Кнопка очистки истории в шапке */
.chat-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.chat-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Typing indicator (три точки) */
.typing-message {
    animation: slideIn 0.3s ease;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 12px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #999;
    animation: typingDot 1.4s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingDot {
    0%, 60%, 100% {
        opacity: 0.3;
        transform: scale(0.8);
    }
    30% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Быстрые ответы */
.quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.quick-reply-btn {
    background: white;
    border: 1px solid #667eea;
    color: #667eea;
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.quick-reply-btn:hover {
    background: #667eea;
    color: white;
}

/* Индикатор записи голоса */
.recording-indicator {
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
    background: #ff4444;
    color: white;
    padding: 12px 20px;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 4px 16px rgba(255, 68, 68, 0.4);
    display: none;
    align-items: center;
    gap: 10px;
    z-index: 10001;
}

.recording-indicator.active {
    display: flex;
}

.wave {
    display: flex;
    gap: 2px;
}

.wave-bar {
    width: 3px;
    height: 12px;
    background: white;
    border-radius: 2px;
    animation: waveAnim 0.6s infinite ease-in-out;
}

.wave-bar:nth-child(2) {
    animation-delay: 0.1s;
}

.wave-bar:nth-child(3) {
    animation-delay: 0.2s;
}

.wave-bar:nth-child(4) {
    animation-delay: 0.3s;
}

@keyframes waveAnim {
    0%, 100% {
        height: 8px;
    }
    50% {
        height: 16px;
    }
}

/* Превью фото */
.photo-preview-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 10002;
    display: none;
    align-items: center;
    justify-content: center;
}

.photo-preview-overlay.active {
    display: flex;
}

.photo-preview-content {
    background: white;
    border-radius: 16px;
    padding: 20px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.photo-preview-image {
    width: 100%;
    max-height: 400px;
    object-fit: contain;
    border-radius: 12px;
    margin-bottom: 16px;
    background: #f0f0f0;
}

.photo-preview-actions {
    display: flex;
    gap: 12px;
}

.preview-btn {
    flex: 1;
    padding: 12px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s;
}

.preview-btn-cancel {
    background: #f0f0f0;
    color: #333;
}

.preview-btn-cancel:hover {
    background: #e0e0e0;
}

.preview-btn-send {
    background: #667eea;
    color: white;
}

.preview-btn-send:hover {
    background: #5568d3;
}

/* Markdown форматирование */
.chat-bubble strong {
    font-weight: 600;
    color: inherit;
}

.chat-bubble em {
    font-style: italic;
}

.chat-bubble ul {
    margin: 8px 0;
    padding-left: 20px;
}

.chat-bubble li {
    margin: 4px 0;
    list-style-type: disc;
}

/* Аватарки */
.chat-message {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.chat-message.user {
    flex-direction: row-reverse;
}

.chat-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.chat-message.user .chat-avatar {
    background: #667eea;
}

.chat-message.assistant .chat-avatar {
    background: #764ba2;
}

.chat-bubble {
    flex: 1;
    max-width: 80%;
}

/* Карточка товара */
.product-card {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
    margin: 8px 0;
    max-width: 280px;
}

.product-card-image {
    width: 100%;
    height: 180px;
    object-fit: cover;
    background: #f0f0f0;
}

.product-card-body {
    padding: 12px;
}

.product-card-title {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 6px;
    color: #333;
}

.product-card-price {
    font-size: 18px;
    font-weight: 700;
    color: #667eea;
    margin-bottom: 10px;
}

.product-card-actions {
    display: flex;
    gap: 8px;
}

.product-btn {
    flex: 1;
    padding: 8px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.product-btn-primary {
    background: #667eea;
    color: white;
}

.product-btn-primary:hover {
    background: #5568d3;
}

.product-btn-secondary {
    background: #f0f0f0;
    color: #333;
}

.product-btn-secondary:hover {
    background: #e0e0e0;
}

/* Анимация появления сообщений */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message {
    animation: slideIn 0.3s ease;
}

.chat-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.chat-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.chat-btn-telegram {
    background: #28a8ea;
}

.chat-btn-telegram:hover {
    background: #1c90d4;
}

.chat-btn-telegram-icon {
    width: 18px;
    height: 18px;
    fill: #ffffff;
}
