/* ===== Chat Widget Styles ===== */
.chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99999;
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

/* Кнопка открытия чата */
.chat-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #8a2be2, #9d4edd);
    border: none;
    color: white;
    font-size: 28px;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(138, 43, 226, 0.4);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.chat-toggle-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 30px rgba(138, 43, 226, 0.6);
}

.chat-toggle-btn .chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #e74c3c;
    color: white;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    border: 2px solid #1a1a1a;
}

.chat-toggle-btn .chat-toggle-icon {
    transition: transform 0.3s ease;
}

.chat-toggle-btn.active .chat-toggle-icon {
    transform: rotate(90deg);
}

/* Окно чата */
.chat-window {
    position: absolute;
    bottom: 76px;
    right: 0;
    width: 380px;
    height: 520px;
    background: var(--dark-gray);
    border-radius: 16px;
    border: 1px solid var(--medium-gray);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: chatSlideUp 0.3s ease;
}

.chat-window.active {
    display: flex;
}

@keyframes chatSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Хедер чата */
.chat-header {
    padding: 16px 20px;
    background: linear-gradient(135deg, #8a2be2, #6a0dad);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
}

.chat-header-info h4 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
}

.chat-header-info p {
    margin: 0;
    font-size: 11px;
    opacity: 0.8;
}

.chat-header-actions {
    display: flex;
    gap: 8px;
}

.chat-header-actions button {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 16px;
    opacity: 0.8;
    transition: opacity 0.2s ease;
    padding: 4px;
}

.chat-header-actions button:hover {
    opacity: 1;
}

/* Сообщения */
.chat-messages {
    flex: 1;
    padding: 16px 20px;
    overflow-y: auto;
    background: var(--black);
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
    background: var(--medium-gray);
    border-radius: 2px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--neon-purple);
    border-radius: 2px;
}

.chat-message {
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
}

.chat-message.outgoing {
    align-items: flex-end;
}

.chat-message.incoming {
    align-items: flex-start;
}

.chat-message .message-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.4;
    word-wrap: break-word;
    position: relative;
}

.chat-message.outgoing .message-bubble {
    background: linear-gradient(135deg, #8a2be2, #9d4edd);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message.incoming .message-bubble {
    background: var(--dark-gray);
    color: var(--white);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--medium-gray);
}

.chat-message .message-time {
    font-size: 10px;
    color: var(--light-gray);
    margin-top: 4px;
    padding: 0 4px;
}

.chat-message.outgoing .message-time {
    color: rgba(255, 255, 255, 0.5);
}

.chat-message .message-file {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    margin-top: 4px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.chat-message .message-file:hover {
    background: rgba(255, 255, 255, 0.1);
}

.chat-message .message-file i {
    font-size: 20px;
    color: var(--neon-purple);
}

.chat-message .message-file span {
    font-size: 12px;
    color: var(--white);
    word-break: break-all;
}

.message-image {
    max-width: 100%;
    max-height: 300px;
    border-radius: 8px;
    border: 1px solid var(--medium-gray);
    background: var(--dark-gray);
    display: block;
}

/* Стили для битых изображений */
.message-image:not([src]), 
.message-image[src=""],
.message-image[src*="error"] {
    display: none;
}

.message-image-error {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 80px;
    padding: 20px;
    background: rgba(231, 76, 60, 0.1);
    border: 1px solid rgba(231, 76, 60, 0.3);
    border-radius: 8px;
    color: #e74c3c;
    font-size: 0.9rem;
}

.message-image-error i {
    margin-right: 10px;
    font-size: 1.2rem;
}

.message-image::before {
    content: '❌ Изображение не загружено';
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100px;
    color: var(--light-gray);
    font-size: 0.9rem;
}

.chat-message .message-image {
    max-width: 100%;
    max-height: 200px;
    border-radius: 8px;
    margin-top: 4px;
    cursor: pointer;
}

/* Индикатор набора текста */
.chat-typing {
    padding: 8px 20px;
    color: var(--light-gray);
    font-size: 12px;
    display: none;
}

.chat-typing.active {
    display: block;
}

.chat-typing span {
    animation: typingDots 1.4s infinite;
}

.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDots {
    0%, 60%, 100% { opacity: 0; }
    30% { opacity: 1; }
}

/* Ввод сообщения */
.chat-input-area {
    padding: 12px 16px;
    border-top: 1px solid var(--medium-gray);
    display: flex;
    gap: 10px;
    align-items: flex-end;
    background: var(--dark-gray);
    flex-shrink: 0;
}

.chat-input-area textarea {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--medium-gray);
    border-radius: 20px;
    background: var(--black);
    color: var(--white);
    font-size: 13px;
    resize: none;
    max-height: 100px;
    min-height: 38px;
    outline: none;
    transition: border-color 0.2s ease;
}

.chat-input-area textarea:focus {
    border-color: var(--neon-purple);
}

.chat-input-area textarea::placeholder {
    color: var(--light-gray);
}

.chat-input-area .chat-input-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: var(--medium-gray);
    color: var(--white);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-input-area .chat-input-btn:hover {
    background: var(--neon-purple);
}

.chat-input-area .chat-input-btn.send-btn {
    background: linear-gradient(135deg, #8a2be2, #9d4edd);
}

.chat-input-area .chat-input-btn.send-btn:hover {
    transform: scale(1.05);
}

/* Смайлы */
.chat-emoji-picker {
    position: absolute;
    bottom: 70px;
    right: 16px;
    background: var(--dark-gray);
    border: 1px solid var(--medium-gray);
    border-radius: 12px;
    padding: 12px;
    width: 280px;
    max-height: 200px;
    overflow-y: auto;
    display: none;
    z-index: 10;
}

.chat-emoji-picker.active {
    display: block;
}

.chat-emoji-picker .emoji-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}

.chat-emoji-picker .emoji-grid button {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.chat-emoji-picker .emoji-grid button:hover {
    background: var(--medium-gray);
}

/* Всплывающее уведомление */
.chat-notification {
    position: fixed;
    bottom: 100px;
    right: 24px;
    background: var(--dark-gray);
    border: 1px solid var(--neon-purple);
    border-radius: 12px;
    padding: 14px 18px;
    max-width: 320px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    display: none;
    animation: chatSlideUp 0.3s ease;
    z-index: 99998;
    cursor: pointer;
}

.chat-notification.active {
    display: block;
}

.chat-notification .notif-sender {
    font-weight: 600;
    color: var(--neon-purple);
    font-size: 13px;
}

.chat-notification .notif-preview {
    color: var(--white);
    font-size: 12px;
    margin-top: 4px;
}

/* Адаптивность */
@media (max-width: 480px) {
    .chat-window {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
        border: none;
    }
    
    .chat-widget {
        bottom: 16px;
        right: 16px;
    }
    
    .chat-toggle-btn {
        width: 52px;
        height: 52px;
        font-size: 22px;
    }
}

/* ===== Chat Widget Styles ===== */
.chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99999;
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

/* Кнопка открытия чата */
.chat-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #8a2be2, #9d4edd);
    border: none;
    color: white;
    font-size: 28px;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(138, 43, 226, 0.4);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.chat-toggle-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 30px rgba(138, 43, 226, 0.6);
}

.chat-toggle-btn .chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #e74c3c;
    color: white;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    border: 2px solid #1a1a1a;
}

.chat-toggle-btn .chat-toggle-icon {
    transition: transform 0.3s ease;
}

.chat-toggle-btn.active .chat-toggle-icon {
    transform: rotate(90deg);
}

/* Окно чата */
.chat-window {
    position: absolute;
    bottom: 76px;
    right: 0;
    width: 480px;
    min-width: 320px;
    max-width: 700px;
    height: 600px;
    min-height: 400px;
    max-height: 80vh;
    background: var(--dark-gray);
    border-radius: 16px;
    border: 1px solid var(--medium-gray);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: chatSlideUp 0.3s ease;
    resize: none; /* Отключаем встроенный resize */
}

.chat-window.active {
    display: flex;
}

/* ===== Ресайз-хендл для изменения ширины ===== */
.chat-resize-handle {
    position: absolute;
    left: -4px;
    top: 0;
    bottom: 0;
    width: 8px;
    cursor: ew-resize;
    z-index: 20;
    background: transparent;
    transition: background 0.15s ease;
    user-select: none;
}

.chat-resize-handle:hover,
.chat-resize-handle.active {
    background: rgba(138, 43, 226, 0.3);
}

.chat-resize-handle::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 2px;
    height: 30px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.chat-resize-handle:hover::after,
.chat-resize-handle.active::after {
    opacity: 1;
}

/* Индикатор изменения размера (визуальный фидбек при ресайзе) */
.chat-window.resizing {
    transition: none !important;
    user-select: none;
}

.chat-window.resizing .chat-resize-handle {
    background: rgba(138, 43, 226, 0.4);
}

/* ===== Остальные стили ===== */
@keyframes chatSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Хедер чата */
.chat-header {
    padding: 12px 16px;
    background: linear-gradient(135deg, #8a2be2, #6a0dad);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    min-height: 56px;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
}

.chat-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}

.chat-header-info {
    flex: 1;
    min-width: 0;
}

.chat-header-info h4 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header-info p {
    margin: 0;
    font-size: 11px;
    opacity: 0.8;
}

.chat-header-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.chat-header-actions button {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 16px;
    opacity: 0.8;
    transition: opacity 0.2s ease;
    padding: 4px 6px;
}

.chat-header-actions button:hover {
    opacity: 1;
}

/* Тело чата - основной контейнер для списка и сообщений */
.chat-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
    position: relative;
}

/* ===== Список чатов ===== */
.chat-list {
    width: 260px;
    min-width: 260px;
    max-width: 320px;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    background: rgba(255, 255, 255, 0.02);
    border-right: 1px solid var(--medium-gray);
    overscroll-behavior: contain;
    flex-shrink: 0;
    transition: all 0.3s ease;
}

.chat-list:not(.visible) {
    width: 0;
    min-width: 0;
    padding: 0;
    border-right: none;
    overflow: hidden;
}

.chat-list.visible {
    display: block;
}

.chat-list::-webkit-scrollbar {
    width: 4px;
}

.chat-list::-webkit-scrollbar-track {
    background: transparent;
}

.chat-list::-webkit-scrollbar-thumb {
    background: var(--neon-purple);
    border-radius: 2px;
}

.chat-list-item {
    display: flex;
    align-items: stretch;
    padding: 10px 12px;
    cursor: pointer;
    transition: background 0.2s ease;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    gap: 10px;
    min-height: 56px;
}

.chat-list-item:hover {
    background: rgba(138, 43, 226, 0.05);
}

.chat-list-item.active {
    background: rgba(138, 43, 226, 0.1);
    border-left: 3px solid var(--neon-purple);
}

/* Аватар */
.chat-list-avatar {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--medium-gray);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.85rem;
    color: #fff;
    overflow: hidden;
}

.chat-list-avatar.guest-avatar {
    background: var(--medium-gray);
}

.chat-list-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
}

.chat-list-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--white);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    line-height: 1.3;
}

.chat-list-last {
    font-size: 0.75rem;
    color: var(--light-gray);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.chat-list-badge {
    flex-shrink: 0;
    background: var(--neon-purple);
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    align-self: center;
    margin-left: auto;
}

/* Кнопка переключения списка чатов */
.chat-list-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--white);
    font-size: 1rem;
    padding: 4px 8px;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.2s ease;
    margin-right: 4px;
}

.chat-list-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
}

.chat-list-toggle:active {
    background: rgba(255, 255, 255, 0.05);
}

/* ===== Область сообщений ===== */
.chat-messages-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--black);
}

.chat-body.chat-list-visible .chat-messages-area {
    width: calc(100% - 260px);
}

.chat-body:not(.chat-list-visible) .chat-messages-area {
    width: 100%;
}

/* Сообщения */
.chat-messages {
    flex: 1;
    padding: 12px 16px;
    overflow-y: auto;
    background: var(--black);
    min-height: 0;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
    background: var(--medium-gray);
    border-radius: 2px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--neon-purple);
    border-radius: 2px;
}

.chat-message {
    margin-bottom: 10px;
    display: flex;
    flex-direction: column;
}

.chat-message.outgoing {
    align-items: flex-end;
}

.chat-message.incoming {
    align-items: flex-start;
}

.chat-message .message-bubble {
    max-width: 85%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.4;
    word-wrap: break-word;
    position: relative;
}

.chat-message.outgoing .message-bubble {
    background: linear-gradient(135deg, #8a2be2, #9d4edd);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message.incoming .message-bubble {
    background: var(--dark-gray);
    color: var(--white);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--medium-gray);
}

.chat-message .message-time {
    font-size: 10px;
    color: var(--light-gray);
    margin-top: 3px;
    padding: 0 4px;
}

.chat-message.outgoing .message-time {
    color: rgba(255, 255, 255, 0.5);
}

.chat-message .message-file {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    margin-top: 4px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.chat-message .message-file:hover {
    background: rgba(255, 255, 255, 0.1);
}

.chat-message .message-file i {
    font-size: 18px;
    color: var(--neon-purple);
}

.chat-message .message-file span {
    font-size: 12px;
    color: var(--white);
    word-break: break-all;
}

.chat-message .message-image {
    max-width: 100%;
    max-height: 180px;
    border-radius: 8px;
    margin-top: 4px;
    cursor: pointer;
}

/* Индикатор набора текста */
.chat-typing {
    padding: 4px 16px;
    color: var(--light-gray);
    font-size: 12px;
    display: none;
    flex-shrink: 0;
}

.chat-typing.active {
    display: block;
}

.chat-typing span {
    animation: typingDots 1.4s infinite;
}

.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDots {
    0%, 60%, 100% { opacity: 0; }
    30% { opacity: 1; }
}

/* Ввод сообщения */
.chat-input-area {
    padding: 8px 12px;
    border-top: 1px solid var(--medium-gray);
    display: flex;
    gap: 8px;
    align-items: flex-end;
    background: var(--dark-gray);
    flex-shrink: 0;
    min-height: 48px;
}

.chat-input-area textarea {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--medium-gray);
    border-radius: 20px;
    background: var(--black);
    color: var(--white);
    font-size: 13px;
    resize: none;
    max-height: 80px;
    min-height: 32px;
    outline: none;
    transition: border-color 0.2s ease;
    font-family: inherit;
}

.chat-input-area textarea:focus {
    border-color: var(--neon-purple);
}

.chat-input-area textarea::placeholder {
    color: var(--light-gray);
}

.chat-input-area .chat-input-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--medium-gray);
    color: var(--white);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
}

.chat-input-area .chat-input-btn:hover {
    background: var(--neon-purple);
}

.chat-input-area .chat-input-btn.send-btn {
    background: linear-gradient(135deg, #8a2be2, #9d4edd);
    width: 36px;
    height: 36px;
}

.chat-input-area .chat-input-btn.send-btn:hover {
    transform: scale(1.05);
}

/* Смайлы */
.chat-emoji-picker {
    position: absolute;
    bottom: 70px;
    right: 16px;
    background: var(--dark-gray);
    border: 1px solid var(--medium-gray);
    border-radius: 12px;
    padding: 10px;
    width: 260px;
    max-height: 180px;
    overflow-y: auto;
    display: none;
    z-index: 10;
}

.chat-emoji-picker.active {
    display: block;
}

.chat-emoji-picker .emoji-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 3px;
}

.chat-emoji-picker .emoji-grid button {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.chat-emoji-picker .emoji-grid button:hover {
    background: var(--medium-gray);
}

/* Всплывающее уведомление */
.chat-notification {
    position: fixed;
    bottom: 100px;
    right: 24px;
    background: var(--dark-gray);
    border: 1px solid var(--neon-purple);
    border-radius: 12px;
    padding: 12px 16px;
    max-width: 300px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    display: none;
    animation: chatSlideUp 0.3s ease;
    z-index: 99998;
    cursor: pointer;
}

.chat-notification.active {
    display: block;
}

.chat-notification .notif-sender {
    font-weight: 600;
    color: var(--neon-purple);
    font-size: 13px;
}

.chat-notification .notif-preview {
    color: var(--white);
    font-size: 12px;
    margin-top: 3px;
}

/* ===== Адаптивность ===== */

/* Планшеты и маленькие экраны */
@media (max-width: 768px) {
    .chat-window {
        width: 400px;
        min-width: 300px;
        max-width: 90vw;
        height: 550px;
        min-height: 350px;
        max-height: 80vh;
    }
    
    .chat-list {
        width: 160px;
        min-width: 120px;
    }

    .chat-list-toggle {
        display: block !important;
    }
    
    /* На мобильных устройствах список чатов по умолчанию скрыт */
    .chat-list {
        position: absolute;
        left: 0;
        top: 0;
        height: 100%;
        z-index: 10;
        background: var(--dark-gray);
        box-shadow: 2px 0 10px rgba(0,0,0,0.3);
        transition: transform 0.3s ease;
        transform: translateX(-100%);
        width: 260px;
        min-width: 260px;
    }
    
    .chat-list.visible {
        transform: translateX(0);
    }
    
    .chat-list:not(.visible) {
        transform: translateX(-100%);
        width: 260px;
        min-width: 260px;
        border-right: 1px solid var(--medium-gray);
    }
    
    /* Затемнение фона при открытом списке */
    .chat-list.visible::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: -1;
    }
}

/* Мобильные устройства */
@media (max-width: 480px) {
    .chat-widget {
        bottom: 16px;
        right: 16px;
    }
    
    .chat-toggle-btn {
        width: 52px;
        height: 52px;
        font-size: 22px;
    }
    
    .chat-window {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        width: 100% !important;
        min-width: 100%;
        max-width: 100%;
        height: 100% !important;
        min-height: 100%;
        max-height: 100%;
        border-radius: 0;
        border: none;
    }
    
    /* Отключаем ресайз на мобильных */
    .chat-resize-handle {
        display: none !important;
    }
    
    .chat-list {
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        z-index: 10;
        border-right: none;
        display: none;
        background: var(--black);
    }
    
    .chat-list.visible {
        display: block;
    }
    
    .chat-list-toggle {
        display: block !important;
    }
    
    .chat-messages-area {
        width: 100%;
    }
    
    .chat-header {
        padding: 10px 12px;
        min-height: 48px;
    }
    
    .chat-header-avatar {
        width: 30px;
        height: 30px;
        font-size: 12px;
    }
    
    .chat-header-info h4 {
        font-size: 13px;
    }
    
    .chat-messages {
        padding: 10px 12px;
    }
    
    .chat-input-area {
        padding: 6px 10px;
        gap: 6px;
    }
    
    .chat-input-area textarea {
        font-size: 12px;
        padding: 6px 10px;
        min-height: 28px;
    }
    
    .chat-input-area .chat-input-btn {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }
    
    .chat-input-area .chat-input-btn.send-btn {
        width: 32px;
        height: 32px;
    }
}

/* Очень маленькие экраны */
@media (max-width: 360px) {
    .chat-window {
        font-size: 12px;
    }
    
    .chat-message .message-bubble {
        font-size: 12px;
        padding: 6px 10px;
    }
    
    .chat-header-info h4 {
        font-size: 12px;
    }
}

.chat-list-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 40px 20px;
    text-align: center;
    color: var(--light-gray);
}

.chat-list-empty i {
    font-size: 48px;
    color: var(--medium-gray);
    margin-bottom: 16px;
}

.chat-list-empty p {
    font-size: 14px;
    margin: 0;
    line-height: 1.5;
}

/* Метка для гостевых чатов в списке */
.chat-list-label {
    font-size: 0.5rem;
    padding: 1px 6px;
    border-radius: 8px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.chat-list-label {
    display: inline-block;
    background: rgba(138, 43, 226, 0.2);
    color: var(--neon-purple);
    font-size: 9px;
    padding: 1px 6px;
    border-radius: 10px;
    margin-left: 6px;
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    vertical-align: middle;
}

/* Стили для новых чатов */
.chat-list-item.new-chat {
    border-left: 3px solid var(--neon-purple);
    background: rgba(138, 43, 226, 0.05);
}

.chat-list-item .new-chat-avatar {
    background: var(--neon-purple);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

.chat-list-label.new-label {
    background: var(--neon-purple);
    color: #fff;
}

.chat-list-action {
    flex-shrink: 0;
    color: var(--neon-purple);
    font-size: 1.1rem;
    opacity: 0.6;
    transition: opacity 0.3s ease;
    align-self: center;
    margin-left: auto;
}

.chat-list-item:hover .chat-list-action {
    opacity: 1;
}

.chat-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    color: var(--neon-purple);
}

.chat-list-item.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* Профиль в списке чатов */
.chat-list-profile {
    display: inline-block;
    font-size: 0.55rem;
    padding: 1px 8px;
    border-radius: 10px;
    background: rgba(138, 43, 226, 0.12);
    color: var(--neon-purple);
    font-weight: 500;
    letter-spacing: 0.3px;
    border: 1px solid rgba(138, 43, 226, 0.15);
    line-height: 1.4;
    max-width: 100%;
    width: fit-content;
}

.chat-list-item.active .chat-list-profile {
    background: rgba(138, 43, 226, 0.25);
    color: #fff;
    border-color: rgba(138, 43, 226, 0.3);
}

/* Цвета профилей для разных ролей */
.chat-list-profile[data-profile="Студент"] {
    background: rgba(46, 204, 113, 0.15);
    color: #2ecc71;
    border-color: rgba(46, 204, 113, 0.3);
}

.chat-list-profile[data-profile="Преподаватель"] {
    background: rgba(52, 152, 219, 0.15);
    color: #3498db;
    border-color: rgba(52, 152, 219, 0.3);
}

.chat-list-profile[data-profile="Админ"] {
    background: rgba(231, 76, 60, 0.15);
    color: #e74c3c;
    border-color: rgba(231, 76, 60, 0.3);
}

.chat-list-profile[data-profile="Директор"] {
    background: rgba(241, 196, 15, 0.15);
    color: #f39c12;
    border-color: rgba(241, 196, 15, 0.3);
}

.chat-list-profile[data-profile="Dev"] {
    background: rgba(155, 89, 182, 0.15);
    color: #9b59b6;
    border-color: rgba(155, 89, 182, 0.3);
}

.chat-list-profile[data-profile="ТП"] {
    background: rgba(26, 188, 156, 0.15);
    color: #1abc9c;
    border-color: rgba(26, 188, 156, 0.3);
}

.chat-list-profile[data-profile="Контент"] {
    background: rgba(243, 156, 18, 0.15);
    color: #f39c12;
    border-color: rgba(243, 156, 18, 0.3);
}

/* Адаптивность для мобильных */
@media (max-width: 480px) {
    .chat-list-item {
        padding: 8px 10px;
        min-height: 48px;
    }
    
    .chat-list-avatar {
        width: 30px;
        height: 30px;
        font-size: 0.7rem;
    }
    
    .chat-list-name {
        font-size: 0.8rem;
    }
    
    .chat-list-profile {
        font-size: 0.5rem;
        padding: 1px 6px;
    }
    
    .chat-list-last {
        font-size: 0.65rem;
    }
    
    .chat-list-badge {
        font-size: 0.5rem;
        min-width: 16px;
        height: 16px;
    }
}

/* Состояние загрузки */
.chat-list-item.loading {
    opacity: 0.6;
    pointer-events: none;
}

.chat-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    color: var(--neon-purple);
    width: 100%;
}

.chat-group-header {
    cursor:pointer;
    margin-left: 22px;
}

/* Сообщения только со смайлами */
.message-bubble.emoji-only {
    font-size: 64px;
    line-height: 1.2;
    background: transparent !important;
    border: none !important;
    padding: 4px 0;
    box-shadow: none !important;
}

.message-bubble.emoji-only .message-text {
    font-size: 64px;
}

/* Для входящих сообщений со смайлами */
.chat-message.incoming .message-bubble.emoji-only {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
}

/* Для исходящих сообщений со смайлами */
.chat-message.outgoing .message-bubble.emoji-only {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
}

/* Убираем лишние отступы у сообщений со смайлами */
.chat-message .message-bubble.emoji-only {
    padding: 2px 4px;
}

/* Стили для контейнера сообщения при смайлах */
.chat-message .message-bubble.emoji-only + .message-time {
    margin-top: 2px;
}

/* Верхний хендл для вертикального ресайза */
.chat-resize-handle-top {
    position: absolute;
    top: -4px;
    left: 0;
    right: 0;
    height: 8px;
    cursor: ns-resize;
    z-index: 20;
    background: transparent;
    transition: background 0.2s ease;
}

.chat-resize-handle-top:hover {
    background: rgba(138, 43, 226, 0.15);
}

.chat-resize-handle-top::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 3px;
    background: var(--medium-gray);
    border-radius: 2px;
    opacity: 0.3;
    transition: opacity 0.3s ease;
}

.chat-resize-handle-top:hover::after {
    opacity: 0.8;
    background: var(--neon-purple);
}

.chat-resize-handle-top.active::after {
    opacity: 1;
    background: var(--neon-purple);
    width: 60px;
}

/* Анимация ресайза */
.chat-window.resizing-vertical {
    transition: none !important;
}

.chat-window.resizing-vertical .chat-resize-handle-top {
    background: rgba(138, 43, 226, 0.1);
}

/* Адаптация для мобильных */
@media (max-width: 480px) {
    .chat-resize-handle-top {
        display: none !important;
    }
}

/* Окно чата */
.chat-window {
    position: fixed;
    bottom: 80px;
    right: 20px;
    width: 480px;
    height: 550px;
    min-height: 400px;
    max-height: calc(100vh - 60px);
    max-width: 1000px;
    background: var(--dark-gray);
    border: 1px solid var(--medium-gray);
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 1000;
    transition: height 0.1s ease;
    /* Добавляем переменную для максимальной высоты */
    max-height: var(--chat-max-height, calc(100vh - 60px));
}

.chat-window.active {
    display: flex;
}

.chat-window.minimized {
    height: 50px !important;
    min-height: 50px !important;
    max-height: 50px !important;
    overflow: hidden;
}

.chat-window.minimized .chat-body,
.chat-window.minimized .chat-input-area,
.chat-window.minimized .chat-resize-handle,
.chat-window.minimized .chat-resize-handle-top {
    display: none;
}

.chat-window.minimized .chat-header {
    border-bottom: none;
}








/* ===== Стили для модального окна поиска пользователей ===== */
.chat-search-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100000;
    backdrop-filter: blur(5px);
}

.chat-search-modal-content {
    background: var(--dark-gray);
    border: 1px solid var(--medium-gray);
    border-radius: 16px;
    width: 90%;
    min-height: 80vh;
    max-width: 420px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    animation: chatSlideUp 0.3s ease;
    overflow: hidden;
}

.chat-search-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: linear-gradient(135deg, #8a2be2, #6a0dad);
    border-bottom: none;
    flex-shrink: 0;
}

.chat-search-modal-header h5 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: white;
}

.chat-search-modal-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 18px;
    opacity: 0.8;
    transition: opacity 0.2s;
    padding: 4px;
}

.chat-search-modal-close:hover {
    opacity: 1;
}

.chat-search-modal-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
    background: var(--dark-gray);
}

.chat-search-modal-body > input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--medium-gray);
    border-radius: 20px;
    background: var(--black);
    color: var(--white);
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s;
    margin-bottom: 15px;
    box-sizing: border-box;
}

.chat-search-modal-body > input:focus {
    border-color: var(--neon-purple);
}

.chat-search-modal-body > input::placeholder {
    color: var(--light-gray);
}

.chat-search-results {
    min-height: 300px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-search-results::-webkit-scrollbar {
    width: 4px;
}

.chat-search-results::-webkit-scrollbar-track {
    background: transparent;
}

.chat-search-results::-webkit-scrollbar-thumb {
    background: var(--neon-purple);
    border-radius: 2px;
}

.chat-search-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    cursor: pointer;
    border-radius: 10px;
    transition: background 0.2s;
    gap: 10px;
    border: 1px solid transparent;
}

.chat-search-item:hover {
    background: rgba(138, 43, 226, 0.05);
    border-color: rgba(138, 43, 226, 0.2);
}

.chat-search-item.selected {
    background: rgba(138, 43, 226, 0.1);
    border-color: var(--neon-purple);
}

.chat-search-item.has-chat {
    opacity: 0.6;
}

.chat-search-item.has-chat:not(.selected) {
    cursor: not-allowed;
}

.chat-search-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    background: var(--medium-gray);
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-search-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-search-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-search-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--white);
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.chat-search-profile {
    font-size: 12px;
    color: var(--light-gray);
}

.chat-search-check {
    color: var(--light-gray);
    font-size: 18px;
    flex-shrink: 0;
}

.chat-search-item.selected .chat-search-check {
    color: var(--neon-purple);
}

.chat-search-empty {
    text-align: center;
    padding: 20px;
    color: var(--light-gray);
    font-size: 13px;
}

.chat-exists-badge {
    display: inline-block;
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 10px;
    background: rgba(231, 76, 60, 0.2);
    color: #e74c3c;
    font-weight: 500;
}

/* Выбранные пользователи */
.chat-selected-users {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--medium-gray);
}

.chat-selected-user {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(138, 43, 226, 0.15);
    border: 1px solid rgba(138, 43, 226, 0.3);
    padding: 5px 10px;
    border-radius: 15px;
    font-size: 12px;
    color: var(--white);
}

.remove-user {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--light-gray);
    padding: 0;
    font-size: 12px;
    transition: color 0.2s;
}

.remove-user:hover {
    color: #e74c3c;
}

/* Кнопка создания */
.chat-search-modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--medium-gray);
    background: var(--dark-gray);
    flex-shrink: 0;
}

.chat-create-btn {
    width: 100%;
    padding: 10px;
    background: linear-gradient(135deg, #8a2be2, #9d4edd);
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s;
}

.chat-create-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(138, 43, 226, 0.4);
}

.chat-create-btn:disabled {
    background: var(--medium-gray);
    cursor: not-allowed;
    opacity: 0.6;
}

/* Поле ввода имени группового чата */
.chat-name-container {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--medium-gray);
}

.chat-name-container input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--medium-gray);
    border-radius: 20px;
    background: var(--black);
    color: var(--white);
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.chat-name-container input:focus {
    border-color: var(--neon-purple);
}

.chat-name-container input::placeholder {
    color: var(--light-gray);
}

/* Стили для групповых чатов */
.chat-list-avatar.group-avatar {
    background: rgba(138, 43, 226, 0.3);
    color: #fff;
}

.chat-list-label.group-label {
    background: rgba(52, 152, 219, 0.2);
    color: #3498db;
}

.chat-new-btn {
    width: 25px;
    height: 25px;
    border-radius: 50%;
    background: linear-gradient(135deg, #8a2be2, #9d4edd);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
    font-size: 12px;
    box-shadow: 0 2px 8px rgba(138, 43, 226, 0.3);
}

.chat-notification {
    z-index: 100001; /* Выше, чем у модального окна (100000) */
}

.chat-participants-tooltip {
    position: fixed;
    background: var(--dark-gray);
    border: 1px solid var(--neon-purple);
    border-radius: 8px;
    padding: 8px 12px;
    color: var(--white);
    font-size: 12px;
    z-index: 100000;
    max-width: 250px;
    pointer-events: none;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

/* Командная панель над списком чатов */
.chat-list-header {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--medium-gray);
    background: var(--dark-gray);
    flex-shrink: 0;
}

.chat-search-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--black);
    border: 1px solid var(--medium-gray);
    border-radius: 20px;
    padding: 6px 12px;
    transition: border-color 0.2s;
}

.chat-search-wrapper:focus-within {
    border-color: var(--neon-purple);
}

.chat-search-wrapper i {
    color: var(--light-gray);
    font-size: 12px;
}

.chat-search-wrapper input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--white);
    font-size: 13px;
    padding: 0;
}

.chat-search-wrapper input::placeholder {
    color: var(--light-gray);
}

.chat-new-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #8a2be2, #9d4edd);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    font-size: 14px;
}

.chat-new-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 15px rgba(138, 43, 226, 0.5);
}

.chat-new-label {
    font-size: 13px;
    color: var(--white);
    font-weight: 500;
    cursor: pointer;
}

.chat-new-chat-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Контекстное меню */
.chat-context-menu {
    position: fixed;
    background: var(--dark-gray);
    border: 1px solid var(--medium-gray);
    border-radius: 10px;
    padding: 6px;
    min-width: 220px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    z-index: 100001;
    animation: chatSlideUp 0.2s ease;
}

.chat-context-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    border-radius: 6px;
    color: var(--white);
    font-size: 13px;
    transition: background 0.2s;
}

.chat-context-menu-item:hover {
    background: rgba(138, 43, 226, 0.15);
}

.chat-context-menu-item i {
    width: 16px;
    text-align: center;
    color: var(--neon-purple);
}

.chat-context-menu-item.danger {
    color: #e74c3c;
}

.chat-context-menu-item.danger i {
    color: #e74c3c;
}

.chat-context-menu-item.danger:hover {
    background: rgba(231, 76, 60, 0.1);
}

/* Кликабельность заголовка */
.chat-header-info {
    cursor: pointer;
    transition: opacity 0.2s;
}

.chat-header-info:hover {
    opacity: 0.85;
}

/* Режим наблюдателя */
.chat-spectator-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    margin: 0 16px 10px;
    background: rgba(243, 156, 18, 0.12);
    border: 1px solid rgba(243, 156, 18, 0.3);
    border-radius: 8px;
    color: #f39c12;
    font-size: 0.8rem;
}

.chat-spectator-banner i {
    font-size: 1rem;
}

.chat-group-spectator .chat-group-header {
    color: #f39c12;
}

.chat-group-spectator .chat-group-count {
    background: rgba(243, 156, 18, 0.2);
    color: #f39c12;
}