* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --secondary-gradient: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --success-gradient: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    --dark-bg: #1a1a2e;
    --light-bg: #f8f9fa;
    --card-bg: #ffffff;
    --text-primary: #2d3748;
    --text-secondary: #718096;
    --border-color: #e2e8f0;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.15);
    --shadow-xl: 0 20px 40px rgba(0, 0, 0, 0.2);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    background: var(--primary-gradient);
    background-attachment: fixed;
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Modal nhập tên */
.modal {
    display: flex;
    justify-content: center;
    align-items: center;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background: var(--card-bg);
    padding: 50px 40px;
    border-radius: 24px;
    box-shadow: var(--shadow-xl);
    text-align: center;
    max-width: 450px;
    width: 90%;
    animation: slideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    overflow: hidden;
}

.modal-content::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--primary-gradient);
}

@keyframes slideUp {
    from {
        transform: translateY(30px) scale(0.95);
        opacity: 0;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.modal-content h2 {
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 12px;
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.modal-content p {
    color: var(--text-secondary);
    margin-bottom: 30px;
    font-size: 16px;
    line-height: 1.6;
}

.modal-content input {
    width: 100%;
    padding: 16px 20px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    font-size: 16px;
    margin-bottom: 12px;
    transition: all 0.3s ease;
    background: var(--light-bg);
    font-weight: 500;
}

.modal-content input:focus {
    outline: none;
    border-color: #667eea;
    background: white;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
    transform: translateY(-2px);
}

#errorMessage {
    background: rgba(229, 62, 62, 0.1);
    border: 1px solid rgba(229, 62, 62, 0.3);
    border-radius: 8px;
    padding: 12px;
    margin-top: 12px;
    animation: shake 0.3s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

.btn-primary {
    background: var(--primary-gradient);
    color: white;
    border: none;
    padding: 16px 40px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

.btn-primary::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn-primary:hover::before {
    width: 300px;
    height: 300px;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.hidden {
    display: none !important;
}

/* Chat container */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: var(--card-bg);
    max-width: 1600px;
    margin: 0 auto;
    box-shadow: var(--shadow-xl);
    border-radius: 0;
}

/* Header */
.chat-header {
    background: var(--primary-gradient);
    color: white;
    padding: 24px 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-md);
    position: relative;
    z-index: 10;
}

.chat-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
}

.chat-header h1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 14px;
}

.user-info span:first-child {
    background: rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(10px);
    padding: 10px 18px;
    border-radius: 24px;
    font-weight: 600;
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.btn-change-name {
    background: rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 10px 14px;
    border-radius: 24px;
    cursor: pointer;
    font-size: 18px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.btn-change-name:hover {
    background: rgba(255, 255, 255, 0.35);
    transform: scale(1.1) rotate(15deg);
}

.users-count {
    background: rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(10px);
    padding: 10px 18px;
    border-radius: 24px;
    font-weight: 600;
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Main layout */
.chat-main {
    display: flex;
    flex: 1;
    overflow: hidden;
    background: var(--light-bg);
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--card-bg);
    border-right: 1px solid var(--border-color);
    padding: 24px;
    overflow-y: auto;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.05);
}

.sidebar h3 {
    color: var(--text-primary);
    margin-bottom: 20px;
    font-size: 18px;
    font-weight: 700;
    padding-bottom: 16px;
    border-bottom: 3px solid;
    border-image: var(--primary-gradient) 1;
    letter-spacing: -0.3px;
}

.sidebar ul {
    list-style: none;
}

.sidebar li {
    padding: 14px 16px;
    margin-bottom: 10px;
    background: var(--light-bg);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 15px;
    font-weight: 500;
    box-shadow: var(--shadow-sm);
    transition: all 0.3s ease;
    border: 2px solid transparent;
    position: relative;
    overflow: hidden;
}

.sidebar li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--primary-gradient);
    transform: scaleY(0);
    transition: transform 0.3s ease;
}

.sidebar li:hover {
    transform: translateX(8px);
    box-shadow: var(--shadow-md);
    border-color: rgba(102, 126, 234, 0.2);
    background: white;
}

.sidebar li:hover::before {
    transform: scaleY(1);
}

.sidebar li::after {
    content: "🟢";
    margin-right: 10px;
    font-size: 12px;
    filter: drop-shadow(0 0 4px rgba(76, 175, 80, 0.6));
}

/* Messages area */
.messages {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    background: var(--light-bg);
    display: flex;
    flex-direction: column;
    gap: 20px;
    position: relative;
}

.messages::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--border-color), transparent);
}

.message {
    display: flex;
    flex-direction: column;
    max-width: 75%;
    animation: messageSlide 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.message.own {
    align-self: flex-end;
}

.message.other {
    align-self: flex-start;
}

.message-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}

.message.own .message-header {
    justify-content: flex-end;
}

.message-username {
    font-weight: 700;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-size: 14px;
}

.message-time {
    color: var(--text-secondary);
    font-size: 12px;
    opacity: 0.7;
}

.message-content {
    padding: 14px 18px;
    border-radius: 20px;
    word-wrap: break-word;
    line-height: 1.5;
    font-size: 15px;
    position: relative;
}

.message.own .message-content {
    background: var(--primary-gradient);
    color: white;
    border-bottom-right-radius: 6px;
    box-shadow: var(--shadow-md);
}

.message.own .message-content::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: -8px;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-bottom: 8px solid #764ba2;
}

.message.other .message-content {
    background: var(--card-bg);
    color: var(--text-primary);
    border-bottom-left-radius: 6px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.message.other .message-content::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: -8px;
    width: 0;
    height: 0;
    border-right: 8px solid var(--card-bg);
    border-bottom: 8px solid var(--card-bg);
}

.system-message {
    text-align: center;
    padding: 12px 20px;
    margin: 16px 0;
    color: var(--text-secondary);
    font-size: 13px;
    font-style: italic;
    background: rgba(102, 126, 234, 0.1);
    border-radius: 20px;
    max-width: 80%;
    margin-left: auto;
    margin-right: auto;
    border: 1px solid rgba(102, 126, 234, 0.2);
}

/* Typing indicator */
.typing-indicator {
    padding: 12px 24px;
    color: var(--text-secondary);
    font-size: 14px;
    font-style: italic;
    display: flex;
    align-items: center;
    gap: 8px;
}

.typing-indicator::before {
    content: '💬';
    font-size: 16px;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* Input area */
.input-area {
    display: flex;
    padding: 24px;
    background: var(--card-bg);
    border-top: 1px solid var(--border-color);
    gap: 12px;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

.input-area input {
    flex: 1;
    padding: 16px 24px;
    border: 2px solid var(--border-color);
    border-radius: 28px;
    font-size: 15px;
    transition: all 0.3s ease;
    background: var(--light-bg);
    font-weight: 500;
}

.input-area input:focus {
    outline: none;
    border-color: #667eea;
    background: white;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
    transform: translateY(-2px);
}

.btn-send {
    background: var(--primary-gradient);
    color: white;
    border: none;
    padding: 16px 36px;
    border-radius: 28px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-md);
    position: relative;
    overflow: hidden;
}

.btn-send::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn-send:hover::before {
    width: 300px;
    height: 300px;
}

.btn-send:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-send:active {
    transform: translateY(0);
}

/* Scrollbar styling */
.messages::-webkit-scrollbar,
.sidebar::-webkit-scrollbar {
    width: 10px;
}

.messages::-webkit-scrollbar-track,
.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.messages::-webkit-scrollbar-thumb,
.sidebar::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #667eea, #764ba2);
    border-radius: 10px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

.messages::-webkit-scrollbar-thumb:hover,
.sidebar::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, #764ba2, #667eea);
}

/* Responsive */
@media (max-width: 1024px) {
    .chat-container {
        max-width: 100%;
        border-radius: 0;
    }
}

@media (max-width: 768px) {
    body {
        overflow: hidden;
    }

    .chat-container {
        height: 100vh;
    }

    .chat-main {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        padding: 16px 20px;
        border-right: none;
        border-top: 1px solid var(--border-color);
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.04);
        max-height: 140px;
    }

    .sidebar h3 {
        margin-bottom: 12px;
        padding-bottom: 10px;
        font-size: 16px;
    }

    .messages {
        padding: 16px 20px;
    }

    .message {
        max-width: 85%;
    }

    .chat-header {
        flex-direction: column;
        gap: 16px;
        text-align: center;
        padding: 18px 16px;
    }

    .chat-header h1 {
        font-size: 24px;
    }

    .user-info {
        flex-wrap: wrap;
        justify-content: center;
    }

    .modal-content {
        padding: 40px 26px;
    }

    .modal-content h2 {
        font-size: 26px;
    }

    .input-area {
        padding: 16px 20px;
    }
}

@media (max-width: 480px) {
    .chat-header h1 {
        font-size: 22px;
    }

    .users-count {
        font-size: 12px;
        padding: 8px 14px;
    }

    .user-info span:first-child {
        padding: 8px 14px;
        font-size: 13px;
    }

    .btn-change-name {
        padding: 8px 10px;
        font-size: 16px;
    }

    .sidebar {
        display: none;
    }

    .messages {
        padding: 12px 14px;
        gap: 14px;
    }

    .message {
        max-width: 90%;
    }

    .message-content {
        font-size: 14px;
        padding: 10px 14px;
    }

    .input-area {
        padding: 12px 14px;
        gap: 8px;
    }

    .input-area input {
        padding: 12px 16px;
        font-size: 14px;
    }

    .btn-send {
        padding: 12px 18px;
        font-size: 14px;
        white-space: nowrap;
    }

    .typing-indicator {
        padding: 8px 14px;
        font-size: 12px;
    }
}
