/* =========================================================
   CRITICAL FIXES (Paste at the VERY TOP of file)
   ========================================================= */

/* 1. Fix Settings Popup Layout - Shaded Containers */
.settings-section { 
    margin-bottom: 15px; 
    background: #f2f2f7 !important; /* Visible light grey background */
    border-radius: 12px; 
    padding: 0 15px; 
    border: 1px solid rgba(0,0,0,0.05);
}

.settings-row {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 15px 0 !important;
    border-bottom: 1px solid rgba(0,0,0,0.05) !important;
    width: 100% !important;
}
.settings-row:last-child { border-bottom: none !important; }

.setting-info { 
    display: flex !important; 
    align-items: center !important; 
    font-size: 15px !important; 
    font-weight: 500 !important; 
    color: var(--text-main); 
}

.setting-icon {
    width: 30px !important; height: 30px !important; border-radius: 6px !important;
    background: var(--ios-blue) !important; color: white !important;
    display: flex !important; align-items: center !important; justify-content: center !important;
    margin-right: 12px !important; font-size: 14px;
}
.icon-grey { background: #8e8e93 !important; }
.icon-orange { background: #ff9500 !important; }
.icon-red { background: #ff3b30 !important; }

/* 2. Professional Pill Buttons for Settings */
.btn-action-sm {
    padding: 6px 15px !important;
    border-radius: 16px !important;
    border: none !important;
    background: #e5e5ea !important; /* Grey button background */
    font-size: 13px !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    color: #000 !important;
    text-decoration: none !important;
    display: inline-block !important;
    line-height: normal !important;
    transition: opacity 0.2s;
}
.btn-action-sm:hover { opacity: 0.7; }

/* Red Buttons (Log Out / Delete) */
.btn-action-sm.text-danger {
    color: #ff3b30 !important;
    background: rgba(255, 59, 48, 0.15) !important; /* Light Red Background */
}

/* 3. Fix Toggle Switches */
.ios-toggle { position: relative !important; display: inline-block !important; width: 50px !important; height: 30px !important; }
.ios-toggle input { opacity: 0 !important; width: 0 !important; height: 0 !important; }
.slider {
    position: absolute !important; cursor: pointer !important; top: 0; left: 0; right: 0; bottom: 0;
    background-color: #e9e9ea !important; transition: .4s !important; border-radius: 34px !important;
}
.slider:before {
    position: absolute !important; content: "" !important; height: 26px !important; width: 26px !important;
    left: 2px !important; bottom: 2px !important; background-color: white !important;
    transition: .4s !important; border-radius: 50% !important; box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
input:checked + .slider { background-color: var(--ios-blue) !important; }
input:checked + .slider:before { transform: translateX(20px) !important; }

/* 4. Highlight Active VIP Group (Gold) */
.nav-item.vip-item.active {
    background: #FFD700 !important;
    color: #000 !important;
    box-shadow: 0 4px 12px rgba(255, 215, 0, 0.4);
}

/* =========================================
   1. CORE VARIABLES & BUBBLE STYLES
   ========================================= */
:root {
    /* Default Colors */
    --bg-color: #ffffff;
    --sidebar-bg: #f8f8f8;
    --text-main: #1a1a1a;
    --glass-border: rgba(0, 0, 0, 0.1);
    --input-bg: #ffffff;
    
    /* Bubble Colors */
    --bubble-me: #007aff;
    --bubble-me-text: #ffffff;
    --bubble-them: #e5e5ea;      
    --bubble-them-text: #000000; 
    
    --ios-blue: #007aff;
    --danger-red: #ff3b30;
    --glow: 0 0 10px rgba(0, 122, 255, 0.3);
    
    /* Additional Defaults for Admin */
    --bg-image: none;
    --scroll-btn-bg: #007aff;
    
    /* Card BG for Popups */
    --card-bg: #ffffff;
}

/* =========================================
   GLOBAL TEXT SELECTION FIX (Make it Visible!)
   MOVED OUTSIDE :root SO IT WORKS
   ========================================= */
::selection {
    background-color: #ffffff !important; /* High Contrast White Background */
    color: #007aff !important;            /* Blue Text */
    -webkit-text-fill-color: #007aff !important;
    opacity: 1 !important;
}

/* Specific fix for Mozilla Firefox */
::-moz-selection {
    background-color: #ffffff !important;
    color: #007aff !important;
}

[data-theme="dark"] {
    /* Dark Mode Bubbles */
    --bubble-me: #0088cc;
    --bubble-me-text: #ffffff;
    --bubble-them: #262628;      
    --bubble-them-text: #ffffff; 
    --glow: 0 0 10px rgba(0, 136, 204, 0.5);
    
    /* Admin Dark Mode Overrides */
    --bg-color: #000000;
    --sidebar-bg: #1c1c1e;
    --text-main: #ffffff;
    --glass-border: rgba(255,255,255,0.15);
    --input-bg: #2c2c2e;
    --bg-image: url('https://www.transparenttextures.com/patterns/carbon-fibre.png');
    --scroll-btn-bg: #0088cc;
    --card-bg: #1c1c1e;
}

/* Base Styles (Chat Default: Fixed Screen) */
body {
    background-color: var(--bg-color);
    background-image: var(--bg-image);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text-main);
    margin: 0;
    height: 100dvh; /* Chat needs fixed height */
    overflow: hidden; /* Chat needs hidden overflow */
    transition: background 0.3s ease, color 0.3s ease;
}

/* Side Navigation Bar (YOUR CUSTOM CODE) */
.side-nav {
    width: 70px;
    background: #000;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 0;
    border-right: 1px solid rgba(255,255,255,0.1);
}

.side-nav i {
    font-size: 20px;
    margin-bottom: 30px;
    color: #8e8e93;
    cursor: pointer;
    transition: 0.3s;
}

.side-nav i:hover, .side-nav i.active {
    color: var(--ios-blue);
    text-shadow: var(--glow);
}

/* Chat Bubbles (Base Design) */
.message-bubble {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 15px;
    margin-bottom: 8px;
    position: relative;
    font-size: 15px;
    line-height: 1.4;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    word-wrap: break-word !important; 
    word-break: break-word !important; 
    overflow-wrap: anywhere !important; 
    white-space: pre-wrap;
}

.message-me {
    align-self: flex-end;
    background: var(--bubble-me);
    color: var(--bubble-me-text);
    box-shadow: var(--glow);
}

.message-them {
    align-self: flex-start;
    background: var(--bubble-them);
    color: var(--bubble-them-text);
    border: 1px solid var(--glass-border);
}

.date-divider { text-align: center; margin: 20px 0; position: relative; }
.date-divider span { background: rgba(0,0,0,0.3); padding: 5px 15px; border-radius: 20px; font-size: 12px; color: var(--ios-blue); border: 1px solid var(--ios-blue); }

/* =========================================
   2. CHAT LAYOUT & INTERFACE 
   ========================================= */

/* Main Structure */
.main-container { display: flex; height: 100dvh; width: 100%; overflow: hidden; position: relative; }
.sidebar { width: 320px; background: var(--sidebar-bg); border-right: 1px solid var(--glass-border); display: flex; flex-direction: column; transition: transform 0.3s ease; z-index: 1000; }

.search-bar-container { position: relative; display: block; width: 100%; padding: 0 15px !important; margin: 15px 0 25px 0 !important; border-bottom: none !important; box-sizing: border-box; }
#searchInput { width: 100%; padding: 10px 35px 10px 15px !important; border-radius: 10px; border: 1px solid var(--glass-border); background: rgba(255,255,255,0.05); color: var(--text-main); box-sizing: border-box; font-size: 14px; margin: 0 !important; }
.clear-search { position: absolute; right: 28px; top: 50%; transform: translateY(-50%); color: var(--text-muted); cursor: pointer; display: none; font-size: 16px; z-index: 10; opacity: 0.6; transition: opacity 0.2s; }
.clear-search:hover { color: var(--ios-blue); opacity: 1; }

.chat-header { 
    padding: 0 20px; 
    height: 60px; 
    border-bottom: 1px solid var(--glass-border); 
    display: flex; 
    align-items: center; 
    justify-content: space-between; 
    background: var(--sidebar-bg); 
    z-index: 10; 
    box-sizing: border-box; 
    flex-shrink: 0; 
}

.chat-main { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; background-color: var(--bg-color); }
.messages-display { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 1; scroll-behavior: smooth; -webkit-overflow-scrolling: touch; }

.message-content img { max-width: 100%; height: auto; border-radius: 12px; display: block; margin-top: 5px; }

/* DEFAULT (DESKTOP) FOOTER - Mobile override is at the bottom */
.chat-input-area { 
    padding: 15px 20px; 
    border-top: 1px solid var(--glass-border); 
    display: flex; 
    gap: 15px; 
    align-items: flex-end; 
    background: var(--sidebar-bg); 
    backdrop-filter: blur(15px);
    z-index: 10; 
    padding-bottom: calc(15px + env(safe-area-inset-bottom)); 
    flex-shrink: 0; 
}

.chat-input-area textarea { 
    flex: 1; 
    min-width: 0; 
    background: var(--input-bg); 
    border-radius: 20px; 
    padding: 12px 15px; 
    color: var(--text-main); 
    border: 1px solid var(--glass-border); 
    outline: none; 
    font-size: 16px; 
    font-family: inherit;
    resize: none; 
    max-height: 120px; 
    min-height: 24px; 
    overflow-y: auto;
    line-height: 1.4;
    box-sizing: border-box;
}

.action-icon { 
    color: var(--ios-blue); 
    cursor: pointer; 
    font-size: 24px; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    width: 40px; 
    height: 40px; 
    padding-bottom: 2px;
    flex-shrink: 0; 
    -webkit-tap-highlight-color: transparent; 
}

/* Modals & Overlays */
.overlay { display: none; position: fixed; z-index: 99999; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.8); backdrop-filter: blur(5px); align-items: center; justify-content: center; }
#lightbox img { max-width: 90%; max-height: 90%; border-radius: 12px; }
.modal-card { background: var(--sidebar-bg); padding: 30px; border-radius: 20px; width: 300px; border: 1px solid var(--glass-border); box-shadow: 0 10px 40px rgba(0,0,0,0.4); text-align: center; color: var(--text-main); }
.profile-avatar { width: 80px; height: 80px; border-radius: 50%; object-fit: cover; border: 3px solid var(--ios-blue); margin-bottom: 15px; }
.profile-name { font-size: 20px; font-weight: bold; margin-bottom: 5px; }
.profile-role { display: inline-block; padding: 4px 10px; border-radius: 15px; font-size: 11px; font-weight: 700; text-transform: uppercase; color: white; margin-bottom: 15px; }
.role-admin { background: var(--ios-blue); }
.role-user { background: #8e8e93; }
.profile-meta { font-size: 12px; opacity: 0.6; }
.edit-input { width: 100%; height: 80px; margin: 15px 0; border-radius: 10px; padding: 10px; background: var(--input-bg); color: var(--text-main); border: 1px solid var(--glass-border); resize: none; outline: none; box-sizing: border-box;}
.modal-actions { display: flex; justify-content: center; gap: 10px; margin-top: 15px; }

.btn-cancel { padding: 10px 20px; border-radius: 8px; border: none; background: rgba(128,128,128,0.2); color: var(--text-main); cursor: pointer; font-weight: 600; font-size: 14px; }
.btn-confirm { padding: 10px 20px; border-radius: 8px; border: none; background: var(--danger-red); color: white; cursor: pointer; font-weight: 600; font-size: 14px; }
.btn-save { padding: 8px 20px; border-radius: 8px; border: none; background: var(--ios-blue); color: white; cursor: pointer; font-weight: 600; }

/* Sidebar Elements */
.broadcast-banner { background: rgba(255, 149, 0, 0.9); color: white; padding: 10px 20px; text-align: center; font-size: 14px; font-weight: 600; display: flex; justify-content: center; align-items: center; position: relative; z-index: 2; backdrop-filter: blur(5px); }
.sidebar-section { padding: 15px; padding-bottom: 5px; opacity: 0.6; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.nav-item { padding: 10px 15px; display: flex; align-items: center; cursor: pointer; margin: 0 10px; border-radius: 8px; transition: 0.2s; color: var(--text-main); font-weight: 500; font-size: 14px; flex-wrap: nowrap; text-decoration: none; }
.nav-item:hover { background: var(--glass-border); }
.nav-item.active { background: var(--ios-blue); color: white; }

.nav-icon { 
    width: 24px; height: 24px; min-width: 24px; min-height: 24px; 
    border-radius: 6px; margin-right: 12px; 
    object-fit: cover; background: rgba(255,255,255,0.1); 
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
}

#soundToggleBtn { justify-content: center; background: var(--glass-border); text-align: center; }

/* Status Indicators */
.status-dot { width: 10px; height: 10px; border-radius: 50%; margin-left: auto; border: 2px solid var(--sidebar-bg); }
.status-online { background-color: #34c759; box-shadow: 0 0 5px #34c759; }
.status-away { background-color: #ff9500; }
.status-offline { background-color: #8e8e93; opacity: 0.3; }
.mention-highlight { background-color: rgba(255, 149, 0, 0.1); border-left: 3px solid #ff9500; padding-left: 8px; }

/* Popups & Notifications */
#dmNotification {
    position: fixed; top: 20px; right: 20px; background: var(--sidebar-bg);
    border: 1px solid var(--ios-blue); border-radius: 15px; padding: 12px 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2); z-index: 10000;
    display: none; align-items: center; gap: 15px;
    animation: slideIn 0.3s ease; max-width: 300px; cursor: pointer;
}
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.notif-avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; }
.notif-text { flex: 1; }
.notif-name { font-weight: bold; font-size: 14px; color: var(--ios-blue); }
.notif-msg { font-size: 12px; opacity: 0.7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.vis-btn { padding: 4px 10px; border-radius: 20px; font-size: 10px; font-weight: bold; text-decoration: none; border: 1px solid var(--ios-blue); display: inline-block; margin-top: 2px; }
.vis-online { color: #34c759; border-color: #34c759; }
.vis-offline { color: #8e8e93; border-color: #8e8e93; }

.user-header-info { line-height: 1.2; margin-right: 15px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.sidebar-footer { margin-top: auto; padding: 20px; font-size: 11px; opacity: 0.6; text-align: center; border-top: 1px solid var(--glass-border); }
.sidebar-footer a { color: var(--text-main); text-decoration: none; transition: 0.2s; }
.sidebar-footer a:hover { color: var(--ios-blue); }
.developer-link { color: var(--ios-blue) !important; font-weight: bold; }

/* Mobile Responsive - FIXED SHADOW ISSUE HERE */
#mobileBtnContainer { display: none; position: fixed; top: 0; left: 0; height: 60px; width: 60px; z-index: 100000; align-items: center; justify-content: center; }
#mobileMenuBtn { font-size: 24px; color: var(--ios-blue); cursor: pointer; background: var(--sidebar-bg); padding: 5px; border-radius: 5px; }
#menuBackdrop { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 9000; backdrop-filter: blur(2px); }
/* =========================================================
   FIX FOR GHOST TEXT & SEND BUTTON (Apply to ALL screens)
   ========================================================= */

/* 1. Fix the Send Button (Remove grey box, make it an icon) */
#sendBtn {
    background: transparent;
    border: none;
    color: var(--ios-blue);
    font-size: 20px;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
    flex-shrink: 0; /* Prevents it from being crushed */
}

#sendBtn:hover {
    transform: scale(1.1);
}

/* 2. Fix the Ghost Text (Hide Reply Bar by default) */
.reply-preview-bar { 
    display: none; /* CRITICAL: Hides it until JS activates it */
    position: absolute; 
    bottom: 100%; /* Puts it right on top of the input bar */
    left: 0;
    width: 100%;
    background: var(--sidebar-bg); 
    border-top: 1px solid var(--glass-border); 
    padding: 10px 20px; 
    box-sizing: border-box;
    font-size: 13px; 
    align-items: center; 
    justify-content: space-between; 
    z-index: 5;
    backdrop-filter: blur(10px);
}

.reply-preview-content { 
    border-left: 3px solid var(--ios-blue); 
    padding-left: 10px; 
    color: var(--text-main); 
    opacity: 0.8; 
}

.reply-preview-close { 
    cursor: pointer; 
    color: var(--text-muted); 
    font-size: 16px; 
}

/* 3. Fix the "Is Typing" bubble position */
.typing-bubble-overlay { 
    position: absolute; 
    bottom: 80px; 
    left: 20px; 
    background: var(--card-bg); 
    padding: 6px 14px; 
    border-radius: 18px; 
    font-size: 11px; 
    color: var(--text-muted); 
    box-shadow: 0 4px 12px rgba(0,0,0,0.1); 
    display: none; /* CRITICAL: Hidden by default */
    align-items: center; 
    gap: 6px; 
    z-index: 50; 
    backdrop-filter: blur(10px); 
    border: 1px solid var(--glass-border); 
}

.typing-dots { display: flex; gap: 3px; }
.typing-dots span { 
    width: 4px; height: 4px; 
    background: var(--ios-blue); 
    border-radius: 50%; 
    display: inline-block; 
    animation: typingBounce 1.4s infinite ease-in-out both; 
}
@keyframes typingBounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }

/* =========================================================
   FIX FOR MENTION POPUP & GIANT AVATAR ISSUE
   ========================================================= */

/* 1. Style the Popup Box */
#mentionPopup {
    position: absolute;
    bottom: 80px; /* Puts it nicely above the text input */
    left: 20px;
    width: 250px;
    max-height: 200px;
    background: var(--card-bg); /* Matches your theme */
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    overflow-y: auto;
    display: none; /* Hidden by default */
    z-index: 10000; /* Ensures it sits ON TOP of everything */
    box-shadow: 0 -5px 30px rgba(0,0,0,0.2);
    backdrop-filter: blur(15px);
}

/* 2. Style the List Items */
.mention-item {
    padding: 10px 15px;
    display: flex;
    align-items: center;
    cursor: pointer;
    border-bottom: 1px solid var(--glass-border);
    transition: 0.2s;
    color: var(--text-main);
}

.mention-item:hover {
    background: var(--ios-blue);
    color: white;
}

/* 3. CRITICAL FIX: Shrink the Profile Image */
.mention-avatar {
    width: 30px !important;   /* Forces the image to be small */
    height: 30px !important;
    border-radius: 50%;       /* Makes it a circle */
    margin-right: 10px;
    object-fit: cover;        /* Crops it neatly */
    flex-shrink: 0;           /* Prevents it from disappearing */
}
/* =========================================================
   FIX FOR COMMUNITY POLL STYLES (Apply to Desktop too)
   ========================================================= */

.poll-card { 
    background: transparent; 
    padding: 5px; 
    width: 100%;
    box-sizing: border-box;
}

.poll-opt { 
    position: relative; 
    margin-bottom: 8px; 
    cursor: pointer; 
    height: 40px; 
    border-radius: 8px; 
    overflow: hidden; 
    background: rgba(128,128,128,0.1); 
    border: 1px solid transparent; 
    transition: 0.2s; 
}

.poll-bar { 
    position: absolute; 
    left: 0; 
    top: 0; 
    bottom: 0; 
    background: rgba(0, 122, 255, 0.2); 
    transition: width 0.5s ease; 
    z-index: 1; 
}

.poll-txt { 
    position: relative; 
    z-index: 2; 
    padding: 0 15px; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    height: 100%; 
    font-size: 14px; 
    font-weight: 500; 
    color: var(--text-main); 
}

.poll-opt:hover { 
    background: rgba(128,128,128,0.15); 
}

.voted-here { 
    border-color: var(--ios-blue); 
    background: rgba(0, 122, 255, 0.05); 
}

.voted-here .poll-bar { 
    background: rgba(0, 122, 255, 0.3); 
}
@media (max-width: 768px) { 
    .sidebar { 
        position: fixed; top: 0; left: 0; bottom: 0; width: 80%; max-width: 300px; 
        z-index: 9999; transform: translateX(-100%); 
        
        /* FIX: Removed box-shadow here so it doesn't show when closed */
        box-shadow: none; 
        transition: transform 0.3s ease; 
    }
    .sidebar.open { 
        transform: translateX(0); 
        /* FIX: Added box-shadow here so it only shows when open */
        box-shadow: 10px 0 50px rgba(0,0,0,0.5); 
    }
    
    #mobileBtnContainer { display: flex; } 
    .chat-header { padding-left: 60px; } 
    .header-desc-text { display: none; }
    .vis-btn span { display: inline-block; }
    .vis-btn i { margin-right: 6px !important; } 
    /* .chat-input-area rule removed from here to be handled by bottom fix */
}

/* Scroll Button (Specific override for this page) */
#scrollDownBtn {
    display: none;
    position: absolute;
    bottom: 90px;
    right: 25px;
    width: 45px;
    height: 45px;
    background-color: var(--scroll-btn-bg);
    color: white;
    border-radius: 50%;
    border: none;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    cursor: pointer;
    z-index: 100;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: transform 0.2s;
}
#scrollDownBtn:hover { transform: scale(1.1); }

/* --- SIDEBAR USER LIST --- */
.user-list { flex: 1; overflow-y: auto; padding: 10px; }
.user-list-item { 
    display: flex; align-items: center; padding: 10px; 
    border-radius: 12px; cursor: pointer; transition: background 0.2s;
    color: var(--text-main); text-decoration: none;
}
.user-list-item:hover { background: rgba(128,128,128,0.1); }
.u-avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; margin-right: 12px; border: 1px solid var(--glass-border); }
.u-info { flex: 1; }
.u-name { font-weight: 600; font-size: 14px; display: block; }
.u-role { font-size: 11px; opacity: 0.6; text-transform: uppercase; }

/* =========================================
   3. ADMIN DASHBOARD STYLES (NEW)
   (Applied ONLY when body has class "admin-body")
   ========================================= */

/* Override fixed layout for Admin Panel so it scrolls */
body.admin-body {
    height: auto !important; 
    min-height: 100vh !important;
    overflow-y: auto !important;
    padding: 20px;
    padding-bottom: 80px;
}

.admin-container { max-width: 1200px; margin: 0 auto; }
.header-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.header-actions { display: flex; align-items: center; gap: 15px; }
.back-btn { background: var(--sidebar-bg); color: var(--ios-blue); padding: 8px 15px; border-radius: 20px; text-decoration: none; font-weight: 600; font-size: 14px; border: 1px solid var(--glass-border); transition: 0.2s; }

/* Stats Grid */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 15px; margin-bottom: 25px; }
.stat-card { background: var(--sidebar-bg); padding: 20px; border-radius: 16px; border: 1px solid var(--glass-border); text-align: center; box-shadow: 0 4px 15px rgba(0,0,0,0.05); }
.stat-num { font-size: 32px; font-weight: 700; color: var(--ios-blue); display: block; margin-bottom: 5px; }
.stat-label { font-size: 13px; text-transform: uppercase; font-weight: 600; opacity: 0.6; letter-spacing: 0.5px; }

/* Tabs (Scrollable Mobile Menu Fix) */
.segmented-control { 
    display: flex; 
    background: rgba(128,128,128,0.15); 
    padding: 4px; 
    border-radius: 12px; 
    margin-bottom: 25px; 
    
    /* SCROLL FIXES */
    overflow-x: auto; /* Enable horizontal scrolling */
    white-space: nowrap; /* Prevent buttons from wrapping to a new line */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iPhone */
    
    /* HIDE SCROLLBAR (Clean Look) */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
}

/* Hide Webkit Scrollbar */
.segmented-control::-webkit-scrollbar {
    display: none;
}

.tab-btn { 
    flex: 0 0 auto; /* Stop buttons from shrinking */
    min-width: auto; /* Allow them to be their natural size */
    padding: 10px 15px; 
    border: none; 
    background: transparent; 
    color: var(--text-main); 
    font-weight: 600; 
    font-size: 14px; 
    cursor: pointer; 
    border-radius: 8px; 
    transition: all 0.2s; 
    opacity: 0.7; 
}

.tab-btn.active { 
    background: var(--bg-color); 
    box-shadow: 0 2px 8px rgba(0,0,0,0.15); 
    opacity: 1; 
    color: var(--ios-blue); 
}

.tab-content { display: none; animation: fadeIn 0.3s ease; }
.tab-content.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

/* Section Cards */
.section-card { background: var(--sidebar-bg); border-radius: 20px; padding: 25px; margin-bottom: 25px; border: 1px solid var(--glass-border); position: relative; }
.section-title { margin-top: 0; font-size: 18px; margin-bottom: 20px; display: flex; align-items: center; gap: 10px; opacity: 0.9; }

/* Form Elements (Admin Specific) */
.admin-body input, .admin-body textarea, .admin-body select { width: 100%; padding: 12px; border-radius: 10px; border: 1px solid var(--glass-border); background: var(--input-bg); color: var(--text-main); font-family: inherit; box-sizing: border-box; outline: none; margin-bottom: 10px; }

/* Buttons */
.btn-action { 
    background: var(--ios-blue); color: white; border: none; 
    padding: 0 20px; border-radius: 10px; font-weight: 600; cursor: pointer; 
    display: inline-flex; align-items: center; justify-content: center;
    height: 40px; min-width: 100px; font-size: 14px; transition: opacity 0.2s;
    text-decoration: none; box-sizing: border-box;
}
.btn-action:hover { opacity: 0.8; }
.btn-danger { background: #ff3b30; }
.btn-backup { background: #af52de; color: white; border: none; padding: 10px 20px; border-radius: 10px; font-weight: 600; cursor: pointer; text-decoration: none; font-size: 13px; display: inline-block; }

.control-row { display: flex; justify-content: space-between; align-items: center; padding: 15px 0; border-bottom: 1px solid var(--glass-border); }
.control-row:last-child { border-bottom: none; }

/* Tables */
.table-responsive { overflow-x: auto; }
.user-table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 800px; }
.user-table th { text-align: left; padding: 10px; border-bottom: 2px solid var(--glass-border); opacity: 0.6; font-size: 12px; text-transform: uppercase; }
.user-table td { padding: 12px 10px; border-bottom: 1px solid var(--glass-border); vertical-align: middle; }
.user-avatar-small { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; margin-right: 12px; vertical-align: middle; background: #fff; }
.user-ip { font-family: monospace; font-size: 12px; color: var(--ios-blue); background: rgba(0,122,255,0.1); padding: 2px 6px; border-radius: 4px; }

/* Pills */
.btn-pill { display: inline-flex; align-items: center; gap: 5px; padding: 6px 12px; border-radius: 20px; text-decoration: none; font-size: 11px; font-weight: 700; color: white; margin-right: 5px; margin-bottom: 5px; transition: 0.2s; }
.btn-pill:hover { opacity: 0.8; }
.pill-green { background: #34c759; }
.pill-orange { background: #ff9500; }
.pill-blue { background: #007aff; }
.pill-purple { background: #af52de; }
.pill-red { background: #ff3b30; }
.pill-grey { background: #8e8e93; }
.pill-dark { background: #333; }

/* Modal Override */
.modal { display: none; position: fixed; z-index: 9999; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); backdrop-filter: blur(5px); }
.modal-content { background: var(--sidebar-bg); margin: 15% auto; padding: 25px; border: 1px solid var(--glass-border); width: 90%; max-width: 400px; border-radius: 20px; color: var(--text-main); }
.close-modal { float: right; font-size: 24px; cursor: pointer; }

@media (max-width: 600px) {
    .control-row { flex-direction: column; align-items: flex-start; gap: 10px; }
    .btn-action { width: 100%; }
}

/* Logs Page Specifics */
.log-window { background: #1e1e1e; color: #00ff00; padding: 20px; border-radius: 10px; height: 600px; overflow-y: auto; font-family: 'Courier New', monospace; font-size: 13px; box-shadow: 0 4px 12px rgba(0,0,0,0.2); border: 1px solid #333; }
.log-entry { padding: 5px 0; border-bottom: 1px solid #333; white-space: pre-wrap; }
.error-type { color: #ff3b30; font-weight: bold; }

/* =========================================
   4. ADVANCED LOGIN & REGISTER STYLES (NEW)
   ========================================= */
.login-body {
    margin: 0; height: 100dvh; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    background-color: #f0f2f5; 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-repeat: no-repeat; background-position: center center; background-size: cover; background-attachment: fixed;
}
.login-overlay { content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0, 0.35); z-index: 0; pointer-events: none; }

.login-card {
    position: relative; z-index: 10;
    backdrop-filter: blur(15px); -webkit-backdrop-filter: blur(15px);
    padding: 45px 40px; border-radius: 24px; width: 90%; max-width: 380px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25); text-align: center;
    border: 1px solid rgba(255,255,255,0.4);
    background: rgba(255, 255, 255, 0.95); /* Default fallback */
}

.brand-logo { max-height: 80px; margin-bottom: 20px; display: block; margin-left: auto; margin-right: auto; }
.login-card h2 { margin: 0 0 10px; font-size: 26px; color: #1a1a1a; letter-spacing: -0.5px; }
.login-card p { margin: 0 0 30px; color: #666; font-size: 15px; line-height: 1.4; }

.login-input-group { position: relative; margin-bottom: 20px; text-align: left; }
.login-input-group i { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: #999; z-index: 2; }

.login-input {
    width: 100%; padding: 14px 15px 14px 45px;
    border: 2px solid transparent; background: rgba(240, 242, 245, 0.9);
    border-radius: 12px; font-size: 15px; outline: none;
    box-sizing: border-box; transition: 0.3s; color: #333;
}

.login-btn {
    width: 100%; padding: 14px; color: white; border: none;
    border-radius: 12px; font-size: 16px; font-weight: 600;
    cursor: pointer; transition: transform 0.2s, opacity 0.2s;
    box-shadow: 0 5px 15px rgba(0,0,0,0.15);
}
.login-btn:hover { transform: translateY(-2px); opacity: 0.9; }

.login-links { margin-top: 25px; font-size: 13px; display: flex; justify-content: space-between; }
.login-links a { color: #555; text-decoration: none; transition: 0.2s; font-weight: 500; }

.alert-error { background: #fee; color: #e33; padding: 12px; border-radius: 8px; margin-bottom: 20px; font-size: 14px; border: 1px solid #fcc; display:flex; align-items:center; gap:10px; text-align: left; }

.footer-text {
    position: relative; z-index: 10; margin-top: 30px; font-size: 12px;
    color: rgba(255,255,255,0.8); text-shadow: 0 1px 2px rgba(0,0,0,0.5); text-align: center;
}
.footer-text a { color: inherit; text-decoration: underline; }

/* Admin Design Page Preview */
.preview-box { height: 150px; background-size: cover; background-position: center; border-radius: 8px; margin-top: 10px; border: 2px solid var(--glass-border); display: flex; align-items: center; justify-content: center; color: var(--text-main); font-weight: bold; font-size: 18px; position: relative; overflow: hidden; background-color: var(--input-bg); }
.preview-box img { max-height: 100px; max-width: 90%; object-fit: contain; }

/* Unread Badge Style */
.unread-badge {
    background-color: #ff3b30;
    color: white;
    font-size: 10px;
    font-weight: bold;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    box-shadow: 0 2px 4px rgba(255, 59, 48, 0.4);
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    0% { transform: scale(0); }
    100% { transform: scale(1); }
}

/* YouTube Embed Styling - FIXED SIZE */
.yt-container {
    position: relative;
    width: 100%;
    min-width: 300px; /* <--- This forces the video to be big enough */
    max-width: 100%;  /* Allows it to fill the bubble */
    padding-bottom: 56.25%; /* Keeps the 16:9 aspect ratio */
    height: 0;
    margin-top: 10px;
    border-radius: 12px;
    overflow: hidden;
    background: #000;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

.yt-container iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
}

/* Mobile Tweak: Ensure it fits on small screens */
@media (max-width: 768px) {
    .yt-container {
        min-width: 260px; /* Slightly smaller for mobile phones */
    }
}

/* --- FIXED SIZE CHAT IMAGES --- */
.chat-media-img {
    display: block;
    max-width: 100%;  /* Ensure it doesn't overflow horizontally on mobile */
    max-height: 250px; /* THE KEY FIX: Limits height so it's not massive */
    width: auto;      /* Maintain aspect ratio */
    height: auto;     /* Maintain aspect ratio */
    border-radius: 12px;
    cursor: pointer;  /* Shows hand cursor indicating it's clickable */
    margin-top: 8px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1); /* Adds depth */
    transition: transform 0.2s ease, opacity 0.2s;
}

/* Optional: nice hover effect */
.chat-media-img:hover {
    transform: scale(1.02);
    opacity: 0.9;
}

/* ============================================================
   FINAL SYSTEM LAYOUT FIXES (CRITICAL)
   Placed at the bottom to override all previous conflicting rules
   ============================================================ */

/* --- DESKTOP FIX: Keep header at the top --- */
@media (min-width: 769px) {
    .chat-main .chat-header {
        position: sticky !important;
        top: 0 !important;
        z-index: 100;
    }
}

/* --- IPHONE 15 PRO MAX / MOBILE ONLY FIXES --- */
@media (max-width: 768px) {

    /* 1. LOCK THE BODY */
    html, body {
        height: 100dvh !important;
        width: 100% !important;
        overflow: hidden !important;
        position: fixed !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* 2. FORCE FLEX COLUMN */
    .main-container, .chat-main {
        display: flex !important;
        flex-direction: column !important;
        height: 100dvh !important;
        width: 100% !important;
        overflow: hidden !important;
    }

    /* 3. HAMBURGER: Highest Z-Index so it floats above the open sidebar */
    #mobileBtnContainer {
        position: fixed !important;
        top: calc(env(safe-area-inset-top) + 12px) !important;
        left: 15px !important;
        z-index: 10005 !important; /* Above the sidebar */
        display: flex !important;
        width: 40px !important;
        height: 40px !important;
    }

    /* 4. MAIN HEADER: Stays at the Top */
    .chat-main .chat-header {
        flex-shrink: 0 !important;
        position: relative !important;
        padding-top: env(safe-area-inset-top) !important;
        min-height: calc(env(safe-area-inset-top) + 60px) !important;
        padding-left: 60px !important; /* Space for hamburger */
        z-index: 10000;
        background: var(--sidebar-bg);
    }
    
    /* 5. SIDEBAR HEADER FIX: Move "ProChat" text right so the 'X' button doesn't overlap it */
    .sidebar .chat-header {
        padding-top: env(safe-area-inset-top) !important;
        min-height: calc(env(safe-area-inset-top) + 60px) !important;
        padding-left: 60px !important; /* Pushes text clear of the button */
        display: flex !important;
        align-items: center !important;
    }

    /* 6. MESSAGES: The ONLY thing that scrolls */
    .messages-display {
        flex: 1 !important;
        height: auto !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 20px !important;
    }

    /* 7. FOOTER: STRICT SYMMETRY (8px Top / 8px Bottom) */
    .chat-input-area {
        flex-shrink: 0 !important;
        position: relative !important;
        z-index: 10000;
        
        min-height: auto !important;
        
        /* STRICT 8px PADDING ON ALL SIDES */
        /* This removes the extra "Safe Area" spacing to make it visually symmetric */
        padding: 8px 10px !important;
        
        display: flex !important;
        align-items: center !important; 
        gap: 8px !important;
        
        background: var(--sidebar-bg) !important;
        border-top: 1px solid var(--glass-border);
        margin-bottom: 0 !important;
    }

    /* STYLE THE INPUT BOX (Like WhatsApp) */
    .chat-input-area textarea {
        border-radius: 18px !important;
        padding: 8px 12px !important;
        min-height: 36px !important; 
        max-height: 100px !important;
        border: 1px solid var(--glass-border) !important;
        background: var(--input-bg) !important;
        line-height: 1.3 !important;
        font-size: 16px !important; 
    }

    /* COMPACT ICONS */
    .action-icon {
        width: 32px !important;
        height: 36px !important;
        font-size: 20px !important;
        padding: 0 !important;
        margin: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    #sendBtn {
        width: 36px !important;
        height: 36px !important;
        padding: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    /* Ensure Sidebar sits between the content and the button */
    .sidebar {
        z-index: 10002 !important;
        padding-top: 0 !important; /* Header inside handles the spacing */
    }

    /* 8. ADMIN DASHBOARD UNLOCK */
    /* Release the "App Lock" so Admin pages can scroll normally */
    html:has(.admin-body), body.admin-body {
        height: auto !important;
        min-height: 100vh !important;
        width: 100% !important;
        overflow-y: auto !important; /* Re-enable scroll */
        position: static !important; /* Stop floating */
        -webkit-overflow-scrolling: touch !important;
    }
    
    /* GALLERY & MODAL FIXES FROM CHAT.PHP MERGED */
    .gallery-drawer { position: fixed; top: 0; right: -320px; width: 320px; height: 100%; background: var(--sidebar-bg); border-left: 1px solid var(--glass-border); z-index: 9001; transition: right 0.3s ease; display: flex; flex-direction: column; box-shadow: -10px 0 30px rgba(0,0,0,0.1); }
    .gallery-drawer.open { right: 0; }
    .gallery-header { padding: 20px; border-bottom: 1px solid var(--glass-border); display: flex; justify-content: space-between; align-items: center; }
    .gallery-content { flex: 1; overflow-y: auto; }
    .gallery-item:hover { transform: scale(1.05); transition: transform 0.2s; }
    .emoji-picker-popup span { font-size: 20px; cursor: pointer; margin: 0 4px; transition: transform 0.2s; }
    .emoji-picker-popup span:hover { transform: scale(1.3); }
    .reply-preview-bar { display: none; background: var(--card-bg); border-top: 1px solid var(--glass-border); padding: 8px 15px; font-size: 12px; align-items: center; justify-content: space-between; }
    .reply-preview-content { border-left: 3px solid var(--ios-blue); padding-left: 10px; color: var(--text-main); opacity: 0.8; }
    .reply-preview-close { cursor: pointer; color: var(--text-muted); font-size: 14px; }
    .reaction-bar div:hover { background: rgba(255,255,255,0.4) !important; }
    .mic-active { color: #ff3b30 !important; animation: pulse 1s infinite; }
    @keyframes pulse { 0% { transform: scale(1); } 50% { transform: scale(1.2); } 100% { transform: scale(1); } }
    .wave-bar { transition: height 0.1s ease; }
    .playing-wave .wave-bar { animation: waveAnim 0.5s infinite ease-in-out; }
    @keyframes waveAnim { 0% { height: 30%; } 50% { height: 100%; } 100% { height: 30%; } }
    .wave-bar:nth-child(odd) { animation-duration: 0.4s; }
    .wave-bar:nth-child(even) { animation-duration: 0.6s; }
    
    .typing-bubble-overlay { position: absolute; bottom: 85px; left: 20px; background: var(--card-bg); padding: 6px 14px; border-radius: 18px; font-size: 11px; color: var(--text-muted); box-shadow: 0 4px 12px rgba(0,0,0,0.1); display: none; align-items: center; gap: 6px; z-index: 50; backdrop-filter: blur(10px); border: 1px solid var(--glass-border); animation: slideUpFade 0.3s ease; }
    @keyframes slideUpFade { from { opacity:0; transform:translateY(10px); } to { opacity:1; transform:translateY(0); } }
    .typing-dots { display: flex; gap: 3px; }
    .typing-dots span { width: 4px; height: 4px; background: var(--ios-blue); border-radius: 50%; display: inline-block; animation: typingBounce 1.4s infinite ease-in-out both; }
    .typing-dots span:nth-child(1) { animation-delay: -0.32s; }
    .typing-dots span:nth-child(2) { animation-delay: -0.16s; }
    @keyframes typingBounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }
    
    .poll-card { background: var(--card-bg); padding: 5px; }
    .poll-q { font-weight: 600; margin-bottom: 12px; display: block; color: var(--text-main); font-size: 15px; }
    .poll-opt { position: relative; margin-bottom: 8px; cursor: pointer; height: 36px; border-radius: 8px; overflow: hidden; background: rgba(0,0,0,0.04); border: 1px solid transparent; transition: 0.2s; }
    .poll-bar { position: absolute; left: 0; top: 0; bottom: 0; background: rgba(0, 122, 255, 0.15); transition: width 0.5s ease; z-index: 1; }
    .poll-txt { position: relative; z-index: 2; padding: 0 12px; display: flex; justify-content: space-between; align-items: center; height: 100%; font-size: 13px; font-weight: 500; color: var(--text-main); }
    .poll-opt:hover { background: rgba(0,0,0,0.08); }
    .voted-here { border-color: var(--ios-blue); background: rgba(0, 122, 255, 0.05); }
    .voted-here .poll-bar { background: rgba(0, 122, 255, 0.3); }

    .mention-popup {
        position: absolute; bottom: 85px; left: 20px; width: 220px;
        max-height: 200px; background: var(--card-bg); border: 1px solid var(--glass-border);
        border-radius: 12px; overflow-y: auto; display: none; z-index: 1000;
        box-shadow: 0 -5px 30px rgba(0,0,0,0.2); backdrop-filter: blur(15px);
    }
    .mention-item { padding: 12px; display: flex; align-items: center; cursor: pointer; border-bottom: 1px solid var(--glass-border); transition: 0.2s; }
    .mention-item:last-child { border-bottom: none; }
    .mention-item:hover { background: var(--ios-blue); color: white; }
    .mention-avatar { width: 24px; height: 24px; border-radius: 50%; margin-right: 10px; object-fit: cover; }
}