/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #667eea;
    --primary-dark: #5a67d8;
    --secondary: #764ba2;
    --success: #48bb78;
    --warning: #ed8936;
    --danger: #f56565;
    --dark: #1a202c;
    --gray: #718096;
    --light-gray: #e2e8f0;
    --bg-light: #f7fafc;
    --white: #ffffff;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

body {
    font-family: 'Cairo', -apple-system, BlinkMacSystemFont, sans-serif;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    min-height: 100vh;
    color: var(--dark);
}

/* Utilities */
.hidden { display: none !important; }

/* Screen Management */
.screen {
    display: none;
    min-height: 100vh;
}

.screen.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ==================== AUTH SCREEN ==================== */
.auth-container {
    background: var(--white);
    padding: 3rem;
    border-radius: 20px;
    box-shadow: var(--shadow-xl);
    text-align: center;
    max-width: 450px;
    width: 90%;
    animation: slideUp 0.5s ease;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

.logo {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.auth-container h1 {
    font-size: 1.8rem;
    color: var(--dark);
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--gray);
    margin-bottom: 2rem;
}

.auth-form h2 {
    font-size: 1.3rem;
    margin-bottom: 1.5rem;
    color: var(--dark);
}

/* Form Elements */
.input-group {
    margin-bottom: 1.25rem;
    text-align: right;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--dark);
    font-size: 0.9rem;
}

.input-group input,
.input-group select {
    width: 100%;
    padding: 0.875rem 1rem;
    border: 2px solid var(--light-gray);
    border-radius: 12px;
    font-size: 1rem;
    font-family: inherit;
    transition: all 0.3s ease;
}

.input-group input:focus,
.input-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.file-input {
    padding: 0.5rem !important;
}

/* Avatar Preview */
.avatar-preview {
    margin-top: 1rem;
    display: flex;
    justify-content: center;
}

.avatar-preview img {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--primary);
}

/* Buttons */
.btn-primary {
    width: 100%;
    padding: 1rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: var(--white);
    border: none;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-secondary {
    padding: 0.75rem 1.5rem;
    background: transparent;
    color: var(--gray);
    border: 2px solid var(--light-gray);
    border-radius: 10px;
    font-size: 1rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    border-color: var(--danger);
    color: var(--danger);
}

.btn-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: var(--light-gray);
}

.switch-auth {
    margin-top: 1.5rem;
    color: var(--gray);
    font-size: 0.95rem;
}

.switch-auth a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}

.switch-auth a:hover {
    text-decoration: underline;
}

.error-message {
    color: var(--danger);
    margin-top: 1rem;
    font-size: 0.9rem;
    min-height: 1.5rem;
}

/* ==================== ROOM SELECTION ==================== */
#room-screen {
    padding: 2rem;
}

.room-container {
    text-align: center;
    max-width: 800px;
    width: 100%;
}

.user-welcome {
    margin-bottom: 2rem;
    color: var(--white);
}

.avatar-large {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    object-fit: cover;
    border: 4px solid var(--white);
    box-shadow: var(--shadow-lg);
    margin-bottom: 1rem;
}

.avatar-small {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--white);
}

.user-welcome h2 {
    font-size: 1.5rem;
}

.room-container h3 {
    color: var(--white);
    font-size: 1.2rem;
    margin-bottom: 1.5rem;
}

.rooms-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.room-card {
    background: var(--white);
    padding: 2rem 1.5rem;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow);
}

.room-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-xl);
}

.room-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.room-card h4 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.room-card p {
    color: var(--gray);
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
}

.room-users {
    display: inline-block;
    background: var(--bg-light);
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.85rem;
    color: var(--gray);
}

/* ==================== CHAT SCREEN ==================== */
#chat-screen {
    padding: 1rem;
}

.chat-container {
    background: var(--white);
    border-radius: 20px;
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 1200px;
    height: calc(100vh - 2rem);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header */
.chat-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: var(--white);
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.room-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.room-info h2 {
    font-size: 1.25rem;
    margin-bottom: 0.25rem;
}

#online-count {
    font-size: 0.875rem;
    opacity: 0.9;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

#header-username {
    font-weight: 600;
}

/* Main Chat Area */
.chat-main {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* Messages */
.messages-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-light);
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Message Bubbles */
.message {
    max-width: 70%;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message-content-wrapper {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}

.message.own .message-content-wrapper {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.message-bubble {
    padding: 1rem;
    border-radius: 18px;
    position: relative;
}

.message.own .message-bubble {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: var(--white);
    border-bottom-left-radius: 4px;
}

.message.other .message-bubble {
    background: var(--white);
    color: var(--dark);
    border-bottom-right-radius: 4px;
    box-shadow: var(--shadow);
}

.message.system {
    align-self: center;
    background: var(--light-gray);
    color: var(--gray);
    font-size: 0.875rem;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    max-width: 90%;
}

.message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}

.message.own .message-header {
    color: rgba(255, 255, 255, 0.9);
}

.message.other .message-header {
    color: var(--primary);
    font-weight: 600;
}

.message-time {
    font-size: 0.75rem;
    opacity: 0.7;
}

.message-content {
    line-height: 1.5;
    word-wrap: break-word;
}

.message-image {
    max-width: 300px;
    max-height: 200px;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.2s;
}

.message-image:hover {
    transform: scale(1.02);
}

/* Typing Indicator */
.typing-indicator {
    padding: 0.5rem 1.5rem;
    font-size: 0.875rem;
    color: var(--gray);
    font-style: italic;
    min-height: 2rem;
}

/* Users Sidebar */
.users-sidebar {
    width: 250px;
    background: var(--white);
    border-right: 1px solid var(--light-gray);
    padding: 1.5rem;
    overflow-y: auto;
}

.users-sidebar h3 {
    font-size: 1rem;
    color: var(--gray);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--light-gray);
}

.users-sidebar ul {
    list-style: none;
}

.user-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: 10px;
    transition: background 0.2s;
}

.user-item:hover {
    background: var(--bg-light);
}

.user-item img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.user-item .online-dot {
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: 50%;
    margin-right: auto;
}

/* Footer / Input */
.chat-footer {
    padding: 1rem 1.5rem;
    background: var(--white);
    border-top: 1px solid var(--light-gray);
    position: relative;
}

.message-form {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

#message-input {
    flex: 1;
    padding: 0.875rem 1.25rem;
    border: 2px solid var(--light-gray);
    border-radius: 25px;
    font-size: 1rem;
    font-family: inherit;
    transition: all 0.2s;
}

#message-input:focus {
    outline: none;
    border-color: var(--primary);
}

.btn-send {
    padding: 0.875rem 1.5rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: var(--white);
    border: none;
    border-radius: 25px;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-send:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

/* Emoji Picker */
.emoji-picker {
    position: absolute;
    bottom: 100%;
    left: 1rem;
    background: var(--white);
    border-radius: 15px;
    box-shadow: var(--shadow-xl);
    padding: 1rem;
    margin-bottom: 0.5rem;
    width: 320px;
    max-height: 300px;
    z-index: 100;
}

.emoji-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--light-gray);
    padding-bottom: 0.5rem;
}

.emoji-tab {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    transition: background 0.2s;
}

.emoji-tab:hover,
.emoji-tab.active {
    background: var(--bg-light);
}

.emoji-container {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 0.5rem;
    max-height: 200px;
    overflow-y: auto;
}

.emoji-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 8px;
    transition: background 0.2s;
}

.emoji-btn:hover {
    background: var(--bg-light);
    transform: scale(1.2);
}

/* Image Preview */
.image-preview {
    position: absolute;
    bottom: 100%;
    right: 1rem;
    background: var(--white);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 0.5rem;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.image-preview img {
    max-width: 150px;
    max-height: 100px;
    border-radius: 8px;
}

.btn-close {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: var(--danger);
    color: var(--white);
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Toast Notification */
.toast {
    position: fixed;
    top: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--dark);
    color: var(--white);
    padding: 1rem 2rem;
    border-radius: 10px;
    box-shadow: var(--shadow-xl);
    z-index: 1000;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from { opacity: 0; transform: translate(-50%, -20px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--light-gray);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--gray);
}

/* Responsive */
@media (max-width: 768px) {
    .users-sidebar {
        display: none;
    }
    
    .message {
        max-width: 85%;
    }
    
    .auth-container {
        padding: 2rem;
    }
    
    .chat-container {
        height: 100vh;
        border-radius: 0;
    }
    
    #chat-screen {
        padding: 0;
    }
    
    .emoji-picker {
        width: calc(100vw - 2rem);
        left: 1rem;
    }
    
    .rooms-grid {
        grid-template-columns: 1fr 1fr;
    }
}
