:root {
    --bg-page: #0f172a;
    --card-bg: #1e293b;
    --card-border: #334155;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-light: rgba(59, 130, 246, 0.15);
    --bubble-mine: #2563eb;
    --bubble-theirs: #334155;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --text-dim: #64748b;
    --online-green: #10b981;
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

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

body {
    font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-page);
    background-image: 
        radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.12) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(99, 102, 241, 0.12) 0px, transparent 50%);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px;
}

/* Wrapper */
.chat-wrapper {
    width: 100%;
    max-width: 900px;
    height: 90vh;
    max-height: 850px;
    position: relative;
}

/* Modal for entering name */
.login-modal {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    z-index: 100;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-lg);
}

.login-modal.active {
    display: flex;
}

.login-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    padding: 40px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 440px;
    text-align: center;
    animation: scaleIn 0.25s ease-out;
}

@keyframes scaleIn {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.login-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.login-card h2 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
}

.login-card p {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 24px;
    line-height: 1.5;
}

.input-group {
    margin-bottom: 16px;
}

.input-group input {
    width: 100%;
    padding: 14px 18px;
    background: #0f172a;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
    color: var(--text-main);
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-group input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.error-msg {
    color: #ef4444;
    font-size: 13px;
    margin-top: 12px;
    min-height: 18px;
}

/* Chat Container */
.chat-container {
    display: none;
    flex-direction: column;
    height: 100%;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.chat-container.active {
    display: flex;
}

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

.header-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.app-avatar {
    width: 44px;
    height: 44px;
    background: var(--primary-light);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.header-info h3 {
    font-size: 17px;
    font-weight: 700;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-muted);
}

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

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.user-badge {
    background: rgba(15, 23, 42, 0.6);
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid var(--card-border);
    font-size: 13px;
}

.user-badge .badge-label {
    color: var(--text-muted);
    margin-right: 4px;
}

.user-badge strong {
    color: var(--primary);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
    font-family: inherit;
}

.btn-primary {
    width: 100%;
    padding: 14px;
    background: var(--primary);
    color: #ffffff;
    font-size: 15px;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    padding: 8px 12px;
    font-size: 13px;
    border: 1px solid transparent;
}

.btn-ghost:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--card-border);
}

/* Online Bar */
.online-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 24px;
    background: rgba(15, 23, 42, 0.5);
    border-bottom: 1px solid var(--card-border);
    font-size: 12px;
    overflow-x: auto;
}

.online-title {
    color: var(--text-dim);
    font-weight: 600;
    white-space: nowrap;
}

.online-list {
    display: flex;
    gap: 6px;
    overflow-x: auto;
}

.online-pill {
    padding: 3px 10px;
    background: #1e293b;
    border: 1px solid var(--card-border);
    border-radius: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

.online-pill.self {
    border-color: var(--primary);
    color: var(--primary);
}

/* Messages area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

.welcome-banner {
    text-align: center;
    padding: 20px;
    background: rgba(59, 130, 246, 0.06);
    border: 1px dashed rgba(59, 130, 246, 0.3);
    border-radius: var(--radius-md);
    margin-bottom: 8px;
}

.welcome-banner .wave {
    font-size: 28px;
    display: block;
    margin-bottom: 6px;
}

.welcome-banner h4 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 4px;
}

.welcome-banner p {
    font-size: 13px;
    color: var(--text-muted);
}

/* System Message */
.msg-system {
    align-self: center;
    background: rgba(148, 163, 184, 0.1);
    color: var(--text-muted);
    font-size: 12px;
    padding: 4px 14px;
    border-radius: 12px;
    text-align: center;
}

/* Message Rows */
.msg-row {
    display: flex;
    gap: 10px;
    max-width: 75%;
    animation: fadeIn 0.15s ease-out;
}

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

.msg-row.mine {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.msg-row.theirs {
    align-self: flex-start;
}

/* User Avatar */
.msg-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
    text-transform: uppercase;
}

.msg-bubble-wrap {
    display: flex;
    flex-direction: column;
}

.msg-row.mine .msg-bubble-wrap {
    align-items: flex-end;
}

.msg-author {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
    padding: 0 4px;
}

.msg-bubble {
    padding: 10px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
    white-space: pre-wrap;
}

.msg-row.mine .msg-bubble {
    background: var(--bubble-mine);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.msg-row.theirs .msg-bubble {
    background: var(--bubble-theirs);
    color: var(--text-main);
    border-bottom-left-radius: 4px;
}

.msg-time {
    font-size: 10px;
    color: var(--text-dim);
    margin-top: 4px;
    padding: 0 4px;
}

/* Footer / Input */
.chat-footer {
    padding: 16px 24px;
    background: rgba(30, 41, 59, 0.95);
    border-top: 1px solid var(--card-border);
}

.message-form {
    display: flex;
    gap: 12px;
}

.message-form input {
    flex: 1;
    padding: 12px 18px;
    background: #0f172a;
    border: 1px solid var(--card-border);
    border-radius: 24px;
    color: var(--text-main);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.message-form input:focus {
    border-color: var(--primary);
}

.btn-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--primary);
    color: #ffffff;
    flex-shrink: 0;
}

.btn-send:hover {
    background: var(--primary-hover);
    transform: scale(1.05);
}

/* Scrollbar customization */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--card-border);
    border-radius: 3px;
}

/* Mobile responsive */
@media (max-width: 640px) {
    body {
        padding: 0;
    }
    .chat-wrapper {
        height: 100vh;
        max-height: 100vh;
    }
    .chat-container {
        border-radius: 0;
        border: none;
    }
    .chat-header {
        padding: 12px 16px;
    }
    .chat-footer {
        padding: 12px 16px;
    }
    .msg-row {
        max-width: 88%;
    }
}
