/* ============================================
   Контейнер виджета
   ============================================ */
#max-chat-widget {
    font-family: Arial, sans-serif;
    font-size: 14px;
}

/* ============================================
   Кнопка-лаунчер — по центру снизу
   ============================================ */
.max-chat-launcher {
    position: fixed;
    bottom: 20px;
    left: 50%;
    z-index: 999999;
    -webkit-transform: translateX(-50%);
    -moz-transform: translateX(-50%);
    -ms-transform: translateX(-50%);
    -o-transform: translateX(-50%);
    transform: translateX(-50%);
    display: inline-block;
    background: #0b7cff;
    color: #fff;
    padding: 12px 22px;
    border-radius: 24px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-animation: chatFadeInUp 0.5s ease-out;
    -moz-animation: chatFadeInUp 0.5s ease-out;
    animation: chatFadeInUp 0.5s ease-out;
}
.max-chat-launcher:hover { background: #0866d6; }
.max-chat-launcher-text { display: inline-block; vertical-align: middle; }

@-webkit-keyframes chatFadeInUp {
    from { opacity: 0; -webkit-transform: translateX(-50%) translateY(25px); }
    to { opacity: 1; -webkit-transform: translateX(-50%) translateY(0); }
}
@-moz-keyframes chatFadeInUp {
    from { opacity: 0; -moz-transform: translateX(-50%) translateY(25px); }
    to { opacity: 1; -moz-transform: translateX(-50%) translateY(0); }
}
@keyframes chatFadeInUp {
    from { opacity: 0; transform: translateX(-50%) translateY(25px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Бейдж непрочитанных */
.max-chat-badge {
    position: absolute;
    top: -8px; right: -8px;
    min-width: 22px; height: 22px; line-height: 22px;
    padding: 0 6px;
    background: #ff3b30; color: #fff;
    border-radius: 11px;
    font-size: 12px; font-weight: bold; text-align: center;
    box-shadow: 0 2px 6px rgba(255, 59, 48, 0.5);
    border: 2px solid #fff;
    box-sizing: content-box;
    -webkit-animation: badgePop 0.3s ease-out;
    animation: badgePop 0.3s ease-out;
}
@-webkit-keyframes badgePop {
    from { -webkit-transform: scale(0); }
    to { -webkit-transform: scale(1); }
}
@keyframes badgePop {
    from { transform: scale(0); }
    to { transform: scale(1); }
}

/* ============================================
   Окно чата — position: fixed
   Позиционирование: по центру снизу
   Анимация появления: только через opacity
   Анимация разворачивания: через JS
   ============================================ */
.max-chat-window {
    position: fixed;
    bottom: 70px;
    left: 50%;
    width: 320px;
    height: 430px;
    margin-left: -160px; /* половина ширины для центрирования */
    background: #fff;
    border: 1px solid #c8c8c8;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 1000000;

    /* Анимация появления/исчезновения */
    opacity: 0;
    visibility: hidden;
    -webkit-transition: opacity 0.3s ease, visibility 0.3s ease;
    -moz-transition: opacity 0.3s ease, visibility 0.3s ease;
    -o-transition: opacity 0.3s ease, visibility 0.3s ease;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.max-chat-window.visible {
    opacity: 1;
    visibility: visible;
}

/* Заголовок окна */
.max-chat-header {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 42px;
    line-height: 22px;
    background: #0b7cff;
    color: #fff;
    padding: 10px;
    font-weight: bold;
    box-sizing: border-box;
}
.max-chat-header-buttons { float: right; }
.max-chat-header-buttons a {
    color: #fff;
    text-decoration: none;
    font-weight: bold;
    font-size: 16px;
    margin-left: 12px;
    display: inline-block;
    vertical-align: middle;
    -webkit-transition: opacity 0.2s ease;
    transition: opacity 0.2s ease;
}
.max-chat-header-buttons a:hover { opacity: 0.7; }

/* Область сообщений */
.max-chat-messages {
    position: absolute;
    top: 42px;
    bottom: 64px;
    left: 0; right: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px;
    background: #f4f6f8;
    box-sizing: border-box;
}

/* Форма ввода */
.max-chat-form {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 64px;
    padding: 8px;
    border-top: 1px solid #ddd;
    background: #fff;
    box-sizing: border-box;
}
.max-chat-input-row {
    position: relative;
    width: 100%;
    height: 100%;
}
#max-chat-text {
    position: absolute;
    top: 0; left: 0; right: 48px;
    height: 48px;
    box-sizing: border-box;
    resize: none;
    padding: 6px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-family: Arial, sans-serif;
    font-size: 14px;
}
#max-chat-send {
    position: absolute;
    top: 0; right: 0;
    width: 40px; height: 48px;
    background: #0b7cff;
    border: 0; color: #fff;
    cursor: pointer;
    border-radius: 4px;
    font-size: 16px; font-weight: bold;
    padding: 0; text-align: center;
    line-height: 48px;
    -webkit-transition: background 0.2s ease;
    transition: background 0.2s ease;
}
#max-chat-send:hover { background: #0866d6; }
#max-chat-send:active { background: #064ea8; }

/* Сообщения */
.max-msg {
    margin-bottom: 8px;
    padding: 7px 9px;
    border-radius: 8px;
    max-width: 85%;
    word-wrap: break-word;
    overflow-wrap: break-word;
    -webkit-animation: msgFadeIn 0.3s ease-out;
    animation: msgFadeIn 0.3s ease-out;
}
.max-msg.manager { background: #e2ffd8; }
.max-msg.user {
    background: #e7f0ff;
    margin-left: auto;
    text-align: right;
}
.max-msg-meta { font-size: 11px; color: #777; margin-bottom: 3px; }
.max-msg-text { word-wrap: break-word; overflow-wrap: break-word; }
.max-msg-text a { color: #0b7cff; text-decoration: underline; }

@-webkit-keyframes msgFadeIn {
    from { opacity: 0; -webkit-transform: translateY(8px); }
    to { opacity: 1; -webkit-transform: translateY(0); }
}
@keyframes msgFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Индикатор "Подготовка ответа" */
.typing-msg {
    display: inline-block;
    padding: 10px 14px;
    background: #e2ffd8;
    border-radius: 8px;
    font-size: 13px;
    color: #555;
}
.typing-text { display: inline-block; vertical-align: middle; }
.typing-dots { display: inline-block; vertical-align: middle; margin-left: 6px; }
.typing-dots span {
    display: inline-block;
    width: 6px; height: 6px;
    margin-left: 3px;
    background: #888;
    border-radius: 50%;
    -webkit-animation: typing-blink 1.4s infinite both;
    animation: typing-blink 1.4s infinite both;
}
.typing-dots span:nth-child(2) {
    -webkit-animation-delay: 0.2s;
    animation-delay: 0.2s;
}
.typing-dots span:nth-child(3) {
    -webkit-animation-delay: 0.4s;
    animation-delay: 0.4s;
}
@-webkit-keyframes typing-blink {
    0%, 80%, 100% { opacity: 0.2; }
    40% { opacity: 1; }
}
@keyframes typing-blink {
    0%, 80%, 100% { opacity: 0.2; }
    40% { opacity: 1; }
}