/* Chat Widget Styles */
.chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

.chat-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.4);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}
.chat-header {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.message-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.message-text {
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.support-message .message-text {
    background: rgba(99, 102, 241, 0.15);
    color: white;
    border: 1px solid rgba(99, 102, 241, 0.3);
}
.message-author {
    font-weight: bold;
    font-size: 12px;
    margin-bottom: 2px;
}

/* Разные цвета и шрифты */
.support-message .message-author {
    color: #6366F1; /* фиолетовый */
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.user-message .message-author {
    color: #ffffff; /* белый */
    font-family: 'Roboto', Helvetica, sans-serif;
}

/* Контейнер сообщения */
.message-content {
    display: flex;
    align-items: flex-start;
    gap: 6px;
}

/* User сообщения справа */
.user-message .message-content {
    flex-direction: row-reverse;
}

.user-message .message-text {
    text-align: right;
}


.user-message .message-wrapper {
    flex-direction: row-reverse;
}

.user-message .message-content {
    align-items: flex-end;
}

.user-message .message-text {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
    border: none;
}

.message-time {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.4);
    padding: 0 4px;
}


.chat-close-btn {
    font-size: 22px;
    line-height: 22px;
    cursor: pointer;
    margin-left: auto;
    color: #fff;
    opacity: 0.8;
    padding: 4px 10px;
    transition: 0.2s;
}

.chat-close-btn:hover {
    opacity: 1;
}


.chat-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 32px rgba(99, 102, 241, 0.5);
}

.chat-toggle:active {
    transform: scale(0.95);
}

.chat-toggle svg {
    color: white;
    transition: all 0.3s ease;
}

.chat-toggle .close-icon {
    display: none;
    position: absolute;
}

.chat-toggle.active .chat-icon {
    display: none;
}


.chat-toggle.active .close-icon {
    display: block;
}

.notification-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background-color: #ef4444;
    color: white;
    font-size: 12px;
    font-weight: 600;
    border-radius: 10px;
    padding: 4px 8px;
    min-width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
}

.notification-badge:empty {
    display: none;
}

.notification-badge.text-badge {
    min-width: auto;
    max-width: 150px;
    white-space: nowrap;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 10px;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.8;
        transform: scale(1.1);
    }
}

.chat-box {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 550px;
    background: rgba(17, 24, 39, 0.95);
    backdrop-filter: blur(20px);
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-box.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

.chat-header {
    padding: 20px;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.2) 0%, rgba(139, 92, 246, 0.2) 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px 16px 0 0;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-header-info svg {
    flex-shrink: 0;
}

.chat-header-title {
    color: white;
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
}

.chat-header-status {
    display: flex;
    align-items: center;
    gap: 6px;
    color: rgba(255, 255, 255, 0.6);
    font-size: 13px;
}

.status-indicator {
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
    animation: statusBlink 2s infinite;
}

@keyframes statusBlink {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

.message {
    display: flex;
    gap: 10px;
    animation: messageSlideIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.message-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.message-text {
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.support-message .message-text {
    background: rgba(99, 102, 241, 0.15);
    color: white;
    border: 1px solid rgba(99, 102, 241, 0.3);
}

.user-message {
    flex-direction: row-reverse;
}

.user-message .message-content {
    align-items: flex-end;
}

.user-message .message-text {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
    border: none;
}

.message-time {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.4);
    padding: 0 4px;
}

.typing-indicator {
    display: none;
    padding: 12px 16px;
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 12px;
    width: fit-content;
    margin-left: 42px;
    gap: 4px;
}

.typing-indicator.active {
    display: flex;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-8px);
    }
}

.chat-input-wrapper {
    padding: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-input-form {
    display: flex;
    gap: 8px;
    align-items: center;
}

.chat-input {
    flex: 1;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    color: white;
    font-size: 14px;
    outline: none;
    transition: all 0.3s ease;
}

.chat-input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.chat-input:focus {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(99, 102, 241, 0.5);
}
/* Автор над сообщением */
.message-author {
    font-weight: bold;
    font-size: 12px;
    margin-bottom: 4px;
}

/* Разные цвета и шрифты */
.support-message .message-author {
    color: #6366F1; /* фиолетовый для Support */
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.user-message .message-author {
    color: #ffffff; /* белый для User */
    font-family: 'Roboto', Helvetica, sans-serif;
}

/* Обёртка контента */
.message-wrapper {
    display: flex;
    align-items: flex-start;
    gap: 6px;
}
.message-label {
    font-size: 11px;
    font-weight: 600;
    opacity: 0.6;
    margin-bottom: 4px;
    color: #fff;
}

/* Аватар слева для Support, скрыт у User */
.support-message .message-avatar {
    flex-shrink: 0;
}

/* User-сообщения справа */
.user-message .message-wrapper {
    flex-direction: row-reverse;
}

.user-message .message-text {
    text-align: right;
}


.chat-send {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.chat-send:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.chat-send:active {
    transform: scale(0.95);
}

.chat-send svg {
    color: white;
}

/* ==================== АДАПТИВНОСТЬ ==================== */

/* Планшеты (средние экраны) */
@media (max-width: 1024px) {
    .chat-box {
        width: 360px;
        height: 520px;
    }
}

/* Планшеты и большие телефоны (портретная ориентация) */
@media (max-width: 768px) {
    .chat-widget {
        bottom: 16px;
        right: 16px;
    }
    
    .chat-toggle {
        width: 56px;
        height: 56px;
    }
    
    .chat-box {
        width: calc(100vw - 32px);
        height: calc(100vh - 120px);
        max-width: 380px;
        max-height: 600px;
        bottom: 76px;
    }
    
    .chat-header {
        padding: 16px;
    }
    
    .chat-header-title {
        font-size: 15px;
    }
    
    .chat-messages {
        padding: 16px;
        gap: 14px;
    }
    
    .message-text {
        font-size: 13px;
        padding: 10px 14px;
    }
    
    .notification-badge {
        font-size: 11px;
    }
}

/* Средние телефоны */
@media (max-width: 600px) {
    .chat-box {
        width: calc(100vw - 24px);
        max-width: none;
    }
}

/* Маленькие телефоны (полноэкранный режим) */
@media (max-width: 480px) {
    .chat-widget {
        bottom: 12px;
        right: 12px;
    }
    
    .chat-toggle {
        width: 52px;
        height: 52px;
    }
    
    .chat-box {
        position: fixed;
        bottom: 0 !important;
        right: 0;
        left: 0;
        width: 100%;
        height: calc(100vh - 70px);
        max-width: none;
        max-height: none;
        border-radius: 16px 16px 0 0;
    }
    
    .chat-header {
        padding: 14px 16px;
    }
    
    .chat-header-title {
        font-size: 14px;
    }
    
    .chat-header-status {
        font-size: 12px;
    }
    
    .chat-messages {
        padding: 12px;
        gap: 12px;
    }
    
    .message-avatar {
        width: 28px;
        height: 28px;
    }
    
    .message-text {
        font-size: 13px;
        padding: 9px 12px;
        border-radius: 10px;
    }
    
    .typing-indicator {
        margin-left: 38px;
        padding: 10px 14px;
    }
    
    .chat-input-wrapper {
        padding: 12px;
    }
    
    .chat-input {
        padding: 10px 14px;
        font-size: 13px;
    }
    
    .chat-send {
        width: 40px;
        height: 40px;
    }
    
    .notification-badge {
        font-size: 10px;
        padding: 3px 6px;
    }
    
    .notification-badge.text-badge {
        max-width: 120px;
        font-size: 9px;
    }
}

/* Очень маленькие экраны */
@media (max-width: 360px) {
    .chat-toggle {
        width: 48px;
        height: 48px;
    }
    
    .chat-header {
        padding: 12px;
    }
    
    .chat-header-info {
        gap: 8px;
    }
    
    .chat-messages {
        padding: 10px;
        gap: 10px;
    }
    
    .message {
        gap: 8px;
    }
    
    .message-avatar {
        width: 26px;
        height: 26px;
    }
    
    .typing-indicator {
        margin-left: 34px;
    }
}

/* Ландшафтная ориентация на мобильных */
@media (max-width: 768px) and (orientation: landscape) {
    .chat-box {
        height: calc(100vh - 80px);
        max-height: 450px;
    }
    
    .chat-header {
        padding: 12px 16px;
    }
    
    .chat-messages {
        padding: 12px 16px;
    }
    
    .chat-input-wrapper {
        padding: 10px 12px;
    }
}

/* Поддержка touch устройств */
@media (hover: none) and (pointer: coarse) {
    .chat-toggle:hover {
        transform: scale(1);
    }
    
    .chat-toggle:active {
        transform: scale(0.9);
    }
    
    .chat-send:hover {
        transform: scale(1);
    }
    
    .chat-send:active {
        transform: scale(0.9);
    }
}

/* Safe area для iPhone с вырезом */
@supports (padding: max(0px)) {
    .chat-widget {
        bottom: max(24px, env(safe-area-inset-bottom));
        right: max(24px, env(safe-area-inset-right));
    }
    
    @media (max-width: 480px) {
        .chat-box {
            height: calc(100vh - max(70px, env(safe-area-inset-bottom) + 70px));
        }
        
        .chat-input-wrapper {
            padding-bottom: max(12px, env(safe-area-inset-bottom));
        }
    }
}