:root {
    --bg-color: #f3f4f6;
    --card-bg: #ffffff;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --msg-bg-other: #f3f4f6;
    --msg-text-other: #1f2937;
    --msg-bg-me: #4f46e5;
    --msg-text-me: #ffffff;
    --shadow-soft: 0 10px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.01);

    --msg-text-me: #ffffff;
    --shadow-soft: 0 10px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.01);
    --link-color: #2563eb; /* Added: Bright blue for light mode */
}

[data-theme="dark"] {
    --bg-color: #111827;
    --card-bg: #1f2937;
    --text-primary: #f9fafb;
    --text-secondary: #9ca3af;
    --border-color: #374151;
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --msg-bg-other: #374151;
    --msg-text-other: #f9fafb;
    --msg-bg-me: #6366f1;
    --msg-text-me: #ffffff;
    --shadow-soft: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.2);

    --msg-text-me: #ffffff;
    --shadow-soft: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.2);
    --link-color: #60a5fa; /* Added: Lighter blue for dark mode readability */
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Inter', sans-serif; }

body { 
    background-color: var(--bg-color); 
    color: var(--text-primary);
    display: flex; justify-content: center; align-items: center; 
    height: 100vh; overflow: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Theme Toggle */
.theme-btn {
    position: absolute; top: 20px; right: 20px;
    background: var(--card-bg); border: 1px solid var(--border-color);
    color: var(--text-primary); border-radius: 50%;
    width: 44px; height: 44px; display: flex; justify-content: center; align-items: center;
    cursor: pointer; box-shadow: var(--shadow-soft); transition: 0.2s; z-index: 100;
}
.theme-btn:hover { transform: scale(1.05); }

.screen { width: 100%; height: 100%; display: flex; justify-content: center; align-items: center; padding: 20px; }

/* Login Card */
.card { 
    background: var(--card-bg); padding: 2.5rem; 
    border-radius: 16px; box-shadow: var(--shadow-soft); 
    text-align: center; width: 100%; max-width: 400px; border: 1px solid var(--border-color);
}
.card-header h2 { font-weight: 600; margin-bottom: 5px; }
.card-header p { color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 25px; }

input[type="text"] {
    width: 100%; padding: 12px 16px; margin-bottom: 15px;
    background: var(--bg-color); border: 1px solid var(--border-color); color: var(--text-primary);
    border-radius: 8px; outline: none; font-size: 1rem; transition: 0.2s;
}
input[type="text"]:focus { border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15); }

.primary-btn {
    width: 100%; padding: 12px; background: var(--primary-color); color: white;
    border: none; border-radius: 8px; font-size: 1rem; font-weight: 500;
    cursor: pointer; transition: background 0.2s, transform 0.1s;
}
.primary-btn:hover { background: var(--primary-hover); }
.primary-btn:active { transform: translateY(1px); }
.primary-btn.icon-only { width: auto; padding: 12px 16px; display: flex; align-items: center; justify-content: center; }

/* Chat UI */
.chat-container { 
    width: 100%; max-width: 800px; height: 90vh; 
    background: var(--card-bg); border-radius: 16px; 
    display: flex; flex-direction: column; box-shadow: var(--shadow-soft); 
    border: 1px solid var(--border-color); overflow: hidden;
}

.chat-header { 
    padding: 20px; border-bottom: 1px solid var(--border-color); 
    display: flex; justify-content: space-between; align-items: center;
}
.chat-header h2 { font-size: 1.25rem; font-weight: 600; }
.subtitle { color: var(--text-secondary); font-size: 0.85rem; }
.status-indicator { width: 10px; height: 10px; background-color: #10b981; border-radius: 50%; box-shadow: 0 0 8px #10b981; }

.messages-area { 
    flex: 1; padding: 20px; overflow-y: auto; 
    display: flex; flex-direction: column; gap: 15px; 
    scroll-behavior: smooth;
}

/* Message Bubbles */
.message { 
    padding: 12px 16px; border-radius: 12px; max-width: 75%; 
    line-height: 1.5; font-size: 0.95rem; word-wrap: break-word;
}
.system-msg { align-self: center; color: var(--text-secondary); font-size: 0.8rem; padding: 4px 12px; background: transparent; }
.chat-msg { align-self: flex-start; background: var(--msg-bg-other); color: var(--msg-text-other); border-bottom-left-radius: 2px; }
.my-msg { align-self: flex-end; background: var(--msg-bg-me); color: var(--msg-text-me); border-bottom-right-radius: 2px; }
.username-label { font-size: 0.75rem; opacity: 0.7; margin-bottom: 4px; display: block; font-weight: 600; }

/* Input Area & Emoji Picker */
.input-area { padding: 20px; border-top: 1px solid var(--border-color); background: var(--card-bg); }
.input-wrapper { display: flex; align-items: center; gap: 10px; position: relative; }
.input-wrapper input { margin-bottom: 0; }
.icon-btn { 
    background: transparent; border: none; color: var(--text-secondary); 
    cursor: pointer; padding: 10px; border-radius: 8px; transition: 0.2s; 
    display: flex; align-items: center;
}
.icon-btn:hover { background: var(--bg-color); color: var(--primary-color); }

emoji-picker { 
    position: absolute; bottom: 100%; left: 0; margin-bottom: 10px; 
    z-index: 100; box-shadow: var(--shadow-soft); border-radius: 8px;
}
emoji-picker.hidden { display: none; }

/* Animations */
.fade-in { animation: fadeIn 0.4s ease-out forwards; }
.slide-up { animation: slideUp 0.3s ease-out forwards; }

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

/* Custom Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }


/* Link Styling */
.message a {
    color: var(--link-color);
    text-decoration: underline;
    text-underline-offset: 2px;
    word-break: break-all; /* Prevents long URLs from breaking the chat box */
    transition: opacity 0.2s;
}

.message a:hover {
    opacity: 0.8;
}

/* Make links white inside your own blue message bubbles so they remain visible */
.my-msg a {
    color: #ffffff; 
}

/* Online Users Dropdown UI */
.online-users-container { position: relative; }

.online-badge {
    display: flex; align-items: center; gap: 8px;
    background: var(--bg-color); padding: 8px 14px;
    border-radius: 20px; font-size: 0.85rem; font-weight: 500;
    cursor: pointer; border: 1px solid var(--border-color);
    color: var(--text-primary); transition: 0.2s;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}
.online-badge:hover { border-color: var(--primary-color); }

.users-dropdown {
    position: absolute; top: 120%; right: 0;
    background: var(--card-bg); border: 1px solid var(--border-color);
    border-radius: 12px; box-shadow: var(--shadow-soft);
    width: 220px; max-height: 250px; overflow-y: auto;
    z-index: 50; padding: 10px 0;
    animation: fadeIn 0.2s ease-out forwards;
}
.users-dropdown.hidden { display: none; }

.user-item {
    padding: 10px 16px; font-size: 0.9rem;
    display: flex; align-items: center; gap: 10px;
    color: var(--text-primary); transition: background 0.2s;
}
.user-item:hover { background: var(--bg-color); }
.user-item .status-indicator { width: 8px; height: 8px; box-shadow: 0 0 6px #10b981; }
.user-me-label { font-size: 0.75rem; color: var(--text-secondary); margin-left: auto; }



/* Image Attachments */
.message-image {
    max-width: 100%;
    max-height: 300px;
    border-radius: 8px;
    margin-top: 8px;
    cursor: zoom-in;
    display: block;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: opacity 0.2s;
}
.message-image:hover { opacity: 0.9; }

/* Image Modal Viewer */
.image-modal {
    position: fixed; z-index: 1000; left: 0; top: 0;
    width: 100%; height: 100%; 
    background-color: rgba(0,0,0,0.85);
    display: flex; justify-content: center; align-items: center;
    backdrop-filter: blur(5px);
    opacity: 1; transition: opacity 0.2s;
}
.image-modal.hidden { opacity: 0; pointer-events: none; }
.modal-content { max-width: 90%; max-height: 90vh; border-radius: 8px; box-shadow: 0 10px 25px rgba(0,0,0,0.5); }
.close-modal {
    position: absolute; top: 20px; right: 30px;
    color: #fff; font-size: 40px; font-weight: bold; cursor: pointer; transition: 0.2s;
}
.close-modal:hover { color: #ccc; }