/* static/css/chat.css */

/* ===== ЧАТ-ВИДЖЕТ ===== */
.chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1050;
}

.chat-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
    font-size: 1.5rem;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    transition: all 0.3s ease;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}

.chat-toggle-btn:active {
    transform: scale(0.95);
}

.chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #dc3545;
    color: white;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    font-size: 0.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

/* ===== ОКНО ЧАТА ===== */
.chat-container {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 420px;
    height: 580px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s ease;
    display: none;
}

.chat-container.show {
    opacity: 1;
    transform: translateY(0) scale(1);
    display: flex;
}

/* ===== ЭКРАНЫ ЧАТА ===== */
.chat-screen {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* ===== ЗАГОЛОВОК ===== */
.chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    min-height: 56px;
}

.chat-header-title {
    font-weight: 600;
    font-size: 1.05rem;
}

.chat-header-actions {
    display: flex;
    gap: 4px;
}

.chat-header-actions .btn {
    color: white;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.2s;
    border: none;
    background: transparent;
}

.chat-header-actions .btn:hover {
    background: rgba(255,255,255,0.2);
}

/* Кнопка "Назад" в комнате чата */
.btn-back {
    color: white;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.2s;
    border: none;
    background: transparent;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-back:hover {
    background: rgba(255,255,255,0.2);
}

/* Выпадающее меню в комнате чата */
.chat-header-actions .dropdown .btn {
    color: white;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.2s;
    border: none;
    background: transparent;
}

.chat-header-actions .dropdown .btn:hover {
    background: rgba(255,255,255,0.2);
}

.chat-header-actions .dropdown-menu {
    background: white;
    border: none;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    padding: 6px 0;
    min-width: 200px;
}

.chat-header-actions .dropdown-menu .dropdown-item {
    padding: 8px 16px;
    font-size: 0.85rem;
    color: #333;
    transition: background 0.15s;
}

.chat-header-actions .dropdown-menu .dropdown-item:hover {
    background: #f0f2f5;
}

.chat-header-actions .dropdown-menu .dropdown-item.text-danger:hover {
    background: #fde8e8;
}

.chat-header-actions .dropdown-menu .dropdown-divider {
    margin: 4px 0;
}

/* ===== СПИСОК ЧАТОВ ===== */
.chat-list-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-search {
    padding: 10px 12px;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}

.chat-item {
    padding: 10px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: background 0.2s;
    border-left: 3px solid transparent;
    position: relative;
}

.chat-item:hover {
    background: #f8f9fa;
}

.chat-item.active {
    background: #e3f2fd;
    border-left-color: #667eea;
}

.chat-avatar-wrapper {
    position: relative;
    margin-right: 10px;
    flex-shrink: 0;
}

.chat-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
}

/* ===== ОНЛАЙН-СТАТУС ===== */
.online-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 14px;
    height: 14px;
    background: #4caf50;
    border: 2px solid white;
    border-radius: 50%;
    display: block;
}

.chat-info {
    flex: 1;
    min-width: 0;
}

.chat-name {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 2px;
}

.chat-preview {
    font-size: 0.8rem;
    color: #6c757d;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-meta {
    flex-shrink: 0;
    text-align: right;
    margin-left: 8px;
}

.chat-time {
    font-size: 0.65rem;
    color: #adb5bd;
}

.chat-unread {
    background: #dc3545;
    color: white;
    border-radius: 12px;
    padding: 0 8px;
    font-size: 0.65rem;
    font-weight: bold;
    min-width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-top: 4px;
}

/* МЕНЮ ЧАТА (три точки) - скрыто в новой версии, оставлено для совместимости */
.chat-item-actions {
    opacity: 0;
    transition: opacity 0.2s;
    margin-left: 4px;
    flex-shrink: 0;
}

.chat-item:hover .chat-item-actions {
    opacity: 1;
}

/* ===== ОКНО СООБЩЕНИЙ ===== */
.chat-messages-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    display: none;
}

.active-chat-header {
    padding: 10px 12px;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    background: #f8f9fa;
    flex-shrink: 0;
}

.active-chat-header .chat-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.active-chat-info {
    flex: 1;
    margin-left: 8px;
}

.active-chat-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.active-chat-status {
    font-size: 0.7rem;
    color: #6c757d;
}

/* Статус онлайн в заголовке */
.active-chat-status.online {
    color: #4caf50;
}

/* ===== СООБЩЕНИЯ ===== */
.chat-messages {
    flex: 1;
    padding: 12px 16px;
    overflow-y: auto;
    background: #f0f2f5;
}

.message {
    display: flex;
    margin-bottom: 8px;
    align-items: flex-end;
}

.message.other {
    justify-content: flex-start;
}

.message.own {
    justify-content: flex-end;
}

.message-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    margin-right: 6px;
    flex-shrink: 0;
}

.message.own .message-avatar {
    margin-right: 0;
    margin-left: 6px;
    order: 1;
}

.message-content {
    max-width: 70%;
}

.message-sender {
    font-size: 0.7rem;
    color: #6c757d;
    margin-bottom: 2px;
}

.message-bubble {
    padding: 6px 12px;
    border-radius: 12px;
    position: relative;
    word-wrap: break-word;
    font-size: 0.9rem;
    line-height: 1.4;
}

.message.other .message-bubble {
    background: white;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.message.own .message-bubble {
    background: #667eea;
    color: white;
    border-bottom-right-radius: 4px;
}

/* Вложения в сообщениях */
.message-image {
    max-width: 100%;
    max-height: 250px;
    border-radius: 6px;
    margin-top: 4px;
    display: block;
    cursor: pointer;
}

.message-file-card {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: rgba(255,255,255,0.15);
    border-radius: 6px;
    margin-top: 4px;
    font-size: 0.8rem;
    text-decoration: none;
    color: inherit;
    transition: background 0.2s;
}

.message.own .message-file-card {
    background: rgba(255,255,255,0.2);
}

.message-file-card:hover {
    background: rgba(0,0,0,0.05);
}

.message-file-icon {
    font-size: 1.3rem;
}

.message-file-name {
    font-weight: 600;
    display: block;
    max-width: 160px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-file-size {
    font-size: 0.7rem;
    opacity: 0.7;
}

.message-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 2px;
}

.message-time {
    font-size: 0.6rem;
    opacity: 0.7;
}

.message.own .message-time {
    color: rgba(255,255,255,0.7);
}

.status-icon {
    font-size: 0.65rem;
}

.status-icon.sending { opacity: 0.5; }
.status-icon.sent { opacity: 0.7; }
.status-icon.delivered { opacity: 0.9; }
.status-icon.read { color: #4fc3f7; }
.status-icon.failed { color: #e74c3c; }

/* ===== ВВОД СООБЩЕНИЯ ===== */
.chat-input-area {
    padding: 8px 12px;
    border-top: 1px solid #eee;
    background: white;
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-shrink: 0;
    position: relative;
}

.chat-actions-row {
    display: flex;
    align-items: flex-end;
    gap: 4px;
}

.chat-message-input {
    flex: 1;
    border: 1px solid #dee2e6;
    border-radius: 20px;
    padding: 6px 14px;
    resize: none;
    max-height: 100px;
    font-size: 0.85rem;
    line-height: 1.3;
    transition: border-color 0.2s;
    min-height: 36px;
}

.chat-message-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102,126,234,0.15);
}

.chat-send-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.2s, opacity 0.2s;
}

.chat-send-btn:hover {
    transform: scale(1.05);
    opacity: 0.9;
}

.chat-send-btn:active {
    transform: scale(0.95);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Кнопки вложений и эмодзи */
.chat-attach-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: #6c757d;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.1rem;
    flex-shrink: 0;
    transition: background 0.2s, color 0.2s;
}

.chat-attach-btn:hover {
    background: #e9ecef;
    color: #333;
}

/* Превью вложения */
.chat-attachment-preview {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* ===== ИНДИКАТОР ПЕЧАТАНИЯ ===== */
.typing-indicator {
    padding: 2px 12px;
    font-size: 0.75rem;
    color: #6c757d;
    background: #f8f9fa;
    border-top: 1px solid #eee;
    display: flex;
    align-items: center;
    gap: 4px;
    min-height: 24px;
}

.typing-indicator .spinner {
    display: inline-block;
    animation: typingDots 1.4s infinite;
}

@keyframes typingDots {
    0%, 20% { opacity: 0.2; }
    40% { opacity: 1; }
    60%, 100% { opacity: 0.2; }
}

/* ===== ПОИСК ПОЛЬЗОВАТЕЛЕЙ ===== */
.user-search-result {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.2s;
    cursor: pointer;
}

.user-search-result:hover {
    background: #f8f9fa;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    margin-right: 10px;
    flex-shrink: 0;
}

.user-info {
    flex: 1;
    min-width: 0;
}

.user-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.user-username {
    font-size: 0.75rem;
    color: #6c757d;
}

.start-chat-btn {
    flex-shrink: 0;
    font-size: 0.8rem;
}

/* Статус онлайн в поиске */
.user-info .badge {
    font-size: 0.6rem;
    padding: 2px 6px;
}

/* ===== ЭМОДЗИ-ПИКЕР ===== */
.emoji-picker {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    max-height: 220px;
    overflow-y: auto;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    padding: 10px;
    display: none;
    z-index: 10;
}

.emoji-picker.show {
    display: block;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
}

.emoji-item {
    font-size: 1.3rem;
    padding: 4px;
    cursor: pointer;
    border-radius: 6px;
    text-align: center;
    transition: background 0.15s;
}

.emoji-item:hover {
    background: #e9ecef;
}

/* ===== КОНТЕКСТНОЕ МЕНЮ ===== */
.ctx-menu {
    position: fixed;
    background: white;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    min-width: 200px;
    z-index: 2000;
    overflow: hidden;
}

.ctx-menu-item {
    padding: 10px 16px;
    cursor: pointer;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.15s;
}

.ctx-menu-item:hover {
    background: #f0f2f5;
}

.ctx-menu-item.danger {
    color: #dc3545;
}

.ctx-menu-item.danger:hover {
    background: #fde8e8;
}

.ctx-menu-divider {
    height: 1px;
    background: #eee;
    margin: 4px 0;
}

/* ===== АНИМАЦИИ ===== */
@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.message {
    animation: messageSlide 0.2s ease;
}

/* ===== СКРОЛЛБАР ===== */
.chat-list::-webkit-scrollbar,
.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-list::-webkit-scrollbar-track,
.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-list::-webkit-scrollbar-thumb,
.chat-messages::-webkit-scrollbar-thumb {
    background: #ced4da;
    border-radius: 2px;
}

.chat-list::-webkit-scrollbar-thumb:hover,
.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #adb5bd;
}

/* ===== ЗАГЛУШКА "НЕТ ЧАТОВ" ===== */
#no-chats-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 20px;
}

#no-chats-placeholder .bi-chat {
    font-size: 4rem;
    color: #ced4da;
}

#no-chats-placeholder h5 {
    color: #6c757d;
    margin-top: 12px;
}

#no-chats-placeholder p {
    color: #adb5bd;
    font-size: 0.85rem;
}

#no-chats-placeholder .btn {
    margin-top: 8px;
}

/* ===== АДАПТИВНОСТЬ ===== */
@media (max-width: 576px) {
    .chat-container {
        width: 100vw;
        height: 100vh;
        bottom: 0;
        right: 0;
        border-radius: 0;
    }
    .chat-widget {
        bottom: 10px;
        right: 10px;
    }
    .chat-toggle-btn {
        width: 52px;
        height: 52px;
        font-size: 1.3rem;
    }
    .chat-messages {
        padding: 8px 10px;
    }
    .message-content {
        max-width: 80%;
    }
    .message-bubble {
        font-size: 0.85rem;
        padding: 5px 10px;
    }
    .emoji-grid {
        grid-template-columns: repeat(6, 1fr);
    }
    .ctx-menu {
        min-width: 170px;
    }
    .chat-header-actions .dropdown-menu {
        min-width: 170px;
    }
}

@media (max-width: 420px) {
    .chat-container {
        width: 100vw;
        height: 100vh;
    }
    .chat-avatar {
        width: 36px;
        height: 36px;
    }
}