/* ============================================================
   AI-чат виджет. Самодостаточный модуль, не зависит от стилей
   сайта. Цветами совпадает с #0156CD (var(--c3) проекта)
   ============================================================ */

.chat-widget {
    /* Брендовые цвета — менять тут */
    --cw-primary: #0156CD;
    --cw-primary-hover: #014BB0;
    --cw-accent: #0156CD;

    --cw-bg: #ffffff;
    --cw-bg-soft: #f4f6fb;
    --cw-text: #0F1822;
    --cw-text-muted: #5a6573;
    --cw-border: #e2e6ee;
    --cw-shadow: 0 16px 48px rgba(15, 24, 34, .18);
    --cw-radius: 16px;

    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--cw-text);
}

/* --- Плавающий виджет в углу --- */
.chat-widget--floating {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 9990;
}

/* --- Встроенный виджет в страницу --- */
.chat-widget--inline {
    position: relative;
    width: 100%;
    margin: 0 auto;
}
.chat-widget--inline .chat-widget__panel {
    width: 100%;
    /* Размер уменьшен на 25%: панель уже ширины колонки и ниже по высоте */
    max-width: 75%;
    margin-left: auto;
    height: 405px;
    max-height: 52vh;
    animation: none;
    box-shadow: 0 8px 32px rgba(15, 24, 34, .08);
}

/* Тёмная тема — синхронизируется с темой сайта */
:root[data-theme="dark"] .chat-widget {
    --cw-bg: #1A2230;
    --cw-bg-soft: #232c3c;
    --cw-text: #E8ECF3;
    --cw-text-muted: #97a1b4;
    --cw-border: #2A3448;
    --cw-shadow: 0 16px 48px rgba(0, 0, 0, .5);
}

/* ----- Плавающая кнопка ----- */
.chat-widget__toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 18px 12px 14px;
    background: var(--cw-primary);
    color: #fff;
    border: 0;
    border-radius: 999px;
    box-shadow: var(--cw-shadow);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background .2s ease, transform .15s ease;
}
.chat-widget__toggle:hover {
    background: var(--cw-primary-hover);
    transform: translateY(-1px);
}
.chat-widget__toggle-icon {
    width: 22px;
    height: 22px;
    flex: none;
}
.chat-widget--open .chat-widget__toggle {
    display: none;
}

/* ----- Окно чата ----- */
.chat-widget__panel {
    display: none; /* скрыто по умолчанию, открывается через .chat-widget--open */
    width: 380px;
    max-width: calc(100vw - 24px);
    height: min(560px, calc(100vh - 48px));
    background: var(--cw-bg);
    border: 1px solid var(--cw-border);
    border-radius: var(--cw-radius);
    box-shadow: var(--cw-shadow);
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
}
.chat-widget--open .chat-widget__panel {
    display: flex;
    animation: chat-widget-pop .2s ease;
}
@keyframes chat-widget-pop {
    from { opacity: 0; transform: scale(.95) translateY(8px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ----- Шапка ----- */
.chat-widget__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    background: var(--cw-primary);
    color: #fff;
}
.chat-widget__title {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 15px;
}
.chat-widget__title-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 0 0 rgba(74, 222, 128, .7);
    animation: chat-widget-pulse 2s infinite;
}
@keyframes chat-widget-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(74, 222, 128, .7); }
    70%  { box-shadow: 0 0 0 8px rgba(74, 222, 128, 0); }
    100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); }
}
.chat-widget__close {
    background: transparent;
    color: #fff;
    border: 0;
    padding: 4px;
    border-radius: 6px;
    cursor: pointer;
    opacity: .85;
    transition: opacity .15s ease, background .15s ease;
}
.chat-widget__close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, .12);
}

/* ----- Сообщения ----- */
.chat-widget__messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--cw-bg);
    scroll-behavior: smooth;
}
.chat-widget__messages::-webkit-scrollbar {
    width: 6px;
}
.chat-widget__messages::-webkit-scrollbar-thumb {
    background: var(--cw-border);
    border-radius: 3px;
}

.chat-widget__msg {
    display: flex;
    max-width: 90%;
}
.chat-widget__msg--bot {
    align-self: flex-start;
}
.chat-widget__msg--user {
    align-self: flex-end;
}

.chat-widget__bubble {
    padding: 10px 14px;
    border-radius: 14px;
    word-wrap: break-word;
    white-space: pre-wrap;
    font-size: 14px;
    line-height: 1.5;
}
.chat-widget__msg--bot .chat-widget__bubble {
    background: var(--cw-bg-soft);
    color: var(--cw-text);
    border-bottom-left-radius: 4px;
}
.chat-widget__msg--user .chat-widget__bubble {
    background: var(--cw-primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.chat-widget__bubble a {
    color: var(--cw-primary);
    text-decoration: underline;
    word-break: break-word;
}
.chat-widget__msg--user .chat-widget__bubble a {
    color: #fff;
}

/* «Печатает…» индикатор */
.chat-widget__typing {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.chat-widget__typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--cw-text-muted);
    animation: chat-widget-typing 1.2s infinite;
}
.chat-widget__typing-dot:nth-child(2) { animation-delay: .15s; }
.chat-widget__typing-dot:nth-child(3) { animation-delay: .3s; }
@keyframes chat-widget-typing {
    0%, 60%, 100% { opacity: .3; transform: translateY(0); }
    30%           { opacity: 1; transform: translateY(-3px); }
}

/* ----- Форма ввода ----- */
.chat-widget__form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--cw-border);
    background: var(--cw-bg);
}
.chat-widget__input {
    flex: 1;
    resize: none;
    max-height: 120px;
    min-height: 40px;
    padding: 10px 12px;
    border: 1px solid var(--cw-border);
    border-radius: 12px;
    background: var(--cw-bg);
    color: var(--cw-text);
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    outline: none;
    transition: border-color .15s ease;
}
.chat-widget__input:focus {
    border-color: var(--cw-primary);
}
.chat-widget__input::placeholder {
    color: var(--cw-text-muted);
}
.chat-widget__send {
    width: 40px;
    height: 40px;
    flex: none;
    background: var(--cw-primary);
    color: #fff;
    border: 0;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background .15s ease;
}
.chat-widget__send:hover:not(:disabled) {
    background: var(--cw-primary-hover);
}
.chat-widget__send:disabled {
    background: var(--cw-text-muted);
    cursor: not-allowed;
    opacity: .6;
}

.chat-widget__footer {
    padding: 8px 14px 10px;
    border-top: 1px solid var(--cw-border);
    background: var(--cw-bg);
    color: var(--cw-text-muted);
    font-size: 11px;
    text-align: center;
}

/* ----- Inline-форма «Имя + Телефон» внутри сообщения ----- */
.chat-widget__bubble--lead {
    background: linear-gradient(135deg, var(--cw-primary) 0%, var(--cw-primary-hover) 100%);
    color: #fff;
    max-width: 100%;
    border-bottom-left-radius: 4px;
    padding: 14px 16px;
}
.chat-widget__lead-intro {
    font-size: 13px;
    margin-bottom: 10px;
    line-height: 1.4;
}
.chat-widget__lead-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.chat-widget__lead-form input {
    width: 100%;
    padding: 10px 12px;
    border: 0;
    border-radius: 10px;
    background: rgba(255, 255, 255, .95);
    color: var(--cw-text);
    font-family: inherit;
    font-size: 14px;
    outline: none;
}
.chat-widget__lead-form input:focus {
    background: #fff;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, .35);
}
.chat-widget__lead-submit {
    background: #fff;
    color: var(--cw-primary);
    border: 0;
    border-radius: 10px;
    padding: 11px 14px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform .15s ease;
}
.chat-widget__lead-submit:hover:not(:disabled) {
    transform: translateY(-1px);
}
.chat-widget__lead-submit:disabled {
    opacity: .6;
    cursor: not-allowed;
}
.chat-widget__lead-status {
    font-size: 12px;
    min-height: 14px;
    color: rgba(255, 255, 255, .9);
}
.chat-widget__lead-status--err {
    color: #ffd2d2;
}

/* ----- Адаптивка ----- */
@media (max-width: 480px) {
    .chat-widget--floating {
        right: 12px;
        bottom: 12px;
    }
    .chat-widget--floating .chat-widget__panel {
        width: calc(100vw - 24px);
        height: calc(100vh - 80px);
    }
    .chat-widget__toggle-label {
        display: none;
    }
    .chat-widget__toggle {
        width: 52px;
        height: 52px;
        padding: 0;
        justify-content: center;
    }
    .chat-widget__toggle-icon {
        width: 26px;
        height: 26px;
    }
    .chat-widget--inline .chat-widget__panel {
        /* На мобильных колонка уже одна — растягиваем на всю ширину */
        max-width: 100%;
        margin-left: 0;
        height: 360px;
        max-height: 75vh;
    }
}
