/*
 * Path: /public/css/app-chat.css
 * File: app-chat.css (v2.0 - Chat Layout, Dialog List & Messages)
 */

/* ==========================================================================
   1. LAYOUT
   ========================================================================== */

.chat-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    height: 65vh;
    min-height: 500px;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow:
        0 4px 6px -1px rgba(0, 0, 0, 0.03),
        0 2px 4px -2px rgba(0, 0, 0, 0.03);
}

/* Левая колонка – список диалогов */

.dialogs-list {
    border-right: 1px solid var(--border-color-light);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    background-color: #fff;
}

.dialogs-list__header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color-light);
    font-weight: 600;
    color: var(--text-dark);
    font-size: 1.1rem;
}

.dialogs-list__empty {
    padding: 1rem;
}

/* Элемент диалога */

.dialog-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color-light);
    transition: background-color 0.2s ease;
    text-decoration: none;
    color: var(--text-regular);
    background-color: #fff;
}

.dialog-item:hover {
    background-color: var(--background-light);
}

.dialog-item.active {
    background-color: var(--primary-color-light);
    border-right: 3px solid var(--primary-color);
}

.dialog-item__avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.dialog-item__info {
    position: relative;
    overflow: hidden;
    flex-grow: 1;
}

.notification-badge-dot {
    display: none;
    position: absolute;
    top: 2px;
    right: 2px;
    width: 10px;
    height: 10px;
    background-color: var(--primary-color, #5D3EFF);
    border-radius: 50%;
    border: 2px solid #fff;
    z-index: 2;
}

.dialog-item.has-unread .notification-badge-dot {
    display: block;
}

.dialog-item.has-unread .dialog-item__name {
    font-weight: 700;
}

.dialog-item.has-unread .dialog-item__last-message {
    color: var(--text-regular);
    font-weight: 500;
}

.dialog-item__name {
    font-weight: 600;
    color: var(--text-dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.25rem;
}

.dialog-item__last-message {
    font-size: 0.875rem;
    color: var(--text-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Правая колонка – окно чата */

.chat-window {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    background-color: #fff;
}

/* ==========================================================================
   2. CHAT HEADER
   ========================================================================== */

.chat-widget__header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: var(--background-light);
    gap: 0.75rem;
    font-size: 0.95rem;
}

.chat-status-indicator {
    font-size: 0.8rem;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    border: 1px solid transparent;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.chat-status-indicator::before {
    content: "";
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-offline {
    background-color: #fef2f2;
    color: #b91c1c;
    border-color: #fecaca;
}

.status-offline::before {
    background-color: #b91c1c;
}

.status-online {
    background-color: #ecfdf5;
    color: #15803d;
    border-color: #bbf7d0;
}

.status-online::before {
    background-color: #22c55e;
}

/* ==========================================================================
   3. CHAT MESSAGES AREA
   ========================================================================== */

.chat-widget__messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    background-color: #fff;
}

/* Плейсхолдеры (выбор диалога, загрузка, нет сообщений) */

.chat-empty-state {
    margin: auto;
    text-align: center;
    color: var(--text-light);
    max-width: 320px;
}

.chat-empty-state__icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

/* Сообщения */

.chat-message {
    max-width: 70%;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    line-height: 1.4;
    display: inline-block;
}

.chat-message.incoming {
    align-self: flex-start;
    background-color: var(--background-light);
    color: var(--text-dark);
    border-top-left-radius: 0;
}

.chat-message.outgoing {
    align-self: flex-end;
    background-color: var(--primary-color);
    color: #fff;
    border-top-right-radius: 0;
}

.message-sender {
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 0.2rem;
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
}

.message-time {
    font-size: 0.75rem;
    opacity: 0.8;
}

.message-body {
    word-wrap: break-word;
    white-space: pre-wrap;
}

/* ==========================================================================
   4. INPUT AREA
   ========================================================================== */

.chat-widget__input-area {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border-color-light);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background-color: #fff;
}

.chat-input {
    flex: 1;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    padding: 0.5rem 0.75rem;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 1px rgba(93, 62, 255, 0.25);
}

.chat-input:disabled {
    background-color: var(--background-light);
    cursor: not-allowed;
}

.chat-send-button {
    width: 40px;
    height: 40px;
    border-radius: 999px;
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background-color: var(--primary-color);
    color: #fff;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    flex-shrink: 0;
}

.chat-send-button:hover:not(:disabled) {
    background-color: var(--primary-color-dark, #4338ca);
    transform: translateY(-1px);
}

.chat-send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ==========================================================================
   5. RESPONSIVE
   ========================================================================== */

@media (max-width: 992px) {
    .chat-layout {
        grid-template-columns: 1fr;
        height: auto;
        max-height: calc(100vh - 81px - 24px);
        min-height: 500px;
        width: 100%;
    }

    .chat-window {
        height: 500px;
        min-width: 0;
    }

    .chat-widget__input-area {
        min-width: 0;
    }

    .dialogs-list {
        height: auto;
        max-height: 300px;
    }
}

@media (max-width: 576px) {
    .chat-message {
        max-width: 85%;
    }
}
