/* AI Chat Widget Styles - Стильный дизайн */

*, *::before, *::after {
    box-sizing: border-box;
}

:root {
    --chat-primary: #248A52;
    --chat-primary-alt: #257287;
    --chat-bg-overlay: rgba(0, 0, 0, 0.5);
    --chat-header-bg: rgba(0, 0, 0, 0.2);
    --chat-message-bg: rgba(0, 0, 0, 0.3);
    --chat-input-bg: rgba(0, 0, 0, 0.3);
    --chat-text: rgba(255, 255, 255, 0.95);
    --chat-text-bright: #fff;
    --chat-shadow: 0 0 15px 5px rgba(0, 0, 0, 0.2);
    --chat-transition: all 0.3s ease;
}

/* Основной контейнер виджета */
.ai-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 100000;
    font-family: 'Open Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    pointer-events: none; /* не блокируем элементы под виджетом, пока он закрыт */
}

.ai-chat-widget .chat-toggle-btn {
    pointer-events: auto; /* кнопка всегда кликабельна */
}

.ai-chat-widget.chat-open {
    pointer-events: auto; /* при открытом чате весь виджет снова интерактивный */
}

/* Кнопка открытия/закрытия чата */
.chat-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-alt));
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--chat-shadow);
    transition: var(--chat-transition);
    color: white;
}

.chat-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 0 25px 8px rgba(0, 0, 0, 0.3);
}

.chat-toggle-btn:active {
    transform: scale(0.95);
}

/* Окно чата */
.chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 400px;
    height: 80vh;
    height: 80dvh; /* Dynamic viewport height для поддержки клавиатуры */
    max-height: 500px;
    background: var(--chat-bg-overlay);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 20px;
    box-shadow: var(--chat-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: chatSlideUp 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes chatSlideUp {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.85);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes chatSlideDown {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateY(30px) scale(0.85);
    }
}

/* Анимация закрытия */
.chat-window.closing {
    animation: chatSlideDown 0.3s ease forwards;
}

/* Заголовок чата */
.chat-header {
    flex: 0 0 65px;
    background: var(--chat-header-bg);
    color: var(--chat-text-bright);
    padding: 10px 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
    z-index: 2;
}

.chat-header-content {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    padding-left: 40px;
}

.chat-header-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.24);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.chat-header-icon img {
    width: 130%;
    height: 100%;
    object-fit: cover;
}

.chat-header-text {
    flex: 1;
}

.chat-header-text h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--chat-text-bright);
}

.chat-status {
    font-size: 10px;
    letter-spacing: 1px;
    display: block;
    margin-top: 2px;
    color: rgba(255, 255, 255, 0.5);
    text-transform: uppercase;
}

.chat-status.online {
    color: #5a8;
}

.chat-status.offline {
    color: #e74c3c;
}

.chat-close-btn {
    background: transparent;
    border: none;
    color: var(--chat-text-bright);
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: var(--chat-transition);
}

.chat-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Область сообщений */
.chat-messages {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 15px;
    position: relative;
    color: var(--chat-text);
}

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

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

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Сообщение */
.message {
    clear: both;
    margin: 8px 0 20px 0;
    position: relative;
    animation: messageAppear 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes messageAppear {
    0% {
        transform: scale(0) translateY(10px);
        opacity: 0;
    }
    50% {
        transform: scale(1.05) translateY(-2px);
    }
    100% {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

.message-avatar {
    position: absolute;
    top: 0;
    left: 0;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.24);
    overflow: hidden;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.message-avatar img {
    width: 130%;
    height: 100%;
    object-fit: cover;
    position: absolute;
    left: -2px;
}

.message-avatar svg {
    width: 18px;
    height: 18px;
    color: var(--chat-text-bright);
}

.message-content {
    float: left;
    padding: 8px 12px;
    border-radius: 0 10px 10px 10px;
    background: var(--chat-message-bg);
    margin-left: 40px;
    max-width: 75%;
    font-size: 14px;
    line-height: 1.4;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
    position: relative;
    word-wrap: break-word;
}

.message-content::before {
    content: '';
    position: absolute;
    top: 0;
    left: -6px;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-right: 6px solid var(--chat-message-bg);
}

.message-content p {
    margin: 0;
    color: var(--chat-text);
}

/* Timestamp */
.message .timestamp {
    position: absolute;
    bottom: -18px;
    left: 40px;
    font-size: 9px;
    color: rgba(255, 255, 255, 0.3);
}

/* Сообщение пользователя */
.user-message {
    text-align: right;
}

.user-message .message-avatar {
    left: auto;
    right: 0;
    background: linear-gradient(120deg, var(--chat-primary), var(--chat-primary-alt));
}

.user-message .message-content {
    float: right;
    margin-left: 0;
    margin-right: 40px;
    background: linear-gradient(120deg, var(--chat-primary), var(--chat-primary-alt));
    border-radius: 10px 0 10px 10px;
}

.user-message .message-content::before {
    left: auto;
    right: -6px;
    top: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-left: 6px solid var(--chat-primary-alt);
}

.user-message .message-content p {
    color: var(--chat-text-bright);
}

.user-message .timestamp {
    left: auto;
    right: 40px;
}

/* Assistant message */
.assistant-message .message-avatar {
    background: var(--chat-message-bg);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Индикатор печатания */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) {
    animation-delay: 0s;
}

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

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

@keyframes typingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

/* Рекомендации услуг */
.service-recommendations {
    padding: 12px 15px;
    background: rgba(0, 0, 0, 0.4);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    max-height: 150px;
    overflow-y: auto;
}

.service-recommendation-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: var(--chat-transition);
    text-decoration: none;
    color: var(--chat-text);
}

.service-recommendation-item:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateX(4px);
}

.service-recommendation-item:last-child {
    margin-bottom: 0;
}

.service-rec-image {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 6px;
}

.service-rec-content {
    flex: 1;
}

.service-rec-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--chat-text-bright);
    margin: 0 0 2px 0;
}

.service-rec-desc {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Message Box */
.chat-input-container {
    flex: 0 0 60px;
    background: var(--chat-input-bg);
    padding: 10px 15px;
    position: relative;
}

.chat-form {
    display: flex;
    gap: 10px;
    align-items: center;
}

.chat-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    resize: none;
    color: rgba(255, 255, 255, 0.7);
    font-size: 16px;
    font-family: inherit;
    height: 40px;
    max-height: 80px;
    padding: 10px;
    line-height: 1.4;
    touch-action: manipulation;
    -webkit-text-size-adjust: 100%;
}

.chat-input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.chat-input:focus {
    color: var(--chat-text-bright);
}

.chat-send-btn {
    background: rgb(34, 170, 255);
    border: none;
    color: var(--chat-text-bright);
    font-size: 12px;
    text-transform: uppercase;
    padding: 10px 15px;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s ease;
    outline: none;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
}

.chat-send-btn:hover:not(:disabled) {
    background: #5a8;
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-input-hint {
    position: absolute;
    bottom: 2px;
    right: 70px;
    font-size: 10px;
    color: rgba(255, 255, 255, 0.3);
}

/* Мобильная адаптация */
@media (max-width: 768px) {
    .ai-chat-widget {
        bottom: 10px;
        right: 10px;
        left: 10px;
        top: 10px;
    }

    .chat-window {
        width: 100%;
        max-width: 100%;
        height: calc(100vh - 90px);
        height: calc(100dvh - 90px); /* Dynamic viewport height */
        max-height: none;
        right: auto;
        left: 0;
        bottom: 80px;
        top: 10px;
    }

    .chat-toggle-btn {
        width: 56px;
        height: 56px;
        position: absolute;
        right: 0;
        bottom: 0;
    }
}

@media (max-width: 480px) {
    .chat-window {
        height: calc(100vh - 90px);
        height: calc(100dvh - 90px); /* Dynamic viewport height */
        bottom: 80px;
        top: 10px;
    }

    .message-content {
        max-width: 70%;
    }

    .chat-input {
        font-size: 16px;
    }

    /* Предотвращаем зум при фокусе на input */
    .chat-input:focus {
        font-size: 16px;
    }
}

/* Когда клавиатура открыта на мобилке */
.chat-window.keyboard-open {
    position: fixed !important;
    left: 10px !important;
    right: 10px !important;
    width: calc(100% - 20px) !important;
}

/* Специально для Android - прижимаем к верху */
@media (max-width: 768px) {
    .chat-window.keyboard-open {
        top: 10px !important;
        bottom: auto !important;
    }
}

/* ============================================
   Markdown стили для AI-сообщений
   ============================================ */

/* Параграфы */
.message-content p {
    margin: 0 0 8px 0;
    line-height: 1.5;
}

.message-content p:last-child {
    margin-bottom: 0;
}

/* Жирный текст */
.message-content strong {
    font-weight: 600;
    color: var(--chat-text-bright);
}

/* Курсив */
.message-content em {
    font-style: italic;
}

/* Ссылки */
.message-content a {
    color: #5a8;
    text-decoration: underline;
    transition: color 0.2s ease;
}

.message-content a:hover {
    color: #6bc;
}

/* Списки */
.message-content ul,
.message-content ol {
    margin: 8px 0;
    padding-left: 20px;
}

.message-content li {
    margin: 4px 0;
    line-height: 1.4;
}

.message-content ul {
    list-style-type: disc;
}

.message-content ol {
    list-style-type: decimal;
}

/* Инлайн код */
.message-content code {
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    color: var(--chat-text-bright);
}

/* Блок кода */
.message-content pre {
    background: rgba(0, 0, 0, 0.4);
    padding: 10px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
}

.message-content pre code {
    background: none;
    padding: 0;
}

/* Цитаты */
.message-content blockquote {
    border-left: 3px solid rgba(255, 255, 255, 0.3);
    padding-left: 12px;
    margin: 8px 0;
    font-style: italic;
    color: rgba(255, 255, 255, 0.7);
}

/* Горизонтальная линия */
.message-content hr {
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    margin: 12px 0;
}

/* Заголовки */
.message-content h1,
.message-content h2,
.message-content h3 {
    color: var(--chat-text-bright);
    margin: 12px 0 8px 0;
    font-weight: 600;
}

.message-content h1 {
    font-size: 18px;
}

.message-content h2 {
    font-size: 16px;
}

.message-content h3 {
    font-size: 15px;
}
