* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Light mode colors */
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-tertiary: #94a3b8;
    --accent-primary: #3b82f6;
    --accent-secondary: #1d4ed8;
    --border-color: #e2e8f0;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
}

[data-theme="dark"] {
    /* Dark mode colors */
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-tertiary: #94a3b8;
    --accent-primary: #3b82f6;
    --accent-secondary: #60a5fa;
    --border-color: #334155;
    --shadow-color: rgba(0, 0, 0, 0.3);
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

#app {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Login Section */
#user-section {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: 0 4px 20px var(--shadow-color);
    padding: 40px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    animation: loginAppear 0.3s ease-out;
}

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

.login-container h2 {
    color: var(--text-primary);
    margin-bottom: 24px;
    font-size: 24px;
    font-weight: 600;
}

#username-input {
    width: 100%;
    padding: 12px 16px;
    font-size: 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 16px;
    transition: all 0.2s ease;
    background: var(--bg-primary);
    color: var(--text-primary);
}

#username-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

#username-input::placeholder {
    color: var(--text-tertiary);
}

#join-btn {
    background: var(--accent-primary);
    color: white;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
    width: 100%;
    transition: all 0.2s ease;
}

#join-btn:hover {
    background: var(--accent-secondary);
    transform: translateY(-1px);
}

/* Chat Container */
#chat-container {
    width: 100%;
    height: 100vh;
    display: flex;
    background: var(--bg-primary);
    animation: chatAppear 0.3s ease-out;
}

@keyframes chatAppear {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Sidebar */
#sidebar {
    width: 280px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    border-right: 1px solid var(--border-color);
    transition: all 0.3s ease;
}

#online-users h3 {
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 12px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
}

#users-list {
    list-style: none;
    max-height: 300px;
    overflow-y: auto;
}

#users-list li {
    padding: 8px 12px;
    margin-bottom: 4px;
    background: var(--bg-secondary);
    border-radius: 6px;
    transition: background-color 0.2s;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);
}

#users-list li:hover {
    background: var(--bg-primary);
}

#users-list li::before {
    content: '●';
    color: var(--success-color);
    margin-right: 8px;
}

#chat-info {
    background: var(--bg-secondary);
    padding: 16px;
    border-radius: 8px;
    margin-top: auto;
}

#chat-info h4 {
    margin-bottom: 8px;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
}

#chat-info p {
    color: var(--text-secondary);
    font-size: 12px;
}

/* Main Chat Area */
#chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

#chat-header {
    background: var(--bg-primary);
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#chat-header h3 {
    color: var(--text-primary);
    font-size: 18px;
    font-weight: 500;
}

#current-user {
    background: var(--accent-primary);
    color: white;
    padding: 6px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

#messages-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding-bottom: 80px; /* Add space for fixed input */
}

#messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.no-messages {
    text-align: center;
    color: var(--text-tertiary);
    font-style: italic;
    padding: 40px;
    font-size: 14px;
}

.message {
    max-width: 75%;
    padding: 10px 14px;
    margin-bottom: 2px;
    border-radius: 12px;
    position: relative;
    animation: fadeIn 0.2s ease-in;
    word-wrap: break-word;
    font-size: 14px;
    line-height: 1.4;
}

.own-message {
    background: var(--accent-primary);
    color: white;
    align-self: flex-end;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.other-message {
    background: var(--bg-primary);
    color: var(--text-primary);
    align-self: flex-start;
    margin-right: auto;
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border-color);
}

.own-message .message-user {
    color: rgba(255, 255, 255, 0.8);
    font-size: 11px;
    font-weight: 500;
}

.own-message .message-time {
    color: rgba(255, 255, 255, 0.7);
}

.other-message .message-user {
    color: var(--accent-primary);
    font-weight: 500;
}

.other-message .message-time {
    color: var(--text-tertiary);
}

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

.message-user {
    font-weight: 500;
    font-size: 11px;
    margin-bottom: 2px;
    display: block;
}

.message-text {
    margin-bottom: 2px;
}

.message-time {
    font-size: 10px;
    text-align: right;
    display: block;
    opacity: 0.8;
}

#typing-indicator {
    padding: 8px 20px;
    font-style: italic;
    color: var(--text-tertiary);
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    min-height: 20px;
    font-size: 12px;
}

#message-input-container {
    display: flex;
    padding: 16px 20px;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    gap: 12px;
    position: fixed;
    bottom: 0;
    left: 280px;
    right: 0;
    z-index: 100;
}

#message-input {
    flex: 1;
    padding: 10px 16px;
    font-size: 14px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    outline: none;
    transition: border-color 0.2s;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

#message-input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

#message-input::placeholder {
    color: var(--text-tertiary);
}

#send-btn {
    background: var(--accent-primary);
    color: white;
    padding: 10px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
    min-width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#send-btn:hover {
    background: var(--accent-secondary);
    transform: scale(1.05);
}

#send-btn:active {
    transform: scale(0.95);
}

#send-btn svg {
    transition: transform 0.2s ease;
}

#send-btn:hover svg {
    transform: translateX(1px);
}

/* Theme toggle button */
.theme-toggle {
    background: var(--warning-color);
    color: white;
    padding: 10px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
    min-width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle:hover {
    background: #d97706;
    transform: scale(1.05);
}

.theme-toggle:active {
    transform: scale(0.95);
}

.theme-toggle svg {
    transition: transform 0.2s ease;
}

.theme-toggle:hover svg {
    transform: rotate(15deg);
}

/* Theme toggle icon container */
.theme-toggle-icons {
    position: relative;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Sun and moon icon positioning */
.theme-toggle .sun-icon,
.theme-toggle .moon-icon {
    position: absolute;
    width: 16px;
    height: 16px;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: center;
}

/* Light mode - show sun, hide moon */
.theme-toggle .sun-icon {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

.theme-toggle .moon-icon {
    opacity: 0;
    transform: rotate(180deg) scale(0.8);
}

/* Dark mode - show moon, hide sun */
[data-theme="dark"] .theme-toggle .sun-icon {
    opacity: 0;
    transform: rotate(-180deg) scale(0.8);
}

[data-theme="dark"] .theme-toggle .moon-icon {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

/* Hover animations */
.theme-toggle:hover .sun-icon {
    transform: rotate(15deg) scale(1.1);
}

[data-theme="dark"] .theme-toggle:hover .moon-icon {
    transform: rotate(15deg) scale(1.1);
}

/* Active state animations */
.theme-toggle:active .sun-icon {
    transform: rotate(0deg) scale(0.9);
}

[data-theme="dark"] .theme-toggle:active .moon-icon {
    transform: rotate(0deg) scale(0.9);
}

/* Enhanced theme toggle button styling for dark mode */
[data-theme="dark"] .theme-toggle {
    background: #6366f1;
}

[data-theme="dark"] .theme-toggle:hover {
    background: #4f46e5;
}

/* Logout button */
.logout-button {
    background: var(--danger-color);
    color: white;
    padding: 10px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
    min-width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.logout-button:hover {
    background: #dc2626;
    transform: scale(1.05);
}

.logout-button:active {
    transform: scale(0.95);
}

.logout-button svg {
    transition: transform 0.2s ease;
}

.logout-button:hover svg {
    transform: translateX(1px);
}

/* Sidebar toggle button */
.sidebar-toggle {
    display: none; /* Hidden on desktop */
    background: linear-gradient(45deg, #007bff, #0056b3);
    color: white;
    padding: 8px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s ease;
    min-width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 123, 255, 0.3);
}

.sidebar-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.4);
}

.sidebar-toggle:active {
    transform: translateY(0);
}

/* Mobile sidebar overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
}

.sidebar-overlay.active {
    display: block;
}

/* Scrollbar styling */
#messages::-webkit-scrollbar {
    width: 6px;
}

#messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

#messages::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

#messages::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Responsive design */
@media (max-width: 768px) {
    body {
        overflow: hidden;
        margin: 0;
        padding: 0;
    }
    
    #app {
        height: 100vh;
        width: 100vw;
        margin: 0;
        padding: 0;
    }
    
    #user-section {
        margin: 10px;
        padding: 20px;
        width: calc(100% - 20px);
        max-width: none;
    }
    
    .login-container h2 {
        font-size: 22px;
        margin-bottom: 16px;
    }
    
    #chat-container {
        flex-direction: row;
        height: 100vh;
        width: 100vw;
        margin: 0;
        padding: 0;
    }
    
    /* Hide sidebar on mobile, show as overlay */
#sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 70%;
    max-width: 320px;
    height: 100vh;
    flex-direction: column;
    padding: 25px;
    z-index: 999;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    border-right: 1px solid #34495e;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
}

#sidebar.active {
    transform: translateX(0);
}

/* Show hamburger menu on mobile */
.sidebar-toggle {
    display: flex;
}
    
    #online-users {
        flex: 1;
        min-width: 200px;
    }
    
    #online-users h3 {
        font-size: 16px;
        margin-bottom: 10px;
    }
    
    #chat-info {
        margin-top: auto;
        margin-left: 0;
        padding: 15px;
        min-width: auto;
    }
    
    #users-list {
        display: block;
        max-height: 400px;
        overflow-y: auto;
    }
    
    #users-list li {
        white-space: normal;
        margin-bottom: 8px;
        padding: 12px 15px;
        font-size: 14px;
    }
    
    #chat-header {
        padding: 10px;
        flex-wrap: nowrap;
        gap: 8px;
        align-items: center;
    }
    
    #chat-header h3 {
        font-size: 14px;
        flex: 1;
        margin-bottom: 0;
    }
    
    /* Right side button container on mobile */
    #chat-header > div:last-child {
        display: flex;
        align-items: center;
        gap: 6px;
        flex-shrink: 0;
        min-width: 0;
    }
    
    #connection-status {
        font-size: 10px;
        min-width: 70px;
        text-align: center;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    #current-user {
        font-size: 10px;
        padding: 3px 6px;
        white-space: nowrap;
        flex-shrink: 0;
    }
    
    .theme-toggle {
        font-size: 12px;
        padding: 6px;
        min-width: 28px;
        height: 28px;
    }
    
    .logout-button {
        font-size: 12px;
        padding: 6px;
        min-width: 28px;
        height: 28px;
    }
    
    #messages {
        padding: 10px;
        gap: 8px;
    }
    
    .message {
        max-width: 85%;
        padding: 10px 14px;
        font-size: 14px;
    }
    
    .message-user {
        font-size: 12px;
    }
    
    .message-text {
        font-size: 14px;
    }
    
    .message-time {
        font-size: 10px;
    }
    
    #messages-container {
        padding-bottom: 70px; /* Reduced bottom padding for mobile */
    }
    
    #message-input-container {
        padding: 8px 12px;
        gap: 8px;
        left: 0;
        right: 0;
        margin: 0;
    }
    
    #message-input {
        padding: 10px 14px;
        font-size: 16px;
        border-radius: 20px;
    }
    
    #send-btn {
        padding: 10px;
        font-size: 14px;
        min-width: 42px;
        height: 42px;
        border-radius: 50%;
    }
    
    #typing-indicator {
        padding: 8px 15px;
        font-size: 12px;
    }
}

/* Small mobile screens */
@media (max-width: 480px) {
    #user-section {
        margin: 10px;
        padding: 20px;
        width: calc(100% - 20px);
    }
    
    .login-container h2 {
        font-size: 22px;
    }
    
    #username-input {
        padding: 12px;
        font-size: 16px;
    }
    
    #join-btn {
        padding: 12px 20px;
        font-size: 16px;
    }
    
    #sidebar {
        padding: 20px;
        width: 80%;
        max-width: 300px;
    }
    
    #chat-info {
        margin-left: 10px;
        padding: 10px;
        min-width: 120px;
    }
    
    #chat-info h4 {
        font-size: 14px;
    }
    
    #chat-info p {
        font-size: 12px;
    }
    
    #chat-header {
        padding: 10px;
    }
    
    #chat-header h3 {
        font-size: 16px;
    }
    
    #messages {
        padding: 10px;
    }
    
    .message {
        max-width: 90%;
        padding: 8px 12px;
    }
    
    #message-input-container {
        padding: 10px;
        left: 0;
        right: 0;
    }
    
    #message-input {
        padding: 10px 14px;
        font-size: 16px;
    }
    
    #send-btn {
        padding: 8px;
        font-size: 14px;
        min-width: 38px;
        height: 38px;
        border-radius: 50%;
    }
}

/* Landscape mobile */
@media (max-width: 768px) and (orientation: landscape) {
    #sidebar {
        height: 100vh;
        width: 60%;
        max-width: 280px;
    }
    
    #chat-header {
        padding: 8px 15px;
    }
    
    #chat-header h3 {
        font-size: 16px;
        margin-bottom: 5px;
    }
}

/* Very small screens */
@media (max-width: 320px) {
    #message-input-container {
        padding: 8px;
        gap: 6px;
        left: 0;
        right: 0;
    }
    
    #message-input {
        padding: 8px 12px;
        font-size: 14px;
    }
    
    #send-btn {
        padding: 6px;
        font-size: 12px;
        min-width: 36px;
        height: 36px;
        border-radius: 50%;
    }
}
