/* === Основное окно чата === */
.chat {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    padding: 0 2vw 2vh 2vw;
    box-sizing: border-box;
    background-color: #fff;
    z-index: 100;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat .content {
    display: block;
    width: 100%;
    height: auto;
    transition: padding-bottom 0.3s ease;
}

/* === Кнопка чата (фиксированная) === */
.chat-button {
    position: fixed;
    left: 40vw;
    top: 3vw;
    display: block;
    width: 15vw;
    height: 15vw;
    background-image: url("../img/chat_button.svg");
    background-position: center;
    background-size: contain;
    background-repeat: no-repeat;
    overflow: visible;
}

/* 🔴 Красная точка — внутри кнопки */
.chat-button .unread-badge {
    position: absolute;
    bottom: 7px;
    right: 4px;
    width: 10px;
    height: 10px;
    background: red;
    border-radius: 50%;
    border: 2px solid white;
    z-index: 1;
    pointer-events: none;
}

/* === Кнопка закрытия чата === */
.chat .close-button {
    position: fixed;
    top: 3vw;
    right: 3vw;
    width: 7vw;
    height: 7vw;
    cursor: pointer;
    z-index: 9990;
    background-image: url("/img/close.svg");
    background-position: center;
    background-repeat: no-repeat;
    background-size: contain;
}

/* === Popup для удаления контакта === */
.chat .overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #ffffff7e;
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
}

.chat .popup-content {
    background: white;
    padding: 3vw;
    border-radius: 2vw;
    box-shadow: 0 0.5vw 2vw rgba(0, 0, 0, 0.3);
    width: 70vw;
    max-width: 400px;
    text-align: center;
    position: relative;
}

.chat .popup-buttons {
    margin-top: 2vw;
    display: flex;
    gap: 1vw;
    justify-content: center;
}

.chat .button {
    display: flex;
    width: 100%;
    height: auto;
    padding: 1.5vw 3vw;
    font-size: 5vw;
    font-weight: 600;
    text-align: center;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    color: white;
    background: #007bff;
    border: none;
    border-radius: 1vw;
    cursor: pointer;
    transition: background 0.3s ease;
}

.chat .button-close {
    background: #6c757d;
}

/* === Панель контактов (горизонтальный скролл) === */
.contacts-bar {
    display: flex;
    overflow-x: auto;
    padding: 10px 0;
    gap: 16px;
    border-bottom: 1px solid #eee;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    height: 90px;
    box-sizing: border-box;
    flex-shrink: 0;
}

.contacts-bar::-webkit-scrollbar {
    display: none;
}

/* === Контакт (аватар + имя + статусы) === */
.contact-item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 72px;
    min-width: 72px;
    flex-shrink: 0;
    box-sizing: border-box;
    padding: 2px;
    /* ← переносим padding сюда, чтобы не влиять на содержимое */
}

.contact-item.active {
    background-color: #f0f8ff;
    border-radius: 8px;
}

.contact-item img {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    object-fit: cover;
    background: #eee;
    /* серый фон, пока грузится */
    /* fallback-аватары уже имеют цвет, так что это безопасно */
}

.contact-name {
    font-size: 12px;
    text-align: center;
    width: 100%;
    padding: 0 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.2;
    color: #333;
    box-sizing: border-box;
}

/* Статусы (непрочитанное, онлайн) — позиционируются относительно contact-item */
.status-wrap {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.online-dot {
    position: absolute;
    top: -2px;
    left: -2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid white;
    background: #4CAF50;
    box-sizing: border-box;
}

.unread-dot {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid white;
    background: red;
    box-sizing: border-box;
}

/* === Область сообщений === */
.chat-area {
    flex: 1;
    padding: 10px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.message {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.message.theirs {
    flex-direction: row;
}

.message.mine {
    flex-direction: row-reverse;
}

.msg-bubble {
    max-width: 70%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 14px;
    word-break: break-word;
}

.message.theirs .msg-bubble {
    background: #f1f1f1;
    border-top-left-radius: 0;
}

.message.mine .msg-bubble {
    background: #4CAF50;
    color: white;
    border-top-right-radius: 0;
}

/* === Поле ввода === */
.input-area {
    display: flex;
    padding: 8px;
    gap: 8px;
    border-top: 1px solid #eee;
    background: white;
    flex-shrink: 0;
}

.input-area input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 20px;
    font-size: 14px;
}

.input-area button {
    padding: 8px 16px;
    background: #4CAF50;
    color: white;
    border: none;
    border-radius: 2vw;
    cursor: pointer;
}

.typing-indicator {
    position: absolute;
    top: 90px;
    left: 2vw;
    right: 2vw;
    padding: 6px 12px;
    font-size: 13px;
    color: #555;
    text-align: center;
    background: #f8f9fa;
    border-bottom: 1px solid #eaeaea;
    border-radius: 4px;
    z-index: 10;
    box-sizing: border-box;
    pointer-events: none;

    /* Плавное появление/исчезновение */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.typing-indicator.show {
    opacity: 1;
    visibility: visible;
}

.chat.hide .typing-indicator {
    display: none !important;
}

.contact-delete {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    background: red;
    color: white;
    border-radius: 50%;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 2;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.contact-deleted-warning {
    background: #fff9c4;
    color: #5d4037;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 14px;
    text-align: center;
    margin: 10px auto;
    max-width: 80%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.msg-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-position: center;
    background-repeat: no-repeat;
    flex-shrink: 0;
}

.contact-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    margin-bottom: 4px;
}