:root {
    --primary: #4CAF50; /* ICQ Green */
    --secondary: #FFC107; /* Status Yellow */
    --danger: #F44336; /* Offline Red */
    --bg-light: #f5f5f5;
    --text-dark: #333;
    --bubble-sent: #DCF8C6;
    --bubble-received: #ffffff;
    --chat-bg: #e5ddd5;
}

* {
    box-sizing: border-box;
}

body, html {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    /* Darker body background to frame the app */
    background: #dcdcdc;
    height: 100%;
    overflow: hidden;
    display: flex;
    justify-content: center; /* Center app horizontally */
}

/* --- Login --- */
#login-screen {
    position: fixed; /* Force full screen overlay */
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #4CAF50, #8BC34A);
    z-index: 2000; /* Above everything */
}

.login-box {
    background: white;
    padding: 2rem;
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    text-align: center;
    width: 300px;
}

.flower-logo {
    width: 60px;
    height: 60px;
    margin: 0 auto 1rem;
    position: relative;
}

.flower-logo .petal {
    width: 20px;
    height: 20px;
    background: var(--primary);
    border-radius: 50%;
    position: absolute;
}
/* Simplified pseudo flower */
.flower-logo .petal:nth-child(1) { top: 0; left: 20px; background: #E91E63; }
.flower-logo .petal:nth-child(2) { top: 10px; left: 38px; background: #FFC107; }
.flower-logo .petal:nth-child(3) { top: 30px; left: 38px; background: #8BC34A; }
.flower-logo .petal:nth-child(4) { top: 40px; left: 20px; background: #00BCD4; }
.flower-logo .petal:nth-child(5) { top: 30px; left: 2px; background: #3F51B5; }
.flower-logo .petal:nth-child(6) { top: 10px; left: 2px; background: #9C27B0; }
.flower-logo .center { 
    width: 16px; height: 16px; 
    background: white; 
    border-radius: 50%; 
    position: absolute; 
    top: 22px; left: 22px; 
}

.login-box input {
    width: 100%;
    padding: 10px;
    margin: 10px 0;
    border: 1px solid #ddd;
    border-radius: 5px;
    box-sizing: border-box;
}

.login-box button {
    width: 100%;
    padding: 10px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
}

.login-box button:hover {
    background: #388E3C;
}

/* --- Main App (DESKTOP FIRST) --- */
#main-app {
    display: none;
    height: 100vh;
    width: 100vw;
    background: #e5ddd5; /* Default fallback */
    overflow: hidden;
    /* Force side-by-side layout on desktop */
    flex-direction: row !important; 
    
    /* Limit max width on very large screens */
    max-width: 1400px; /* Max width for the whole app */
    box-shadow: 0 0 20px rgba(0,0,0,0.2); /* Shadow around app */
}

#main-app.active {
    display: flex; /* This makes it visible */
}

/* Sidebar is fixed width on desktop */
.sidebar {
    width: 300px;
    min-width: 300px;
    background: rgba(255, 255, 255, 0.4); /* Much more transparent */
    backdrop-filter: blur(20px); /* Stronger blur for readability */
    border-right: 1px solid rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    position: static; 
    transform: none !important;
}

/* Chat area takes remaining space */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: transparent; /* Totally clear */
    position: relative;
    transform: none !important;
}

/* --- Sidebar Content --- */
#admin-btn {
    cursor: pointer;
    background: none;
    border: none;
    font-size: 1.4rem;
    padding: 5px;
    margin-right: 5px;
}
#admin-btn:hover { transform: scale(1.1); }

.user-profile {
    padding: 15px;
    background: rgba(255, 255, 255, 0.2); /* Very subtle */
    display: flex;
    align-items: center;
    border-bottom: 1px solid rgba(0,0,0,0.1);
}

.avatar {
    width: 40px;
    height: 40px;
    background: #ccc;
    border-radius: 50%;
    margin-right: 10px;
    background-size: cover;
    cursor: pointer; /* Click to edit profile */
}
.avatar:hover { opacity: 0.8; }

.icon-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
}

.logout-btn { margin-left: auto; }

.contact-list { flex: 1; overflow-y: auto; }

.contact-item {
    padding: 10px 15px;
    display: flex;
    align-items: center;
    cursor: pointer;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    transition: background 0.2s;
    position: relative; /* For absolute status dot */
}

.contact-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: #ccc;
    background-size: cover;
    background-position: center;
    margin-right: 12px;
    flex-shrink: 0;
}

/* Mini status dot overlay on avatar in list */
.contact-status-mini {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    position: absolute;
    left: 45px; /* avatar width + padding - overlap */
    top: 35px;
    border: 2px solid white;
    z-index: 2;
}
.contact-status-mini.online { background: var(--primary); }
.contact-status-mini.offline { background: #999; }
.contact-status-mini.away { background: var(--secondary); }

/* Hide old standalone status if present, or repurposed above */
.contact-status { display: none; }

/* Hide old standalone status if present, or repurposed above */
.contact-status { display: none; }

.contact-item:hover { background: rgba(0,0,0,0.05); }
.contact-item.active { background: rgba(0,0,0,0.1); }

/* Remove old contact-status block if it exists below */

.contact-info {
    flex: 1;
}
.contact-uin {
    font-size: 0.7rem;
    color: #666;
    display: flex;
    justify-content: space-between;
}
.contact-status-msg {
    font-size: 0.75rem;
    color: #555;
    font-style: italic;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
}
/* Reply Preview (above input) */
.reply-preview {
    display: none;
    background: rgba(255,255,255,0.8);
    border-left: 4px solid var(--primary);
    padding: 8px;
    margin: 0 10px;
    border-radius: 4px 4px 0 0;
    font-size: 0.85rem;
    color: #555;
    position: relative;
    max-width: 700px; /* same as input wrapper */
}
.reply-preview.active { display: block; }
.reply-preview-content {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.reply-close {
    position: absolute;
    right: 5px;
    top: 5px;
    cursor: pointer;
    font-weight: bold;
}

/* Quoted Message (in chat) */
.quoted-message {
    background: rgba(0,0,0,0.05);
    border-left: 3px solid var(--primary);
    padding: 5px;
    margin-bottom: 5px;
    border-radius: 4px;
    font-size: 0.8rem;
    color: #444;
    cursor: pointer;
}

/* Link Preview Card */
.link-preview {
    margin-top: 5px;
    border: 1px solid rgba(0,0,0,0.1);
    background: rgba(255,255,255,0.5);
    border-radius: 5px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-width: 300px;
    text-decoration: none;
    color: inherit;
    transition: background 0.2s;
}
.link-preview:hover { background: rgba(255,255,255,0.8); }
.lp-image {
    width: 100%;
    height: 120px;
    background-size: cover;
    background-position: center;
}
.lp-content { padding: 8px; }
.lp-title { font-weight: bold; font-size: 0.9rem; margin-bottom: 4px; display:block;}
.lp-desc { font-size: 0.75rem; color: #666; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lp-site { font-size: 0.7rem; color: #888; margin-top: 5px; text-transform: uppercase; }

/* Markdown Styles */
.md-bold { font-weight: bold; }
.md-italic { font-style: italic; }
.md-code { 
    background: rgba(0,0,0,0.1); 
    padding: 2px 4px; 
    border-radius: 3px; 
    font-family: monospace; 
    font-size: 0.9em;
}

/* Context Menu for Messages */
.msg-context-menu {
    position: absolute;
    background: white;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    border-radius: 5px;
    padding: 5px 0;
    z-index: 1000;
    display: none;
}
.msg-context-menu div {
    padding: 8px 15px;
    cursor: pointer;
    font-size: 0.9rem;
}
.msg-context-menu div:hover { background: #eee; }

/* --- Unread Badge --- */
.contact-info {
    flex: 1;
}
.contact-uin {
    font-size: 0.7rem;
    color: #666;
}

.unread-badge {
    background: #FF5722;
    color: white;
    border-radius: 50%;
    padding: 2px 6px;
    font-size: 0.75rem;
    font-weight: bold;
    min-width: 14px;
    text-align: center;
    margin-left: 5px;
    display: none; /* Hidden by default */
}
.unread-badge.active {
    display: inline-block;
}

/* --- Chat Area --- */
.chat-header {
    padding: 10px 15px;
    background: rgba(237, 237, 237, 0.9); /* Glass effect header */
    backdrop-filter: blur(5px);
    border-bottom: 1px solid rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    height: 60px;
}

.chat-contact-info {
    display: flex;
    align-items: center;
    flex: 1;
    overflow: hidden;
}

.chat-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: #ccc;
    background-size: cover;
    background-position: center;
    margin-right: 10px;
    border: 2px solid white;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

/* Status dot positioning relative to avatar if desired, or kept separate */
#chat-status {
    /* If we want the dot ON the avatar, we need relative positioning. 
       Currently it's a span next to it. Let's keep it simple for now or adjust. */
    margin-right: 10px;
    display: none; /* Hide old standalone dot if we integrate it or just keep it */
}
/* Let's actually keep the status dot but maybe make it smaller or overlapping */
.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: #ccc;
    border: 2px solid white;
    /* Overlap logic */
    margin-left: -20px; 
    margin-top: 25px;
    margin-right: 10px;
    z-index: 2;
}
.status-dot.online { background-color: var(--primary); }
.status-dot.offline { background-color: var(--danger); }

.header-details {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    white-space: nowrap;
    margin-right: 10px;
}

#chat-title {
    margin: 0;
    font-size: 1.1rem;
    font-weight: bold;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-subtitle {
    font-size: 0.8rem;
    color: #666;
    font-style: italic;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 300px; /* Prevent header overflow */
}

.back-btn {
    display: none; /* Hidden on Desktop */
    background: none;
    border: none;
    font-size: 2rem;
    margin-right: 15px;
    cursor: pointer;
    color: var(--primary);
    padding: 5px 10px;
}

.messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    
    /* Limit width for better readability on large screens */
    max-width: 700px; /* Compact chat width */
    width: 100%;
    margin: 0 auto; /* Center it */
    
    /* Subtle frame/shadow to distinguish from background */
    background: rgba(255, 255, 255, 0.15); /* Very faint white tint */
    box-shadow: 0 0 15px rgba(0,0,0,0.05); /* Soft shadow */
    border-radius: 8px; /* Rounded corners */
    margin-top: 10px; /* Spacing from header */
    margin-bottom: 10px; /* Spacing from input */
}

.message {
    max-width: 70%;
    padding: 8px 12px;
    border-radius: 7px;
    position: relative;
    word-wrap: break-word;
    font-size: 0.95rem;
    line-height: 1.4;
    cursor: default; /* Remove default text cursor */
    user-select: text; /* Allow text selection */
}
.message:hover .msg-actions { opacity: 1; }

.msg-actions {
    position: absolute;
    top: -10px;
    right: 5px;
    background: white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    border-radius: 10px;
    padding: 2px 5px;
    opacity: 0;
    transition: opacity 0.2s;
    font-size: 0.8rem;
    display: flex;
    gap: 5px;
}
.msg-action-btn { cursor: pointer; color: #555; }
.msg-action-btn:hover { color: var(--primary); }

.message.sent {
    align-self: flex-end;
    background: var(--bubble-sent);
    border-bottom-right-radius: 0;
}

.message.received {
    align-self: flex-start;
    background: var(--bubble-received);
    border-bottom-left-radius: 0;
    box-shadow: 0 1px 1px rgba(0,0,0,0.1);
}

.message img {
    max-width: 100%;
    border-radius: 5px;
    margin-top: 5px;
}

.timestamp {
    font-size: 0.7rem;
    color: #999;
    text-align: right;
    display: block;
    margin-top: 4px;
}

/* --- Copy Icon --- */
.copy-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.2s, transform 0.1s;
    margin-left: 5px;
    vertical-align: middle;
}

.copy-icon:hover {
    opacity: 1;
    transform: scale(1.1);
}

.copy-icon:active {
    transform: scale(0.95);
}

.copy-icon.copied {
    color: var(--primary);
    opacity: 1;
    animation: bounce 0.3s;
}

@keyframes bounce {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.3); }
}

/* --- Code Blocks --- */
.code-block {
    background: #2d2d2d;
    color: #f8f8f2;
    padding: 10px;
    border-radius: 5px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.9rem;
    overflow-x: auto;
    white-space: pre;
    margin: 5px 0;
    box-shadow: inset 0 0 5px rgba(0,0,0,0.5);
}
.code-block code {
    font-family: inherit;
}

/* --- Input Area --- */
.input-area {
    padding: 10px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom)); /* iPhone Safe Area */
    background: rgba(255, 255, 255, 0.3); /* Transparent */
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(0,0,0,0.1);
    display: flex;
    justify-content: center; /* Center content */
    flex-direction: column; /* Stack reply preview */
    align-items: center; /* Center both reply and input */
}

/* Reply Preview (above input) */
.reply-preview {
    width: 100%;
    max-width: 700px;
    box-sizing: border-box;
    display: none; /* hidden by default */
    background: rgba(255,255,255,0.9);
    border-left: 4px solid var(--primary);
    padding: 8px 30px 8px 10px; /* Right padding for close btn */
    border-radius: 5px 5px 0 0; /* Attach to input */
    position: relative;
    font-size: 0.85rem;
    color: #444;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-shadow: 0 -2px 5px rgba(0,0,0,0.05);
    margin-bottom: -1px; /* Connect visually */
    z-index: 10;
}
.reply-preview.active { display: block; }

.reply-close {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    font-weight: bold;
    color: #888;
}
.reply-close:hover { color: #000; }

/* Inner wrapper for input to limit width */
.input-wrapper {
    display: flex;
    align-items: flex-end; /* Align to bottom as text area grows */
    gap: 10px;
    max-width: 700px; /* Match messages width */
    width: 100%;
}

.input-area textarea {
    flex: 1;
    padding: 10px;
    background: rgba(255, 255, 255, 0.7); /* Slightly more opaque for typing */
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 20px;
    resize: none;
    min-height: 40px;
    height: 40px; /* Base height */
    max-height: 120px; /* Expand up to 5 lines */
    overflow-y: auto;
    font-family: inherit;
    outline: none;
}
.input-area textarea:focus {
    background: white; /* Full white when typing */
    box-shadow: 0 0 5px rgba(0,0,0,0.1);
}

.send-btn, .attach-btn, .code-btn, .md-btn {
    background: none;
    margin-bottom: 8px; /* Align with bottom of textarea */
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--primary);
    padding: 0 5px;
    line-height: 1;
}

.md-btn {
    font-size: 1.1rem;
    color: #555;
    padding: 2px 5px;
    border-radius: 4px;
}
.md-btn:hover { background: rgba(0,0,0,0.05); }

.attach-btn { color: #666; font-size: 1.5rem; }
.code-btn { color: #444; font-weight: bold; font-family: monospace; font-size: 1.2rem; border: 1px solid #ccc; border-radius: 5px; padding: 2px 5px; }
.code-btn:hover { background: #eee; }

/* --- Profile Modal --- */
.profile-section {
    margin-bottom: 20px;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
}
.profile-section label {
    font-weight: bold;
    display: block;
    margin-bottom: 5px;
    color: #444;
}
/* Toggle Switch Wrapper */
.toggle-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}
/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 20px;
    vertical-align: middle;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 20px;
}
.slider:before {
    position: absolute;
    content: "";
    height: 16px; width: 16px;
    left: 2px; bottom: 2px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}
input:checked + .slider { background-color: var(--primary); }
input:checked + .slider:before { transform: translateX(20px); }

/* --- Modals (Admin & Profile) --- */
.modal {
    display: none; 
    position: fixed; 
    z-index: 100; 
    left: 0; top: 0; width: 100%; height: 100%; 
    background-color: rgba(0,0,0,0.5); 
    overflow-y: auto; /* Allow scrolling the backdrop if needed */
}

.modal-content {
    background-color: #fefefe;
    margin: 20px auto; /* Reduced from 5% or 10% to fit on smaller screens */
    padding: 20px;
    border: 1px solid #888;
    width: 90%;
    max-width: 500px;
    border-radius: 8px;
    position: relative;
    max-height: 85vh; /* Ensure it fits in viewport */
    overflow-y: auto; /* Scroll inside the modal content */
    display: flex;
    flex-direction: column;
}

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}
.close:hover { color: black; }

.admin-controls, .profile-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid #eee;
}

.admin-controls input, .profile-controls input, .profile-controls select {
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
}

.admin-controls button, .profile-controls button {
    padding: 10px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

#user-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

#user-list li {
    display: flex;
    justify-content: space-between;
    padding: 10px;
    border-bottom: 1px solid #eee;
}

/* Background Selector Grid */
.bg-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 5px;
    margin: 10px 0;
    max-height: 300px; /* Double height */
    overflow-y: auto;
    border: 1px solid #eee;
    padding: 5px;
}
.bg-option {
    width: 100%;
    padding-bottom: 100%; /* square */
    border-radius: 5px;
    cursor: pointer;
    border: 2px solid transparent;
}
.bg-option.selected { border-color: black; }

/* --- Toast Notification --- */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #333;
    color: white;
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    animation: slideIn 0.3s ease-out;
    max-width: 300px;
}
.toast.hide {
    animation: slideOut 0.3s ease-in forwards;
}
@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
@keyframes slideOut {
    to { transform: translateX(100%); opacity: 0; }
}
.toast-avatar {
    width: 30px; height: 30px; border-radius: 50%; background: #ccc;
}

/* --- MOBILE ONLY (Override Desktop) --- */
@media (max-width: 768px) {
    #main-app {
        max-width: 100%;
        height: 100vh;
        margin: 0;
        box-shadow: none;
    }

    .sidebar {
        width: 100%;
        position: absolute;
        z-index: 10;
        height: 100%;
        left: 0; top: 0;
        transform: translateX(0);
        transition: transform 0.3s ease;
    }

    .chat-area {
        width: 100%;
        position: absolute;
        height: 100%;
        left: 0; top: 0;
        transform: translateX(100%);
        transition: transform 0.3s ease;
    }

    .messages {
        max-width: 100%;
    }

    .input-wrapper {
        max-width: 100%;
    }

    /* When chat is open, slide sidebar OUT and chat IN */
    .chat-open .sidebar {
        transform: translateX(-100%) !important;
    }

    .chat-open .chat-area {
        transform: translateX(0) !important;
    }

    /* Show back button only on mobile */
    .back-btn {
        display: block !important;
    }
}

/* WebRTC Video Overlay */
#video-call-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.95);
    z-index: 3000;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

.video-container {
    position: relative;
    width: 100%;
    max-width: 1280px;
    height: 80vh;
    background: #000;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 0 20px rgba(255,255,255,0.1);
}

#remote-video {
    width: 100%;
    height: 100%;
    object-fit: contain; /* Don't crop, show full video */
    background: #222;
}

/* Audio-only indicator */
.audio-only-placeholder {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    font-size: 5rem;
    color: #555;
    display: none; /* Show via JS when video is off */
}

#local-video {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 180px;
    height: 135px; /* 4:3 aspect */
    object-fit: cover;
    border-radius: 8px;
    border: 2px solid white;
    background: #333;
    z-index: 10;
    transition: all 0.3s ease;
    cursor: grab;
}
#local-video:hover { transform: scale(1.05); }

.call-controls {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 20px;
    z-index: 20;
    background: rgba(0,0,0,0.5);
    padding: 15px 30px;
    border-radius: 50px;
    backdrop-filter: blur(5px);
}

.control-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    background: rgba(255,255,255,0.2);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.control-btn:hover { background: rgba(255,255,255,0.4); }
.control-btn.active { background: white; color: black; } /* Toggle state */
.hangup-btn { background: #F44336; }
.hangup-btn:hover { background: #D32F2F; }

/* Call Alert Modal */
.call-alert {
    text-align: center;
    border-top: 5px solid var(--primary);
}
.call-alert h3 { margin-top: 0; }
.call-actions {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 20px;
}
.accept-btn, .reject-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    font-weight: bold;
    cursor: pointer;
    font-size: 1rem;
    color: white;
}
.accept-btn { background: var(--primary); }
.reject-btn { background: #F44336; }

/* Mobile Adjustments */
@media (max-width: 768px) {
    .video-container {
        width: 100%;
        height: 100%;
        border-radius: 0;
    }
    #local-video {
        width: 100px;
        height: 75px;
        bottom: 100px; /* Above controls */
        right: 10px;
    }
    .call-controls {
        bottom: 30px;
        width: 80%;
        justify-content: space-around;
    }
}

@media (max-width: 768px) {
    /* Prevent messages from hugging edges or overflowing */
    .messages {
        padding: 10px;
        gap: 8px;
    }
    
    .message {
        max-width: 85%; /* Use more width on mobile */
        font-size: 1rem;
    }

    .message.sent {
        margin-right: 5px;
    }
    
    .message.received {
        margin-left: 5px;
    }

    /* Prevent iOS auto-zoom on input focus */
    .input-area textarea {
        font-size: 16px !important;
    }


    /* Move text input below icons on mobile */
    .input-wrapper {
        flex-wrap: wrap;
    }
    
    #message-input {
        order: 10;
        /* Force line break before the textarea */
        width: 100%; 
        flex: 1 1 70%; 
        margin-top: 5px;
        margin-left: 0;
    }
    
    .send-btn {
        order: 11;
        margin-top: 5px;
        flex: 0 0 auto;
        align-self: flex-end; /* Align to bottom of textarea */
    }

    /* Force a line break BEFORE the textarea */
    .input-wrapper::before {
        content: "";
        width: 100%;
        order: 9;
    }
    
    .attach-btn, .code-btn, .md-btn, .input-wrapper > div {
        order: 1;
        margin-bottom: 0; /* Remove bottom margin we added earlier */
    }

    
    /* Ensure the app fits viewport tightly */
    body, html, #main-app {
        width: 100vw;
        max-width: 100vw;
        overflow-x: hidden;
    }
    
    .chat-area {
        width: 100vw;
        max-width: 100vw;
    }
}

.back-btn { position: relative; }

#chat-subtitle {
    margin: 0;
    font-size: 0.8rem;
    color: #666;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-actions {
    display: flex;
    gap: 10px;
    flex-shrink: 0; /* Never shrink the buttons */
    margin-left: auto;
}


/* --- Typing Indicator --- */
.typing-indicator {
    display: none;
    align-self: flex-start;
    background: var(--bubble-received);
    padding: 10px 15px;
    border-radius: 20px;
    margin-bottom: 10px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.1);
    align-items: center;
    gap: 4px;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background-color: #aaa;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
.typing-indicator span:nth-child(3) { animation-delay: 0s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

