:root {
    --primary-color: #7289da;
    --secondary-color: #2c2f33;
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --success-color: #43b581;
    --bg-image: url('https://images.unsplash.com/photo-1451187580459-43490279c0fa?q=80&w=2072&auto=format&fit=crop');
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: #fff;
    line-height: 1.6;
    background-image: var(--bg-image);
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    height: 100vh;
    margin: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

body::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: -1;
    backdrop-filter: blur(8px);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 4px;
}

/* =========================================
   LOGIN SCREEN (Centered Card)
   ========================================= */
/* =========================================
   LOGIN SCREEN (Glass Overlay)
   ========================================= */
.join-container {
    background: rgba(20, 20, 20, 0.85);
    /* Very dark glass */
    width: 420px;
    max-width: 90vw;
    border-radius: 16px;
    padding: 0;
    box-shadow:
        0 20px 50px rgba(0, 0, 0, 0.8),
        0 0 0 1px rgba(255, 255, 255, 0.1);
    /* Subtle border ring */
    backdrop-filter: blur(25px);
    overflow: hidden;
    animation: fadeIn 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
    z-index: 100;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Distinct Header */
.join-header {
    background: linear-gradient(135deg, rgba(114, 137, 218, 0.2), rgba(0, 0, 0, 0));
    padding: 30px 20px;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.join-header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-shadow: 0 2px 10px rgba(114, 137, 218, 0.5);
    margin: 0;
}

.join-main {
    padding: 30px;
}

.form-control {
    margin-bottom: 20px;
}

.form-control label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
}

.form-control input,
.form-control select {
    width: 100%;
    padding: 10px;
    border-radius: 5px;
    border: 1px solid #444;
    background: rgba(0, 0, 0, 0.2);
    color: #fff;
    font-size: 1rem;
}

/* =========================================
   CHAT SCREEN (Full Viewport)
   ========================================= */
.chat-container {
    display: flex;
    /* Flex Column: Header top, Layout below */
    flex-direction: column;

    /* CRITICAL: Force Full Screen */
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw !important;
    height: 100vh !important;

    background: rgba(44, 47, 51, 0.95);
    border-radius: 0 !important;
    box-shadow: none !important;
    border: none !important;
    margin: 0 !important;
    z-index: 5;
    animation: fadeIn 0.5s ease;
}

/* Header */
.chat-header {
    height: 60px;
    padding: 0 1.5rem;
    background: rgba(35, 39, 42, 0.98);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--glass-border);
    flex-shrink: 0;
    /* Cannot shrink */
}

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

/* Main Layout Area (Sidebar + Content) */
/* Uses simple Flex Row */
.chat-layout {
    display: flex;
    flex-direction: row;
    width: 100%;
    height: calc(100vh - 60px);
    /* Remaining height */
    overflow: hidden;
}

/* Sidebar */
.chat-sidebar {
    width: 260px;
    background: rgba(32, 34, 37, 1);
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    padding: 20px 10px;
    overflow: hidden;
    flex-shrink: 0;
    /* Fixed width */
}

.chat-sidebar h2 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
    color: #ccc;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

/* -- BRANDING & TERMS ADDITIONS -- */
.brand-logo {
    width: 80px;
    height: 80px;
    margin-bottom: 10px;
}

.header-branding {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-logo-small {
    width: 32px;
    height: 32px;
}

.terms-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    color: #ccc;
    font-size: 0.9rem;
    justify-content: center;
}

.terms-checkbox input {
    width: auto;
    cursor: pointer;
}

.room-list {
    list-style: none;
    padding: 0;
    margin: 0;
    flex: 1;
    overflow-y: auto;
}

.room-item {
    padding: 10px 15px;
    margin-bottom: 5px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    color: #aaa;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 12px;
}

.room-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
}

.room-item.active {
    background: rgba(114, 137, 218, 0.15);
    color: var(--primary-color);
    font-weight: 600;
    border-left: 3px solid var(--primary-color);
}

.room-item.locked {
    opacity: 0.7;
}

/* Chat Content (Right Side) */
.chat-content {
    flex: 1;
    /* Take remaining space */
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
    height: 100%;
}

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* Pinned Bar */
.pinned-bar {
    background: rgba(255, 215, 0, 0.15);
    border-bottom: 1px solid rgba(255, 215, 0, 0.3);
    padding: 10px 15px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    min-height: 50px;
}

.pinned-content {
    flex: 1;
    overflow: hidden;
}

.pinned-author {
    font-weight: bold;
    font-size: 0.75rem;
    color: var(--primary-color);
    display: block;
}

.pinned-text {
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.close-pin,
.pinned-icon {
    color: #f5a623;
    background: none;
    border: none;
    cursor: pointer;
}

.close-pin {
    color: #fff;
    opacity: 0.7;
}

/* Messages Area */
.chat-messages {
    padding: 1rem;
    display: flex;
    flex-direction: column-reverse;
    /* Bottom up? No, standard is top-down usually but let's stick to standard flex-col and scrollTop */
    flex-direction: column;
    gap: 15px;
    overflow-y: auto;
    flex: 1;
}

/* Message Bubbles */
.message {
    padding: 10px 15px;
    background-color: var(--glass-bg);
    border-radius: 8px;
    max-width: 80%;
    position: relative;
    align-self: flex-start;
    /* LEFT ALIGNED (Others) */
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(5px);
    animation: fadeIn 0.3s ease;
}

.my-message {
    align-self: flex-end;
    /* RIGHT ALIGNED (You) */
    background-color: rgba(114, 137, 218, 0.2);
    border-color: rgba(114, 137, 218, 0.4);
}

.admin-message {
    background-color: rgba(255, 215, 0, 0.1);
    border: 1px solid #ffd700;
    box-shadow: 0 0 5px rgba(255, 215, 0, 0.2);
}

.meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 5px;
    font-size: 0.85rem;
}

.username {
    font-weight: bold;
    color: var(--primary-color);
}

.time {
    color: #777;
    font-size: 0.75rem;
}

.text {
    word-wrap: break-word;
    line-height: 1.5;
}

/* Input Area */
.chat-form-container {
    padding: 15px;
    background: rgba(35, 39, 42, 0.95);
    border-top: 1px solid var(--glass-border);
    flex-shrink: 0;
}

#chat-form {
    display: flex;
    gap: 10px;
    align-items: center;
}

#msg {
    flex: 1;
    padding: 12px;
    border-radius: 20px;
    border: 1px solid #444;
    background: rgba(0, 0, 0, 0.3);
    color: white;
    outline: none;
}

/* Buttons */
.btn {
    cursor: pointer;
    padding: 10px 20px;
    background: var(--primary-color);
    color: #fff;
    border: 0;
    border-radius: 5px;
    font-size: 1rem;
    transition: all 0.3s ease;
}

.btn:hover {
    background-color: #5b6eae;
    transform: translateY(-2px);
}

.btn-icon {
    padding: 10px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    width: 40px;
    height: 40px;
}

.btn-sm {
    padding: 8px 12px;
    font-size: 0.9rem;
}

.btn-leave {
    padding: 8px 15px;
    background: #f04747;
    color: white;
    text-decoration: none;
    border-radius: 5px;
}

/* Misc */
.reply-preview {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.3);
    padding: 8px 12px;
    border-left: 3px solid var(--primary-color);
    margin-bottom: 10px;
    border-radius: 4px;
}

.reply-cancel {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
}

.online-badge {
    background: rgba(0, 0, 0, 0.3);
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 0.85rem;
    color: #43b581;
}

.emoji-picker {
    position: fixed;
    background: #2c2f33;
    border: 1px solid #444;
    padding: 10px;
    border-radius: 8px;
    display: flex;
    gap: 10px;
    z-index: 1000;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
}

.emoji-picker span {
    cursor: pointer;
    font-size: 1.5rem;
}

.emoji-picker span:hover {
    transform: scale(1.2);
}

.reactions {
    display: flex;
    gap: 5px;
    margin-top: 5px;
    flex-wrap: wrap;
}

.reaction-badge {
    font-size: 0.8rem;
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 10px;
    cursor: pointer;
}

.message-image {
    max-width: 100%;
    max-height: 250px;
    border-radius: 8px;
    margin-top: 5px;
    cursor: pointer;
}

.message-actions {
    display: none;
    margin-left: auto;
    gap: 5px;
}

.message:hover .message-actions {
    display: flex;
}

.action-btn {
    background: none;
    border: none;
    color: #aaa;
    cursor: pointer;
}

/* Hidden Export Container (for Image Gen) */
.export-container {
    position: fixed;
    top: -9999px;
    left: -9999px;
    width: 600px;
    background: #2c2f33;
    padding: 20px;
    border-radius: 10px;
    color: #fff;
    z-index: -1;
    visibility: hidden;
    /* Hide it visually */
}

.export-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 10px;
}

.export-brand {
    font-size: 1.5rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 15px;
    /* Increased gap */
    line-height: 1;
    /* Reset line height */
}

.export-brand img {
    display: block;
    /* Remove inline gap */
    margin: 0;
}

.export-tagline {
    font-size: 0.8rem;
    color: #bbb;
}

/* Force high contrast for exported messages */
.export-messages .message {
    background: rgba(40, 43, 48, 1) !important;
    /* Solid dark grey */
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    color: #ffffff !important;
    box-shadow: none !important;
    margin-bottom: 10px;
}

.export-messages .text {
    color: #ffffff !important;
    font-weight: 500;
}

.export-messages .username {
    text-shadow: none !important;
}

.export-messages .time {
    color: #bbbbbb !important;
}


/* -- MODAL STYLES (Fixed) -- */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    /* Flex is critical for centering */
    justify-content: center;
    align-items: center;
    z-index: 2000;
    backdrop-filter: blur(5px);
}

.modal-content {
    background: #1e1e1e;
    /* Solid background */
    padding: 30px;
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    text-align: left;
    color: #fff;
    position: relative;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    border: 1px solid #333;
    animation: fadeIn 0.3s ease;
}

.close-modal {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 28px;
    cursor: pointer;
    color: #888;
    transition: color 0.2s;
}

.close-modal:hover {
    color: #fff;
}

.terms-content h2 {
    margin-bottom: 20px;
    border-bottom: 1px solid #333;
    padding-bottom: 15px;
    color: #FFD700;
    display: flex;
    align-items: center;
    gap: 10px;
}

.terms-text {
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 25px;
    font-size: 0.95rem;
    line-height: 1.6;
    color: #ccc;
    padding-right: 10px;
}

.terms-text p {
    margin-bottom: 10px;
}

.terms-text strong {
    color: #fff;
}

#accept-terms {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
    background: #7289da;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

#accept-terms:hover {
    background: #5b6eae;
}