/* Persistent bottom-right HUD chat */
#chat-panel {
    position: fixed;
    left: calc(50% + 315px);
    bottom: 18px;
    top: auto;
    width: min(330px, calc(50vw - 330px));
    min-width: 260px;
    height: 250px;
    display: flex;
    flex-direction: column;
    background: rgba(5,5,5,0.78);
    border: 2px solid #8b1b16;
    border-radius: 8px;
    overflow: hidden;
    z-index: 11040;
    box-sizing: border-box;
    transition: background .12s, border-color .12s;
}

/* Only used while outside the active game. */
#chat-panel.hidden-chat {
    display: none;
}

#chat-panel.chat-focused {
    background: rgba(5,5,5,0.94);
}

#chat-header {
    height: 34px;
    padding: 4px 6px;
    background: rgba(0,0,0,0.45);
    border-bottom: 2px solid #8b1b16;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 0 0 auto;
}

.chat-tab {
    padding: 3px 10px;
    margin-right: 4px;
    background: rgba(40,0,0,0.75);
    color: #d4c8b2;
    border: 1px solid #8b1b16;
    border-radius: 4px;
    cursor: pointer;
}

.chat-tab.active {
    background: #8b1b16;
    color: white;
}

#chat-log {
    flex: 1;
    min-height: 0;
    font-size: 12px;
    line-height: 1.35;
    padding: 6px;
    overflow-y: auto;
    overflow-x: hidden;
}

#chat-input-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px;
    background: rgba(0,0,0,0.4);
    border-top: 2px solid #8b1b16;
    flex: 0 0 auto;
}

#chat-input {
    flex: 1;
    min-width: 0;
    background: #0c0c0c;
    border: 1px solid #8b1b16;
    padding: 6px;
    border-radius: 4px;
    color: #d4c8b2;
}

/* If the screen cannot fit chat beside the centered hotbar, keep it visible
   in the bottom-right without covering the bar. */
@media (max-width: 1050px) {
    #chat-panel {
        left: auto;
        right: 12px;
        bottom: 86px;
        width: min(330px, calc(100vw - 24px));
        min-width: 0;
        height: 220px;
    }
}


/* ===== Canonical in-game chat placement ===== */
#chat-panel {
    position: fixed;
    left: calc(50% + 315px);
    right: auto;
    bottom: 18px;
    top: auto;
    width: 330px;
    height: 250px;
    z-index: 11040;
    pointer-events: auto;
}

@media (max-width: 1250px) {
    #chat-panel {
        left: auto;
        right: 12px;
        bottom: 86px;
        width: 330px;
        max-width: calc(100vw - 24px);
    }
}


/* ===== Authoritative bottom-right chat placement on every map ===== */
#chat-panel {
    position: fixed !important;
    right: 18px !important;
    left: auto !important;
    bottom: 18px !important;
    top: auto !important;
    width: 330px !important;
    height: 250px !important;
    z-index: 11040 !important;
}

@media (max-width: 800px) {
    #chat-panel {
        right: 10px !important;
        left: auto !important;
        bottom: 10px !important;
        top: auto !important;
        max-width: calc(100vw - 20px) !important;
    }
}
