:root {
    --primary-color: #7b1fa2;
    /* Deep Purple */
    --primary-light: #9c27b0;
    --primary-dark: #4a148c;
    --bg-color: #121212;
    --bg-secondary: #1e1e1e;
    --bg-tertiary: #2c2c2c;
    --text-primary: #ffffff;
    --text-secondary: #b0b0b0;
    --message-incoming: #2c2c2c;
    --message-outgoing: #7b1fa2;
    --online-color: #4caf50;
    --offline-color: #9e9e9e;
    --border-radius: 12px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

html {
    width: 100%;
    height: 100%;
    -webkit-user-select: none;
    user-select: none;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    width: 100%;
    height: 100%;
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
    position: fixed;
}

#app-container {
    display: flex;
    width: 100%;
    height: 100%;
    max-width: 100%;
    background-color: var(--bg-secondary);
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 250px;
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--bg-tertiary);
    display: flex;
    flex-direction: column;
    padding: 1rem;
}

.profile-section {
    display: flex;
    align-items: center;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--bg-tertiary);
    margin-bottom: 1rem;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-right: 10px;
    background-color: var(--primary-light);
}

.username {
    font-weight: bold;
}

.channels-list {
    flex-grow: 1;
    overflow-y: auto;
}

.channel-item {
    padding: 10px;
    margin-bottom: 5px;
    border-radius: var(--border-radius);
    cursor: pointer;
    color: var(--text-secondary);
    transition: background 0.2s;
}

.channel-item:hover,
.channel-item.active {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.channel-item.active {
    border-left: 3px solid var(--primary-light);
}

/* Chat Area */
.chat-area {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-color);
}

.chat-header {
    padding: 1rem;
    border-bottom: 1px solid var(--bg-tertiary);
    font-weight: bold;
    font-size: 1.2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-messages {
    flex-grow: 1;
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    display: flex;
    align-items: flex-start;
    max-width: 70%;
}

.message.outgoing {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-content {
    background-color: var(--message-incoming);
    padding: 10px 15px;
    border-radius: var(--border-radius);
    border-top-left-radius: 2px;
    position: relative;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.message.outgoing .message-content {
    background-color: var(--message-outgoing);
    border-top-left-radius: var(--border-radius);
    border-top-right-radius: 2px;
}

.message-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 3px;
    display: block;
}

.message.outgoing .message-meta {
    text-align: right;
}

/* Input Area */
.chat-input-area {
    padding: 1rem;
    background-color: var(--bg-secondary);
    display: flex;
    align-items: center;
    gap: 10px;
}

input[type="text"] {
    flex-grow: 1;
    padding: 12px;
    border-radius: 20px;
    border: none;
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    outline: none;
    font-size: 16px;
    -webkit-appearance: none;
    appearance: none;
    min-height: 44px;
}

button.send-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    flex-shrink: 0;
    -webkit-appearance: none;
    appearance: none;
}

button.send-btn:hover {
    background-color: var(--primary-light);
    transform: scale(1.1);
}

/* Login Page */
.login-container {
    background-color: var(--bg-secondary);
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: 0 0 20px rgba(123, 31, 162, 0.3);
    width: 350px;
    max-width: 90%;
    text-align: center;
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.login-container h2 {
    color: var(--primary-light);
    margin-bottom: 2rem;
    font-size: 1.8rem;
}

.login-form input {
    width: 100%;
    margin-bottom: 1rem;
    background-color: var(--bg-tertiary);
    border: none;
    padding: 12px;
    border-radius: 20px;
    color: var(--text-primary);
    outline: none;
    font-size: 16px;
    -webkit-appearance: none;
    appearance: none;
    min-height: 44px;
}

.login-btn {
    width: 100%;
    padding: 12px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-weight: bold;
    font-size: 0.95rem;
    min-height: 44px;
    -webkit-appearance: none;
    appearance: none;
}

/* Responsive */
@media (max-width: 768px) {
    html, body {
        width: 100%;
        height: 100%;
        max-height: 100vh;
        overflow: hidden;
        position: fixed;
    }

    body {
        height: 100vh;
        height: 100dvh;
    }

    #app-container {
        flex-direction: column;
        position: relative;
        width: 100%;
        height: 100%;
        max-height: 100vh;
    }

    /* Mobile Sidebar - Slide-in Menu */
    .sidebar {
        position: fixed;
        top: 0;
        left: -280px;
        width: 280px;
        height: 100%;
        max-height: 100vh;
        z-index: 1000;
        transition: left 0.3s ease;
        padding: 1rem;
        border-right: 1px solid var(--bg-tertiary);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .sidebar.open {
        left: 0;
    }

    /* Overlay when sidebar is open */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }

    .sidebar-overlay.active {
        display: block;
    }

    /* Mobile Header with Menu Button */
    .chat-header {
        padding: 0.75rem 1rem;
        font-size: 1rem;
        min-height: 44px;
        display: flex;
        align-items: center;
        gap: 10px;
    }

    .menu-btn {
        display: flex !important;
        background: none;
        border: none;
        color: var(--text-primary);
        font-size: 1.5rem;
        cursor: pointer;
        padding: 8px;
        margin-right: 10px;
        min-width: 44px;
        min-height: 44px;
        align-items: center;
        justify-content: center;
        -webkit-user-select: none;
        user-select: none;
        flex-shrink: 0;
    }

    /* Chat Area Full Width */
    .chat-area {
        width: 100%;
        height: 100%;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    /* Messages */
    .chat-messages {
        padding: 0.75rem;
        gap: 0.75rem;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        flex: 1;
    }

    .message {
        max-width: 85%;
        word-wrap: break-word;
        word-break: break-word;
    }

    .message-content {
        padding: 8px 12px;
        font-size: 0.9rem;
        line-height: 1.4;
    }

    /* Input Area */
    .chat-input-area {
        padding: 0.75rem;
        gap: 8px;
        background-color: var(--bg-secondary);
        flex-shrink: 0;
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    input[type="text"] {
        padding: 10px 15px;
        font-size: 16px;
        min-height: 44px;
        -webkit-appearance: none;
        appearance: none;
    }

    button.send-btn {
        padding: 8px;
        min-width: 44px;
        min-height: 44px;
        flex-shrink: 0;
    }

    /* Profile Section in Sidebar */
    .profile-section {
        padding: 12px;
    }

    .avatar {
        width: 36px;
        height: 36px;
    }

    .user-info .username {
        font-size: 0.9rem;
    }

    /* Channel Items */
    .channel-item {
        padding: 12px;
        font-size: 0.95rem;
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    /* Online Users */
    .online-users {
        max-height: 150px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Close button in sidebar */
    .sidebar-close {
        display: block !important;
        position: absolute;
        top: 10px;
        right: 10px;
        background: none;
        border: none;
        color: var(--text-secondary);
        font-size: 1.5rem;
        cursor: pointer;
        padding: 8px;
        min-width: 44px;
        min-height: 44px;
        z-index: 1001;
    }

    /* Login Container Mobile */
    .login-container {
        width: 95%;
        max-width: 100%;
        padding: 1.5rem;
        max-height: 100vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* Extra small devices */
@media (max-width: 480px) {
    body {
        height: 100vh;
        height: 100dvh;
    }

    #app-container {
        width: 100%;
        height: 100%;
    }

    .login-container {
        width: 95%;
        padding: 1.5rem;
        margin: 10px;
        max-height: 100vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .login-container h2 {
        font-size: 1.5rem;
        margin-bottom: 1.5rem;
    }

    .login-form input {
        padding: 12px;
        font-size: 16px;
        -webkit-appearance: none;
        appearance: none;
        min-height: 44px;
    }

    .login-btn, .google-btn {
        padding: 12px;
        font-size: 0.95rem;
        min-height: 44px;
        -webkit-appearance: none;
        appearance: none;
    }

    .message {
        max-width: 90%;
    }

    .chat-header {
        font-size: 0.9rem;
        min-height: 50px;
    }

    .sidebar {
        width: 260px;
        left: -260px;
    }

    .sidebar.open {
        left: 0;
    }

    .chat-input-area {
        min-height: 50px;
    }

    .online-user {
        min-height: 40px;
        padding: 8px 10px;
    }
}

/* Desktop - Hide mobile elements */
@media (min-width: 769px) {
    .menu-btn,
    .sidebar-close,
    .sidebar-overlay {
        display: none !important;
    }

    .sidebar {
        position: relative;
        left: 0;
        width: 250px;
    }
}

/* Compatibility fixes for older Android devices */
@media (max-width: 480px) and (hover: none) {
    /* Android devices with touch - remove hover effects that don't work well */
    button:hover {
        opacity: 0.8;
    }
    
    .channel-item:hover {
        background-color: var(--bg-tertiary);
    }
}

/* Fix for notched phones (iPhone X and similar) */
@supports (padding: max(0px)) {
    body {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }
    
    @media (max-width: 768px) {
        .sidebar {
            padding-left: max(1rem, env(safe-area-inset-left));
            padding-right: max(1rem, env(safe-area-inset-right));
        }
        
        .chat-input-area {
            padding-bottom: max(1rem, env(safe-area-inset-bottom));
        }
    }
}

/* Prevent double-tap zoom */
input, button, select, textarea {
    -webkit-touch-callout: none;
}

/* Ensure text inputs don't zoom on focus (iOS) */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    textarea {
        font-size: 16px !important;
    }
}

/* Fix for browsers that don't support 100dvh */
@supports not (height: 100dvh) {
    html, body {
        height: 100%;
    }
}

/* Logout Button */
.logout-form {
    display: inline-block;
    margin-left: 10px;
}

.logout-btn {
    background: none;
    border: none;
    color: #a0a0a0;
    cursor: pointer;
    font-size: 1.2rem;
    transition: color 0.3s;
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-user-select: none;
    user-select: none;
}

.logout-btn:hover {
    color: #ff4444;
}

/* Alert Messages */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 15px;
    font-size: 0.9rem;
    text-align: center;
}

.alert-success {
    background-color: rgba(76, 175, 80, 0.2);
    color: #4caf50;
    border: 1px solid rgba(76, 175, 80, 0.3);
}

.alert-warning {
    background-color: rgba(255, 193, 7, 0.2);
    color: #ffc107;
    border: 1px solid rgba(255, 193, 7, 0.3);
}

.alert-error {
    background-color: rgba(244, 67, 54, 0.2);
    color: #f44336;
    border: 1px solid rgba(244, 67, 54, 0.3);
}

#message-box {
    width: 100%;
    max-width: 300px;
}

/* Profile Section - Improved */
.profile-section {
    display: flex;
    align-items: center;
    padding: 15px;
    border-bottom: 1px solid var(--bg-tertiary);
    margin-bottom: 1rem;
    background-color: var(--bg-secondary);
    gap: 10px;
}

.user-info {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.user-info .username {
    font-weight: bold;
    font-size: 0.95rem;
}

.user-status {
    font-size: 0.75rem;
    color: var(--online-color);
}

/* Google Sign In Button */
.google-btn {
    width: 100%;
    padding: 12px;
    background-color: #fff;
    color: #333;
    border: 1px solid #ddd;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
    font-size: 0.95rem;
    min-height: 44px;
    -webkit-appearance: none;
    appearance: none;
}

.google-btn:hover {
    background-color: #f5f5f5;
}

/* Online Users List */
.online-users {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--bg-tertiary);
}

.online-users h3 {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.online-user {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 10px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.online {
    background-color: var(--online-color);
}

.status-dot.offline {
    background-color: var(--offline-color);
}

.status-dot.away {
    background-color: #ffc107;
}

/* System Messages */
.system-message {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.8rem;
    padding: 5px;
    margin: 10px 0;
}

/* Avatar Image */
.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    background-color: var(--primary-light);
}

/* Alert info style */
.alert-info {
    background-color: rgba(33, 150, 243, 0.2);
    color: #2196F3;
    border: 1px solid rgba(33, 150, 243, 0.3);
}

/* Login container adjustments for Firebase */
.login-container {
    max-width: 400px;
    width: 90%;
}
