/**
 * AI Assistant Widget Styles
 * Современный дизайн чат-виджета
 */

:root {
    --ai-primary: #0080b7;
    --ai-primary-dark: #006a9b;
    --ai-bg: #FFFFFF;
    --ai-bg-secondary: #F9FAFB;
    --ai-text: #111827;
    --ai-text-secondary: #6B7280;
    --ai-border: #E5E7EB;
    --ai-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    --ai-shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.15);
}

/* Кнопка открытия чата */
.ai-chat-button {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--ai-primary) 0%, var(--ai-primary-dark) 100%);
    border-radius: 50%;
    box-shadow: var(--ai-shadow);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9998;
    transition: all 0.3s ease;
}

.ai-chat-button:hover {
    transform: scale(1.1);
    box-shadow: var(--ai-shadow-lg);
}

.ai-chat-button svg {
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.ai-chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #EF4444;
    color: white;
    border-radius: 12px;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: 600;
    min-width: 20px;
    text-align: center;
}

/* Контейнер чата */
.ai-chat-container {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 400px;
    max-width: calc(100vw - 48px);
    height: 600px;
    max-height: calc(100vh - 140px);
    max-height: calc(100dvh - 140px); /* Динамическая высота viewport для iOS */
    background: var(--ai-bg);
    border-radius: 16px;
    box-shadow: var(--ai-shadow-lg);
    display: flex;
    flex-direction: column;
    z-index: 9999;
    overflow: hidden;
    animation: slideIn 0.3s ease;
}

/* Мобильные устройства */
@media (max-width: 768px) {
    .ai-chat-container {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: 100vh;
        height: 100dvh; /* Динамическая высота для iOS */
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
    }
    
    .ai-chat-button {
        bottom: 15%;
        right: 25px;
        width: 56px;
        height: 56px;
    }
}

/* Для iOS Safari - учитываем безопасные зоны */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .ai-chat-input-wrapper {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
    
    @media (max-width: 768px) {
        .ai-chat-container {
            padding-bottom: 0;
        }
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Заголовок чата */
.ai-chat-header {
    background: linear-gradient(135deg, var(--ai-primary) 0%, var(--ai-primary-dark) 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

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

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

.ai-chat-title {
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 2px;
}

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

.ai-status-indicator {
    width: 8px;
    height: 8px;
    background: #10B981;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

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

.ai-chat-actions {
    display: flex;
    gap: 8px;
}

.ai-btn-icon {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.ai-btn-icon:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Область сообщений */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--ai-bg-secondary);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.ai-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: #CBD5E1;
    border-radius: 3px;
}

/* Сообщение */
.ai-message {
    display: flex;
    gap: 10px;
    animation: messageIn 0.3s ease;
}

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

.ai-message-assistant {
    align-self: flex-start;
}

.ai-message-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.ai-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ai-message-user .ai-message-avatar {
    background: var(--ai-primary);
}

.ai-message-content {
    max-width: 75%;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ai-message-user .ai-message-content {
    align-items: flex-end;
}

.ai-message-text {
    background: white;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    color: var(--ai-text);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap; /* Сохраняем переносы строк и пробелы */
}

/* Форматирование текста в сообщениях */
.ai-message-text strong {
    font-weight: 600;
    color: var(--ai-primary);
}

/* Стили для вопросов от AI */
.ai-questions-container {
    margin: 8px 0;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid var(--ai-primary);
}

.ai-questions-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.ai-question-item {
    padding: 6px 0;
    font-size: 14px;
    line-height: 1.4;
    color: var(--ai-text);
    position: relative;
    padding-left: 20px;
}

.ai-question-item:before {
    content: "•";
    color: var(--ai-primary);
    font-weight: bold;
    position: absolute;
    left: 0;
}

.ai-message-text em {
    font-style: italic;
}

.ai-message-text br {
    display: block;
    content: "";
    margin: 0.5em 0;
}

.ai-message-text ul {
    margin: 8px 0;
    padding-left: 20px;
    list-style: none;
}

.ai-message-text li {
    margin: 4px 0;
    padding-left: 8px;
    position: relative;
}

.ai-message-text li:before {
    content: "•";
    position: absolute;
    left: -12px;
    color: var(--ai-primary);
    font-weight: bold;
}

.ai-message-text code {
    background: #f3f4f6;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
}

.ai-message-text a {
    color: var(--ai-primary);
    text-decoration: underline;
}

.ai-message-text a:hover {
    text-decoration: none;
}

.ai-message-user .ai-message-text {
    background: var(--ai-primary);
    color: white;
}

.ai-message-user .ai-message-text strong {
    color: white;
    font-weight: 700;
}

.ai-message-user .ai-message-text code {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.ai-message-user .ai-message-text a {
    color: white;
    text-decoration: underline;
}

.ai-message-time {
    font-size: 11px;
    color: var(--ai-text-secondary);
    padding: 0 4px;
}

/* Индикатор печатания */
.ai-typing-indicator .ai-typing-dots {
    background: white;
    padding: 16px 20px;
    border-radius: 12px;
    display: flex;
    gap: 6px;
}

.ai-typing-dots span {
    width: 8px;
    height: 8px;
    background: var(--ai-primary);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.ai-typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Карточка товара */
.ai-product-card {
    background: white;
    border-radius: 12px;
    padding: 12px;
    display: flex;
    gap: 12px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    margin-top: 8px;
    border: 1px solid var(--ai-border);
}

.ai-product-image {
    width: 80px;
    height: 80px;
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
    background: var(--ai-bg-secondary);
}

.ai-product-image a {
    display: block;
    width: 100%;
    height: 100%;
}

.ai-product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.2s;
}

.ai-product-image:hover img {
    transform: scale(1.05);
}

.ai-product-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ai-product-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--ai-text);
    line-height: 1.3;
}

.ai-product-name a {
    color: inherit;
    text-decoration: none;
}

.ai-product-name a:hover {
    color: var(--ai-primary);
}

.ai-product-characteristics {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 4px;
}

.ai-product-option {
    background: var(--ai-bg-secondary);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    color: var(--ai-text-secondary);
}

.ai-product-price {
    font-size: 16px;
    font-weight: 700;
    color: var(--ai-primary);
}

.ai-product-status {
    font-size: 12px;
    color: #10B981;
    font-weight: 500;
}

.ai-product-actions {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

.ai-btn-add-cart {
    background: var(--ai-primary);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    flex: 1;
}

.ai-btn-add-cart:hover {
    background: var(--ai-primary-dark);
}

.ai-btn-add-cart:disabled {
    background: var(--ai-border);
    cursor: not-allowed;
}

.ai-btn-view {
    background: transparent;
    color: var(--ai-primary);
    border: 1px solid var(--ai-primary);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s;
    text-align: center;
    flex: 1;
}

.ai-btn-view:hover {
    background: var(--ai-primary);
    color: white;
}


/* Поле ввода */
.ai-chat-input-container {
    background: white;
    border-top: 1px solid var(--ai-border);
    padding: 12px 20px;
    flex-shrink: 0;
}

.ai-recording-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    background: #FEF3C7;
    border-radius: 8px;
    margin-bottom: 12px;
    color: #92400E;
    font-size: 14px;
}

.ai-recording-animation {
    display: flex;
    gap: 4px;
}

.ai-recording-animation span {
    width: 4px;
    height: 16px;
    background: #F59E0B;
    border-radius: 2px;
    animation: recording 0.8s infinite;
}

.ai-recording-animation span:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-recording-animation span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes recording {
    0%, 100% {
        height: 12px;
    }
    50% {
        height: 20px;
    }
}

.ai-chat-input-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    padding-bottom: env(safe-area-inset-bottom, 0px); /* Безопасная зона iOS */
}

.ai-btn-voice {
    width: 40px;
    height: 40px;
    background: var(--ai-bg-secondary);
    border: 1px solid var(--ai-border);
    border-radius: 10px;
    color: var(--ai-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.ai-btn-voice:hover {
    background: var(--ai-primary);
    color: white;
    border-color: var(--ai-primary);
}

.ai-btn-voice.recording {
    background: #EF4444;
    color: white;
    border-color: #EF4444;
    animation: pulseButton 1s infinite;
}

.ai-btn-voice.playing {
    background: #10B981;
    color: white;
    border-color: #10B981;
    animation: soundWave 1.2s ease-in-out infinite;
}

@keyframes pulseButton {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

@keyframes soundWave {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    }
    25% {
        transform: scale(1.05);
        box-shadow: 0 0 0 5px rgba(16, 185, 129, 0.5);
    }
    50% {
        transform: scale(1.1);
        box-shadow: 0 0 0 10px rgba(16, 185, 129, 0.3);
    }
    75% {
        transform: scale(1.05);
        box-shadow: 0 0 0 5px rgba(16, 185, 129, 0.5);
    }
}

.ai-chat-input {
    flex: 1;
    border: 1px solid var(--ai-border);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 100px;
    overflow-y: auto;
    transition: border-color 0.2s;
}

.ai-chat-input:focus {
    outline: none;
    border-color: var(--ai-primary);
}

.ai-btn-send {
    width: 40px;
    height: 40px;
    background: var(--ai-primary);
    border: none;
    border-radius: 10px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

.ai-btn-send:hover {
    background: var(--ai-primary-dark);
}

.ai-btn-send:disabled {
    background: var(--ai-border);
    cursor: not-allowed;
}

.ai-chat-footer-text {
    text-align: center;
    font-size: 11px;
    color: var(--ai-text-secondary);
    margin-top: 8px;
}

/* Мобильная адаптация */
@media (max-width: 768px) {
    .ai-chat-container {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
    }

    .ai-chat-button {
        bottom: 15%;
        right: 25px;
        width: 56px;
        height: 56px;
        box-shadow: 0px 0px 3px #000;
    }
}

/* Вспомогательные классы */
.ai-hidden {
    display: none !important;
}

.ai-loading {
    opacity: 0.6;
    pointer-events: none;
}

