.chats-container {
    position: fixed;
    right: 20px;
    top: 100px;
    bottom: 20px;
    width: 450px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    z-index: 1000;
    display:none;
}

.chat-card {
    background: white;
    border-radius: 10px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 120px);
    min-height: 400px;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.chat-header {
    background: #3ba9f5;
    color: white;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h3 {
    font-size: 1.2em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.close-chat {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 16px;
    transition: background 0.3s;
}

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

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: fadeIn 0.3s ease-in;
}

.message-own {
    align-self: flex-end;
}

.message-other {
    align-self: flex-start;
}

.message-bubble {
    padding: 10px 12px;
    border-radius: 12px;
    word-wrap: break-word;
    position: relative;
}

.message-own .message-bubble {
    background: #3bc8f5;
    color: white;
    border-bottom-right-radius: 4px;
}

.message-other .message-bubble {
    background: white;
    color: #333;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.message-username {
    font-size: 0.8em;
    font-weight: bold;
    margin-bottom: 4px;
    display: block;
}

.message-own .message-username {
    color: rgba(255,255,255,0.9);
    text-align: right;
}

.message-other .message-username {
    color: #3bc8f5;
}

.message-text {
    font-size: 0.95em;
    line-height: 1.4;
}

.message-time {
    font-size: 0.7em;
    margin-top: 4px;
    display: block;
}

.message-own .message-time {
    color: rgba(255,255,255,0.7);
    text-align: right;
}

.message-other .message-time {
    color: #999;
}

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

.chat-input {
    padding: 15px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    gap: 10px;
    background: white;
}

.chat-input input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 20px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.3s;
}

.chat-input input:focus {
    border-color: #3bc8f5;
}

.chat-input button {
    padding: 8px 20px;
    background: #3bc8f5;
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    transition: transform 0.2s, opacity 0.3s;
}

.chat-input button:hover {
    transform: scale(1.05);
    opacity: 0.9;
}

.empty-chat {
    text-align: center;
    color: #999;
    padding: 40px;
    font-style: italic;
}

.status {
    position: fixed;
    bottom: 20px;
    left: 20px;
    color: white;
    font-size: 0.9em;
    z-index: 1001;
    transition: opacity 0.5s;
}

/* Стили для скроллбара */
.messages-container::-webkit-scrollbar {
    width: 6px;
}

.messages-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.messages-container::-webkit-scrollbar-thumb {
    background: #3bc8f5;
    border-radius: 3px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: #3bc8f5;
}

/* Адаптивность */
@media (max-width: 768px) {
    .chats-container {
        right: 10px;
        left: 10px;
        width: auto;
    }
    
    .chat-card {
        height: calc(100vh - 100px);
    }
    
    .join-chat-form {
        flex-direction: column;
        width: 90%;
    }
    
    .message {
        max-width: 95%;
    }
}

/* Оверлей для затемнения фона при открытых чатах */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.3);
    pointer-events: none;
    z-index: 999;
}

.chats-container:empty + .overlay {
    display: none;
}

.open-chat {
    position: relative;
    display: inline-block;
    padding: 8px 16px;
    margin: 5px;
    background: #3bc8f5;
    color: white;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s;
}

.open-chat:hover {
    background: #007bff;
    transform: scale(1.05);
}

.unread-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #ff4444;
    color: white;
    border-radius: 50%;
    padding: 2px;
    font-size: 12px;
    font-weight: bold;
    min-width: 18px;
    text-align: center;
    animation: pulse 1s infinite;
}

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

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* === Контейнер превью файлов (под полем ввода) === */
.attachments-preview {
    display: none; /* скрыт по умолчанию, пока нет файлов */
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 15px 0 15px;
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
    align-items: center;
}

/* Элемент с одним файлом в превью */
.attachment-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: white;
    padding: 4px 10px 4px 8px;
    border-radius: 16px;
    border: 1px solid #dee2e6;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    font-size: 13px;
    transition: all 0.2s;
    cursor: default;
    max-width: 200px;
}

.attachment-item:hover {
    background: #f1f3f5;
    border-color: #3bc8f5;
    box-shadow: 0 2px 6px rgba(59, 200, 245, 0.15);
}

/* Иконка файла */
.attachment-item .file-icon {
    font-size: 16px;
    line-height: 1;
}

/* Имя файла – обрезаем длинные названия */
.attachment-item .file-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #495057;
    font-weight: 500;
}

/* Кнопка удаления (крестик) */
.attachment-item .remove-attachment {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(255, 68, 68, 0.1);
    color: #ff4444;
    font-size: 14px;
    font-weight: bold;
    line-height: 1;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    padding: 0;
    user-select: none;
}

.attachment-item .remove-attachment:hover {
    background: #ff4444;
    color: white;
    transform: scale(1.1);
}

/* === Вложения внутри сообщения === */
.message-attachments {
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-top: 4px;
    border-top: 1px dashed rgba(0,0,0,0.08);
}

/* Ссылка на файл в сообщении */
.attachment-link {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 6px;
    background: rgba(59, 200, 245, 0.08);
    transition: background 0.2s;
    font-size: 0.9em;
}

.attachment-link a {
    color: #007bff;
    text-decoration: none;
    word-break: break-all;
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
}

.attachment-link a:hover {
    text-decoration: underline;
    color: #0056b3;
}

/* Для собственных сообщений – ссылки светлее */
.message-own .attachment-link {
    background: rgba(255,255,255,0.15);
}
.message-own .attachment-link a {
    color: #ffffff;
}
.message-own .attachment-link a:hover {
    color: #e0f0fa;
}

/* Если нужно показать превью изображений – добавляем класс */
.attachment-image {
    max-width: 200px;
    max-height: 200px;
    border-radius: 6px;
    margin-top: 4px;
    border: 1px solid #ddd;
    display: block;
}

/* Адаптивность для мобильных устройств */
@media (max-width: 768px) {
    .attachments-preview {
        padding: 6px 10px 0 10px;
        gap: 5px;
    }
    .attachment-item {
        font-size: 12px;
        padding: 3px 8px 3px 6px;
        max-width: 150px;
    }
    .attachment-item .remove-attachment {
        width: 16px;
        height: 16px;
        font-size: 12px;
    }
    .attachment-image {
        max-width: 150px;
        max-height: 150px;
    }
}