/* ===== ЧАТ-ВИДЖЕТ: СТИЛИ ===== */
:root {
    --chat-primary: #1a73e8;
    --chat-primary-dark: #1557b0;
    --chat-bg: #ffffff;
    --chat-header-bg: #1a73e8;
    --chat-header-text: #ffffff;
    --operator-bubble: #f1f3f4;
    --operator-text: #202124;
    --client-bubble: #1a73e8;
    --client-text: #ffffff;
    --input-bg: #f8f9fa;
    --border-color: #e0e0e0;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.12);
    --radius-lg: 18px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

.chat-widget {
    -webkit-text-size-adjust: 100%;
}

.chat-widget *,
.chat-widget *::before,
.chat-widget *::after {
    box-sizing: border-box;
}

/* Баббл */
.chat-widget__bubble {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 9998;
    width: 62px;
    height: 62px;
    border-radius: 50%;
    background: var(--chat-primary);
    border: none;
    cursor: pointer;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
    -webkit-tap-highlight-color: transparent;
    outline: none;
    animation: chatBubbleIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}
.chat-widget__bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 12px 40px rgba(26, 115, 232, 0.35);
    background: var(--chat-primary-dark);
}
.chat-widget__bubble:active {
    transform: scale(0.94);
    transition: transform 0.1s ease;
}
.chat-widget__bubble--hidden {
    transform: scale(0) !important;
    opacity: 0 !important;
    pointer-events: none;
}
.chat-widget__bubble svg {
    width: 28px;
    height: 28px;
    fill: #fff;
}
.chat-widget__badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #ea4335;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    opacity: 0;
    transform: scale(0);
    transition: opacity 0.3s, transform 0.3s;
    font-family: var(--font-family);
}
.chat-widget__badge--visible {
    opacity: 1;
    transform: scale(1);
}

/* Индикатор онлайн на баббле (теперь слева вверху) */
.chat-widget__bubble--online::after {
    content: '';
    position: absolute;
    top: 1px;
    left: 1px;          /* было right, теперь left – исключает пересечение с бейджем */
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #4caf50;
    border: 2px solid #fff;
    box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.6);
    animation: onlinePulse 2s infinite;
}
@keyframes onlinePulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.6); }
    50% { box-shadow: 0 0 0 6px rgba(76, 175, 80, 0); }
}

/* Окно чата */
.chat-widget__window {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 9999;
    width: 390px;
    max-width: calc(100vw - 40px);
    height: 560px;
    max-height: calc(100vh - 100px);
    background: var(--chat-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    transform: scale(0);
    opacity: 0;
    pointer-events: none;
    transition: transform var(--transition), opacity var(--transition);
    font-family: var(--font-family);
}
.chat-widget__window--open {
    transform: scale(1);
    opacity: 1;
    pointer-events: all;
}
.chat-widget__window--closing {
    transform: scale(0.7);
    opacity: 0;
    transition: transform 0.25s ease-in, opacity 0.2s ease-in;
}

/* Заголовок */
.chat-widget__header {
    background: var(--chat-header-bg);
    color: var(--chat-header-text);
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    user-select: none;
}
.chat-widget__avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    background: rgba(255,255,255,0.25);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    overflow: hidden;
    border: 2px solid rgba(255,255,255,0.5);
}
.chat-widget__avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.chat-widget__avatar-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.2);
    font-size: 18px;
    font-weight: 700;
}
.chat-widget__name {
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-widget__status {
    font-size: 12px;
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 5px;
}
.chat-widget__status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4caf50;
    animation: pulseDot 2s infinite;
}
.chat-widget__status-dot--offline {
    background: #bdbdbd;
    animation: none;
}
.chat-widget__close {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.chat-widget__close:hover {
    background: rgba(255,255,255,0.3);
}
.chat-widget__close svg {
    width: 16px;
    height: 16px;
    stroke: #fff;
    stroke-width: 2.5;
}

/* Сообщения */
.chat-widget__messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #fafbfc;
    scroll-behavior: smooth;
}
.chat-widget__empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: #9aa0a6;
    font-size: 14px;
    padding: 30px;
    flex-direction: column;
    gap: 8px;
}
.chat-widget__message {
    display: flex;
    gap: 8px;
    max-width: 85%;
    animation: msgIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}
.chat-widget__message--operator {
    align-self: flex-start;
}
.chat-widget__message--client {
    align-self: flex-end;
    flex-direction: row-reverse;
}
.chat-widget__message--system {
    align-self: center;
    max-width: 90%;
    flex-direction: column;
    align-items: center;
}
.chat-widget__message--system .chat-widget__message-bubble {
    background: #f1f3f4;
    color: #5f6368;
    border-radius: 16px;
    padding: 8px 16px;
    font-size: 13px;
    border: none;
    box-shadow: none;
}
.chat-widget__message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    overflow: hidden;
    background: #e8eaed;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    align-self: flex-end;
}
.chat-widget__message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.chat-widget__message-body {
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.chat-widget__message-bubble {
    padding: 10px 14px;
    border-radius: var(--radius-md);
    font-size: 14px;
    line-height: 1.45;
    word-wrap: break-word;
    position: relative;
}
.chat-widget__message--operator .chat-widget__message-bubble {
    background: #fff;
    color: var(--operator-text);
    border: 1px solid #e8eaed;
    border-bottom-left-radius: 4px;
}
.chat-widget__message--client .chat-widget__message-bubble {
    background: var(--client-bubble);
    color: var(--client-text);
    border-bottom-right-radius: 4px;
}
.chat-widget__message-time {
    font-size: 10.5px;
    color: #9aa0a6;
    padding: 0 4px;
}
.chat-widget__message--client .chat-widget__message-time {
    text-align: right;
}

/* Индикатор печати */
.chat-widget__typing {
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 85%;
    align-self: flex-start;
    animation: msgIn 0.3s ease both;
}
.chat-widget__typing-bubble {
    background: #fff;
    border: 1px solid #e8eaed;
    border-radius: var(--radius-md);
    border-bottom-left-radius: 4px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 5px;
}
.chat-widget__typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #bcc0c5;
    animation: typingBounce 1.4s infinite ease-in-out;
}
.chat-widget__typing-dot:nth-child(1) { animation-delay: 0s; }
.chat-widget__typing-dot:nth-child(2) { animation-delay: 0.2s; }
.chat-widget__typing-dot:nth-child(3) { animation-delay: 0.4s; }

/* Поле ввода */
.chat-widget__input-area {
    padding: 10px 14px;
    background: #fff;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-shrink: 0;
    z-index: 2;
}
.chat-widget__input {
    flex: 1;
    border: 1.5px solid #e0e0e0;
    border-radius: 22px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: var(--font-family);
    resize: none;
    outline: none;
    max-height: 100px;
    background: var(--input-bg);
    -webkit-text-size-adjust: 100%;
}
.chat-widget__input:focus {
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 3px rgba(26,115,232,0.1);
    background: #fff;
}
.chat-widget__send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--chat-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
    box-shadow: 0 2px 8px rgba(26,115,232,0.3);
    flex-shrink: 0;
}
.chat-widget__send:hover {
    background: var(--chat-primary-dark);
}
.chat-widget__send:disabled {
    background: #c5c9ce;
    box-shadow: none;
}
.chat-widget__send svg {
    width: 18px;
    height: 18px;
    fill: #fff;
}

/* Анимации */
@keyframes chatBubbleIn {
    0% { transform: scale(0); opacity: 0; }
    70% { transform: scale(1.12); }
    100% { transform: scale(1); opacity: 1; }
}
@keyframes msgIn {
    0% { opacity: 0; transform: translateY(16px); }
    100% { opacity: 1; transform: translateY(0); }
}
@keyframes typingBounce {
    0%,60%,100% { transform: translateY(0); background: #bcc0c5; }
    30% { transform: translateY(-9px); background: #7b818c; }
}
@keyframes pulseDot {
    0%,100% { box-shadow: 0 0 0 0 rgba(76,175,80,0.6); }
    50% { box-shadow: 0 0 0 8px rgba(76,175,80,0); }
}

/* Мобильная адаптация */
@media (max-width: 480px) {
    .chat-widget__window {
        width: 100%;
        max-width: 100%;
        height: calc(100% - 30px);
        bottom: 0;
        right: 0;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    }
    .chat-widget__window--open {
        border-radius: 0;
    }
    .chat-widget__bubble {
        bottom: 20px;
        right: 20px;
        width: 56px;
        height: 56px;
    }
    .chat-widget__input {
        font-size: 16px;
        padding: 10px 14px;
    }
    .chat-widget__input-area {
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
        padding-left: calc(14px + env(safe-area-inset-left, 0px));
        padding-right: calc(14px + env(safe-area-inset-right, 0px));
    }
    .chat-widget__send {
        width: 38px;
        height: 38px;
    }
}