/* ========================================= */
/* 💬 CHAT MODULE (FULLSCREEN) */
/* ========================================= */

#screen-chat {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg);
    z-index: 9000 !important;
    display: flex;
    flex-direction: column;
    height: 100dvh;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

    #screen-chat.active {
        transform: none !important;
        padding-bottom: 0 !important;
    }

/* Верхняя панель */
.chat-header-overlay {
    flex-shrink: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding-top: env(safe-area-inset-top);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.modal-drag-handle {
    width: 40px;
    height: 5px;
    background: var(--border);
    border-radius: 3px;
    margin: 8px 0;
    opacity: 0.6;
}

.chat-header-content {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px 10px 10px;
}

.btn-icon-back {
    background: transparent;
    border: none;
    color: var(--text);
    padding: 8px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

    .btn-icon-back:active {
        background: var(--hover);
    }

/* Инфо о собеседнике */
.chat-partner-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.chat-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-size: cover;
    background-position: center;
    background-color: var(--hover);
    margin-bottom: 2px;
    display: none;
}

.chat-partner-name {
    font-size: 14px;
    font-weight: bold;
    color: var(--text);
}

.chat-partner-status {
    font-size: 10px;
    color: var(--primary);
    opacity: 0.8;
}

/* Контейнер чата */
.chat-container-fullscreen {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    background: var(--bg);
}

.chat-messages {
    flex: 1;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    overflow-y: auto;
    padding: 15px;
    padding-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    -webkit-overflow-scrolling: touch;
}

/* --- Стили сообщений (ОТРЕФАКТОРЕНО) --- */
.msg-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    max-width: 100%;
}

    .msg-row.row-own {
        flex-direction: row-reverse;
        align-self: flex-end;
    }

    .msg-row.row-other {
        flex-direction: row;
        align-self: flex-start;
    }

.msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background-size: cover;
    background-position: center;
    background-color: var(--surface);
    flex-shrink: 0;
    margin-bottom: 4px;
}

.msg-bubble {
    position: relative;
    border-radius: 18px;
    padding: 10px 14px;
    max-width: 100%;
    line-height: 1.4;
    word-wrap: break-word;
    font-size: 15px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.row-own .msg-bubble {
    /* ОТВЯЗЫВАЕМ от var(--primary). Ставим фиксированный приятный фиолетовый */
    background: #6c38cc !important;
    /* Текст всегда белый */
    color: #ffffff !important;
    border-bottom-right-radius: 4px;
    border: 1px solid transparent; /* Чтобы размер совпадал с чужими */
}

.row-other .msg-bubble {
    /* ОТВЯЗЫВАЕМ от var(--surface). Ставим фиксированный темно-серый */
    background: #2b2b2e !important;
    /* Текст всегда светло-серый/белый для контраста */
    color: #e0e0e0 !important;
    /* Фиксированная рамка, чтобы не сливалось с темным фоном */
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    border-bottom-left-radius: 4px;
}

/* Мета-данные и Кнопки действий */
.msg-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px; /* Больше отступа между элементами */
    margin-top: 4px;
    opacity: 0.9;
    min-height: 20px; /* Чтобы не прыгало */
}

.msg-time {
    font-size: 10px;
    opacity: 0.7;
    margin-right: 2px;
}

/* Общий стиль кнопок действий */
.msg-action-btn {
    background: transparent;
    border: none;
    padding: 4px; /* Увеличена зона клика */
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    opacity: 0.6; /* Всегда немного видны */
    color: inherit; /* Наследуют цвет текста бабла */
}

    .msg-action-btn span {
        font-size: 16px !important; /* Иконки чуть крупнее */
    }

    /* Ховер эффекты (для десктопа) и активные состояния */
    .msg-action-btn:hover,
    .msg-action-btn:active {
        opacity: 1;
        background: rgba(255, 255, 255, 0.2); /* Светлая подложка при наведении */
    }

/* Специфика для кнопки удаления */
.msg-btn-delete:hover,
.msg-btn-delete:active {
    color: #ff5252; /* Красный оттенок */
    background: rgba(255, 82, 82, 0.15);
}
/* Если сообщение свое (фон синий), делаем красный ярче */
.row-own .msg-btn-delete:hover {
    color: #ff8a80;
    background: rgba(0, 0, 0, 0.2);
}

/* Специфика для кнопки редактирования */
.msg-btn-edit:hover {
    color: #40c4ff;
    background: rgba(64, 196, 255, 0.15);
}

.row-own .msg-btn-edit:hover {
    color: #fff;
    background: rgba(0, 0, 0, 0.2);
}

/* 4. Исправление цвета мета-информации (время, галочки) */
.row-own .msg-meta {
    color: rgba(255, 255, 255, 0.7) !important;
}

.row-other .msg-meta {
    color: rgba(255, 255, 255, 0.4) !important;
}


/* Область ввода (Input Area) */
.chat-input-area {
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    flex-shrink: 0;
    padding: 10px 15px;
    padding-bottom: calc(env(safe-area-inset-bottom) + 10px);
    background: var(--bg);
    border-top: 1px solid var(--border);
    z-index: 60;
}

.chat-bar-pill {
    display: flex;
    align-items: center;
    background: var(--surface);
    /* Делаем рамку нейтральной */
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 6px 6px 6px 12px;
    gap: 8px;
    width: 100%;
    transition: border-color 0.2s, background-color 0.2s;
}

    /* При вводе текста (фокусе) */
    .chat-bar-pill:focus-within {
        /* 1. Убираем яркий primary цвет, оставляем чуть более заметный серый/белый */
        border-color: rgba(255, 255, 255, 0.3);
        /* Или просто оставь var(--border), если не хочешь изменений вообще: */
        /* border-color: var(--border); */
        /* 2. Можно немного подсветить фон, чтобы было понятно, что поле активно (по желанию) */
        background: rgba(255, 255, 255, 0.05);
        /* 3. ВАЖНО: Убираем стандартную голубую обводку браузера и тени */
        outline: none !important;
        box-shadow: none !important;
    }


/* Кнопки внутри инпута */
.chat-btn-icon, #chat-send-btn, #chat-cancel-edit {
    background: transparent;
    border: none;
    color: var(--text-sec);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: 0.2s;
    padding: 0;
    margin: 0;
}

    .chat-btn-icon:hover {
        color: var(--text);
        background: var(--hover);
    }

#chat-input {
    flex: 1;
    background: transparent !important;
    border: none !important;
    /* Убираем все виды обводок и теней */
    outline: none !important;
    box-shadow: none !important;
    -webkit-box-shadow: none !important;
    -moz-box-shadow: none !important;
    padding: 8px 0;
    margin: 0;
    font-size: 15px;
    color: var(--text);
    max-height: 120px;
    min-height: 24px;
    line-height: 1.4;
    resize: none;
    /* Убираем стандартное оформление input в Webkit */
    -webkit-appearance: none;
}

#chat-send-btn {
    background: var(--primary);
    color: #fff;
    margin-left: auto;
}

    #chat-send-btn:hover {
        filter: brightness(1.1);
    }

#chat-cancel-edit {
    display: none;
    color: var(--error);
    background: rgba(255, 23, 68, 0.1);
}

/* 3. Исправление цвета ссылок внутри сообщений */
.chat-link {
    text-decoration: underline;
    word-break: break-all;
}

/* Ссылки в СВОИХ сообщениях (на фиолетовом фоне) */
.row-own .chat-link {
    color: #ffffff !important;
    text-decoration-color: rgba(255, 255, 255, 0.7);
}

/* Ссылки в ЧУЖИХ сообщениях (на сером фоне) */
.row-other .chat-link {
    color: #9147ff !important; /* Делаем ссылку фиолетовой */
    text-decoration-color: rgba(145, 71, 255, 0.5);
}

/* Медиа (Видео/Фото) */
.chat-media-wrapper {
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.08) !important;
    border-radius: 14px; /* Немного увеличим скругление */
    overflow: hidden;
    /* === ИЗМЕНЕНИЯ: Уменьшаем рамки === */
    /* Растягиваем блок шире родительского контейнера на 20px */
    width: calc(100% + 20px) !important;
    /* Сдвигаем влево и вправо, чтобы компенсировать боковые отступы (было 14px, станет ~4px) */
    margin-left: -10px !important;
    margin-right: -10px !important;
    /* Подтягиваем вверх и вниз, чтобы уменьшить вертикальные отступы (было 10px, станет ~4-5px) */
    margin-top: -5px !important;
    margin-bottom: -5px !important;
    /* ================================= */

    background: #000;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    min-width: 250px;
    transform: translateZ(0);
}

    .chat-media-wrapper iframe, .chat-media-wrapper img, .chat-media-wrapper video {
        border: none !important;
        display: block;
        width: 100%;
        height: 100%;
    }

    .chat-media-wrapper.image img {
        height: auto;
        max-height: 300px;
        object-fit: cover;
        cursor: pointer;
        transition: opacity 0.2s;
    }

        .chat-media-wrapper.image img:hover {
            opacity: 0.95;
        }

/* Превью загрузки */
#chat-preview-bar {
    width: 100%;
    margin-bottom: 10px;
    padding: 0 5px;
    animation: fadeIn 0.2s ease;
}

.preview-content {
    position: relative;
    display: inline-block;
    max-width: 100px;
    border-radius: 12px;
}

#chat-preview-media-container img, #chat-preview-media-container video {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 12px;
    border: 1px solid var(--border);
    display: block;
}

.btn-remove-attach {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 24px;
    height: 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 50%;
    color: var(--text-sec);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    z-index: 2;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}
