/**
 * Chatbot DeepSeek Support — Стили виджета
 * Использует CSS Custom Properties из wp_add_inline_style
 */

/* ── Переменные по умолчанию ──────────────────────────────── */
:root {
    --cds-primary: #0073aa;
    --cds-bg: #ffffff;
    --cds-user-msg-bg: #0073aa;
    --cds-bot-msg-bg: #f0f0f0;
    --cds-text: #333333;
    --cds-input-bg: #f9f9f9;
    --cds-font-family: inherit;
    --cds-font-size: 14px;
    --cds-border-radius: 12px;
    --cds-widget-width: 380px;
    --cds-widget-height: 520px;
    --cds-offset-x: 20px;
    --cds-offset-y: 20px;
}

/* ── Inline-режим ────────────────────────────────────────── */
.cds-chat-inline-container {
    width: 100%;
    max-width: var(--cds-widget-width);
    margin: 0 auto;
}

.cds-chat-inline-mode {
    position: relative !important;
    width: 100% !important;
    height: var(--cds-widget-height) !important;
    border-radius: var(--cds-border-radius) !important;
    border: 1px solid #e0e0e0;
    box-shadow: 0 2px 12px rgba(0,0,0,0.1) !important;
}

/* ── Popup-контейнер ─────────────────────────────────────── */
.cds-chat-popup-container {
    position: fixed;
    z-index: 999998;
    font-family: var(--cds-font-family);
    font-size: var(--cds-font-size);
}

.cds-chat-popup-container[data-position="bottom-right"] {
    right: var(--cds-offset-x);
    bottom: var(--cds-offset-y);
}
.cds-chat-popup-container[data-position="bottom-left"] {
    left: var(--cds-offset-x);
    bottom: var(--cds-offset-y);
}
.cds-chat-popup-container[data-position="top-right"] {
    right: var(--cds-offset-x);
    top: var(--cds-offset-y);
}
.cds-chat-popup-container[data-position="top-left"] {
    left: var(--cds-offset-x);
    top: var(--cds-offset-y);
}

/* ── Кнопка запуска ──────────────────────────────────────── */
.cds-chat-button {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--cds-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    transition: transform 0.2s, box-shadow 0.2s;
    z-index: 999999;
    padding: 12px;
}

.cds-chat-button:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}

.cds-chat-button-icon {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: brightness(0) invert(1);
}

/* ── Bubble Tooltip ──────────────────────────────────────── */
.cds-chat-tooltip {
    position: absolute;
    width: 220px;
    padding: 10px 14px;
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    font-size: 13px;
    line-height: 1.4;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
    z-index: 1;
}

/* Позиция tooltip зависит от data-position контейнера */
.cds-chat-popup-container[data-position="bottom-right"] .cds-chat-tooltip,
.cds-chat-popup-container[data-position="bottom-left"] .cds-chat-tooltip {
    bottom: 70px;
}
.cds-chat-popup-container[data-position="bottom-right"] .cds-chat-tooltip {
    right: 0;
}
.cds-chat-popup-container[data-position="bottom-left"] .cds-chat-tooltip {
    left: 0;
}
.cds-chat-popup-container[data-position="top-right"] .cds-chat-tooltip,
.cds-chat-popup-container[data-position="top-left"] .cds-chat-tooltip {
    top: 70px;
}
.cds-chat-popup-container[data-position="top-right"] .cds-chat-tooltip {
    right: 0;
}
.cds-chat-popup-container[data-position="top-left"] .cds-chat-tooltip {
    left: 0;
}

/* Текст tooltip */
.cds-tooltip-text {
    display: block;
}

/* Стрелка — реальный span, не псевдоэлемент */
.cds-tooltip-arrow {
    position: absolute;
    width: 12px;
    height: 12px;
    background: inherit;
    transform: rotate(45deg);
    z-index: -1;
}

.cds-chat-popup-container[data-position="bottom-right"] .cds-tooltip-arrow,
.cds-chat-popup-container[data-position="bottom-left"] .cds-tooltip-arrow {
    bottom: -5px;
}
.cds-chat-popup-container[data-position="bottom-right"] .cds-tooltip-arrow {
    right: 24px;
}
.cds-chat-popup-container[data-position="bottom-left"] .cds-tooltip-arrow {
    left: 24px;
}
.cds-chat-popup-container[data-position="top-right"] .cds-tooltip-arrow,
.cds-chat-popup-container[data-position="top-left"] .cds-tooltip-arrow {
    top: -5px;
}
.cds-chat-popup-container[data-position="top-right"] .cds-tooltip-arrow {
    right: 24px;
}
.cds-chat-popup-container[data-position="top-left"] .cds-tooltip-arrow {
    left: 24px;
}

.cds-chat-tooltip.visible {
    opacity: 1;
    transform: translateY(0);
}

/* ── Виджет чата (popup) ─────────────────────────────────── */
.cds-chat-popup-widget {
    position: absolute;
    bottom: 70px;
    width: var(--cds-widget-width);
    height: var(--cds-widget-height);
    background: var(--cds-bg);
    border-radius: var(--cds-border-radius);
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 999997;
}

/* ПОЗИЦИЯ ВИДЖЕТА: правые углы — right, левые углы — left */
.cds-chat-popup-container[data-position="bottom-right"] .cds-chat-popup-widget,
.cds-chat-popup-container[data-position="top-right"] .cds-chat-popup-widget {
    right: 0;
}
.cds-chat-popup-container[data-position="bottom-left"] .cds-chat-popup-widget,
.cds-chat-popup-container[data-position="top-left"] .cds-chat-popup-widget {
    left: 0;
}

/* TOP-позиции: виджет над кнопкой */
.cds-chat-popup-container[data-position="top-right"] .cds-chat-popup-widget,
.cds-chat-popup-container[data-position="top-left"] .cds-chat-popup-widget {
    top: 70px;
    bottom: auto;
}

.cds-chat-popup-widget.open {
    display: flex;
    animation: cds-slideUp 0.3s ease;
}

@keyframes cds-slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Шапка виджета ───────────────────────────────────────── */
.cds-chat-header {
    background: var(--cds-primary);
    color: #fff;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    gap: 8px;
}

.cds-chat-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.cds-chat-header-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 2px solid rgba(255,255,255,0.5);
}

.cds-chat-header-title {
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cds-chat-header-actions {
    display: flex;
    gap: 8px;
}

.cds-chat-close {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 16px;
    padding: 2px 6px;
    border-radius: 4px;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.cds-chat-close:hover {
    opacity: 1;
}

/* ── Область сообщений ───────────────────────────────────── */
.cds-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

.cds-chat-messages::-webkit-scrollbar {
    width: 5px;
}
.cds-chat-messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 10px;
}

/* ── Приветствие ─────────────────────────────────────────── */
.cds-chat-greeting .cds-msg-content {
    background: var(--cds-bot-msg-bg);
    color: var(--cds-text);
    border-radius: var(--cds-border-radius);
    border-bottom-left-radius: 4px;
    padding: 10px 14px;
    font-size: var(--cds-font-size);
    line-height: 1.5;
}

/* ── Сообщения ───────────────────────────────────────────── */
.cds-msg {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: cds-fadeIn 0.3s ease;
}

@keyframes cds-fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.cds-msg-user {
    align-self: flex-end;
}

.cds-msg-bot {
    align-self: flex-start;
}

.cds-msg-content {
    padding: 10px 14px;
    font-size: var(--cds-font-size);
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.cds-msg-user .cds-msg-content {
    background: var(--cds-user-msg-bg);
    color: #fff;
    border-radius: var(--cds-border-radius);
    border-bottom-right-radius: 4px;
}

.cds-msg-bot .cds-msg-content {
    background: var(--cds-bot-msg-bg);
    color: var(--cds-text);
    border-radius: var(--cds-border-radius);
    border-bottom-left-radius: 4px;
}

.cds-msg-time {
    font-size: 11px;
    color: #999;
    margin-top: 3px;
    padding: 0 4px;
}

.cds-msg-user .cds-msg-time {
    text-align: right;
}

/* ── Быстрые ответы (Suggests) ────────────────────────────── */
.cds-chat-suggests {
    padding: 0 16px 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex-shrink: 0;
}

.cds-suggest-btn {
    background: var(--cds-suggest-bg, #f0f0f0);
    color: var(--cds-suggest-color, #0073aa);
    border: 1px solid var(--cds-suggest-color, #0073aa);
    padding: 6px 14px;
    border-radius: 16px;
    cursor: pointer;
    font-size: var(--cds-suggest-font-size, 12px);
    font-family: var(--cds-suggest-font-family, inherit);
    transition: background 0.2s, color 0.2s;
    white-space: nowrap;
}

.cds-suggest-btn:hover {
    background: var(--cds-suggest-color, #0073aa);
    color: #fff;
}

/* ── Поле ввода ──────────────────────────────────────────── */
.cds-chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid #e0e0e0;
    background: var(--cds-input-bg);
    flex-shrink: 0;
}

.cds-chat-input {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: var(--cds-border-radius);
    padding: 10px 12px;
    font-family: var(--cds-font-family);
    font-size: var(--cds-font-size);
    resize: none;
    max-height: 120px;
    outline: none;
    transition: border-color 0.2s;
}

.cds-chat-input:focus {
    border-color: var(--cds-primary);
}

.cds-chat-send-btn {
    background: var(--cds-primary);
    color: #fff;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.2s;
    flex-shrink: 0;
}

.cds-chat-send-btn:hover {
    background: color-mix(in srgb, var(--cds-primary) 85%, black);
    transform: scale(1.05);
}

.cds-chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ── Индикатор «печатает» ────────────────────────────────── */
.cds-typing-indicator {
    align-self: flex-start;
    background: var(--cds-bot-msg-bg);
    border-radius: var(--cds-border-radius);
    border-bottom-left-radius: 4px;
    padding: 10px 16px;
    display: flex;
    gap: 4px;
    align-items: center;
}

.cds-typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #999;
    animation: cds-typing-bounce 1.4s infinite;
}

.cds-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.cds-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes cds-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ── Ошибки ──────────────────────────────────────────────── */
.cds-msg-error .cds-msg-content {
    background: #fff0f0;
    color: #c00;
    border: 1px solid #fcc;
    text-align: center;
    max-width: 100%;
    font-size: 13px;
}

/* ── Прокрутка (мобильные) ───────────────────────────────── */
@media (max-width: 767px) {
    .cds-chat-popup-widget {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important;
        border-radius: 0 !important;
    }

    .cds-chat-popup-widget.open {
        animation: cds-slideUpMobile 0.3s ease;
    }

    @keyframes cds-slideUpMobile {
        from { opacity: 0; transform: translateY(40px); }
        to   { opacity: 1; transform: translateY(0); }
    }

    .cds-chat-header {
        padding-top: env(safe-area-inset-top, 12px);
    }

    .cds-chat-messages {
        padding: 12px;
    }
}

/* ── Форматированный текст ───────────────────────────────── */
.cds-msg-content a {
    color: inherit;
    text-decoration: underline;
}

.cds-msg-bot .cds-msg-content a {
    color: var(--cds-primary);
}

.cds-msg-content strong {
    font-weight: 600;
}
