/* client/src/css/chat.css — автономный чат-модуль (см. js/chat.js).
   Включается классом body.chat-on, который ставит chat.js при config.chatEnabled.
   Весь UI живёт в #chat-root; при выключенном чате эти стили ничего не меняют. */

/* --- меню: ужать список комнат, чат встаёт под ним --- */
body.chat-on #menu-scene-container{
    /* .page имеет padding-top: 20px (main.css) — иначе переполнение и скролл страницы */
    height: calc(100vh - 20px);
    max-height: calc(100vh - 20px);
}
body.chat-on #menu-middle-block{
    flex: 1 1 auto;
    min-height: 0;
    justify-content: flex-start;
}
body.chat-on #rooms-list,
body.chat-on #rooms-list-offline{
    flex: 0 0 30vh;
    height: auto;
    min-height: 120px;
}

#chat-root.chat-hidden{ display: none; }

#chat-root{
    display: flex;
    flex-direction: column;
    font-family: system-ui, sans-serif;
    color: var(--text, #eee);
    box-sizing: border-box;
}
#chat-root *{ box-sizing: border-box; }

/* --- режим меню: обычный блок под списком комнат --- */
#chat-root.chat-in-menu{
    margin-top: 6px;
    flex: 1 1 auto;
    height: auto;
    min-height: 120px;
    border-radius: var(--radius-md, 12px);
    border: 1px solid var(--border-faint, rgba(255,255,255,0.12));
    background: rgba(44, 44, 44, 0.86);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    overflow: hidden;
}
#chat-root.chat-in-menu .chat-toggle{ display: none; }
#chat-root.chat-in-menu .chat-close{ display: none; }
#chat-root.chat-in-menu .chat-panel{
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}
#chat-root.chat-in-menu .chat-messages{ flex: 1; min-height: 0; }
#chat-root.chat-in-menu .chat-input-row{ flex-shrink: 0; }

/* --- режим игры: оверлей-панель, прижатая к правому краю, поверх всего --- */
#chat-root.chat-in-game{
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 900;
    pointer-events: none;
}
#chat-root.chat-in-game .chat-panel{
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 85vw;
    max-width: 340px;
    display: flex;
    flex-direction: column;
    background: rgba(28, 28, 30, 0.84);
    backdrop-filter: blur(8px);
    border-left: 1px solid var(--border-faint, rgba(255,255,255,0.12));
    box-shadow: -8px 0 30px rgba(0, 0, 0, 0.45);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    pointer-events: auto;
}
#chat-root.chat-in-game.open .chat-panel{ transform: none; }
#chat-root.chat-no-anim .chat-panel{ transition: none; }

/* Широкие экраны: постоянная колонка справа (по умолчанию открыта) */
@media (min-width: 480px){
    #chat-root.chat-in-game .chat-panel{
        width: 320px;
        transform: none;
    }
    #chat-root.chat-in-game:not(.open) .chat-panel{ transform: translateX(100%); }
}

/* --- кнопка-полоска (видна в игре, когда панель закрыта) --- */
.chat-toggle{
    position: absolute;
    right: 0;
    top: 42%;
    transform: translateY(-50%);
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    width: 30px;
    height: 88px; /* фиксированная высота: бейдж внизу не меняет размер кнопки */
    padding: 12px 4px;
    border-radius: 14px 0 0 14px;
    background: rgba(44, 44, 44, 0.92);
    border: 1px solid var(--border-faint, rgba(255,255,255,0.12));
    border-right: none;
    cursor: pointer;
    z-index: 2;
    user-select: none;
}
.chat-toggle-label{
    writing-mode: vertical-rl;
    font-size: 12px;
    letter-spacing: 3px;
    opacity: 0.9;
    margin-top: 8px;
}
.chat-badge{
    position: absolute;
    top: auto;
    bottom: 10px;
    right: 4px;
    display: none;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: #2f81f7;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
}
.chat-badge.visible{ display: block; }

/* --- панель --- */
.chat-header{
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-faint, rgba(255,255,255,0.1));
    background: rgba(0, 0, 0, 0.25);
    flex-shrink: 0;
}
.chat-title{ font-size: 15px; font-weight: 700; flex: 1; min-width: 0; }
.chat-conn{ width: 8px; height: 8px; border-radius: 50%; background: #888; flex-shrink: 0; }
.chat-conn.on{ background: #4caf50; }
.chat-conn.wait{ background: #ffc107; }
.chat-close{
    background: none;
    border: none;
    color: var(--text, #ddd);
    font-size: 15px;
    cursor: pointer;
    padding: 2px 8px;
    flex-shrink: 0;
}

.chat-messages{
    flex: 1;
    overflow-y: auto;
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 0;
}
.chat-messages::-webkit-scrollbar{ width: 6px; }
.chat-messages::-webkit-scrollbar-thumb{ background: #4a4a4a; border-radius: 3px; }

.chat-msg{ display: flex; gap: 8px; align-items: baseline; font-size: 13px; line-height: 1.35; }
.chat-msg .chat-msg-name{
    font-weight: 700;
    flex-shrink: 0;
    max-width: 40%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-msg .chat-msg-text{ word-break: break-word; min-width: 0; }
.chat-msg .chat-msg-time{ margin-left: auto; font-size: 10px; opacity: 0.55; flex-shrink: 0; }

.chat-empty{ opacity: 0.6; font-size: 12px; text-align: center; padding: 24px 10px; }

.chat-input-row{
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    border-top: 1px solid var(--border-faint, rgba(255,255,255,0.1));
    background: rgba(0, 0, 0, 0.25);
    flex-shrink: 0;
}
.chat-input{
    flex: 1;
    min-width: 0;
    padding: 8px 12px;
    border-radius: 18px;
    border: 1px solid var(--border-faint, rgba(255,255,255,0.18));
    background: rgba(0, 0, 0, 0.35);
    color: var(--text, #eee);
    font-size: 13px;
    font-family: inherit;
    outline: none;
}
.chat-counter{ font-size: 11px; opacity: 0.6; width: 28px; text-align: right; flex-shrink: 0; }
.chat-counter.over{ color: #ff5252; font-weight: 700; }
.chat-send{
    border: none;
    border-radius: 50%;
    width: 34px;
    height: 34px;
    background: var(--btn-green, #4caf50);
    color: #fff;
    font-size: 15px;
    cursor: pointer;
    flex-shrink: 0;
}
.chat-send:disabled{ opacity: 0.4; cursor: default; }

.chat-hint{
    padding: 10px;
    font-size: 12px;
    opacity: 0.85;
    text-align: center;
    border-top: 1px solid var(--border-faint, rgba(255,255,255,0.1));
    display: none;
    flex-shrink: 0;
}
.chat-hint.show{ display: block; }

/* --- инструменты: меню действий сообщения, баны, блокировки --- */
/* Панель — контейнер позиционирования поповеров (в игре она absolute, в меню relative). */
.chat-panel{ position: relative; }

.chat-tools{
    background: none;
    border: none;
    color: var(--text, #ddd);
    font-size: 14px;
    cursor: pointer;
    padding: 2px 4px;
    flex-shrink: 0;
    opacity: 0.8;
    line-height: 1;
}
.chat-tools:hover{ opacity: 1; }

.chat-msg-more{
    background: none;
    border: none;
    color: var(--text, #bbb);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
    flex-shrink: 0;
    opacity: 0;
    align-self: center;
}
.chat-msg:hover .chat-msg-more,
.chat-msg.own .chat-msg-more{ opacity: 1; }
@media (hover: none){
    .chat-msg-more{ opacity: 0.55; }
}

/* Поповеры (меню сообщения, бан, инструменты) — поверх панели. */
.chat-popup{
    position: absolute;
    z-index: 950;
    min-width: 150px;
    max-width: 260px;
    padding: 6px;
    border-radius: 10px;
    border: 1px solid var(--border-faint, rgba(255,255,255,0.14));
    background: rgba(36, 36, 38, 0.98);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.chat-popup-item{
    background: none;
    border: none;
    color: var(--text, #eee);
    font-size: 13px;
    text-align: left;
    padding: 8px 10px;
    border-radius: 7px;
    cursor: pointer;
    white-space: nowrap;
}
.chat-popup-item:hover{ background: rgba(255,255,255,0.08); }
.chat-popup-sep{ height: 1px; background: var(--border-faint, rgba(255,255,255,0.1)); margin: 4px 6px; }

/* Поповер бана: пароль + срок. */
.chat-ban-title{ font-size: 13px; font-weight: 700; padding: 4px 6px 8px; }
.chat-ban-warn{ font-size: 11px; color: #ffa657; padding: 0 6px 8px; }
.chat-ban-pass{
    width: 100%;
    padding: 7px 10px;
    margin-bottom: 8px;
    border-radius: 8px;
    border: 1px solid var(--border-faint, rgba(255,255,255,0.18));
    background: rgba(0, 0, 0, 0.35);
    color: var(--text, #eee);
    font-size: 13px;
    font-family: inherit;
    outline: none;
}
.chat-ban-durs{ display: flex; flex-wrap: wrap; gap: 6px; padding: 0 2px 4px; }
.chat-ban-dur{
    border: none;
    border-radius: 8px;
    padding: 7px 12px;
    background: rgba(255,255,255,0.1);
    color: var(--text, #eee);
    font-size: 12px;
    cursor: pointer;
}
.chat-ban-dur:hover{ background: rgba(255,255,255,0.18); }

/* Поповер инструментов: мои блокировки + админ-баны. */
.chat-tools-popup{ min-width: 210px; max-width: 260px; }
.chat-tools-sec{ padding: 4px 2px; }
.chat-tools-sec + .chat-tools-sec{
    border-top: 1px solid var(--border-faint, rgba(255,255,255,0.1));
    margin-top: 4px;
    padding-top: 8px;
}
.chat-tools-title{ font-size: 12px; font-weight: 700; opacity: 0.75; padding: 0 6px 6px; }
.chat-tools-empty{ font-size: 12px; opacity: 0.6; padding: 2px 6px 4px; }
.chat-block-row{ display: flex; align-items: center; gap: 6px; padding: 3px 6px; }
.chat-block-name{
    flex: 1;
    min-width: 0;
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-block-until{ font-size: 11px; opacity: 0.6; flex-shrink: 0; }
.chat-block-un{
    background: none;
    border: none;
    color: var(--text, #bbb);
    font-size: 13px;
    cursor: pointer;
    padding: 2px 4px;
    flex-shrink: 0;
}
.chat-block-un:hover{ color: #ff5252; }
.chat-ban-load{
    margin: 6px;
    border: none;
    border-radius: 8px;
    padding: 7px 12px;
    background: rgba(255,255,255,0.1);
    color: var(--text, #eee);
    font-size: 12px;
    cursor: pointer;
}
.chat-ban-load:hover{ background: rgba(255,255,255,0.18); }
