/* Чат-виджет fooq.ru: плавающая кнопка + панель переписки.
   Подключается из js/chat.js на всех страницах. */

.chat-fab {
    position: fixed;
    right: 16px;
    /* 90px — выше плавающих кнопок «Оставить заявку» и телефона (bottom: 20px) */
    bottom: 90px;
    z-index: 9998;
    width: 52px;
    height: 52px;
    border: none;
    border-radius: 50%;
    background: #4f46e5;
    color: #fff;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}
.chat-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 18px rgba(79, 70, 229, 0.6);
}
.chat-fab--hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.6);
}

/* hidden должен побеждать display: flex/inline у панели и пузыря */
.chat-panel[hidden],
.chat-teaser[hidden] {
    display: none;
}

/* пузырь-приветствие над кнопкой чата */
.chat-teaser {
    position: fixed;
    right: 16px;
    /* над кнопкой чата: bottom кнопки 90 + высота 52 + зазор 10 */
    bottom: 152px;
    z-index: 9997;
    width: 250px;
    max-width: calc(100vw - 32px);
    background: #fff;
    border: 1px solid #e9ecef;
    border-radius: 12px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
    padding: 9px 26px 10px 12px;
    cursor: pointer;
}
.chat-teaser::after {
    content: '';
    position: absolute;
    right: 20px;
    bottom: -6px;
    width: 10px;
    height: 10px;
    background: #fff;
    border-right: 1px solid #e9ecef;
    border-bottom: 1px solid #e9ecef;
    transform: rotate(45deg);
}
.chat-teaser__author {
    font-size: 10px;
    font-weight: 600;
    color: #4f46e5;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 2px;
}
.chat-teaser__text {
    font-size: 13px;
    line-height: 1.35;
    color: #333;
}
.chat-teaser__close {
    position: absolute;
    top: 4px;
    right: 5px;
    border: none;
    background: none;
    color: #adb5bd;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    padding: 2px;
}
.chat-teaser__close:hover {
    color: #6c757d;
}

.chat-panel {
    position: fixed;
    right: 16px;
    bottom: 90px;
    z-index: 9999;
    width: 310px;
    max-width: calc(100vw - 24px);
    height: 400px;
    max-height: calc(100vh - 32px);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-panel__head {
    background: linear-gradient(135deg, #4f46e5, #764ba2);
    color: #fff;
    padding: 10px 14px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-shrink: 0;
}
.chat-panel__title {
    font-size: 15px;
    font-weight: 600;
}
.chat-panel__status {
    font-size: 11px;
    opacity: 0.85;
    margin-top: 1px;
}
.chat-panel__close {
    background: none;
    border: none;
    color: #fff;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
    opacity: 0.85;
}
.chat-panel__close:hover {
    opacity: 1;
}

.chat-msgs {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.chat-empty {
    color: #6c757d;
    font-size: 13px;
    text-align: center;
    padding: 20px 10px;
}
.chat-error {
    color: #dc3545;
    font-size: 12px;
    text-align: center;
    padding: 4px;
}

.chat-msg {
    max-width: 84%;
    padding: 7px 10px;
    border-radius: 11px;
    font-size: 13px;
    line-height: 1.35;
    word-wrap: break-word;
}
.chat-msg--visitor {
    align-self: flex-end;
    background: #4f46e5;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.chat-msg--master {
    align-self: flex-start;
    background: #fff;
    border: 1px solid #e9ecef;
    border-bottom-left-radius: 4px;
}
.chat-msg__author {
    font-size: 10px;
    font-weight: 600;
    color: #4f46e5;
    margin-bottom: 2px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.chat-msg__time {
    font-size: 9px;
    opacity: 0.65;
    margin-top: 2px;
    text-align: right;
}

/* «Менеджер печатает...» */
.chat-typing {
    display: flex;
    gap: 4px;
    padding: 5px 2px;
}
.chat-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #b0b8d4;
    animation: chatblink 1s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes chatblink {
    0%, 80%, 100% { opacity: 0.3; }
    40% { opacity: 1; }
}

.chat-form {
    border-top: 1px solid #e9ecef;
    padding: 8px;
    background: #fff;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.chat-form__name {
    width: 100%;
    box-sizing: border-box;
    padding: 6px 9px;
    border: 1px solid #e9ecef;
    border-radius: 7px;
    font-size: 12px;
    outline: none;
}
.chat-form__name:focus {
    border-color: #4f46e5;
}
.chat-form__row {
    display: flex;
    gap: 6px;
}
.chat-form__input {
    flex: 1;
    min-width: 0;
    box-sizing: border-box;
    padding: 8px 10px;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    font-size: 13px;
    outline: none;
}
.chat-form__input:focus {
    border-color: #4f46e5;
}
.chat-form__send {
    height: 34px;
    flex-shrink: 0;
    border: none;
    border-radius: 8px;
    background: #4f46e5;
    color: #fff;
    cursor: pointer;
    padding: 0 14px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    white-space: nowrap;
    transition: background 0.15s ease;
}
.chat-form__send:hover {
    background: #5a6fd6;
}
.chat-form__send:disabled {
    opacity: 0.6;
    cursor: default;
}

@media (max-width: 480px) {
    .chat-panel {
        right: 10px;
        left: 10px;
        bottom: 70px;
        width: auto;
        height: 60vh;
        max-height: none;
    }
    .chat-fab {
        right: 12px;
        bottom: 70px;
    }
    .chat-teaser {
        right: 12px;
        bottom: 132px;
    }
}
