/* Современный стиль для списка чатов как в Telegram/WhatsApp */
.chat-index-page {
    background-color: #f8f9fa;
    min-height: 100vh;
}

.chat-list-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Кнопки действий */
.chat-actions {
    display: flex;
    gap: 15px;
    margin-bottom: 25px;
    flex-wrap: wrap;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.3s;
    text-decoration: none;
    color: white;
}

.action-btn i {
    font-size: 16px;
}

.action-btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.action-btn-success {
    background: linear-gradient(135deg, #2ecc71 0%, #27ae60 100%);
}

.action-btn-info {
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
}

.action-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

/* Быстрый поиск */
.quick-search-card {
    background: white;
    border-radius: 15px;
    padding: 20px;
    margin-bottom: 25px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.05);
    border: 1px solid #eef2f7;
}

.quick-search-card .card-header {
    background: none;
    border: none;
    padding: 0 0 15px 0;
}

.quick-search-card .card-header h5 {
    color: #2d3436;
    font-weight: 600;
    font-size: 18px;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.search-input-container {
    position: relative;
}

.search-input {
    width: 100%;
    padding: 15px 20px 15px 45px;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    font-size: 16px;
    transition: all 0.3s;
    background: #f8f9fa;
}

.search-input:focus {
    border-color: #667eea;
    background: white;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
    outline: none;
}

.search-icon {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: #95a5a6;
    font-size: 18px;
}

/* Результаты поиска */
.search-results {
    margin-top: 15px;
    border-radius: 12px;
    background: white;
    border: 1px solid #eef2f7;
    max-height: 300px;
    overflow-y: auto;
    display: none;
}

.search-result-item {
    padding: 15px;
    border-bottom: 1px solid #f1f2f6;
    transition: background-color 0.2s;
}

.search-result-item:hover {
    background-color: #f8f9fa;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.search-result-info {
    flex: 1;
}

.search-result-name {
    font-weight: 600;
    color: #2d3436;
    margin-bottom: 3px;
}

.search-result-email {
    font-size: 13px;
    color: #636e72;
}

.start-dialog-btn {
    padding: 8px 15px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    gap: 5px;
}

.start-dialog-btn:hover {
    background: #5a6fd8;
}

/* Список чатов */
.chat-list-card {
    background: white;
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.05);
    border: 1px solid #eef2f7;
}

.chat-list-header {
    padding: 20px;
    border-bottom: 1px solid #eef2f7;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-list-title {
    font-size: 18px;
    font-weight: 600;
    color: #2d3436;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.unread-badge {
    background: linear-gradient(135deg, #ff7675 0%, #fd79a8 100%);
    color: white;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
}

.chat-list-empty {
    padding: 50px 20px;
    text-align: center;
    color: #95a5a6;
}

.chat-list-empty i {
    font-size: 48px;
    margin-bottom: 15px;
    opacity: 0.5;
}

.chat-list-empty h5 {
    font-size: 18px;
    margin-bottom: 10px;
    color: #7f8c8d;
}

.chat-list-empty p {
    font-size: 14px;
}

/* Элемент чата */
.chat-item {
    padding: 15px 20px;
    border-bottom: 1px solid #eef2f7;
    text-decoration: none;
    color: inherit;
    display: block;
    transition: all 0.2s;
    position: relative;
}

.chat-item:hover {
    background-color: #f8f9fa;
    transform: translateX(5px);
}

.chat-item.active {
    background-color: #f0f4ff;
    border-left: 4px solid #667eea;
}

.chat-item-content {
    display: flex;
    align-items: center;
    gap: 15px;
}

.chat-avatar {
    position: relative;
    flex-shrink: 0;
}

.avatar-circle {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 18px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.avatar-group {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.avatar-channel {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.avatar-private {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

.online-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    background: #00d046;
    border: 2px solid white;
    border-radius: 50%;
}

.chat-info {
    flex: 1;
    min-width: 0;
}

.chat-name-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}

.chat-name {
    font-weight: 600;
    color: #2d3436;
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-time {
    font-size: 12px;
    color: #95a5a6;
    white-space: nowrap;
    margin-left: 10px;
}

.chat-type-badge {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: 600;
    text-transform: uppercase;
    margin-left: 5px;
}

.chat-last-message {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.message-preview {
    font-size: 14px;
    color: #636e72;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.you-label {
    color: #667eea;
    font-weight: 600;
    margin-right: 5px;
}

.message-badge {
    background: #ff7675;
    color: white;
    font-size: 12px;
    font-weight: 600;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 10px;
}

/* Анимации */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-item {
    animation: fadeIn 0.3s ease-out;
}

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

.search-results.show {
    animation: slideIn 0.3s ease-out;
}

/* Адаптивность */
@media (max-width: 768px) {
    .chat-list-container {
        padding: 15px;
    }

    .chat-header {
        padding: 20px;
    }

    .chat-title {
        font-size: 24px;
    }

    .action-btn {
        padding: 10px 15px;
        font-size: 14px;
    }

    .chat-actions {
        gap: 10px;
    }

    .chat-item-content {
        gap: 12px;
    }

    .avatar-circle {
        width: 45px;
        height: 45px;
        font-size: 16px;
    }

    .chat-name {
        font-size: 15px;
    }
}

@media (max-width: 576px) {
    .chat-actions {
        flex-direction: column;
    }

    .action-btn {
        width: 100%;
        justify-content: center;
    }

    .chat-item {
        padding: 12px 15px;
    }
}

/* Темная тема */
@media (prefers-color-scheme: dark) {
    .chat-index-page {
        background-color: #1a1a1a;
    }

    .quick-search-card,
    .chat-list-card {
        background-color: #2d2d2d;
        border-color: #3d3d3d;
    }

    .search-input {
        background-color: #3d3d3d;
        border-color: #4d4d4d;
        color: #ffffff;
    }

    .search-input:focus {
        border-color: #667eea;
        background-color: #3d3d3d;
    }

    .chat-item {
        border-color: #3d3d3d;
    }

    .chat-item:hover {
        background-color: #3d3d3d;
    }

    .chat-item.active {
        background-color: #2d3748;
    }

    .chat-name,
    .quick-search-card .card-header h5 {
        color: #ffffff;
    }

    .chat-time,
    .message-preview,
    .search-result-email {
        color: #b0b0b0;
    }

    .search-results,
    .search-result-item {
        background-color: #2d2d2d;
        border-color: #3d3d3d;
    }

    .search-result-item:hover {
        background-color: #3d3d3d;
    }

    .chat-list-empty {
        color: #b0b0b0;
    }
}

/* Отладка классов сообщений */
.message-bubble.outgoing {
    background: #0088cc;
    color: white;
    margin-left: auto;
    margin-right: 10px;
    border-bottom-right-radius: 0;
}

.message-bubble.incoming {
    background: #2a2f32;
    color: white;
    margin-right: auto;
    margin-left: 10px;
    border-bottom-left-radius: 0;
}

/* Яркие стили для отладки */
.debug-outgoing {
    border: 2px solid #00ff00 !important;
}

.debug-incoming {
    border: 2px solid #ff0000 !important;
}

/* Отладочные стили */
.message-bubble.outgoing[data-debug] {
    position: relative;
}

.message-bubble.outgoing[data-debug]::before {
    content: 'OUTGOING';
    position: absolute;
    top: -15px;
    left: 5px;
    font-size: 9px;
    color: #00ff00;
    background: rgba(0, 0, 0, 0.7);
    padding: 2px 5px;
    border-radius: 3px;
    z-index: 1000;
}

.message-bubble.incoming[data-debug]::before {
    content: 'INCOMING';
    position: absolute;
    top: -15px;
    left: 5px;
    font-size: 9px;
    color: #ff0000;
    background: rgba(0, 0, 0, 0.7);
    padding: 2px 5px;
    border-radius: 3px;
    z-index: 1000;
}

/* Яркие цвета для отладки */
.message-bubble.outgoing {
    background: #0088cc !important;
    color: white !important;
    margin-left: auto;
    margin-right: 10px;
    max-width: 70%;
}

.message-bubble.incoming {
    background: #2a2f32 !important;
    color: white !important;
    margin-right: auto;
    margin-left: 10px;
    max-width: 70%;
}

/* Принудительные стили для поля ввода */
#message-input {
    min-height: 40px !important;
    max-height: 120px !important;
    resize: none !important;
    transition: height 0.2s ease !important;
}

/* Убедитесь, что высота сбрасывается */
.message-input-wrapper textarea[style*="height"] {
    height: auto !important;
    min-height: 40px !important;
}

/* Стили для кнопки отправки */
#send-btn {
    cursor: pointer !important;
    transition: opacity 0.2s ease !important;
}

#send-btn:disabled {
    opacity: 0.5 !important;
    cursor: not-allowed !important;
}