/* Modern Chat App Styling */
:root {
    --bg-primary: #0f172a;
    --bg-card: #1e293b;
    --bg-card-secondary: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent-blue: #3b82f6;
    --accent-indigo: #6366f1;
    --accent-gradient: linear-gradient(135deg, #3b82f6 0%, #6366f1 100%);
    --msg-incoming: #283548;
    --border-color: #334155;
    --status-green: #22c55e;
    --status-yellow: #eab308;
    --status-red: #ef4444;
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4), 0 4px 6px -4px rgb(0 0 0 / 0.4);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

/* App Container */
#app {
    width: 100%;
    max-width: 960px;
}

/* ==========================================================================
   LOBBY / INDEX SCREEN
   ========================================================================== */
.lobby-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 40px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    text-align: center;
}

.lobby-header h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 8px;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.lobby-header p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 32px;
}

.form-group {
    text-align: left;
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-input {
    width: 100%;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    color: var(--text-primary);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

.btn-primary {
    width: 100%;
    background: var(--accent-gradient);
    color: #ffffff;
    border: none;
    border-radius: var(--radius-sm);
    padding: 14px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: opacity 0.2s, transform 0.1s;
}

.btn-primary:hover {
    opacity: 0.95;
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
}

.error-banner {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid var(--status-red);
    color: #fca5a5;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    margin-bottom: 20px;
    text-align: left;
}

/* ==========================================================================
   CHAT ROOM SCREEN
   ========================================================================== */
.chat-container {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    height: 85vh;
    max-height: 850px;
    overflow: hidden;
}

/* Room Header */
.chat-header {
    background: rgba(30, 41, 59, 0.95);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border-color);
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.room-info h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.user-tag {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.user-tag strong {
    color: var(--accent-blue);
}

/* Status Pill */
.status-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: var(--radius-full);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-connected .status-dot {
    background: var(--status-green);
    box-shadow: 0 0 8px var(--status-green);
}

.status-connecting .status-dot {
    background: var(--status-yellow);
    box-shadow: 0 0 8px var(--status-yellow);
}

.status-disconnected .status-dot {
    background: var(--status-red);
    box-shadow: 0 0 8px var(--status-red);
}

.btn-leave {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s, color 0.2s;
    margin-left: 12px;
}

.btn-leave:hover {
    background: rgba(239, 68, 68, 0.15);
    border-color: var(--status-red);
    color: #fca5a5;
}

/* Chat Body (Main Stream + Sidebar) */
.chat-body {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* Message Stream Area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.messages-box {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.messages-box::-webkit-scrollbar {
    width: 6px;
}

.messages-box::-webkit-scrollbar-thumb {
    background: var(--bg-card-secondary);
    border-radius: var(--radius-full);
}

/* Chat Message Bubbles */
.message-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 75%;
}

.message-wrapper.outgoing {
    align-self: flex-end;
    align-items: flex-end;
}

.message-wrapper.incoming {
    align-self: flex-start;
    align-items: flex-start;
}

.message-sender {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
    padding: 0 4px;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    line-height: 1.45;
    word-break: break-word;
    box-shadow: var(--shadow-md);
}

.message-wrapper.outgoing .message-bubble {
    background: var(--accent-gradient);
    color: #ffffff;
    border-bottom-right-radius: 2px;
}

.message-wrapper.incoming .message-bubble {
    background: var(--msg-incoming);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 2px;
}

/* System Notifications (Joins/Leaves/Greetings) */
.message-system {
    align-self: center;
    background: rgba(51, 65, 85, 0.5);
    border: 1px solid rgba(100, 116, 139, 0.3);
    color: var(--text-secondary);
    font-size: 0.8rem;
    padding: 6px 14px;
    border-radius: var(--radius-full);
    text-align: center;
    margin: 4px 0;
}

.message-system.user-join {
    border-color: rgba(34, 197, 94, 0.3);
    color: #86efac;
    background: rgba(34, 197, 94, 0.1);
}

.message-system.user-leave {
    border-color: rgba(245, 158, 11, 0.3);
    color: #fde047;
    background: rgba(245, 158, 11, 0.1);
}

/* Empty State */
.empty-chat {
    margin: auto;
    text-align: center;
    color: var(--text-muted);
}

.empty-chat svg {
    width: 48px;
    height: 48px;
    margin-bottom: 8px;
    opacity: 0.5;
}

/* Online Users Sidebar */
.chat-sidebar {
    width: 220px;
    background: rgba(15, 23, 42, 0.6);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-header h3 {
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

.count-badge {
    background: var(--bg-card-secondary);
    color: var(--text-primary);
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-weight: 600;
}

.user-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.user-list::-webkit-scrollbar {
    width: 4px;
}

.user-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: var(--radius-full);
}

.user-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    color: var(--text-primary);
    background: rgba(30, 41, 59, 0.4);
    border: 1px solid transparent;
    transition: background 0.15s;
}

.user-item:hover {
    background: var(--bg-card-secondary);
}

.user-item.is-me {
    border-color: rgba(59, 130, 246, 0.4);
    background: rgba(59, 130, 246, 0.1);
}

.user-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--status-green);
    box-shadow: 0 0 6px var(--status-green);
}

.user-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.badge-you {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--accent-blue);
    background: rgba(59, 130, 246, 0.15);
    padding: 2px 6px;
    border-radius: var(--radius-full);
}

/* Message Input Area */
.chat-footer {
    padding: 16px 24px;
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
}

.input-container {
    display: flex;
    gap: 12px;
}

.chat-input {
    flex: 1;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    color: var(--text-primary);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}

.chat-input:focus {
    border-color: var(--accent-blue);
}

.btn-send {
    background: var(--accent-gradient);
    color: #ffffff;
    border: none;
    border-radius: var(--radius-sm);
    padding: 0 24px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: var(--shadow-md);
    transition: opacity 0.2s, transform 0.1s;
}

.btn-send:hover:not(:disabled) {
    opacity: 0.95;
    transform: translateY(-1px);
}

.btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Responsive adjustments */
@media (max-width: 640px) {
    .chat-sidebar {
        display: none; /* Can be toggled on mobile */
    }
}
