/* Reset và Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

.hidden {
    display: none !important;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    padding: 2rem;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    max-width: 400px;
    width: 90%;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-content h2 {
    text-align: center;
    margin-bottom: 1.5rem;
    color: #667eea;
    font-size: 1.5rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #555;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid #e1e1e1;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #667eea;
}

.modal-content button {
    width: 100%;
    padding: 0.75rem;
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.modal-content button:hover {
    transform: translateY(-2px);
}

/* Chat Container */
#chatContainer {
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: white;
}

/* Header */
.chat-header {
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-left h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

.current-room {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.2);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-weight: 600;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

#logoutBtn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 0.5rem;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.3s ease;
}

#logoutBtn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Main Chat Area */
.chat-main {
    display: flex;
    flex: 1;
    height: calc(100vh - 80px);
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: #f8f9fa;
    border-right: 1px solid #e1e1e1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.sidebar-section {
    padding: 1rem;
    border-bottom: 1px solid #e1e1e1;
}

.sidebar-section h3 {
    margin-bottom: 0.75rem;
    color: #555;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.rooms-list,
.users-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.room-item,
.user-item {
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.room-item:hover,
.user-item:hover {
    background: #e9ecef;
}

.room-item.active {
    background: #667eea;
    color: white;
}

.room-count {
    margin-left: auto;
    background: #6c757d;
    color: white;
    font-size: 0.75rem;
    padding: 0.2rem 0.5rem;
    border-radius: 10px;
}

.room-item.active .room-count {
    background: rgba(255, 255, 255, 0.3);
}

.user-status {
    width: 8px;
    height: 8px;
    background: #28a745;
    border-radius: 50%;
    display: inline-block;
}

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.messages-container {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    scroll-behavior: smooth;
    background: linear-gradient(to bottom, #f8f9fa, #ffffff);
}

/* Messages */
.message {
    margin-bottom: 1rem;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #e1e1e1;
}

.user-avatar-placeholder {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #667eea;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
}

.user-avatar-small {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    object-fit: cover;
}

.user-avatar-small-placeholder {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #667eea;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.7rem;
}

.message-username {
    font-weight: 600;
    color: #667eea;
}

.message-timestamp {
    font-size: 0.75rem;
    color: #6c757d;
}

.message-content {
    background: white;
    padding: 0.75rem 1rem;
    border-radius: 10px 10px 10px 2px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    word-wrap: break-word;
}

.system-message {
    text-align: center;
    color: #6c757d;
    font-style: italic;
    margin: 0.5rem 0;
    font-size: 0.9rem;
}

/* Typing Indicator */
.typing-indicator {
    padding: 0.5rem 1rem;
    color: #6c757d;
    font-style: italic;
    font-size: 0.9rem;
}

.typing-dots {
    display: inline-block;
    animation: typing 1.5s infinite;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    30% {
        transform: scale(1.2);
        opacity: 0.7;
    }
}

/* Message Input */
.message-input-container {
    padding: 1rem;
    background: white;
    border-top: 1px solid #e1e1e1;
}

.input-group {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.image-btn {
    background: #6c757d;
    color: white;
    border: none;
    padding: 0.75rem;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-btn:hover {
    background: #5a6268;
    transform: scale(1.05);
}

#messageInput {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 2px solid #e1e1e1;
    border-radius: 25px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

#messageInput:focus {
    outline: none;
    border-color: #667eea;
}

#sendBtn {
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
    border: none;
    padding: 0.75rem 1rem;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

#sendBtn:hover {
    transform: scale(1.05);
}

#sendBtn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Image Preview */
.image-preview {
    margin-top: 1rem;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 10px;
    border: 2px dashed #dee2e6;
}

.preview-content {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.preview-content img {
    max-width: 200px;
    max-height: 150px;
    object-fit: cover;
    border-radius: 8px;
    align-self: flex-start;
}

.preview-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.preview-info span:first-child {
    font-weight: 600;
    color: #333;
}

.preview-info span:last-child {
    font-size: 0.9rem;
    color: #6c757d;
}

.preview-actions {
    display: flex;
    gap: 0.5rem;
}

.cancel-btn {
    background: #dc3545;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s ease;
}

.cancel-btn:hover {
    background: #c82333;
}

.send-btn {
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: transform 0.2s ease;
}

.send-btn:hover {
    transform: translateY(-1px);
}

/* Message Images */
.message-image {
    margin-top: 0.5rem;
}

.message-image img {
    max-width: 300px;
    max-height: 200px;
    object-fit: cover;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: block;
}

.message-image img:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.image-name {
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: #6c757d;
    font-style: italic;
}

/* Image Modal */
.image-modal-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    background: white;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.close-modal {
    position: absolute;
    top: 10px;
    right: 15px;
    color: white;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    z-index: 1002;
    background: rgba(0, 0, 0, 0.5);
    width: 35px;
    height: 35px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.close-modal:hover {
    background: rgba(0, 0, 0, 0.7);
}

#modalImage {
    width: 100%;
    height: auto;
    max-height: 80vh;
    object-fit: contain;
    display: block;
}

.image-info {
    padding: 1rem;
    background: #f8f9fa;
    border-top: 1px solid #dee2e6;
    text-align: center;
    font-weight: 600;
    color: #333;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1003;
}

.loading-spinner {
    background: white;
    padding: 2rem;
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.loading-spinner i {
    font-size: 2rem;
    color: #667eea;
    margin-bottom: 1rem;
}

.loading-spinner span {
    display: block;
    color: #333;
    font-weight: 600;
}

/* Toast Notifications */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #333;
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1001;
    animation: slideInRight 0.3s ease-out;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast.success {
    background: #28a745;
}

.toast.error {
    background: #dc3545;
}

.toast.info {
    background: #17a2b8;
}

/* Responsive Design */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -280px;
        top: 80px;
        height: calc(100vh - 80px);
        z-index: 999;
        transition: left 0.3s ease;
    }

    .sidebar.show {
        left: 0;
    }

    .chat-main {
        flex-direction: column;
    }

    .header-left h1 {
        font-size: 1.2rem;
    }

    .current-room {
        display: none;
    }

    .modal-content {
        margin: 1rem;
    }

    .message-image img {
        max-width: 250px;
        max-height: 150px;
    }

    .preview-content img {
        max-width: 150px;
        max-height: 100px;
    }

    .image-modal-content {
        max-width: 95vw;
        max-height: 95vh;
        margin: 1rem;
    }
}

@media (max-width: 480px) {
    .chat-header {
        padding: 0.75rem 1rem;
    }

    .messages-container {
        padding: 0.75rem;
    }

    .message-input-container {
        padding: 0.75rem;
    }

    #messageInput {
        font-size: 16px; /* Prevent zoom on iOS */
    }
}

/* Scrollbar Styling */
.messages-container::-webkit-scrollbar,
.sidebar::-webkit-scrollbar {
    width: 6px;
}

.messages-container::-webkit-scrollbar-track,
.sidebar::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.messages-container::-webkit-scrollbar-thumb,
.sidebar::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.messages-container::-webkit-scrollbar-thumb:hover,
.sidebar::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}