/* Chat Container Styles */
.chat-container {
     /* Sidebar (1 phần) và nội dung chính (2 phần) */
     max-width: 1200px;
     margin: 20px auto;
     background: #ffffff;
     border-radius: 12px;
     box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
     overflow: hidden;
     font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Sidebar Styles */
.chat-header {
    grid-column: 1 / 2; /* Sidebar chiếm cột đầu tiên */
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    font-size: 24px;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-direction: row;
}

.chat-header::before {
    content: '💬';
    margin-right: 10px;
    font-size: 20px;
}

.chat-header a {
    color: #fff;
    text-decoration: none;
    background: rgba(255, 255, 255, 0.2);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    transition: background 0.3s ease;
}

.chat-header a:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Error Message */
#chat-error {
    background: #fee;
    color: #d32f2f;
    padding: 12px 20px;
    border-left: 4px solid #d32f2f;
    margin: 0;
    font-weight: 500;
    animation: slideDown 0.3s ease;
}

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

/* Chat Messages Area */
.chat-messages {
    grid-column: 2 / 3; /* Nội dung chính chiếm cột thứ hai */
    height: 400px;
    overflow-y: auto;
    padding: 20px;
    background: #f8f9fa;
    position: relative;
}

.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #e9ecef;
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #adb5bd;
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #6c757d;
}

/* Individual Chat Message */
.chat-message {
    background: white;
    margin-bottom: 15px;
    padding: 15px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    position: relative;
    animation: fadeInUp 0.3s ease;
    border-left: 4px solid #667eea;
}

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

.chat-message strong {
    color: #667eea;
    font-weight: 600;
    display: block;
    margin-bottom: 5px;
}

.chat-message .timestamp {
    color: #6c757d;
    font-size: 12px;
    float: right;
    margin-top: 8px;
}

.chat-message a {
    color: #28a745;
    text-decoration: none;
    font-weight: 500;
    background: #e8f5e8;
    padding: 4px 8px;
    border-radius: 6px;
    margin-left: 8px;
    transition: all 0.3s ease;
}

.chat-message a:hover {
    background: #d4edda;
    transform: translateY(-1px);
}

/* Delete Buttons */
.delete-msg-btn, .delete-file-btn {
    background: #dc3545;
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    margin-left: 8px;
    transition: all 0.3s ease;
    opacity: 0.7;
}

.delete-msg-btn:hover, .delete-file-btn:hover {
    background: #c82333;
    opacity: 1;
    transform: scale(1.05);
}

.chat-message:hover .delete-msg-btn,
.chat-message:hover .delete-file-btn {
    opacity: 1;
}

/* Copy Buttons */
.copy-msg-btn {
    background: #007bff;
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    margin-left: 8px;
    transition: all 0.3s ease;
    opacity: 0.7;
}

.copy-msg-btn:hover {
    background: #0056b3;
    opacity: 1;
    transform: scale(1.05);
}

/* Chat Input Section */
.chat-input {
    grid-column: 2 / 3; /* Chat input nằm trong cột thứ hai */
    padding: 20px;
    background: white;
    border-top: 1px solid #e9ecef;
}

#chat-form {
    display: flex;
    gap: 12px;
    margin-bottom: 15px;
}

#chat-input {
    flex: 1;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    padding: 12px;
    font-size: 14px;
    resize: vertical;
    min-height: 60px;
    font-family: inherit;
    transition: border-color 0.3s ease;
}

#chat-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

#chat-form button {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 80px;
}

#chat-form button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

/* File Upload Section */
.file-upload {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-top: 15px;
    border-top: 1px solid #f1f3f4;
}

#file-input {
    flex: 1;
    padding: 8px;
    border: 2px solid #e9ecef;
    border-radius: 6px;
    font-size: 14px;
}

#upload-btn {
    background: #28a745;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

#upload-btn:hover {
    background: #218838;
    transform: translateY(-1px);
}

#upload-progress {
    width: 100%;
    height: 6px;
    margin-top: 10px;
    border-radius: 3px;
    appearance: none;
}

#upload-progress::-webkit-progress-bar {
    background: #e9ecef;
    border-radius: 3px;
}

#upload-progress::-webkit-progress-value {
    background: linear-gradient(90deg, #28a745, #20c997);
    border-radius: 3px;
}

#prev-page, #next-page {
    background: #6c757d;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
}

#prev-page:hover, #next-page:hover {
    background: #5a6268;
    transform: translateY(-1px);
}

#prev-page:disabled, #next-page:disabled {
    background: #adb5bd;
    cursor: not-allowed;
    transform: none;
}

#page-num {
    font-weight: 600;
    color: #495057;
    min-width: 30px;
    text-align: center;
}

/* Password Form */
.chat-password-form {
    max-width: 400px;
    margin: 50px auto;
    padding: 40px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.chat-password-form::before {
    content: '🔒';
    font-size: 48px;
    display: block;
    margin-bottom: 20px;
}

.chat-password-form label {
    display: block;
    margin-bottom: 15px;
    font-weight: 600;
    color: #495057;
    font-size: 16px;
}

.chat-password-form input[type="password"] {
    width: 100%;
    padding: 15px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    font-size: 16px;
    margin-bottom: 20px;
    box-sizing: border-box;
    transition: border-color 0.3s ease;
}

.chat-password-form input[type="password"]:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.chat-password-form input[type="submit"] {
    width: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 15px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.chat-password-form input[type="submit"]:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.chat-password-form p {
    margin-top: 15px;
    padding: 12px;
    border-radius: 6px;
    font-weight: 500;
}

/* Responsive Design */
@media (max-width: 768px) {
    .chat-container {
        grid-template-columns: 1fr; /* Chuyển sang bố cục một cột trên màn hình nhỏ */
    }

    .chat-header {
        grid-column: 1 / 2; /* Sidebar chiếm toàn bộ chiều rộng */
    }

    .chat-messages, .chat-input {
        grid-column: 1 / 2; /* Nội dung chính chiếm toàn bộ chiều rộng */
    }
}

@media (max-width: 480px) {
    .chat-message {
        padding: 12px;
        margin-bottom: 10px;
    }
    
    .chat-header a {
        padding: 6px 12px;
        font-size: 12px;
    }
    
    .delete-msg-btn, .delete-file-btn {
        display: block;
        margin: 5px 0 0 0;
        width: fit-content;
    }
}

/* Loading Animation */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Success Message */
.success-message {
    background: #d4edda;
    color: #155724;
    padding: 12px 20px;
    border-left: 4px solid #28a745;
    margin: 0;
    font-weight: 500;
    animation: slideDown 0.3s ease;
}

/* Empty State */
.chat-messages:empty::before {
    content: 'No messages yet. Start the conversation! 💬';
    display: block;
    text-align: center;
    color: #6c757d;
    font-style: italic;
    padding: 40px 20px;
    background: white;
    border-radius: 8px;
    margin: 20px 0;
}

/* Online Indicator */
.online-indicator {
    width: 8px;
    height: 8px;
    background: #28a745;
    border-radius: 50%;
    display: inline-block;
    margin-left: 8px;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}