/* --- Integrated Chat Widget --- */
#chat-widget {
    position: fixed;
    /* Position and size are primarily set by JS logic, these are safe fallbacks */
    bottom: 15px;
    left: 15px;
    width: 350px;
    height: 450px; /* Default expanded height */
    min-width: 300px;
    min-height: 200px;
    max-width: 90vw;
    max-height: 80vh;
    
    background-color: rgba(30, 30, 30, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid #444;
    border-radius: 8px;
    
    display: flex;
    flex-direction: column;
    z-index: 999;
    
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    transition: opacity 0.3s ease, box-shadow 0.3s ease;
    opacity: 0.6; /* Default transparency when inactive */
    overflow: hidden; /* Important for border-radius clipping */
}

/* Becomes fully opaque on hover or interaction */
#chat-widget:hover,
#chat-widget:focus-within {
    opacity: 1;
    box-shadow: 0 15px 40px rgba(0,0,0,0.7);
    border-color: #666;
}

/* Header: Draggable Area */
#chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #2a2a2a;
    border-bottom: 1px solid #444;
    color: #e0e0e0;
    cursor: move; /* Indicates dragability */
    flex-shrink: 0;
    height: 36px;
    padding-left: 4px;
    user-select: none;
}

#chat-toggle-btn {
    background: none;
    border: none;
    color: #aaa;
    font-size: 0.9em;
    padding: 0 12px;
    cursor: pointer;
    height: 100%;
    transition: color 0.2s, background-color 0.2s;
}
#chat-toggle-btn:hover {
    color: #fff;
    background-color: #3a3a3a;
}

/* Collapsed State */
#chat-widget.collapsed {
    height: 36px !important; 
    min-height: 36px !important; 
    resize: none; /* Disable native resize if any */
}

/* Content Area */
#chat-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* Tabs Container */
#chat-tabs {
    display: flex;
    gap: 1px;
    height: 100%;
    overflow-x: auto;
    scrollbar-width: none; /* Hide scrollbar */
}
#chat-tabs::-webkit-scrollbar { display: none; }

.chat-tab {
    padding: 0 12px;
    background-color: transparent;
    border: none;
    color: #888;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9em;
    transition: background-color 0.2s, color 0.2s;
    border-right: 1px solid #333;
}
.chat-tab:hover {
    background-color: #333;
    color: #ccc;
}
.chat-tab.active {
    background-color: #3a3a3a;
    color: #fff;
    font-weight: 600;
    box-shadow: inset 0 -2px 0 #00aaff; /* Active indicator */
}

/* Tab Close Button */
.close-tab-btn {
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    font-size: 1.1em;
    line-height: 1;
    padding: 0;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
}
.close-tab-btn:hover {
    color: #ff5555;
    background-color: rgba(255, 85, 85, 0.1);
}

/* Log Panels */
#chat-log-panels {
    flex-grow: 1;
    position: relative;
    background-color: #1e1e1e;
}

.chat-log-panel {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    overflow-y: auto;
    padding: 10px;
    font-size: 0.9em;
    line-height: 1.4;
    display: none;
    scrollbar-width: thin;
    scrollbar-color: #444 #1e1e1e;
}
.chat-log-panel.active {
    display: block;
}

/* Chat Messages */
.chat-message { 
    margin-bottom: 6px; 
    word-wrap: break-word; 
}
.chat-message .sender { 
    font-weight: 700; 
    margin-right: 4px; 
    cursor: pointer; /* Hint that names might be clickable later */
}
.chat-message .content {
    color: #ddd;
}

/* Input Form */
#chat-form { 
    display: flex; 
    border-top: 1px solid #444; 
    padding: 8px; 
    gap: 8px; 
    flex-shrink: 0; 
    background-color: #252525;
    position: relative;
}

#chat-input { 
    flex-grow: 1; 
    background-color: #181818; 
    border: 1px solid #444; 
    color: #e0e0e0; 
    padding: 8px 10px; 
    border-radius: 4px; 
    font-size: 0.9em;
    transition: border-color 0.2s;
}
#chat-input:focus {
    outline: none;
    border-color: #00aaff;
}

#chat-form button { 
    background-color: #007acc; 
    border: none; 
    color: white; 
    font-weight: bold; 
    border-radius: 4px; 
    padding: 0 12px; 
    cursor: pointer; 
    transition: background-color 0.2s;
}
#chat-form button:hover {
    background-color: #0099ff;
}

/* Character Counter */
.char-counter {
    position: absolute;
    top: -25px;
    right: 10px;
    font-size: 0.75em;
    color: #aaa;
    background-color: rgba(0, 0, 0, 0.6);
    padding: 2px 6px;
    border-radius: 4px;
    pointer-events: none;
}
.char-counter.limit-exceeded {
    color: #ff5555;
    font-weight: bold;
}

/* Resize Handle */
#chat-resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    cursor: se-resize;
    background: linear-gradient(135deg, transparent 50%, #666 50%);
    opacity: 0.7;
    z-index: 10;
}
#chat-resize-handle:hover {
    opacity: 1;
    background: linear-gradient(135deg, transparent 50%, #00aaff 50%);
}

/* New Message Pulse Animation */
@keyframes pulse-border-yellow {
    0% { box-shadow: 0 0 0 0 rgba(255, 215, 0, 0.7); border-color: #ffd700; }
    70% { box-shadow: 0 0 0 10px rgba(255, 215, 0, 0); border-color: #ffe44d; }
    100% { box-shadow: 0 0 0 0 rgba(255, 215, 0, 0); border-color: #444; }
}

#chat-widget.new-message.collapsed {
    animation: pulse-border-yellow 1.5s ease-out;
    animation-iteration-count: 3;
}

/* Lobby Links in Chat */
.lobby-link {
    background-color: #005a99;
    color: #fff;
    padding: 2px 6px;
    border-radius: 3px;
    cursor: pointer;
    text-decoration: none;
    font-size: 0.9em;
    display: inline-block;
    margin-top: 2px;
}
.lobby-link:hover {
    background-color: #0088cc;
}
.lobby-link[data-joinable="false"] {
    background-color: #444;
    color: #aaa;
    cursor: not-allowed;
    text-decoration: line-through;
}
.lobby-link-invalid {
    color: #777;
    font-style: italic;
}

/* Lobby Links in Chat */
.lobby-link {
    background-color: #005a99;
    color: #fff;
    padding: 2px 6px;
    border-radius: 3px;
    cursor: pointer;
    text-decoration: none;
    font-size: 0.9em;
    display: inline-block;
    margin-top: 2px;
}
.lobby-link:hover {
    background-color: #0088cc;
}
.lobby-link[data-joinable="false"] {
    background-color: #444;
    color: #aaa;
    cursor: not-allowed;
    text-decoration: line-through;
}
.lobby-link-invalid {
    color: #777;
    font-style: italic;
}

/* Wipe Animation for Removed Messages */
@keyframes wipe-out {
    0% {
        opacity: 1;
        transform: scaleX(1);
        filter: blur(0);
    }
    50% {
        opacity: 0.5;
        transform: scaleX(1.1); /* Stretch slightly */
        filter: blur(2px);
        background-color: rgba(255, 0, 0, 0.2);
    }
    100% {
        opacity: 0;
        transform: scaleX(0);
        height: 0;
        margin: 0;
        padding: 0;
        overflow: hidden;
    }
}

.chat-message.wiping-out {
    animation: wipe-out 0.6s cubic-bezier(0.55, 0.055, 0.675, 0.19) forwards;
    transform-origin: left; /* Wipe from right to left look */
}