@import url('https://fonts.googleapis.com/css2?family=Lobster&display=swap');

:root {
    --bg-primary: #0f1419;
    --bg-secondary: #1a1f2e;
    --bg-tertiary: #252b3b;
    --text-primary: #e4e6eb;
    --text-secondary: #a8b2c7;
    --text-muted: #6c7689;
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --border: rgba(255,255,255,0.08);
    --glass-bg: rgba(26,31,46,0.7);
    --glass-border: rgba(255,255,255,0.1);
    --shadow: 0 8px 32px rgba(0,0,0,0.3);
    --radius: 12px;
    --radius-sm: 8px;

    /* Brand gradient accent */
    --brand-gradient: linear-gradient(90deg, #7fd39a 0%, #9c9cf2 50%, #f5a9c2 100%);
    --brand-gradient-soft: linear-gradient(90deg, rgba(127,211,154,0.18) 0%, rgba(156,156,242,0.18) 50%, rgba(245,169,194,0.18) 100%);
    --brand-gold: #d8ae2e;
    --brand-font: 'Lobster', 'Segoe UI', sans-serif;
}

[data-theme="light"] {
    --bg-primary: #f5f7fb;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f0f2f5;
    --text-primary: #1a1f2e;
    --text-secondary: #5c6677;
    --text-muted: #8b95a7;
    --border: rgba(0,0,0,0.08);
    --glass-bg: rgba(255,255,255,0.8);
    --glass-border: rgba(0,0,0,0.08);
    --shadow: 0 8px 32px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; }

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

.auth-body {
    overflow: auto;
    background: var(--brand-gradient);
    min-height: 100vh;
}

.auth-body::before {
    content: '';
    position: fixed;
    inset: 0;
    background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="60" height="60"><circle cx="30" cy="30" r="1" fill="rgba(255,255,255,0.15)"/></svg>');
    z-index: 0;
}

.glass-card {
    background: #ffffff;
    border: 1px solid rgba(0,0,0,0.06);
    border-radius: 18px;
    box-shadow: 0 12px 40px rgba(30,20,60,0.25);
    padding: 0;
    overflow: hidden;
}

.auth-card {
    position: relative;
    z-index: 1;
}

.auth-card .auth-card-banner {
    background: var(--brand-gradient);
    padding: 1.75rem 2rem 1.5rem;
    text-align: center;
    border-bottom: 1px solid rgba(0,0,0,0.05);
}

.auth-card .auth-card-body {
    padding: 1.75rem 2rem 2rem;
    background: #ffffff;
}

.brand-logo {
    width: 64px;
    height: 64px;
    margin: 0 auto 0.6rem;
    background: rgba(255,255,255,0.55);
    border-radius: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255,255,255,0.7);
}

.brand-logo i { color: #4a3d7a !important; }

.brand-title {
    font-family: var(--brand-font);
    font-size: 2.1rem;
    font-weight: 400;
    letter-spacing: 0.5px;
    margin-bottom: 0.15rem;
    color: #2c2c3a;
    text-shadow: 0 1px 0 rgba(255,255,255,0.4);
}

.auth-body .brand-subtitle { color: #3d3d4d; opacity: 0.85; margin: 0; }
.auth-body .auth-card-body .form-label,
.auth-body .auth-card-body small { color: #5c6677 !important; }

.auth-body .auth-card-body .form-control {
    background: #f5f6fb;
    border: 1px solid #e2e4f0;
    color: #1a1f2e;
}

.auth-body .auth-card-body .form-control:focus {
    background: #ffffff;
    color: #1a1f2e;
    border-color: #9c9cf2;
    box-shadow: 0 0 0 3px rgba(156,156,242,0.25);
}

.auth-body .auth-card-body .input-group-text {
    background: #eef0f9;
    border-color: #e2e4f0;
    color: #6c6c8a;
}

.auth-body .nav-pills .nav-link {
    background: #f0f1f8;
    color: #5c6677;
    border-radius: 10px;
    font-weight: 600;
}

.auth-body .nav-pills .nav-link.active {
    background: var(--brand-gradient);
    color: #2c2c3a;
}

.btn {
    border-radius: var(--radius-sm);
    font-weight: 500;
    transition: all 0.2s ease;
    padding: 0.6rem 1.25rem;
}

.btn-primary {
    background: var(--brand-gradient);
    border: none;
    color: #2c2c3a;
}

.btn-primary:hover {
    filter: brightness(0.96);
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(120,120,220,0.35);
    color: #2c2c3a;
}

.auth-body .btn-success {
    background: var(--brand-gradient);
    border: none;
    color: #2c2c3a;
}
.auth-body .btn-success:hover { filter: brightness(0.96); color: #2c2c3a; }

/* CHAT APP */
.chat-app {
    display: flex;
    height: 100vh;
    width: 100vw;
}

.chat-sidebar {
    width: 320px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    box-shadow: inset 4px 0 0 -3px transparent;
}

.chat-sidebar::before {
    content: '';
    display: block;
    height: 4px;
    background: var(--brand-gradient);
    flex-shrink: 0;
}

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

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
    min-width: 0;
}

.avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border);
    flex-shrink: 0;
}

.avatar-lg {
    width: 100px;
    height: 100px;
}

.user-info { min-width: 0; }
.user-info h5 {
    margin: 0;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.status-badge {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.status-badge.online { color: var(--success); }

.sidebar-search { padding: 1rem; }
.sidebar-search .form-control,
.sidebar-search .input-group-text {
    background: var(--bg-tertiary);
    border-color: var(--border);
    color: var(--text-primary);
}

.sidebar-section-title {
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.rooms-list, .users-list {
    overflow-y: auto;
    flex: 1;
    padding: 0 0.5rem;
}

.room-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.2s ease;
    margin-bottom: 2px;
}

.room-item:hover { background: var(--bg-tertiary); }
.room-item.active {
    background: var(--brand-gradient);
    color: #2c2c3a;
}

.room-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--primary);
}

.room-item.active .room-icon {
    background: rgba(255,255,255,0.45);
    color: #2c2c3a;
}

.room-info-text { flex: 1; min-width: 0; }
.room-name {
    font-weight: 500;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0;
}

.room-last-msg {
    font-size: 0.78rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 2px 0 0;
}

.room-item.active .room-last-msg { color: rgba(30,30,45,0.75); }

.room-unread {
    background: var(--brand-gradient);
    color: #2c2c3a;
    font-size: 0.7rem;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    font-weight: 700;
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-icon:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-icon.btn-lg {
    padding: 0.75rem 1rem;
    font-size: 1.1rem;
}

.user-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.user-item:hover { background: var(--bg-tertiary); }
.user-avatar-wrapper { position: relative; }
.online-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    background: var(--success);
    border: 2px solid var(--bg-secondary);
    border-radius: 50%;
}

/* MAIN CHAT */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    min-width: 0;
}

.chat-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
    gap: 1rem;
    position: relative;
}

.chat-header::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: var(--brand-gradient);
}

.chat-header .room-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1;
    min-width: 0;
}

.chat-header .room-info h4 { margin: 0; font-size: 1.1rem; }
.chat-header .room-info p { margin: 0; font-size: 0.85rem; color: var(--text-muted); }

.room-actions { display: flex; gap: 0.5rem; }

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.empty-state {
    margin: auto;
    text-align: center;
    color: var(--text-muted);
}

.empty-state i { opacity: 0.5; }

.message {
    display: flex;
    gap: 0.75rem;
    max-width: 75%;
    animation: slideIn 0.3s ease;
}

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

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

.message .avatar {
    width: 38px;
    height: 38px;
}

.message-content {
    background: var(--bg-secondary);
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    position: relative;
    min-width: 120px;
}

.message.mine .message-content {
    background: var(--brand-gradient);
    color: #2c2c3a;
    border: none;
}

.message-meta {
    display: flex;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.message.mine .message-meta {
    color: rgba(30,30,45,0.7);
    flex-direction: row-reverse;
}

.message-text {
    word-wrap: break-word;
    white-space: pre-wrap;
    line-height: 1.5;
}

.message-file {
    margin-top: 0.5rem;
}

.message-file img {
    max-width: 300px;
    max-height: 300px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: block;
}

.message-file a {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    color: inherit;
    text-decoration: none;
}

.message-menu {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    opacity: 0;
    transition: opacity 0.2s;
}

.message-content:hover .message-menu { opacity: 1; }

.message.mine .message-menu { right: auto; left: 0.5rem; }

.message-menu .btn-icon {
    background: rgba(0,0,0,0.3);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
}

.chat-input-area {
    padding: 1rem 1.5rem;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
}

.chat-input-area .input-group {
    background: var(--bg-tertiary);
    border-radius: 30px;
    overflow: hidden;
    padding: 0.25rem;
}

.chat-input-area .form-control {
    background: transparent;
    border: none;
    color: var(--text-primary);
    padding: 0.75rem 1rem;
}

.chat-input-area .form-control:focus {
    box-shadow: none;
    background: transparent;
    color: var(--text-primary);
}

.typing-indicator {
    padding: 0.5rem 1.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    font-style: italic;
}

.typing-indicator::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    background: var(--primary);
    border-radius: 50%;
    margin-right: 0.5rem;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.preview-container {
    padding: 0.5rem 1rem;
    background: var(--bg-tertiary);
    margin-bottom: 0.5rem;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.preview-container img {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: var(--radius-sm);
}

.emoji-picker {
    position: fixed;
    bottom: 90px;
    left: 320px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
    width: 320px;
    max-height: 280px;
    overflow-y: auto;
    box-shadow: var(--shadow);
    z-index: 1000;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 0.25rem;
}

.emoji-item {
    font-size: 1.5rem;
    padding: 0.25rem;
    cursor: pointer;
    text-align: center;
    border-radius: var(--radius-sm);
    transition: background 0.2s;
}

.emoji-item:hover { background: var(--bg-tertiary); }

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: 20px;
}

.modal-header { border-bottom-color: var(--border); }
.modal .form-control, .modal .form-label { color: var(--text-primary); }
.modal .form-control {
    background: var(--bg-tertiary);
    border-color: var(--border);
    color: var(--text-primary);
}

.toast {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

/* Responsive */
@media (max-width: 991.98px) {
    .chat-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 1050;
        transform: translateX(-100%);
        width: 300px;
    }
    .chat-sidebar.show { transform: translateX(0); }
    
    .emoji-picker { left: 1rem; right: 1rem; width: auto; }
    
    .message { max-width: 90%; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Loading */
.loading-dots { display: inline-flex; gap: 4px; }
.loading-dots span {
    width: 6px; height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}
.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}