/* Chat room styles */
.right-sidebar {
    position: sticky;
    top: 20px;
    height: fit-content;
}

.chat-container {
    background: white;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 600px;
    min-height: 500px;
    max-height: calc(100vh - 40px);
}

.chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.chat-header > div:first-child {
    flex: 1;
    min-width: 0;
}

.chat-header strong {
    font-size: 1em;
}

.chat-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.user-count {
    background: rgba(255, 255, 255, 0.2);
    padding: 4px 10px;
    border-radius: 15px;
    font-size: 0.85em;
    white-space: nowrap;
    flex-shrink: 0;
}

.chat-identity {
    background: #f7fafc;
    padding: 10px 15px;
    border-bottom: 1px solid #e2e8f0;
    font-size: 0.9em;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-identity strong {
    color: #667eea;
}

.btn-link {
    background: none;
    border: none;
    color: #667eea;
    cursor: pointer;
    text-decoration: underline;
    font-size: 0.9em;
    padding: 2px 8px;
}

.btn-link:hover {
    color: #764ba2;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    background: #ffffff;
}

.chat-message {
    margin-bottom: 15px;
    padding: 10px;
    border-radius: 8px;
    background: #f7fafc;
    max-width: 80%;
}

.chat-message.own-message {
    background: #e6fffa;
    margin-left: auto;
}

.message-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
}

.message-username {
    font-weight: 600;
    color: #dc2626;
    font-size: 0.9em;
}

.own-message .message-username {
    color: #2563eb;
}

.message-time {
    color: #718096;
    font-size: 0.75em;
}

.message-text {
    color: #2d3748;
    word-wrap: break-word;
}

.system-message {
    text-align: center;
    color: #718096;
    font-size: 0.85em;
    margin: 10px 0;
    font-style: italic;
}

.chat-input-container {
    display: flex;
    gap: 10px;
    padding: 15px;
    border-top: 1px solid #e2e8f0;
    background: #f7fafc;
    flex-shrink: 0;
}

#message-input {
    flex: 1;
    padding: 10px;
    border: 2px solid #e2e8f0;
    border-radius: 5px;
    font-size: 1em;
}

#message-input:focus {
    outline: none;
    border-color: #667eea;
}

#send-btn {
    padding: 10px 20px;
}

/* Scrollbar styling */
.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

.typing-indicator {
    padding: 8px 20px;
    font-size: 0.85em;
    color: #718096;
    font-style: italic;
    background: #f7fafc;
    border-top: 1px solid #e2e8f0;
    min-height: 30px;
    display: none;
}

.error-message {
    color: #e53e3e;
    font-size: 0.9em;
    margin: 10px 0;
}

.btn-icon {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1em;
    transition: background 0.2s;
    flex-shrink: 0;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.3);
}

.user-count {
    background: rgba(255, 255, 255, 0.2);
    padding: 4px 10px;
    border-radius: 15px;
    font-size: 0.85em;
    white-space: nowrap;
    flex-shrink: 0;
}

.online-users-list {
    padding: 10px;
    max-height: 400px;
    overflow-y: auto;
}

.online-user-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 4px;
    margin-bottom: 4px;
}

.online-user-item:hover {
    background: #f7fafc;
}

.online-user-item.current-user {
    background: #eff6ff;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
    flex-shrink: 0;
}

.online-user-item .username {
    font-weight: 500;
    color: #2d3748;
    flex: 1;
}

.you-badge {
    font-size: 0.75em;
    color: #2563eb;
    font-weight: 600;
}

.loading-text,
.no-users {
    text-align: center;
    color: #718096;
    padding: 20px;
    font-style: italic;
}

@media (max-width: 768px) {
    .chat-container {
        height: 600px;
        max-height: 80vh;
    }
    
    .right-sidebar {
        position: static;
        margin-bottom: 20px;
    }
    
    .chat-header {
        padding: 12px 10px;
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .chat-header h3 {
        font-size: 1.1em;
    }
    
    .chat-controls {
        gap: 6px;
    }
    
    .chat-controls button,
    .chat-controls .icon-btn {
        padding: 6px 10px;
        font-size: 0.9em;
    }
    
    .chat-controls .icon-btn {
        width: 32px;
        height: 32px;
    }
    
    .chat-messages {
        padding: 10px;
    }
    
    .chat-message {
        padding: 8px 10px;
        margin-bottom: 8px;
    }
    
    .message-username {
        font-size: 0.85em;
    }
    
    .message-text {
        font-size: 0.95em;
    }
    
    .message-time {
        font-size: 0.7em;
    }
    
    .chat-input-container {
        padding: 10px;
        gap: 8px;
    }
    
    #chat-input {
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    #send-message {
        padding: 10px 16px;
    }
    
    /* Username change modal */
    #username-modal .modal-content {
        width: 90%;
        padding: 20px;
    }
    
    #username-modal input {
        font-size: 16px;
    }
    
    /* Online users modal */
    #online-users-modal .modal-content {
        width: 90%;
        max-width: 400px;
    }
    
    .online-users-list {
        max-height: 60vh;
    }
    
    /* Ensure colors match desktop */
    .online-user-item .username {
        color: inherit;
    }
    
    .typing-indicator {
        font-size: 0.8em;
        padding: 6px 10px;
    }
}

/* Small mobile devices */
@media (max-width: 480px) {
    .chat-container {
        height: 550px;
    }
    
    .chat-header h3 {
        font-size: 1em;
        width: 100%;
        text-align: center;
    }
    
    .chat-controls {
        width: 100%;
        justify-content: center;
    }
    
    .chat-controls button span {
        display: none; /* Hide text, show icons only */
    }
    
    .chat-message {
        padding: 6px 8px;
    }
    
    .message-text {
        font-size: 0.9em;
    }
}
