/* chat.css - Вкладка "Чат" в ЛК туриста и гида: master-detail, список чатов, диалог, сообщения, адаптив */
/* Версия: 1.0 */

/**
 * chat.css - Стили для вкладки "Чат"
 * 
 * Компоненты:
 *   - .chat-layout — master-detail контейнер (2 колонки на десктопе, 1 на мобильном)
 *   - .chat-sidebar — левая колонка: заголовок, поиск, фильтры, список чатов
 *   - .chat-main — правая колонка: пустое состояние или диалог
 *   - .chat-dialog — активный диалог
 *   - .chat-messages — область сообщений
 *   - .chat-dialog-input — поле ввода
 * 
 * Цвета проекта: #1f6392, #0e4a6e, #1f3a5f, #5b6e8c, #94a3b8, #f5f7fa
 */

/* ============================================
   ОСНОВНОЙ КОНТЕЙНЕР (MASTER-DETAIL)
   ============================================ */

.chat-layout {
    display: grid;
    grid-template-columns: minmax(280px, 340px) 1fr;
    gap: 0;
    background: white;
    border-radius: 16px;
    border: 1px solid #e2e8f0;
    overflow: hidden;
    height: calc(100vh - 300px);
    min-height: 500px;
    max-height: 800px;
}

/* ============================================
   ЛЕВАЯ КОЛОНКА: СПИСОК ЧАТОВ
   ============================================ */

.chat-sidebar {
    display: flex;
    flex-direction: column;
    border-right: 1px solid #e2e8f0;
    background: #fafbfc;
    overflow: hidden;
}

.chat-sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #e2e8f0;
    background: white;
    flex-shrink: 0;
}

.chat-sidebar-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: #0f2c3d;
}

.chat-total {
    font-size: 0.75rem;
    color: #94a3b8;
    background: #f1f5f9;
    padding: 2px 10px;
    border-radius: 12px;
    font-weight: 600;
}

/* Поиск */
.chat-search-wrap {
    padding: 12px 16px 8px;
    flex-shrink: 0;
}

.chat-search-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #dce2ec;
    border-radius: 10px;
    font-size: 0.9rem;
    background: white;
    color: #0f2c3d;
    transition: all 0.2s;
    box-sizing: border-box;
    font-family: inherit;
}

.chat-search-input:focus {
    outline: none;
    border-color: #1f6392;
    box-shadow: 0 0 0 3px rgba(31, 99, 146, 0.1);
}

.chat-search-input::placeholder {
    color: #94a3b8;
}

/* Фильтры */
.chat-filters {
    display: flex;
    gap: 6px;
    padding: 8px 16px 12px;
    flex-shrink: 0;
}

.chat-filter-btn {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #dce2ec;
    background: white;
    color: #475569;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
}

.chat-filter-btn:hover {
    background: #f0f7ff;
    border-color: #1f6392;
    color: #1f6392;
}

.chat-filter-btn.active {
    background: #1f6392;
    border-color: #1f6392;
    color: white;
    box-shadow: 0 2px 8px rgba(31, 99, 146, 0.25);
}

.chat-filter-count {
    background: rgba(255, 255, 255, 0.25);
    color: white;
    padding: 1px 7px;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 700;
    min-width: 16px;
    text-align: center;
}

.chat-filter-btn:not(.active) .chat-filter-count {
    background: #dc3545;
    color: white;
}

/* Список чатов */
.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px 12px;
    scrollbar-width: thin;
}

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

.chat-list::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 10px;
}

.chat-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

.chat-list::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.chat-empty-small {
    text-align: center;
    padding: 40px 20px;
    color: #94a3b8;
    font-size: 0.9rem;
}

/* ============================================
   КАРТОЧКА ЧАТА В СПИСКЕ
   ============================================ */

.chat-card {
    display: flex;
    gap: 12px;
    padding: 12px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.15s;
    border: 1px solid transparent;
    margin-bottom: 4px;
    background: white;
    align-items: center;
}

.chat-card:hover {
    background: #f0f7ff;
    border-color: #cbd5e1;
}

.chat-card.active {
    background: #e8f2fa;
    border-color: #1f6392;
}

.chat-card.unread {
    background: #fff9ef;
    border-left: 3px solid #f39c12;
}

.chat-card.unread:hover {
    background: #fff5e8;
}

.chat-card.unread.active {
    background: #ffe9d1;
    border-color: #f39c12;
}

/* Аватар */
.chat-card-avatar {
    position: relative;
    flex-shrink: 0;
    width: 52px;
    height: 52px;
}

.chat-card-avatar img {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #e2e8f0;
    background-color: #e9ecef;
    display: block;
}

.chat-card-unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #dc3545;
    color: white;
    border-radius: 20px;
    padding: 1px 7px;
    font-size: 0.7rem;
    font-weight: 700;
    min-width: 18px;
    text-align: center;
    border: 2px solid white;
    z-index: 2;
}

/* Контент карточки */
.chat-card-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-card-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
}

.chat-card-name {
    font-weight: 700;
    font-size: 0.95rem;
    color: #0f2c3d;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-card.unread .chat-card-name {
    color: #0f2c3d;
}

.chat-card-time {
    font-size: 0.7rem;
    color: #94a3b8;
    flex-shrink: 0;
}

.chat-card-preview {
    font-size: 0.83rem;
    color: #5b6e8c;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

.chat-card.unread .chat-card-preview {
    color: #1f3a5f;
    font-weight: 500;
}

.chat-card-preview .sender-prefix {
    color: #94a3b8;
}

/* Кнопка "Показать все" */
.chat-show-all-btn {
    display: block;
    width: 100%;
    padding: 12px 16px;
    margin-top: 8px;
    background: #f8fafc;
    border: 1px dashed #cbd5e1;
    border-radius: 10px;
    color: #475569;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.chat-show-all-btn:hover {
    background: #f0f7ff;
    border-color: #1f6392;
    color: #1f6392;
}

/* ============================================
   ПРАВАЯ КОЛОНКА: ДИАЛОГ
   ============================================ */

.chat-main {
    display: flex;
    flex-direction: column;
    background: #fafbfc;
    overflow: hidden;
}

/* Пустое состояние */
.chat-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
    color: #94a3b8;
}

.chat-empty-icon {
    font-size: 4rem;
    margin-bottom: 16px;
    opacity: 0.5;
}

.chat-empty-text {
    font-size: 1.1rem;
    font-weight: 600;
    color: #475569;
    margin-bottom: 6px;
}

.chat-empty-hint {
    font-size: 0.85rem;
    color: #94a3b8;
}

/* Диалог */
.chat-dialog {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Шапка диалога */
.chat-dialog-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    background: white;
    border-bottom: 1px solid #e2e8f0;
    flex-shrink: 0;
}

.chat-back-btn {
    display: none;
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: #1f6392;
    padding: 4px 8px;
    border-radius: 8px;
    transition: all 0.2s;
    font-family: inherit;
}

.chat-back-btn:hover {
    background: #f0f7ff;
}

.chat-dialog-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #e2e8f0;
    background-color: #e9ecef;
    flex-shrink: 0;
}

.chat-dialog-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-dialog-name {
    font-size: 1rem;
    font-weight: 700;
    color: #0f2c3d;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-dialog-status {
    font-size: 0.75rem;
    color: #94a3b8;
}

/* Область сообщений */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scrollbar-width: thin;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Разделитель даты */
.chat-date-separator {
    text-align: center;
    font-size: 0.72rem;
    color: #94a3b8;
    margin: 12px 0;
    font-weight: 500;
}

/* Сообщение */
.chat-msg {
    display: flex;
    max-width: 100%;
}

.chat-msg.incoming {
    justify-content: flex-start;
}

.chat-msg.outgoing {
    justify-content: flex-end;
}

.chat-msg-bubble {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: 18px;
    position: relative;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Входящие (от партнёра) — белые */
.chat-msg.incoming .chat-msg-bubble {
    background: white;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
    color: #1f3a5f;
}

/* Исходящие (мои) — синие */
.chat-msg.outgoing .chat-msg-bubble {
    background: #1f6392;
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 1px 3px rgba(31, 99, 146, 0.2);
}

/* Модерированное сообщение */
.chat-msg.moderated .chat-msg-bubble {
    background: #fef2f2;
    border: 1px dashed #fecaca;
    color: #991b1b;
    font-style: italic;
}

.chat-msg.outgoing.moderated .chat-msg-bubble {
    background: #fef2f2;
    border: 1px dashed #fecaca;
    color: #991b1b;
}

.chat-msg-text {
    font-size: 0.9rem;
    line-height: 1.45;
    white-space: pre-wrap;
}

.chat-msg-time {
    font-size: 0.65rem;
    margin-top: 4px;
    text-align: right;
    opacity: 0.75;
}

.chat-msg.incoming .chat-msg-time {
    color: #94a3b8;
}

.chat-msg.outgoing .chat-msg-time {
    color: rgba(255, 255, 255, 0.8);
}

/* Баннер блокировки */
.chat-blocked-banner {
    padding: 10px 20px;
    background: #fef2f2;
    border-top: 1px solid #fecaca;
    border-left: 4px solid #dc2626;
    color: #991b1b;
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
    flex-shrink: 0;
}

/* Поле ввода */
.chat-dialog-input {
    display: flex;
    gap: 10px;
    padding: 12px 16px;
    background: white;
    border-top: 1px solid #e2e8f0;
    align-items: flex-end;
    flex-shrink: 0;
}

.chat-input-field {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #dce2ec;
    border-radius: 12px;
    font-size: 0.9rem;
    font-family: inherit;
    color: #0f2c3d;
    background: white;
    resize: none;
    max-height: 120px;
    min-height: 42px;
    line-height: 1.4;
    transition: border-color 0.2s;
    box-sizing: border-box;
    overflow-y: auto;
}

.chat-input-field:focus {
    outline: none;
    border-color: #1f6392;
    box-shadow: 0 0 0 3px rgba(31, 99, 146, 0.1);
}

.chat-input-field:disabled {
    background: #f8fafc;
    color: #94a3b8;
    cursor: not-allowed;
}

.chat-send-btn {
    background: #1f6392;
    color: white;
    border: none;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-send-btn:hover:not(:disabled) {
    background: #0e4a6e;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(31, 99, 146, 0.3);
}

.chat-send-btn:active:not(:disabled) {
    transform: translateY(0);
}

.chat-send-btn:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
    opacity: 0.6;
}

/* ============================================
   АДАПТИВ
   ============================================ */

@media (max-width: 768px) {
    .chat-layout {
        grid-template-columns: 1fr;
        height: calc(100vh - 220px);
        min-height: 400px;
        max-height: none;
        border-radius: 12px;
    }

    .chat-sidebar {
        border-right: none;
    }

    .chat-main {
        display: none;
    }

    /* Когда диалог открыт — показываем правую колонку, скрываем левую */
    .chat-layout.dialog-open .chat-sidebar {
        display: none;
    }

    .chat-layout.dialog-open .chat-main {
        display: flex;
    }

    .chat-back-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .chat-sidebar-header {
        padding: 12px 16px;
    }

    .chat-sidebar-header h3 {
        font-size: 0.95rem;
    }

    .chat-search-wrap {
        padding: 10px 12px 6px;
    }

    .chat-filters {
        padding: 6px 12px 10px;
    }

    .chat-card {
        padding: 10px;
    }

    .chat-card-avatar,
    .chat-card-avatar img {
        width: 48px;
        height: 48px;
    }

    .chat-dialog-header {
        padding: 10px 14px;
    }

    .chat-dialog-avatar {
        width: 38px;
        height: 38px;
    }

    .chat-dialog-name {
        font-size: 0.95rem;
    }

    .chat-messages {
        padding: 14px;
    }

    .chat-msg-bubble {
        max-width: 82%;
        padding: 9px 12px;
    }

    .chat-msg-text {
        font-size: 0.88rem;
    }

    .chat-dialog-input {
        padding: 10px 12px;
    }

    .chat-input-field {
        min-height: 40px;
        padding: 9px 12px;
    }

    .chat-send-btn {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }
}

@media (max-width: 480px) {
    .chat-layout {
        height: calc(100vh - 180px);
        min-height: 360px;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    .chat-card-avatar,
    .chat-card-avatar img {
        width: 44px;
        height: 44px;
    }

    .chat-card-name {
        font-size: 0.9rem;
    }

    .chat-card-preview {
        font-size: 0.78rem;
    }

    .chat-filter-btn {
        font-size: 0.78rem;
        padding: 7px 10px;
    }

    .chat-dialog-avatar {
        width: 34px;
        height: 34px;
    }

    .chat-dialog-name {
        font-size: 0.9rem;
    }

    .chat-msg-text {
        font-size: 0.85rem;
    }

    .chat-msg-bubble {
        max-width: 88%;
    }
}

/* ============================================
   АНИМАЦИЯ ПОЯВЛЕНИЯ КАРТОЧКИ ЧАТА
   ============================================ */

.chat-card {
    animation: chatCardFadeIn 0.2s ease;
}

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