/* =====================================================
   MATRIX CHAT WIDGET — hydrogen-chat.css
   Этап 3: Стили — ТЁМНАЯ ТЕМА
   ===================================================== */

/* ── ПЕРЕМЕННЫЕ (тёмная палитра по макету) ─────────── */
#matrix-chat-popup {
    --accent:         #F5C400;
    --accent-hover:   #E0B200;

    /* Фоны */
    --bg-main:        #1C1C1C;   /* основной фон ленты */
    --bg-elevated:    #262626;   /* поле ввода, чуть светлее фона */
    --bg-input:       #2E2E2E;   /* сам textarea */

    /* Пузыри */
    --bubble-in:      #2F2F2F;   /* менеджер — слева, темнее */
    --bubble-out:     #3F3F3F;   /* гость — справа, светлее */
    --bubble-text:    #EDEDED;

    /* Текст */
    --text-main:      #EDEDED;
    --text-muted:     #8C8C8C;
    --text-dim:       #6E6E6E;

    /* Границы/разделители */
    --border:         #333333;
    --border-soft:    #2A2A2A;

    /* Дата-пилюля */
    --pill-bg:        #2A2A2A;

    --radius:         12px;
    --font:           'Inter', Arial, sans-serif;
}

/* ── ИЗОЛЯЦИЯ ОТ СТИЛЕЙ ТЕМЫ OPENCART ──────────────
   Тема магазина агрессивно задаёт наследуемые свойства
   через `body *` и Bootstrap-классы. Этот reset не даёт
   им протечь в виджет. */
#matrix-chat-popup,
#matrix-chat-popup *,
#matrix-chat-popup *::before,
#matrix-chat-popup *::after {
    box-sizing: border-box;
    font-family: var(--font);
    letter-spacing: normal;
    text-transform: none;
}

/* Гасим Bootstrap-стили кнопок внутри виджета
   (кнопка "Начать диалог" в твиге имеет классы .btn.btn-primary.btn-lg) */
#matrix-chat-popup button,
#matrix-chat-popup .btn {
    all: unset;
    box-sizing: border-box;
    cursor: pointer;
    font-family: var(--font);
}

/* ── ВИДИМОСТЬ ─────────────────────────────────────── */
#matrix-chat-popup.matrix-popup-hidden {
    display: none !important;
}

/* ── КАРКАС ПОПАПА ─────────────────────────────────── */
#matrix-chat-popup {
    display: flex;
    flex-direction: column;
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 370px;
    min-width: 370px;
    max-width: 370px;
    height: 580px;
    min-height: 580px;
    max-height: 580px;
    z-index: 999999;
    background: var(--bg-main);
    box-shadow: 0 12px 40px rgba(0,0,0,0.5);
    border-radius: var(--radius);
    overflow: hidden;
    font-size: 14px;
    color: var(--text-main);
    line-height: 1.4;
}

/* ── ШАПКА (жёлтая, без изменений) ─────────────────── */
#matrix-chat-popup .matrix-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--accent);
    flex-shrink: 0;
}

#matrix-chat-popup .matrix-popup-header__info {
    display: flex;
    align-items: center;
    gap: 10px;
}

#matrix-chat-popup .matrix-popup-header__avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 15px;
    color: #000;
    flex-shrink: 0;
}

#matrix-chat-popup .matrix-popup-header__text {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

#matrix-chat-popup .matrix-popup-title {
    font-weight: 700;
    font-size: 14px;
    color: #000;
    line-height: 1.2;
}

#matrix-chat-popup .matrix-popup-status {
    font-size: 11px;
    color: rgba(0,0,0,0.55);
    line-height: 1.2;
}

#matrix-chat-popup .matrix-popup-close {
    background: none;
    border: none;
    font-size: 22px;
    line-height: 1;
    color: #000;
    cursor: pointer;
    padding: 0 0 0 8px;
    opacity: 0.55;
    transition: opacity 0.15s;
}

#matrix-chat-popup .matrix-popup-close:hover {
    opacity: 1;
}

/* ── ПРЕ-ЧАТ ЭКРАН ─────────────────────────────────── */
#matrix-chat-popup #matrix-prechat-screen {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px 20px;
    gap: 24px;
    background: var(--bg-main);
}

#matrix-chat-popup #matrix-prechat-message {
    font-size: 14px;
    color: var(--text-main);
    line-height: 1.6;
    text-align: center;
}

/* Кнопка "Начать диалог" — жёлтая, поверх Bootstrap */
#matrix-chat-popup #matrix-start-dialog-btn {
    display: inline-block;
    padding: 12px 32px;
    background: var(--accent);
    color: #000;
    font-size: 14px;
    font-weight: 600;
    border-radius: 10px;
    text-align: center;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    border: none;
}

#matrix-chat-popup #matrix-start-dialog-btn:hover {
    background: var(--accent-hover);
}

#matrix-chat-popup #matrix-start-dialog-btn:active {
    transform: scale(0.97);
}

#matrix-chat-popup #matrix-start-dialog-btn:disabled {
    background: var(--border);
    color: var(--text-muted);
    cursor: not-allowed;
}

/* ── ЛЕНТА СООБЩЕНИЙ ───────────────────────────────── */
#matrix-chat-popup #matrix-timeline {
    flex: 1 1 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 14px 14px 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--bg-main);
    min-height: 0;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    scroll-behavior: smooth;
}

/* Скроллбар — тонкий и тёмный */
#matrix-chat-popup #matrix-timeline::-webkit-scrollbar { width: 4px; }
#matrix-chat-popup #matrix-timeline::-webkit-scrollbar-track { background: transparent; }
#matrix-chat-popup #matrix-timeline::-webkit-scrollbar-thumb {
    background: #3A3A3A;
    border-radius: 4px;
}

/* ── ПУЗЫРИ СООБЩЕНИЙ ──────────────────────────────── */
#matrix-chat-popup .matrix-bubble-wrap {
    display: flex;
    flex-direction: column;
    max-width: 78%;
}

/* Гость — справа */
#matrix-chat-popup .matrix-bubble-wrap.matrix-out {
    align-self: flex-end;
    align-items: flex-end;
}

/* Менеджер — слева */
#matrix-chat-popup .matrix-bubble-wrap.matrix-in {
    align-self: flex-start;
    align-items: flex-start;
}

#matrix-chat-popup .matrix-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    color: var(--bubble-text);
    word-break: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
}

#matrix-chat-popup .matrix-bubble-wrap.matrix-out .matrix-bubble {
    background: var(--bubble-out);
    border-bottom-right-radius: 4px;
}

#matrix-chat-popup .matrix-bubble-wrap.matrix-in .matrix-bubble {
    background: var(--bubble-in);
    border-bottom-left-radius: 4px;
}

/* Неотправленное сообщение */
#matrix-chat-popup .matrix-bubble-failed .matrix-bubble {
    opacity: 0.5;
    border: 1px dashed #D64545;
}

/* Время сообщения */
#matrix-chat-popup .matrix-bubble-time {
    font-size: 10px;
    color: var(--text-dim);
    margin-top: 3px;
    padding: 0 4px;
}

/* Системные сообщения */
#matrix-chat-popup .matrix-system-msg {
    align-self: center;
    font-size: 11px;
    color: var(--text-muted);
    padding: 2px 10px;
    text-align: center;
}

/* Разделитель даты — тёмная пилюля */
#matrix-chat-popup .matrix-date-divider {
    align-self: center;
    font-size: 11px;
    color: var(--text-muted);
    background: var(--pill-bg);
    border-radius: 10px;
    padding: 3px 12px;
    margin: 6px 0;
}

/* Превью изображения */
#matrix-chat-popup .matrix-bubble img {
    max-width: 100%;
    border-radius: 8px;
    display: block;
    margin-top: 4px;
    cursor: pointer;
}

/* Файл в пузыре */
#matrix-chat-popup .matrix-bubble-file {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: var(--bubble-in);
    border-radius: 12px;
    text-decoration: none;
    color: var(--text-main);
    font-size: 13px;
    border-bottom-left-radius: 4px;
}

#matrix-chat-popup .matrix-bubble-wrap.matrix-out .matrix-bubble-file {
    background: var(--bubble-out);
    border-radius: 12px;
    border-bottom-right-radius: 4px;
    border-bottom-left-radius: 12px;
}

#matrix-chat-popup .matrix-bubble-file svg {
    flex-shrink: 0;
    opacity: 0.7;
}

/* ── ИНДИКАТОР "ПЕЧАТАЕТ..." ───────────────────────── */
#matrix-chat-popup .matrix-typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 18px 10px;
    flex-shrink: 0;
    background: var(--bg-main);
}

#matrix-chat-popup .matrix-typing-hidden {
    display: none !important;
}

#matrix-chat-popup .matrix-typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: matrix-typing-bounce 1.2s infinite;
}

#matrix-chat-popup .matrix-typing-dot:nth-child(2) { animation-delay: 0.2s; }
#matrix-chat-popup .matrix-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes matrix-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30%           { transform: translateY(-5px); opacity: 1; }
}

/* ── ПОЛЕ ВВОДА ────────────────────────────────────── */
#matrix-chat-popup .matrix-composer {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--border-soft);
    background: var(--bg-elevated);
    flex-shrink: 0;
}

#matrix-chat-popup .matrix-composer__attach {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    border-radius: 50%;
    transition: background 0.15s, color 0.15s;
}

#matrix-chat-popup .matrix-composer__attach:hover {
    background: var(--bg-input);
    color: var(--text-main);
}

#matrix-chat-popup .matrix-composer__input {
    flex: 1 1 auto;
    resize: none !important;
    border: 1px solid transparent;
    border-radius: 18px;
    padding: 9px 14px;
    font-family: var(--font);
    font-size: 14px;
    color: var(--text-main);
    background: var(--bg-input);
    line-height: 1.4;
    max-height: 96px;
    overflow-y: auto;
    outline: none;
    transition: border-color 0.15s, background 0.15s;
}

#matrix-chat-popup .matrix-composer__input:focus {
    border-color: #4A4A4A;
    background: #353535;
}

#matrix-chat-popup .matrix-composer__input::placeholder {
    color: var(--text-dim);
}

#matrix-chat-popup .matrix-composer__send {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #000;
    transition: background 0.15s, transform 0.1s;
}

#matrix-chat-popup .matrix-composer__send:hover {
    background: var(--accent-hover);
}

#matrix-chat-popup .matrix-composer__send:active {
    transform: scale(0.93);
}

#matrix-chat-popup .matrix-composer__send:disabled {
    background: var(--border);
    color: var(--text-dim);
    cursor: not-allowed;
}

/* ── МОБИЛЬНЫЙ АДАПТИВ (iOS Safari) ───────────────── */
@media screen and (max-width: 768px) {
    #matrix-chat-popup:not(.matrix-popup-hidden) {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: auto !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: unset !important;
        height: 100% !important;
        min-height: unset !important;
        max-height: unset !important;
        border-radius: 0 !important;
    }
}