/* Чат-виджет стили */
.chat-widget {
    position: fixed;
    z-index: 9999;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 14px;
    line-height: 1.4;
}

.chat-widget.bottom-right {
    bottom: 30px;
    right: 20px;
}

.chat-widget.bottom-left {
    bottom: 30px;
    left: 20px;
}

@keyframes chatAppear {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(20px);
        transform-origin: bottom right;
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
        transform-origin: bottom right;
    }
}

/* Анимация для левой позиции */
.chat-widget.bottom-left .chat-window {
    animation: chatAppearLeft 0.3s ease-out;
}

@keyframes chatAppearLeft {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(20px);
        transform-origin: bottom left;
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
        transform-origin: bottom left;
    }
}

/* Кнопка переключения чата */
.chat-toggle {
    position: relative;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #0088cc, #0066aa);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(0, 136, 204, 0.3);
    transition: all 0.3s ease;
    user-select: none;
}

.chat-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 32px rgba(0, 136, 204, 0.4);
}

.chat-toggle svg {
    color: white;
    transition: all 0.3s ease;
}

.chat-notification {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4757;
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    animation: pulse 2s infinite;
}

.operator-status {
    position: absolute;
    left: -120px;
    top: 50%;
    background: #4CAF50;
    color: white;
    padding: 6px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    transform: translateY(-50%) translateX(10px);
    transition: all 0.3s ease;
    pointer-events: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 10001;
}

.chat-toggle:hover .operator-status {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* Окно чата - позиционирование снизу */
.chat-window {
    position: absolute;
    bottom: 70px;
    right: 0;
    max-width: 350px;
    width: 350px;
    height: 500px;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: chatAppear 0.3s ease-out;
    z-index: 10000;
    max-height: calc(100vh - 120px);
    min-height: 400px;
    border: 1px solid #e5e5ea;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    transform-origin: bottom right;
    box-sizing: border-box;
}

/* Специальное позиционирование для bottom-left */
.chat-widget.bottom-left .chat-window {
    right: auto;
    left: 0;
    transform-origin: bottom left;
}

/* Шапка чата - копия telegram-demo */
.chat-window .telegram-demo__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: #0088cc;
    color: white;
    height: 56px;
    flex-shrink: 0;
}

.chat-window .chat-info {
    display: flex;
    align-items: center;
    flex: 1;
}

.chat-window .chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    margin-right: 12px;
    flex-shrink: 0;
}

.chat-window .chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-window .chat-details {
    flex: 1;
    min-width: 0;
}

.chat-window .chat-name {
    font-size: 16px;
    font-weight: 500;
    line-height: 1.2;
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-window .chat-status {
    display: flex;
    align-items: center;
    font-size: 13px;
    opacity: 0.8;
    line-height: 1;
}

.chat-window .online-indicator {
    width: 8px;
    height: 8px;
    background: #4CAF50;
    border-radius: 50%;
    margin-right: 6px;
    animation: pulse-online 2s infinite;
}

@keyframes pulse-online {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

.chat-window .chat-actions {
    display: flex;
    gap: 8px;
}

.chat-window .chat-action-btn {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-window .chat-action-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
}

/* Область сообщений - копия telegram-demo */
.chat-window .telegram-demo__messages {
    height: 320px;
    padding: 12px;
    background: #f4f4f5;
    overflow-y: auto;
    scroll-behavior: smooth;
    flex: 1;
}

.chat-window .telegram-demo__messages::-webkit-scrollbar {
    width: 4px;
}

.chat-window .telegram-demo__messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-window .telegram-demo__messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 2px;
}

/* Сообщения как в telegram-demo */
.chat-window .telegram-message {
    margin-bottom: 8px;
    opacity: 0;
    transform: translateY(10px);
    animation: messageAppear 0.3s ease forwards;
}

@keyframes messageAppear {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-window .telegram-message--incoming {
    display: flex;
    justify-content: flex-start;
}

.chat-window .telegram-message--outgoing {
    display: flex;
    justify-content: flex-end;
}

.chat-window .message-bubble {
    max-width: 75%;
    padding: 8px 12px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
    position: relative;
}

.chat-window .telegram-message--incoming .message-bubble {
    background: white;
    color: #333;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.chat-window .telegram-message--outgoing .message-bubble {
    background: #0088cc;
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-window .message-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 4px;
    text-align: right;
    line-height: 1;
}

.chat-window .telegram-message--incoming .message-time {
    text-align: left;
    color: #999;
}

.chat-window .telegram-message--outgoing .message-time {
    color: rgba(255, 255, 255, 0.8);
}

/* Строка ввода - копия telegram-demo */
.chat-window .telegram-demo__input {
    padding: 12px;
    background: white;
    border-top: 1px solid #e5e5ea;
    flex-shrink: 0;
}

.chat-window .input-wrapper {
    display: flex;
    align-items: center;
    background: #f7f7f7;
    border-radius: 20px;
    padding: 8px 12px;
    transition: all 0.2s ease;
    gap: 8px;
    box-sizing: border-box;
}

.chat-window .input-wrapper:focus-within {
    background: white;
    box-shadow: 0 0 0 2px rgba(0, 136, 204, 0.2);
}

.chat-window .telegram-demo__input input {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    font-size: 14px;
    line-height: 1.4;
    padding: 4px 8px;
    color: #333;
    min-width: 0;
    flex-shrink: 1;
}

.chat-window .telegram-demo__input input::placeholder {
    color: #999;
}

.chat-window .send-btn {
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
    background: #0088cc;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 0;
    line-height: 1;
}

.chat-window .send-btn:hover {
    background: #006ba6;
    transform: scale(1.05);
}

.chat-window .send-btn i {
    font-size: 12px;
}

/* Анимации для чата */
@keyframes chatAppear {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Шапка чата - точно как в демо */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: #0088cc;
    color: white;
    height: 56px;
    flex-shrink: 0;
}

.chat-info {
    display: flex;
    align-items: center;
    flex: 1;
}

.chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    margin-right: 12px;
}

.chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-details {
    flex: 1;
}

.chat-title {
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 2px;
}

.chat-status {
    display: flex;
    align-items: center;
    font-size: 13px;
    opacity: 0.9;
}

.online-indicator {
    width: 8px;
    height: 8px;
    background: #4CAF50;
    border-radius: 50%;
    margin-right: 6px;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

.chat-controls {
    display: flex;
    gap: 8px;
}

.chat-minimize,
.chat-close {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: background 0.2s;
}

.chat-minimize:hover,
.chat-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.chat-minimize {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: background 0.2s;
}

.chat-minimize:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Сообщения - точно как в демо */
.chat-messages {
    height: 320px;
    padding: 12px;
    background: #f4f4f5;
    overflow-y: auto;
    scroll-behavior: smooth;
    flex: 1;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 2px;
}

/* Сообщения как в демо */
.message {
    margin-bottom: 8px;
    opacity: 0;
    transform: translateY(10px);
    animation: messageAppear 0.3s ease forwards;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

@keyframes messageAppear {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user-message {
    flex-direction: row-reverse;
    margin-left: auto;
    gap: 4px;
    align-items: flex-end;
    justify-content: flex-start;
    width: 100%;
}

.message.operator-message {
    flex-direction: row;
}

.operator-message .message-bubble {
    background: white;
    color: #333;
    border-bottom-left-radius: 4px;
    border-bottom-right-radius: 16px;
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
}

.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.message-content {
    max-width: 75%;
}

.message.user-message .message-content {
    text-align: right;
    max-width: 75%;
    margin-left: auto;
}

.message-bubble {
    background: white;
    border-radius: 16px;
    padding: 8px 12px;
    font-size: 14px;
    line-height: 1.4;
    color: #333;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    word-wrap: break-word;
    max-width: 75%;
}

/* Стили для пользовательских сообщений - максимальный приоритет */
.chat-widget .message.user-message .message-bubble {
    background: #0088cc !important;
    color: white !important;
    border-bottom-right-radius: 4px !important;
    border-bottom-left-radius: 16px !important;
    border-top-left-radius: 16px !important;
    border-top-right-radius: 16px !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2) !important;
}

.message.user-message .message-bubble {
    background: #0088cc !important;
    color: white !important;
    border-bottom-right-radius: 4px;
    border-bottom-left-radius: 16px;
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
}

.message-time {
    font-size: 11px;
    color: #999;
    margin-top: 4px;
    text-align: left;
}

.message.user-message .message-time {
    text-align: right !important;
    color: rgba(255, 255, 255, 0.8) !important;
}

/* Дополнительный селектор для максимального приоритета */
.chat-widget .message.user-message .message-time {
    text-align: right !important;
    color: rgba(255, 255, 255, 0.8) !important;
}

.message.manager {
    align-self: flex-start;
    margin-right: auto;
}

.message.manager .message-bubble {
    background: linear-gradient(145deg, #4CAF50, #45a049);
    color: white;
    border: 1px solid rgba(76, 175, 80, 0.3);
}

.message.manager .message-avatar::before {
    content: "👨‍💼";
    font-size: 20px;
    line-height: 32px;
    text-align: center;
}

.message-avatar {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
}

.message-avatar img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.message-content {
    flex: 1;
}

/* Поле ввода - точно как в демо */
.chat-input-container {
    padding: 12px;
    background: white;
    border-top: 1px solid #e5e5ea;
    flex-shrink: 0;
}

.chat-input-wrapper {
    display: flex;
    align-items: center;
    background: #f7f7f7;
    border-radius: 20px;
    padding: 8px 12px;
    transition: all 0.2s ease;
}

.chat-input-wrapper:focus-within {
    background: #eeeeee;
}

#chatMessageInput {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    font-size: 14px;
    line-height: 1.4;
    padding: 4px 8px;
    color: #333;
    font-family: inherit;
}

#chatMessageInput::placeholder {
    color: #999;
}

#chatSendButton {
    width: 28px;
    height: 28px;
    background: #0088cc;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 8px;
}

#chatSendButton:hover {
    background: #006ba6;
    transform: scale(1.05);
}

#chatSendButton svg {
    width: 12px;
    height: 12px;
}

.chat-send-btn:hover {
    background: #0066aa;
    transform: scale(1.05);
}

.chat-send-btn:active {
    transform: scale(0.95);
}

/* Быстрые действия */
.chat-quick-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.quick-action {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    padding: 8px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    color: #374151;
    white-space: nowrap;
}

.quick-action:hover {
    background: #0088cc;
    color: white;
    border-color: #0088cc;
    transform: translateY(-1px);
}

/* Темы */
.chat-widget.dark .chat-window {
    background: #1f2937;
    color: white;
}

.chat-widget.dark .chat-messages {
    background: #111827;
}

.chat-widget.dark .message-text {
    background: #374151;
    color: white;
    border-color: #4b5563;
}

.chat-widget.dark .chat-input-container {
    background: #1f2937;
    border-color: #4b5563;
}

.chat-widget.dark .chat-input-wrapper {
    background: #374151;
    border-color: #4b5563;
}

.chat-widget.dark #chat-input {
    color: white;
}

.chat-widget.dark .quick-action {
    background: #374151;
    border-color: #4b5563;
    color: white;
}

/* Адаптивность */
@media (max-width: 768px) {
    .chat-widget.bottom-right .chat-window,
    .chat-widget.bottom-left .chat-window {
        max-width: 360px;
        width: 360px;
        box-sizing: border-box;
    }
    
    .chat-messages {
        height: 350px;
    }
    
    .message-bubble {
        max-width: 80%;
    }
    
    .chat-window .send-btn {
        width: 36px;
        height: 36px;
        min-width: 36px;
        min-height: 36px;
    }
    
    .chat-window .send-btn i {
        font-size: 14px;
    }
    
    .chat-window .input-wrapper {
        gap: 6px;
    }
}

@media (max-width: 480px) {
    /* Полноэкранный режим на мобильных */
    .chat-widget.bottom-right .chat-window,
    .chat-widget.bottom-left .chat-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        max-width: none;
        max-height: none;
        border-radius: 0;
        z-index: 10001;
        box-sizing: border-box;
        animation: chatAppearFullscreen 0.3s ease-out;
    }
    
    @keyframes chatAppearFullscreen {
        from {
            opacity: 0;
            transform: translateY(100%);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
    
    .chat-messages {
        height: calc(100vh - 140px);
        padding: 12px;
    }
    
    .message-bubble {
        max-width: 85%;
        font-size: 14px;
        padding: 8px 12px;
    }
    
    .chat-quick-actions {
        flex-direction: column;
        align-items: stretch;
    }
    
    .quick-action {
        text-align: center;
    }
    
    .chat-window .send-btn {
        width: 36px;
        height: 36px;
        min-width: 36px;
        min-height: 36px;
    }
    
    .chat-window .send-btn i {
        font-size: 14px;
    }
    
    .chat-window .input-wrapper {
        gap: 6px;
        padding: 8px 12px;
    }
    
    /* Кнопки управления чатом на мобильных */
    .chat-minimize,
    .chat-close {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }
    
    /* Шапка чата */
    .chat-window .telegram-demo__header,
    .chat-header {
        height: 60px;
        padding: 16px;
    }
}

/* Анимации */
.chat-toggle {
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

/* Скрытие на мобильных при необходимости */
@media (max-width: 320px) {
    .chat-widget {
        display: none;
    }
}