/* Современные стили чата */
:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --border-color: #dee2e6;
    --accent-color: #007bff;
    --accent-hover: #0056b3;
    --message-own-bg: #007bff;
    --message-other-bg: #f8f9fa;
    --message-own-text: #ffffff;
    --message-other-text: #212529;
    --sidebar-bg: #2c3e50;
    --sidebar-hover: #34495e;
    --sidebar-active: #3498db;
}

[data-theme="dark"] {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --bg-tertiary: #3d3d3d;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --border-color: #404040;
    --accent-color: #4dabf7;
    --accent-hover: #339af0;
    --message-own-bg: #1864ab;
    --message-other-bg: #2d2d2d;
    --message-own-text: #ffffff;
    --message-other-text: #ffffff;
    --sidebar-bg: #1a1a1a;
    --sidebar-hover: #2d2d2d;
    --sidebar-active: #1864ab;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    transition: background-color 0.3s, color 0.3s;
}

/* Контейнер чата */
.chat-container {
    display: flex;
    height: 100vh;
    max-width: 1400px;
    margin: 0 auto;
    background: var(--bg-primary);
    box-shadow: 0 0 40px rgba(0,0,0,0.1);
}

/* Сайдбар - современный дизайн */
.sidebar {
    width: 320px;
    background: var(--sidebar-bg);
    color: white;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
}

.user-info {
    padding: 20px;
    background: rgba(255,255,255,0.05);
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.user-info img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid var(--accent-color);
}

.user-info span {
    font-weight: 600;
    font-size: 16px;
    flex: 1;
}

.profile-link {
    color: #bdc3c7;
    text-decoration: none;
    font-size: 16px;
    padding: 8px;
    border-radius: 6px;
    transition: all 0.2s;
}

.profile-link:hover {
    color: white;
    background: rgba(255,255,255,0.1);
}

/*
.search-container {
    padding: 15px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
*/

/* Контейнер поиска с кнопкой отмены */
.search-container {
    padding: 15px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    gap: 10px;
    align-items: center;
}

.search-container input {
    width: 100%;
    padding: 10px 15px;
    border: none;
    border-radius: 8px;
    background: rgba(255,255,255,0.1);
    color: white;
    font-size: 14px;
    backdrop-filter: blur(10px);
}

.search-container input::placeholder {
    color: rgba(255,255,255,0.5);
}

.search-container input:focus {
    outline: none;
    background: rgba(255,255,255,0.15);
}

.chat-list {
    flex: 1;
    overflow-y: auto;
}

.chat-list h3 {
    padding: 15px 20px;
    font-size: 12px;
    color: rgba(255,255,255,0.6);
    text-transform: uppercase;
    letter-spacing: 1px;
    background: rgba(0,0,0,0.2);
    font-weight: 600;
}

.chat-item {
    display: flex;
    padding: 12px 15px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    cursor: pointer;
    transition: all 0.2s;
    gap: 12px;
}

.chat-item:hover {
    background: var(--sidebar-hover);
}

.chat-item.active {
    background: var(--sidebar-active);
}

.chat-item img {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
}

.chat-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
}

.chat-name {
    font-weight: 600;
    margin-bottom: 4px;
    font-size: 14px;
}

.last-message {
    font-size: 12px;
    color: rgba(255,255,255,0.7);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item.active .last-message {
    color: rgba(255,255,255,0.9);
}

/* Основная область чата */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
}

.chat-header {
    padding: 15px 20px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.chat-header .chat-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-header span {
    font-weight: 600;
    font-size: 16px;
    color: var(--text-primary);
}

.participants-count {
    font-size: 12px;
    color: var(--text-secondary);
}

.messages-container {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: var(--bg-secondary);
}

/* Сообщения - современный дизайн */
.message {
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    max-width: 100%;
    animation: messageAppear 0.3s ease-out;
}

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

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

.message-content {
    padding: 12px 16px;
    border-radius: 18px;
    position: relative;
    word-wrap: break-word;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.own-message .message-content {
    background: var(--message-own-bg);
    color: var(--message-own-text);
    border-bottom-right-radius: 6px;
}

.other-message .message-content {
    background: var(--message-other-bg);
    color: var(--message-other-text);
    border-bottom-left-radius: 6px;
    border: 1px solid var(--border-color);
}

.sender-name {
    font-weight: 600;
    margin-bottom: 4px;
    font-size: 13px;
    color: var(--accent-color);
}

.message-time {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
    padding: 0 8px;
}

/* Стили для файловых вложений - упрощенные */
.file-attachment {
    margin: 8px 0;
    border-radius: 8px;
    overflow: hidden;
    transition: all 0.2s ease;
}

/* Изображения */
.image-attachment {
    cursor: pointer;
    max-width: 300px;
    border: 1px solid var(--border-color);
}

.image-preview {
    position: relative;
    overflow: hidden;
}

.image-preview img {
    width: 100%;
    height: auto;
    display: block;
    transition: transform 0.3s ease;
}

.image-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.3);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.image-attachment:hover .image-overlay {
    opacity: 1;
}

.image-attachment:hover .image-preview img {
    transform: scale(1.05);
}

.zoom-icon {
    font-size: 20px;
    color: white;
    background: rgba(0,0,0,0.7);
    padding: 8px 12px;
    border-radius: 50%;
}

.file-meta {
    padding: 8px 12px;
    background: var(--bg-tertiary);
    font-size: 12px;
}

.file-name {
    font-weight: 500;
    color: var(--text-primary);
    word-break: break-word;
}

.file-size {
    color: var(--text-secondary);
    margin-top: 2px;
}

/* Документы */
.document-attachment {
    cursor: pointer;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    transition: all 0.2s ease;
}

.document-attachment:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-color);
    transform: translateX(4px);
}

.file-icon {
    font-size: 24px;
    flex-shrink: 0;
}

.file-info {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.download-hint {
    font-size: 16px;
    opacity: 0.7;
    transition: all 0.2s ease;
}

.document-attachment:hover .download-hint {
    opacity: 1;
    transform: scale(1.1);
}

/* Собственные сообщения */
.own-message .file-attachment.image-attachment {
    border-color: rgba(255,255,255,0.2);
}

.own-message .file-meta {
    background: rgba(255,255,255,0.1);
}

.own-message .file-name {
    color: white;
}

.own-message .file-size {
    color: rgba(255,255,255,0.7);
}

.own-message .document-attachment {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.2);
}

.own-message .document-attachment:hover {
    background: rgba(255,255,255,0.2);
}

/* Поле ввода сообщения */
.message-input-container {
    padding: 20px;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: flex-end;
    gap: 12px;
}

.message-input-container textarea {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    resize: none;
    height: 44px;
    max-height: 120px;
    font-size: 14px;
    font-family: inherit;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: border-color 0.2s;
}

.message-input-container textarea:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(0,123,255,0.1);
}

#attachButton {
    width: 44px;
    height: 44px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.2s;
    color: var(--text-secondary);
}

#attachButton:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

#sendButton {
    padding: 12px 24px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 14px;
}

#sendButton:hover {
    background: var(--accent-hover);
}

#sendButton:disabled {
    background: var(--text-secondary);
    cursor: not-allowed;
}

/* Модальное окно для изображений - исправленная версия */
.image-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.95);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    padding: 20px;
    box-sizing: border-box;
}

.image-modal.active {
    display: flex;
    animation: modalAppear 0.3s ease;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: zoom-out;
}

.modal-content {
    position: relative;
    max-width: calc(100vw - 140px);
    max-height: calc(100vh - 140px);
    background: transparent;
    border-radius: 12px;
    overflow: auto; /* Добавляем прокрутку если контент не помещается */
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    display: flex;
    justify-content: center;
    align-items: flex-start; /* Выравнивание по верху для очень высоких изображений */
}

.modal-content img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
}

/* Контролы модального окна */
.modal-controls {
    position: fixed; /* Фиксируем относительно окна браузера */
    top: 30px;
    right: 30px;
    display: flex;
    gap: 10px;
    z-index: 10001;
}

.modal-btn {
    background: rgba(255,255,255,0.9);
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
}

.modal-btn:hover {
    background: white;
    transform: scale(1.1);
}

.image-info {
    position: fixed;
    bottom: 30px;
    left: 30px;
    color: white;
    background: rgba(0,0,0,0.7);
    padding: 10px 15px;
    border-radius: 8px;
    font-size: 14px;
    max-width: calc(100vw - 100px);
    word-break: break-word;
    backdrop-filter: blur(10px);
    z-index: 10001;
}

/* Анимация появления */
@keyframes modalAppear {
    from {
        opacity: 0;
        backdrop-filter: blur(0px);
    }
    to {
        opacity: 1;
        backdrop-filter: blur(10px);
    }
}

/* Специфичные стили для разных ориентаций изображений */
.modal-content.portrait img {
    max-height: 90vh;
    max-width: 90vw;
}

.modal-content.landscape img {
    max-width: 90vw;
    max-height: 90vh;
}

/* Поиск */
/*.search-results {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--sidebar-bg);
    z-index: 100;
    overflow-y: auto;
}*/

.search-results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    background: rgba(0,0,0,0.2);
}

.search-results-header h3 {
    margin: 0;
    color: white;
    font-size: 16px;
}

.close-search {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 5px;
    color: rgba(255,255,255,0.7);
}

.close-search:hover {
    color: white;
}

.search-results-content {
    padding: 15px;
}


/* Стили для нового поиска */
.search-input-wrapper {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
}

.search-input-wrapper input {
    padding-right: 35px;
    width: 100%;
}

.clear-search {
    position: absolute;
    right: 10px;
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    font-size: 14px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
}

.clear-search:hover {
    background: rgba(255,255,255,0.1);
    color: white;
}


/* Кнопка отмены поиска */
.cancel-search-btn {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
    white-space: nowrap;
}

.cancel-search-btn:hover {
    background: rgba(255,255,255,0.2);
}

/* Индикатор активного поиска */
.search-active .search-container {
    background: rgba(52, 152, 219, 0.1);
}

.search-active .search-input-wrapper input {
    background: rgba(255,255,255,0.15);
}

/* Результаты поиска в основном списке */
.search-results {
    flex: 1;
    overflow-y: auto;
}

.search-section {
    margin-bottom: 0;
}

.search-section h4 {
    padding: 15px 20px;
    font-size: 14px;
    color: #95a5a6;
    text-transform: uppercase;
    letter-spacing: 1px;
    background: #253341;
    margin: 0;
    border-bottom: 1px solid #34495e;
}

.search-result-item {
    display: flex;
    padding: 12px 15px;
    border-bottom: 1px solid #34495e;
    cursor: pointer;
    transition: background 0.2s;
    gap: 12px;
}

.search-result-item:hover {
    background: #34495e;
}

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

.search-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.search-item-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
}

.search-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.search-item-name {
    font-weight: 600;
    color: white;
    font-size: 14px;
}

.search-item-type {
    font-size: 11px;
    color: rgba(255,255,255,0.7);
    background: rgba(255,255,255,0.1);
    padding: 2px 6px;
    border-radius: 4px;
}

.search-message-time {
    font-size: 11px;
    color: rgba(255,255,255,0.7);
}

.search-item-preview {
    font-size: 13px;
    color: rgba(255,255,255,0.8);
    line-height: 1.4;
}

/* Специальные стили для элементов сообщений в поиске */
.search-message-item {
    padding: 10px 15px;
}

.search-message-item .search-item-preview {
    background: rgba(255,255,255,0.05);
    padding: 8px;
    border-radius: 6px;
    border-left: 3px solid #3498db;
    margin-top: 4px;
}

.search-message-highlight {
    background: rgba(52, 152, 219, 0.3);
    padding: 1px 2px;
    border-radius: 2px;
    font-weight: 600;
}

/* Индикаторы загрузки и пустых результатов */
.search-loading, .search-empty {
    padding: 20px;
    text-align: center;
    color: rgba(255,255,255,0.7);
    font-style: italic;
}

.search-error {
    padding: 20px;
    text-align: center;
    color: #e74c3c;
}

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

/* Индикатор новых сообщений */
#newMessageIndicator {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent-color);
    color: white;
    padding: 10px 20px;
    border-radius: 20px;
    cursor: pointer;
    z-index: 100;
    font-size: 14px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    transition: all 0.3s ease;
    border: none;
    font-weight: 600;
}

#newMessageIndicator:hover {
    background: var(--accent-hover);
    transform: translateX(-50%) scale(1.05);
}

/* Статус соединения */
.connection-info {
    position: fixed;
    bottom: 10px;
    left: 10px;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    z-index: 1000;
    background: #27ae60;
    color: white;
    font-weight: 600;
}

.connection-info.disconnected {
    background: #e74c3c;
}

.connection-info.connecting {
    background: #f39c12;
}

/* Приветственное сообщение */
.welcome-message {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.welcome-message h3 {
    margin-bottom: 12px;
    color: var(--text-primary);
    font-size: 24px;
    font-weight: 300;
}

.welcome-message p {
    font-size: 16px;
    opacity: 0.8;
}

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

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

.messages-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

.chat-list::-webkit-scrollbar {
    width: 4px;
}

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

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

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

/* Адаптивность */
@media (max-width: 768px) {
    .chat-container {
        flex-direction: column;
    }
    
    .image-modal {
        padding: 10px;
    }
    
    .sidebar {
        width: 100%;
        height: 40vh;
    }
    
    .chat-area {
        height: 60vh;
    }
    
    .message {
        max-width: 85%;
    }
    
    .image-attachment {
        max-width: 250px;
    }
    
    .modal-content {
        max-width: calc(100vw - 20px);
        max-height: calc(100vh - 20px);
    }
    
    .modal-controls {
        top: 15px;
        right: 15px;
    }

    .image-info {
        bottom: 15px;
        left: 15px;
        max-width: calc(100vw - 60px);
        font-size: 12px;
    }

    .modal-btn {
        width: 40px;
        height: 40px;
    }
    
}
/* Особые случаи для очень больших изображений */
@media (max-height: 600px) {
    .modal-content {
        align-items: flex-start;
        margin-top: 20px;
    }
}

/* Подсказка для поля поиска */
.search-container {
    position: relative;
}

.search-container::after {
    content: 'Нажмите Enter для поиска';
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 10px;
    color: rgba(255,255,255,0.5);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}

.search-container:focus-within::after {
    opacity: 1;
}

/* Убираем подсказку когда есть текст */
.search-container input:not(:placeholder-shown) + .search-container::after {
    opacity: 0;
}

/* Подсветка найденного сообщения в чате */
.message.highlighted {
    animation: highlight-pulse 2s ease-in-out;
    border-left: 3px solid #ffc107 !important;
}

@keyframes highlight-pulse {
    0% { background-color: rgba(255, 235, 59, 0.3); }
    50% { background-color: rgba(255, 235, 59, 0.6); }
    100% { background-color: rgba(255, 235, 59, 0.3); }
}

.own-message.highlighted {
    border-left: 3px solid #ffc107 !important;
}

/* Плавные переходы для поиска */
.search-container {
    transition: all 0.3s ease;
}

.search-input-wrapper input:focus {
    background: rgba(255,255,255,0.15) !important;
}

/* Подсказка при наведении на элементы поиска */
.search-result-item {
    position: relative;
}

.search-result-item:hover::after {
    content: 'Нажмите чтобы перейти';
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    pointer-events: none;
}

/* Анимация появления кнопок */
.clear-search, .cancel-search-btn {
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

/* Стили для статусов сообщений */
.message-status {
    margin-left: 8px;
    font-size: 12px;
    opacity: 0.7;
    transition: all 0.3s ease;
}

.message-status.status-sending {
    opacity: 0.5;
}

.message-status.status-sent {
    color: var(--text-secondary);
}

.message-status.status-delivered {
    color: var(--accent-color);
}

.message-status.status-read {
    color: #4CAF50;
}

.own-message .message-time {
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

/* Улучшенные стили прокрутки */
.messages-container {
    scroll-behavior: smooth;
}

/* Индикатор новых сообщений */
.new-messages-indicator {
    background: var(--accent-color);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    position: sticky;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    font-size: 14px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.7; }
    100% { opacity: 1; }
}