/* ============================================================
   Быстрый чат: плавающий виджет игрока + консоль персонала.
   Использует CSS-переменные темы (--surface, --text, --border,
   --accent, --primary-light) — автоматически поддерживает
   светлую и тёмную темы.
   ============================================================ */

/* --- Плавающая кнопка (игрок) --- */
.tmine-chat-btn {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 1060;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent, #6366f1);
    color: #fff;
    border: none;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    cursor: pointer;
    transition: transform .15s ease, box-shadow .15s ease;
}
.tmine-chat-btn:hover {
    transform: scale(1.07);
    box-shadow: 0 8px 26px rgba(0, 0, 0, .32);
}
.tmine-chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #dc3545;
    color: #fff;
    font-size: .7rem;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    border: 2px solid var(--surface, #fff);
}
/* Пульсация бейджа при поступлении нового сообщения */
.tmine-chat-badge-pulse {
    animation: chatBadgePulse .6s ease;
}
@keyframes chatBadgePulse {
    0% { transform: scale(1); }
    40% { transform: scale(1.45); background: #f97316; }
    100% { transform: scale(1); }
}

/* --- Панель чата (игрок) --- */
.tmine-chat-panel {
    position: fixed;
    right: 20px;
    bottom: 88px;
    z-index: 1060;
    width: 340px;
    max-width: calc(100vw - 40px);
    height: 440px;
    max-height: calc(100vh - 120px);
    background: var(--surface, #fff);
    border: 1px solid var(--border, rgba(15, 23, 42, .08));
    border-radius: 16px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, .22);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.tmine-chat-header {
    background: var(--accent, #6366f1);
    color: #fff;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    flex-shrink: 0;
}
.tmine-chat-close {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 1rem;
    cursor: pointer;
    opacity: .85;
    line-height: 1;
}
.tmine-chat-close:hover { opacity: 1; }
.tmine-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.tmine-chat-loading,
.tmine-chat-empty {
    color: var(--text-muted, #64748b);
    font-size: .85rem;
    text-align: center;
    margin: auto;
}
.tmine-chat-msg { max-width: 85%; display: flex; flex-direction: column; min-width: 0; }
.tmine-chat-msg-me { align-self: flex-end; align-items: flex-end; }
.tmine-chat-msg-staff { align-self: flex-start; align-items: flex-start; }
.tmine-chat-msg-meta {
    font-size: .7rem;
    color: var(--text-muted, #64748b);
    margin-bottom: 3px;
}
.tmine-chat-msg-text {
    padding: 8px 12px;
    border-radius: 14px;
    font-size: .9rem;
    line-height: 1.35;
    /* Перенос длинных слов без пробелов (AAAA...):
       break-word рвёт слово, min-width:0 на flex-цепочке
       не даёт пузырю распирать контейнер */
    overflow-wrap: break-word;
    word-break: break-word;
    white-space: pre-wrap;
    text-align: left;
    max-width: 100%;
}
.tmine-chat-msg-me .tmine-chat-msg-text {
    background: var(--accent, #6366f1);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.tmine-chat-msg-staff .tmine-chat-msg-text {
    background: var(--primary-light, #e0e7ff);
    color: var(--text, #1e293b);
    border-bottom-left-radius: 4px;
}
.tmine-chat-form {
    display: flex;
    gap: 8px;
    padding: 10px;
    border-top: 1px solid var(--border, rgba(15, 23, 42, .08));
    flex-shrink: 0;
}
.tmine-chat-form input[type="text"] {
    flex: 1;
    border: 1px solid var(--border, rgba(15, 23, 42, .08));
    border-radius: 20px;
    padding: 8px 14px;
    font-size: .9rem;
    background: transparent;
    color: var(--text, #1e293b);
    min-width: 0;
}
.tmine-chat-form input[type="text"]:focus {
    outline: none;
    border-color: var(--accent, #6366f1);
}
.tmine-chat-send {
    border: none;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    background: var(--accent, #6366f1);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.tmine-chat-send:hover { opacity: .9; }

/* --- Консоль персонала (chat.php) --- */
.chat-messages-box {
    height: 420px;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.chat-msg {
    max-width: 80%;
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.chat-msg-user { align-self: flex-start; align-items: flex-start; }
.chat-msg-staff { align-self: flex-end; align-items: flex-end; }
.chat-msg-meta {
    font-size: .72rem;
    color: var(--text-muted, #64748b);
    margin-bottom: 3px;
}
.chat-msg-text {
    padding: 8px 12px;
    border-radius: 14px;
    font-size: .92rem;
    line-height: 1.4;
    overflow-wrap: break-word;
    word-break: break-word;
    max-width: 100%;
}
.chat-msg-user .chat-msg-text {
    background: var(--primary-light, #e0e7ff);
    color: var(--text, #1e293b);
    border-bottom-left-radius: 4px;
}
.chat-msg-staff .chat-msg-text {
    background: var(--accent, #6366f1);
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* --- Мобильные экраны --- */
@media (max-width: 576px) {
    .tmine-chat-btn { right: 16px; bottom: 16px; }
    .tmine-chat-panel {
        right: 12px;
        left: 12px;
        width: auto;
        bottom: 84px;
        height: min(70vh, 440px);
    }
}

/* ============================================================
   v2: онлайны, typing, удаление сообщений, плашка новых
   ============================================================ */

/* --- Индикатор онлайн --- */
.tmine-chat-online-dot,
.chat-online-dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #94a3b8;
    flex-shrink: 0;
}
.tmine-chat-online-dot-on,
.chat-online-dot-on {
    background: #22c55e;
    box-shadow: 0 0 6px rgba(34, 197, 94, .6);
}

/* --- Плашка «печатает…» --- */
.tmine-chat-typing,
.chat-typing-bar {
    padding: 6px 14px;
    font-size: .78rem;
    color: var(--text-muted, #64748b);
    border-top: 1px solid var(--border, rgba(15, 23, 42, .08));
    display: flex;
    align-items: center;
    gap: 8px;
}
.chat-typing-dots {
    display: inline-flex;
    gap: 3px;
    align-items: center;
}
.chat-typing-dots i {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--text-muted, #64748b);
    animation: chatBlink 1.2s infinite;
}
.chat-typing-dots i:nth-child(2) { animation-delay: .2s; }
.chat-typing-dots i:nth-child(3) { animation-delay: .4s; }
@keyframes chatBlink {
    0%, 60%, 100% { opacity: .25; }
    30% { opacity: 1; }
}

/* --- Кнопка удаления сообщения (консоль оператора) --- */
.chat-msg-inner {
    position: relative;
    display: inline-block;
    max-width: 100%;
    min-width: 0;
}
.chat-msg-del {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, .25);
    color: #fff;
    font-size: .8rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity .12s ease;
    padding: 0;
}
.chat-msg:hover .chat-msg-del { opacity: 1; }
.chat-msg-del:hover { background: #dc3545; }

/* --- Плашка «новые сообщения» --- */
.chat-scroll-pill {
    position: absolute;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    border: none;
    border-radius: 16px;
    padding: 6px 14px;
    font-size: .8rem;
    background: var(--accent, #6366f1);
    color: #fff;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
    cursor: pointer;
    z-index: 5;
}
.chat-scroll-pill:hover { opacity: .92; }

/* --- Плашка «диалог закрыт оператором» (виджет игрока) --- */
.tmine-chat-archived-note {
    padding: 8px 14px;
    font-size: .78rem;
    color: var(--text-muted, #64748b);
    background: var(--primary-light, #e0e7ff);
    border-top: 1px solid var(--border, rgba(15, 23, 42, .08));
    flex-shrink: 0;
}
.tmine-chat-archived-note i { margin-right: 6px; }

/* --- Вкладки в списке --- */
#chatTabs .btn.active {
    background: var(--accent, #6366f1);
    border-color: var(--accent, #6366f1);
    color: #fff;
}

/* ============================================================
   Ревизия дизайна консоли (chat.php) для светлой и тёмной тем:
   все элементы — на переменных темы, никаких голых bootstrap-цветов
   ============================================================ */

/* --- Карточки страницы чата --- */
.chat-page .card,
.chat-page .card-header,
.chat-page .card-footer {
    background: var(--surface, #fff);
    border-color: var(--border, rgba(15, 23, 42, .08));
}
.chat-page .card { color: var(--text, #1e293b); }

/* --- Список диалогов --- */
#chatConvList .list-group-item {
    background: var(--surface, #fff);
    color: var(--text, #1e293b);
    border-color: var(--border, rgba(15, 23, 42, .08));
    transition: background .12s ease;
}
#chatConvList .list-group-item:hover {
    background: var(--primary-light, #e0e7ff);
}
#chatConvList .list-group-item.active {
    background: var(--accent, #6366f1);
    border-color: var(--accent, #6366f1);
    color: #fff;
}
#chatConvList .list-group-item.active small,
#chatConvList .list-group-item.active .text-muted {
    color: rgba(255, 255, 255, .85) !important;
}

/* --- Инпуты страницы чата (поиск, ответ) --- */
.chat-page .form-control {
    background: var(--surface, #fff);
    color: var(--text, #1e293b);
    border-color: var(--border, rgba(15, 23, 42, .08));
}
.chat-page .form-control::placeholder {
    color: var(--text-muted, #64748b);
}
.chat-page .form-control:focus {
    background: var(--surface, #fff);
    color: var(--text, #1e293b);
    border-color: var(--accent, #6366f1);
    box-shadow: 0 0 0 .2rem color-mix(in srgb, var(--accent, #6366f1) 25%, transparent);
}

/* --- Футер диалога: поле + кнопка без «прилипания» --- */
.chat-staff-form {
    display: flex;
    gap: 10px;
    align-items: center;
    padding-top: 4px;
}
.chat-staff-form .form-control {
    flex: 1;
    min-width: 0;
    border-radius: 22px;
    padding: 10px 18px;
}
#chatStaffSendBtn {
    flex-shrink: 0;
    border-radius: 22px;
    padding: 10px 18px;
    background: var(--accent, #6366f1);
    border-color: var(--accent, #6366f1);
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 7px;
}
#chatStaffSendBtn:hover:not(:disabled) {
    background: var(--primary-hover, #4f46e5);
    border-color: var(--primary-hover, #4f46e5);
    opacity: 1;
}
#chatStaffSendBtn:disabled {
    opacity: .7;
}

/* --- Фон окна переписки чуть отличается от карточки --- */
.chat-messages-box {
    background: var(--surface, #fff);
}

/* --- Кнопки в шапке диалога (профиль/архив) --- */
.chat-page .btn-outline-secondary {
    color: var(--text, #1e293b);
    border-color: var(--border, rgba(15, 23, 42, .18));
}
.chat-page .btn-outline-secondary:hover {
    background: var(--primary-light, #e0e7ff);
    color: var(--text, #1e293b);
}

/* --- «Вернуть» из архива: зелёная outline, одинаковая геометрия с «Удалить» --- */
.chat-btn-restore {
    color: #198754 !important;
    border: 1.5px solid #198754 !important;
    background: transparent !important;
    font-weight: 600;
}
.chat-btn-restore:hover,
.chat-btn-restore:focus,
.chat-btn-restore:active {
    color: #fff !important;
    background: #198754 !important;
    border-color: #198754 !important;
}
html[data-theme="dark"] .chat-btn-restore {
    color: #34d399 !important;
    border-color: #34d399 !important;
}
html[data-theme="dark"] .chat-btn-restore:hover,
html[data-theme="dark"] .chat-btn-restore:focus,
html[data-theme="dark"] .chat-btn-restore:active {
    color: #0f172a !important;
    background: #34d399 !important;
}

/* --- Колокольчик с пузырьком-счётчиком --- */
.chat-bell-btn {
    position: relative;
}
.chat-bell-count {
    position: absolute;
    top: -7px;
    right: -7px;
    min-width: 19px;
    height: 19px;
    border-radius: 10px;
    background: #dc3545;
    color: #fff;
    font-size: .68rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    border: 2px solid var(--surface, #fff);
    line-height: 1;
}
/* --- Звук: кнопка-переключатель --- */
#chatSoundToggle.active {
    background: var(--accent, #6366f1);
    border-color: var(--accent, #6366f1);
    color: #fff;
}

/* --- Бейдж «Чат» в верхнем меню (игрок) --- */
.nav-chat-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    margin-left: 6px;
    padding: 0 5px;
    border-radius: 9px;
    background: #dc3545;
    color: #fff;
    font-size: .68rem;
    font-weight: 700;
    vertical-align: middle;
    line-height: 1;
}

/* --- Ссылка «Чат с поддержкой» в футере --- */
.footer-chat-link {
    color: var(--text-muted, #64748b);
    text-decoration: none;
    font-size: .9rem;
}
.footer-chat-link:hover {
    color: var(--accent, #6366f1);
}

/* --- Окно переписки на полностраничном чате: выше --- */
.chat-me-box {
    height: min(58vh, 560px);
}

/* --- На мобильных: кнопка «Отправить» сжимается до иконки --- */
@media (max-width: 576px) {
    #chatStaffSendBtn .chat-send-label { display: none; }
    #chatStaffSendBtn { padding: 10px 12px; }
    .chat-staff-form { gap: 6px; }
}