/* Виджет чат-бота ChatMCP.
   Правый нижний угол занят Carrot Quest: его контейнер — полоса 260×80 с
   pointer-events: auto (кнопка 80×80 справа + область тултипа слева), сдвинутая
   на bottom: 60px ради мобильного .bottom-nav (_Layout.cshtml). Встать левее не
   получится — полоса перехватит клики, поэтому наш пузырь стоит НАД «морковью»
   в той же правой колонке: 60px (сдвиг) + 80px (высота) + отступ.
   Позиционирование в px, а не в rem: базовый font-size на сайте плавающий,
   а развести два виджета нужно по абсолютной геометрии. */
#chat-widget {
    --cw-bubble-size: 56px;
    --cw-bubble-right: 42px;   /* центр под кнопкой «моркови»: она занимает 30..110 справа */
    --cw-bubble-bottom: 175px; /* верх «моркови» — на 155px от низа */
    --cw-accent: var(--primary-color, #cf000c);
    --cw-radius: 1.2rem;
    --cw-z: 2147483140; /* ниже .voice-btn из _Ai.cshtml, выше остального контента */
}

#chat-widget__bubble {
    position: fixed;
    right: var(--cw-bubble-right);
    bottom: var(--cw-bubble-bottom);
    z-index: var(--cw-z);
    width: var(--cw-bubble-size);
    height: var(--cw-bubble-size);
    padding: 0;
    border: none;
    border-radius: 50%;
    background-color: var(--cw-accent);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .25);
    transition: transform .2s, box-shadow .2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

#chat-widget__bubble:hover {
    transform: scale(1.06);
    box-shadow: 0 6px 22px rgba(0, 0, 0, .3);
}

#chat-widget__bubble svg {
    width: 2.6rem;
    height: 2.6rem;
    fill: currentColor;
}

#chat-widget__panel {
    position: fixed;
    right: 24px;
    bottom: calc(var(--cw-bubble-bottom) + var(--cw-bubble-size) + 12px);
    z-index: var(--cw-z);
    width: 400px;
    max-width: calc(100vw - 32px);
    height: 600px;
    max-height: calc(100vh - 260px);
    display: none;
    flex-direction: column;
    background-color: #fff;
    border-radius: var(--cw-radius);
    box-shadow: 0 8px 40px rgba(0, 0, 0, .28);
    overflow: hidden;
    font-size: 1.4rem;
}

#chat-widget.is-open #chat-widget__panel {
    display: flex;
}

#chat-widget.is-open #chat-widget__bubble {
    opacity: 0;
    pointer-events: none;
}

.chat-widget__header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.2rem 1.6rem;
    background-color: var(--cw-accent);
    color: #fff;
    flex: 0 0 auto;
}

.chat-widget__title {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0;
    line-height: 1.2;
}

.chat-widget__role {
    font-size: 1.2rem;
    opacity: .85;
    margin-left: auto;
    white-space: nowrap;
}

.chat-widget__icon-btn {
    padding: 0;
    border: none;
    background: none;
    color: #fff;
    cursor: pointer;
    line-height: 1;
    font-size: 1.8rem;
    opacity: .85;
}

.chat-widget__icon-btn:hover {
    opacity: 1;
}

.chat-widget__messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 1.6rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background-color: #f6f6f7;
}

.chat-widget__message {
    display: flex;
}

.chat-widget__message--user {
    justify-content: flex-end;
}

.chat-widget__bubble-text {
    max-width: 85%;
    padding: .9rem 1.2rem;
    border-radius: var(--cw-radius);
    background-color: #fff;
    color: #1a1a1a;
    line-height: 1.45;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .08);
}

.chat-widget__message--user .chat-widget__bubble-text {
    background-color: var(--cw-accent);
    color: #fff;
}

.chat-widget__error {
    align-self: center;
    max-width: 90%;
    padding: .8rem 1.2rem;
    border-radius: var(--cw-radius);
    background-color: #fdeaea;
    color: #9b1c1c;
    font-size: 1.3rem;
    text-align: center;
}

.chat-widget__status {
    flex: 0 0 auto;
    padding: 0 1.6rem .8rem;
    background-color: #f6f6f7;
    color: #777;
    font-size: 1.3rem;
}

.chat-widget__status[hidden] {
    display: none;
}

.chat-widget__composer {
    flex: 0 0 auto;
    display: flex;
    align-items: flex-end;
    gap: .8rem;
    padding: 1.2rem;
    border-top: 1px solid #e6e6e8;
    background-color: #fff;
}

.chat-widget__input {
    flex: 1 1 auto;
    resize: none;
    max-height: 12rem;
    padding: .9rem 1.2rem;
    border: 1px solid #d8d8dc;
    border-radius: var(--cw-radius);
    font-family: inherit;
    font-size: 1.4rem;
    line-height: 1.4;
}

.chat-widget__input:focus {
    outline: none;
    border-color: var(--cw-accent);
}

.chat-widget__send {
    flex: 0 0 auto;
    width: 4rem;
    height: 4rem;
    padding: 0;
    border: none;
    border-radius: 50%;
    background-color: var(--cw-accent);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-widget__send:disabled {
    opacity: .45;
    cursor: default;
}

.chat-widget__send svg {
    width: 1.8rem;
    height: 1.8rem;
    fill: currentColor;
}

/* Мобильные: панель раскрывается на весь экран, пузырь по-прежнему над «морковью» */
@media only screen and (max-width: 640px) {
    #chat-widget {
        --cw-bubble-right: 16px;
        --cw-bubble-size: 50px;
    }

    #chat-widget__panel {
        right: 0;
        left: 0;
        top: 0;
        bottom: 0;
        width: 100%;
        max-width: none;
        height: 100%;
        max-height: none;
        border-radius: 0;
    }
}
