:root {
    --bg-color: #0d1117;
    --card-bg: rgba(22, 27, 34, 0.7);
    --primary-color: #00ff41;
    --secondary-color: #8b949e;
    --accent-color: #238636;
    --text-color: #c9d1d9;
    --danger-color: #da3633;
    --font-family: 'JetBrains Mono', monospace;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh;
    height: 100dvh;
    /* Dynamic viewport height for mobile browsers */
    display: flex;
    overflow: hidden;
    position: fixed;
    /* Prevent rubber-banding/scrolling on some mobile OS */
    width: 100%;
}

.background-animation {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 50% 50%, #161b22 0%, #0d1117 100%);
    z-index: -1;
}

/* Screens */
.screen {
    display: none;
    width: 100%;
    height: 100%;
    flex-direction: column;
}

.screen.active {
    display: flex;
}

/* Login - Centered Card */
#login-screen {
    justify-content: center;
    align-items: center;
}

.card {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    border: 1px solid #30363d;
    padding: 2.5rem;
    border-radius: 12px;
    width: 95%;
    max-width: 400px;
    box-shadow: 0 0 20px rgba(0, 255, 65, 0.05);
}

.header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 0.5rem;
}

h1 {
    font-size: 1.5rem;
    letter-spacing: -1px;
    color: #fff;
    white-space: nowrap;
}

.subtitle {
    color: var(--secondary-color);
    font-size: 0.8rem;
    margin-bottom: 2rem;
}

.status-dot {
    width: 10px;
    height: 10px;
    background-color: var(--primary-color);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--primary-color);
}

.status-dot.blink {
    animation: blink 2s infinite;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

/* Form Styles */
.input-group {
    margin-bottom: 1.5rem;
}

label {
    display: block;
    font-size: 0.75rem;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
}

input {
    width: 100%;
    padding: 12px;
    background: #0d1117;
    border: 1px solid #30363d;
    color: #fff;
    border-radius: 6px;
    font-family: var(--font-family);
}

input:focus {
    outline: none;
    border-color: var(--primary-color);
}

button {
    padding: 12px;
    border: 1px solid var(--primary-color);
    background: #161b22;
    color: var(--primary-color);
    border-radius: 6px;
    font-family: var(--font-family);
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    font-size: 0.75rem;
}

button:hover {
    background: var(--primary-color);
    color: #000;
    box-shadow: 0 0 10px var(--primary-color);
}

.btn-primary {
    background: var(--accent-color);
    border-color: var(--accent-color);
    color: #fff;
    width: 100%;
}

.btn-primary:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: #000;
}

.error-msg {
    color: var(--danger-color);
    font-size: 0.8rem;
    text-align: center;
    margin-top: 10px;
}

/* Chat Layout */
.chat-layout {
    display: flex;
    flex: 1;
    height: 100%;
    position: relative;
    overflow: hidden;
}

/* Sidebar as Drawer on Mobile */
.sidebar {
    width: 250px;
    background: rgba(13, 17, 23, 0.98);
    border-right: 1px solid #30363d;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    z-index: 1000;
}

.main-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #30363d;
    margin-bottom: 1rem;
}

.sidebar-header h2 {
    font-size: 0.8rem;
    color: var(--secondary-color);
}

#close-sidebar {
    border: 1px solid var(--danger-color);
    color: var(--danger-color);
    background: transparent;
}

#close-sidebar:hover {
    background: var(--danger-color);
    color: #fff;
}

#user-count {
    background: var(--primary-color);
    color: #000;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.7rem;
}

#user-list {
    list-style: none;
    overflow-y: auto;
    flex: 1;
}

#user-list li {
    padding: 8px 10px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

#user-list li::before {
    content: '';
    width: 8px;
    height: 8px;
    background: #8b949e;
    border-radius: 50%;
}

#user-list li.me {
    color: var(--primary-color);
}

#user-list li.me::before {
    background: var(--primary-color);
    box-shadow: 0 0 5px var(--primary-color);
}

/* Tabs Bar */
.tabs-bar {
    display: flex;
    background: #0d1117;
    border-bottom: 1px solid #30363d;
    gap: 2px;
    overflow-x: auto;
    padding: 2px 5px 0;
}

.tab {
    padding: 8px 15px;
    background: #161b22;
    border: 1px solid #30363d;
    border-bottom: none;
    border-radius: 4px 4px 0 0;
    font-size: 0.75rem;
    color: var(--secondary-color);
    cursor: pointer;
    white-space: nowrap;
}

.tab.active {
    background: var(--bg-color);
    color: var(--primary-color);
    border-top: 2px solid var(--primary-color);
}

/* Chat Header */
.chat-header {
    height: 55px;
    background: var(--card-bg);
    border-bottom: 1px solid #30363d;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1rem;
}

.connection-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: bold;
    color: var(--primary-color);
    font-size: 0.9rem;
}

#menu-toggle {
    background: transparent;
    color: var(--primary-color);
    font-size: 1.2rem;
    display: none;
    margin-right: 5px;
    cursor: pointer;
    border: none;
    padding: 5px;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

#search-input {
    width: 120px;
    padding: 5px 10px;
    font-size: 0.8rem;
    background: #000;
}

#explorer-btn {
    background: transparent;
    border: 1px solid #30363d;
    padding: 5px 8px;
}

#disconnect-btn {
    background: transparent;
    border: 1px solid var(--danger-color);
    color: var(--danger-color);
    font-size: 0.7rem;
    padding: 6px 10px;
    width: auto;
}

/* Chat Container */
#chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 15px;
    scroll-behavior: smooth;
    min-height: 0;
    /* Critical for flex scrolling */
}

/* Messages - REINFORCED FORMATTING */
.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 8px;
    background: #161b22;
    border: 1px solid #30363d;
    position: relative;
    word-wrap: break-word;
    animation: slideIn 0.2s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.message.self {
    align-self: flex-end;
    background: rgba(35, 134, 54, 0.1);
    border-color: var(--accent-color);
}

.message.system {
    align-self: center;
    background: transparent;
    border: none;
    color: var(--secondary-color);
    font-size: 0.75rem;
}

.meta {
    font-size: 0.7rem;
    color: var(--secondary-color);
    margin-bottom: 6px;
    display: flex;
    justify-content: space-between;
}

.self .meta {
    color: var(--primary-color);
}

/* THIS IS THE FIX FOR FORMATTING */
.text {
    display: block;
    white-space: pre-wrap !important;
    white-space: -moz-pre-wrap !important;
    white-space: -pre-wrap !important;
    white-space: -o-pre-wrap !important;
    word-wrap: break-word !important;
    line-height: 1.5;
    font-size: 0.95rem;
}

/* Multimedia */
.message img,
.message video {
    max-width: 280px;
    max-height: 200px;
    object-fit: cover;
    border-radius: 6px;
    margin-top: 10px;
    border: 1px solid #30363d;
    cursor: pointer;
    transition: transform 0.2s;
}

.message img:hover,
.message video:hover {
    transform: scale(1.02);
}

.message .doc-preview {
    background: #0d1117;
    padding: 12px;
    border-radius: 6px;
    margin-top: 10px;
    border: 1px solid var(--primary-color);
    display: flex;
    justify-content: space-between;
}

/* File Explorer */
.file-explorer {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 300px;
    background: rgba(13, 17, 23, 0.95);
    backdrop-filter: blur(10px);
    border-left: 1px solid #30363d;
    z-index: 2000;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

.file-explorer.open {
    transform: translateX(0);
}

.file-explorer-header {
    padding: 1rem;
    border-bottom: 1px solid #30363d;
    display: flex;
    justify-content: space-between;
}

/* Input Area */
#chat-form {
    padding: 1rem;
    background: var(--bg-color);
    border-top: 1px solid #30363d;
    display: flex;
    gap: 8px;
}

#msg-input {
    flex: 1;
}

#chat-form button {
    width: auto;
    padding: 0 16px;
}

#chat-form .btn-icon {
    background: #161b22;
    border: 1px solid #30363d;
    color: var(--secondary-color);
    padding: 0 12px;
}

#chat-form .btn-send {
    background: var(--primary-color);
    color: #000;
}

#voice-btn.recording {
    background: var(--danger-color);
    color: #fff;
    animation: pulse 1s infinite;
}

/* Mobile Only Utility */
.mobile-only {
    display: none;
}

/* Premium Mobile Responsiveness */
@media (max-width: 768px) {
    .mobile-only {
        display: flex;
    }

    #menu-toggle {
        display: block;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: 10px 0 20px rgba(0, 0, 0, 0.5);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .header-controls #search-input {
        display: none;
    }

    h1 {
        font-size: 1.1rem;
    }

    .chat-header {
        height: auto;
        min-height: 50px;
        padding: 5px 10px;
        flex-wrap: wrap;
        gap: 10px;
    }

    .tabs-bar {
        padding: 5px 5px 0;
        background: #161b22;
    }

    .tab {
        font-size: 0.75rem;
        padding: 10px 12px;
    }

    .main-chat {
        width: 100%;
        flex: 1;
        min-height: 0;
    }

    .message {
        max-width: 90%;
        padding: 10px;
        font-size: 0.9rem;
    }

    .text {
        font-size: 0.9rem;
    }

    #chat-form {
        padding: 5px;
        gap: 5px;
    }

    #msg-input {
        padding: 10px;
        font-size: 0.9rem;
    }

    /* Overlay when sidebar is open */
    .chat-layout::before {
        content: '';
        position: absolute;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        display: none;
    }

    .chat-layout.sidebar-active::before {
        display: block;
    }
}

/* Utility */
.hidden {
    display: none !important;
}

/* Reply Preview Bar */
#reply-preview {
    background: #161b22;
    border-top: 1px solid var(--primary-color);
    padding: 8px 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--secondary-color);
}

#reply-text {
    flex: 1;
    margin-left: 10px;
    color: var(--text-color);
    font-style: italic;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#cancel-reply {
    background: transparent;
    color: var(--danger-color);
    padding: 2px 8px;
    font-size: 1rem;
}

/* Message Actions (Reply/React) */
.msg-actions {
    position: absolute;
    right: 10px;
    top: -15px;
    background: #0d1117;
    border: 1px solid #30363d;
    border-radius: 20px;
    padding: 2px 8px;
    display: flex;
    gap: 5px;
    opacity: 0;
    transition: opacity 0.2s, top 0.2s;
    z-index: 10;
}

.message:hover .msg-actions {
    opacity: 1;
    top: -20px;
}

.msg-actions button {
    background: transparent;
    padding: 4px;
    font-size: 0.9rem;
    cursor: pointer;
    border-radius: 50%;
}

.msg-actions button:hover {
    background: #30363d;
}

.reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 8px;
}

.reactions span {
    background: #0d1117;
    border: 1px solid #30363d;
    padding: 2px 6px;
    border-radius: 10px;
}

/* Animations */
@keyframes pulse {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.6;
    }

    100% {
        opacity: 1;
    }
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #30363d;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}