/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: white;
    min-height: 100vh;
    color: #333;
}

/* Screen Management */
.screen {
    display: none;
}

.screen.active {
    display: flex;
}

/* Username Entry Screen */
#username-screen {
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.username-container {
    background: white;
    padding: 40px;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    text-align: center;
    min-width: 400px;
}

.username-container h1 {
    color: #667eea;
    margin-bottom: 10px;
    font-size: 32px;
}

.username-container p {
    color: #666;
    margin-bottom: 30px;
}

#username-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

#username-input {
    padding: 15px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    font-size: 16px;
    transition: border-color 0.3s;
}

#username-input:focus {
    outline: none;
    border-color: #667eea;
}

#username-form button {
    padding: 15px;
    background: #ff6b35;
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

#username-form button:hover {
    transform: translateY(-2px);
    background: #ff8556;
    box-shadow: 0 4px 12px rgba(255, 107, 53, 0.4);
}

.error-message {
    color: #e74c3c;
    font-size: 14px;
    margin-top: 10px;
    min-height: 20px;
}

/* Chat Screen */
#chat-screen {
    min-height: 100vh;
    padding: 10px;
}

.chat-container {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    background: white;
    border-radius: 15px;
    overflow: hidden;
    border: 2px solid #e0e0e0;
    height: calc(100vh - 20px);
    display: flex;
    flex-direction: column;
}

/* Header */
.chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.header-left h1 {
    font-size: 20px;
}

.user-badge {
    background: rgba(255, 255, 255, 0.2);
    padding: 5px 15px;
    border-radius: 20px;
    font-size: 14px;
}

.online-count {
    background: rgba(255, 255, 255, 0.2);
    padding: 8px 15px;
    border-radius: 20px;
    font-size: 14px;
    transition: transform 0.3s ease;
    position: relative;
    overflow: visible;
}

#online-users {
    display: inline-block;
    font-weight: bold;
    perspective: 200px;
}

.online-count.pulse {
    animation: counterPulse 0.5s ease;
}

.online-count.rainbow-border {
    animation: rainbowBorder 2s linear;
}

@keyframes counterPulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
    }
}

@keyframes rainbowBorder {
    0% {
        box-shadow: 0 0 0 2px #ff0000;
    }
    14% {
        box-shadow: 0 0 0 2px #ff7f00;
    }
    28% {
        box-shadow: 0 0 0 2px #ffff00;
    }
    42% {
        box-shadow: 0 0 0 2px #00ff00;
    }
    57% {
        box-shadow: 0 0 0 2px #0000ff;
    }
    71% {
        box-shadow: 0 0 0 2px #4b0082;
    }
    85% {
        box-shadow: 0 0 0 2px #9400d3;
    }
    100% {
        box-shadow: 0 0 0 0px transparent;
    }
}

/* Flip animation for number */
.number-flip {
    animation: flipNumber 0.6s ease-in-out;
    display: inline-block;
}

@keyframes flipNumber {
    0% {
        transform: rotateX(0deg);
    }
    50% {
        transform: rotateX(90deg);
        opacity: 0;
    }
    51% {
        transform: rotateX(-90deg);
    }
    100% {
        transform: rotateX(0deg);
        opacity: 1;
    }
}

.mobile-menu-btn {
    display: none;
    position: fixed;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    width: 35px;
    height: 35px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
    font-size: 22px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15);
    z-index: 998;
    transition: all 0.3s;
}

#username-screen.active ~ .mobile-menu-btn {
    display: none !important;
}

.mobile-menu-btn:hover {
    transform: translateY(-50%) scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.mobile-menu-btn:active {
    transform: translateY(-50%) scale(0.95);
}

/* Main Content Area */
.chat-main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 200px;
    border-left: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 15px;
}

.sidebar-header h3 {
    color: #667eea;
    font-size: 14px;
}

.users-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.user-item {
    padding: 6px 12px;
    margin: 1px 0;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-item:hover {
    background: #f5f5f5;
}

.user-item.current-user {
    background: #e8f0fe;
    cursor: default;
}

.user-status {
    display: none;
}

.user-name {
    flex: 1;
    font-weight: 500;
    color: #333;
    font-size: 14px;
}

.chat-icon {
    font-size: 18px;
    opacity: 0;
    transition: opacity 0.2s;
}

.user-item:hover .chat-icon {
    opacity: 1;
}

.user-item.current-user .chat-icon {
    display: none;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.7;
        transform: scale(1.1);
    }
}

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

/* Chat Tabs */
.chat-tabs {
    display: flex;
    gap: 5px;
    padding: 8px 15px 0 15px;
    border-bottom: 1px solid #e0e0e0;
    overflow-x: auto;
    background: white;
    flex-shrink: 0;
}

.tab-button {
    padding: 8px 16px;
    border: none;
    background: #f5f5f5;
    border-radius: 8px 8px 0 0;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: #666;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
    white-space: nowrap;
    position: relative;
}

.tab-button:hover {
    background: #e8e8e8;
}

.tab-button.active {
    background: white;
    color: #667eea;
    border-bottom: 2px solid white;
}

.tab-icon {
    font-size: 16px;
}

.tab-notification-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ff4444;
    position: absolute;
    top: 8px;
    right: 8px;
    animation: pulse 2s infinite;
}

.close-tab {
    margin-left: 8px;
    padding: 2px 6px;
    border-radius: 50%;
    font-size: 12px;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.close-tab:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.1);
}

.private-tabs {
    display: flex;
    gap: 5px;
}

/* Private Chats Container */
#private-chats {
    display: contents;
}

/* Chat Box */
.chat-box {
    display: none;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    height: 100%;
}

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

/* Messages Area */
.messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-height: 0;
}

.message {
    display: flex;
    align-items: baseline;
    gap: 5px;
    max-width: 100%;
    animation: fadeIn 0.3s;
    padding: 2px 0;
}

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

.message-username {
    font-weight: 600;
    color: #667eea;
    font-size: 14px;
    white-space: nowrap;
}

.message.own .message-username {
    color: #764ba2;
}

.message-separator {
    color: #666;
}

.message-content {
    word-wrap: break-word;
    line-height: 1.4;
    color: #333;
    flex: 1;
}

/* Mentions */
.mention {
    background: #667eea;
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.mention:hover {
    background: #5568d3;
}

.message.mention-highlight {
    background: rgba(102, 126, 234, 0.1);
    border-left: 3px solid #667eea;
    padding-left: 8px;
    margin-left: -8px;
}

/* System Messages */
.system-message {
    text-align: center;
    color: #ff6b35;
    font-size: 13px;
    font-weight: bold;
    padding: 10px;
    margin: 10px 0;
}

/* Typing Indicator */
.typing-indicator {
    padding: 10px 20px;
    min-height: 30px;
    color: #999;
    font-size: 13px;
    font-style: italic;
    flex-shrink: 0;
}

.typing-dots {
    display: inline-block;
}

.typing-dots span {
    animation: blink 1.4s infinite;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes blink {
    0%, 60%, 100% {
        opacity: 0;
    }
    30% {
        opacity: 1;
    }
}

/* Message Input */
.message-input-container {
    display: flex;
    gap: 0px;
    padding: 12px 15px;
    border-top: 1px solid #e0e0e0;
    background: white;
    flex-shrink: 0;
}

.message-input {
    flex: 1;
    padding: 10px 15px;
    border: 2px solid #e0e0e0;
    border-radius: 25px;
    font-size: 14px;
    transition: border-color 0.3s;
}

.message-input:focus {
    outline: none;
    border-color: #667eea;
}

.send-button {
    display: none;
}

/* Scrollbar Styling */
.messages::-webkit-scrollbar,
.users-list::-webkit-scrollbar {
    width: 8px;
}

.messages::-webkit-scrollbar-track,
.users-list::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.messages::-webkit-scrollbar-thumb,
.users-list::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.messages::-webkit-scrollbar-thumb:hover,
.users-list::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Sidebar Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* Version Indicator */
.version-indicator {
    padding: 12px 15px;
    text-align: center;
    background: rgba(0, 0, 0, 0.03);
    color: rgba(0, 0, 0, 0.03);
    font-size: 11px;
    font-weight: 500;
    border-top: 1px solid #f0f0f0;
    user-select: text;
    cursor: text;
}

.version-indicator::selection {
    background: #667eea;
    color: white;
}

/* Responsive Design */
@media (max-width: 768px) {
    .username-container {
        min-width: 90%;
        padding: 30px 20px;
    }

    .chat-container {
        height: 100vh;
        border-radius: 0;
    }

    #chat-screen {
        padding: 0;
    }

    .mobile-menu-btn {
        display: block;
    }

    .sidebar {
        position: fixed;
        right: -280px;
        top: 0;
        height: 100%;
        width: 280px;
        background: white;
        z-index: 1000;
        transition: right 0.3s;
        box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
    }

    .sidebar.open {
        right: 0;
    }

    .message {
        max-width: 85%;
    }
}
