.chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    font-family: 'Inter', sans-serif;
}

.chat-button {
    min-width: 92px;
    height: 64px;
    padding: 10px 16px;
    border-radius: 14px;
    background: linear-gradient(135deg, #00b0ff 0%, #0096e6 100%);
    border: none;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    box-shadow: 0 4px 20px rgba(0, 176, 255, 0.4);
    transition: all 0.3s ease;
    position: relative;
}

.chat-button-label {
    color: white;
    font-size: 0.78rem;
    font-weight: 600;
    line-height: 1.1;
    white-space: nowrap;
}

.chat-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(0, 176, 255, 0.5);
}

.chat-button svg {
    width: 28px;
    height: 28px;
    fill: white;
}

.chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 360px;
    max-height: 500px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    display: none;
    flex-direction: column;
}

.chat-window.active {
    display: flex;
}

.chat-header {
    background: linear-gradient(135deg, #00b0ff 0%, #0096e6 100%);
    color: white;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-avatar {
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-avatar svg {
    width: 24px;
    height: 24px;
    fill: white;
}

.chat-header-info h4 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

.chat-header-info p {
    font-size: 0.8rem;
    opacity: 0.9;
    margin: 0;
}

.chat-close {
    margin-left: auto;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.chat-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.chat-close svg {
    width: 18px;
    height: 18px;
    fill: white;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    min-height: 200px;
    max-height: 300px;
    background: #f8f9fa;
}

.chat-message {
    margin-bottom: 16px;
    display: flex;
    flex-direction: row;
}

.chat-message.client {
    align-items: flex-end;
}

.chat-message.manager {
    align-items: flex-start;
}

/* Аватар Марины в приветственном пузыре */
.chat-msg-avatar {
    flex-shrink: 0;
    align-self: flex-end;
    margin-right: 8px;
}

.chat-msg-avatar img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.chat-msg-body {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    min-width: 0;
    max-width: calc(100% - 40px);
}

.chat-bubble {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
}

.chat-message.client .chat-bubble {
    background: #00b0ff;
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message.manager .chat-bubble {
    background: white;
    color: #333;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.chat-time {
    font-size: 0.7rem;
    color: #999;
    margin-top: 4px;
}

.chat-input-area {
    padding: 16px;
    background: white;
    border-top: 1px solid #eee;
}

.chat-form {
    display: flex;
    gap: 8px;
}

.chat-input, .chat-input textarea, #chatInput {
    font-family: inherit;
}

#chatInput {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #e0e0e0;
    border-radius: 18px;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
    resize: none;
    max-height: 120px;
    line-height: 1.4;
}

.chat-input:focus {
    border-color: #00b0ff;
}

.chat-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #00b0ff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.chat-send:hover {
    background: #0096e6;
}

.chat-send svg {
    width: 20px;
    height: 20px;
    fill: white;
}

.chat-form-name {
    margin-bottom: 8px;
}

.chat-form-name input {
    width: 100%;
    padding: 10px 16px;
    border: 1px solid #e0e0e0;
    border-radius: 24px;
    font-size: 0.9rem;
    outline: none;
}

.chat-form-name input:focus {
    border-color: #00b0ff;
}

.chat-status {
    padding: 8px 16px;
    background: #e8f5e9;
    color: #2e7d32;
    font-size: 0.8rem;
    text-align: center;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-message {
    animation: fadeIn 0.3s ease;
}

@media (max-width: 480px) {
    .chat-window {
        width: calc(100vw - 32px);
        right: -8px;
        bottom: 70px;
    }
}

.chat-message.pending .chat-bubble { opacity: 0.55; }
.chat-message.failed .chat-bubble { background: #ffebee; color: #c62828; }


/* AI agent messages render like manager */
.chat-message.ai_agent { align-items: flex-start; }
.chat-message.ai_agent .chat-bubble { background: #ffffff; color: #1a1a1a; border: 1px solid #e0e0e0; }

/* typing indicator */
.chat-bubble .typing-dot {
    display: inline-block;
    width: 7px; height: 7px;
    margin: 0 2px;
    border-radius: 50%;
    background: #b0b0b0;
    animation: chatTyping 1.2s infinite;
}
.chat-bubble .typing-dot:nth-child(2) { animation-delay: 0.2s; }
.chat-bubble .typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes chatTyping {
    0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-3px); }
}

.chat-attach {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    opacity: 0.65;
}
.chat-attach:hover { opacity: 1; }
.chat-attach svg { width: 20px; height: 20px; fill: #666; }

.chat-form-name input.name-locked{background:#f1f5f9;color:#64748b;cursor:not-allowed;opacity:.85}


/* ===== Полноэкранный режим + непрочитанные (v2) ===== */
.chat-widget { z-index: 2147483000; }

.notification-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 11px;
    background: #e53935;
    color: #fff;
    font: 700 12px/22px -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    text-align: center;
    box-shadow: 0 2px 8px rgba(229,57,53,.45);
    display: none;
    z-index: 2147483001;
    animation: badge-pulse 2s ease-in-out infinite;
}
@keyframes badge-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.12); }
}

.chat-maximize {
    background: none;
    border: none;
    color: #fff;
    width: 34px;
    height: 34px;
    margin-left: auto;
    cursor: pointer;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: .85;
    flex-shrink: 0;
}
.chat-maximize:hover { opacity: 1; background: rgba(255,255,255,.15); }
.chat-close { margin-left: 0; }

.chat-window.active.chat-fullscreen {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: auto;
    max-height: none;
    border-radius: 0;
    z-index: 2147483600;
}
.chat-fullscreen .chat-messages { max-height: none; }

/* десктоп: окно крупнее по умолчанию */
@media (min-width: 769px) {
    .chat-window.active {
        width: min(480px, 92vw);
        height: min(720px, 90vh);
        max-height: none;
    }
    .chat-window.active:not(.chat-fullscreen) .chat-messages { max-height: none; min-height: 0; }
}

/* мобайл: всегда фулскрин */
@media (max-width: 768px) {
    .chat-window.active {
        position: fixed;
        inset: 0;
        width: 100vw;
        height: auto;
        max-height: none;
        border-radius: 0;
        bottom: 0;
        right: 0;
        z-index: 2147483600;
    }
    .chat-window.active .chat-messages { max-height: none; }
    .chat-header { padding: calc(14px + env(safe-area-inset-top)) 16px 14px; }
    .chat-input-area { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
    .chat-maximize { display: none; } /* на мобиле и так фулскрин */
    .chat-close { width: 44px; height: 44px; }
}

/* --- Quick replies (подсказки-кнопки под приветствием) --- */
.chat-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 4px 12px 8px 52px;
    animation: chatQrIn .25s ease;
}
@keyframes chatQrIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.chat-quick-btn {
    border: 1.5px solid #e3e6ea;
    background: #fff;
    color: #1a1a2e;
    font-size: 13.5px;
    font-weight: 500;
    padding: 9px 14px;
    border-radius: 18px;
    cursor: pointer;
    transition: all .15s ease;
    line-height: 1.2;
    -webkit-tap-highlight-color: transparent;
}
.chat-quick-btn:active { background: #f2f4f7; transform: scale(.97); }
@media (hover:hover) {
    .chat-quick-btn:hover { border-color: #b9c2cd; background: #f7f9fb; }
}
