:root {
    --primary: #05070a;
    --secondary: #00e5ff;
    --accent: #ff00e5;
    --text-main: #ffffff;
    --text-muted: rgba(255, 255, 255, 0.6);
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-bg-hover: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
    
    --msg-sent: linear-gradient(135deg, rgba(0, 229, 255, 0.2), rgba(0, 229, 255, 0.4));
    --msg-received: rgba(255, 255, 255, 0.08);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', 'Segoe UI', Roboto, sans-serif;
}

body {
    background: #020406;
    color: var(--text-main);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden; /* Prevent global horizontal scroll */
}

/* Premium Background Blobs */
.bg-blobs {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: -1;
    overflow: hidden;
    filter: blur(80px);
}

.blob {
    position: absolute;
    border-radius: 50%;
    opacity: 0.3;
    animation: move 20s infinite alternate cubic-bezier(0.45, 0, 0.55, 1);
}

.blob-1 {
    width: 600px; height: 600px;
    background: var(--secondary);
    top: -10%; left: -10%;
    animation-duration: 25s;
}

.blob-2 {
    width: 500px; height: 500px;
    background: var(--accent);
    bottom: -10%; right: -10%;
    animation-duration: 18s;
}

.blob-3 {
    width: 400px; height: 400px;
    background: #7000ff;
    top: 30%; right: 20%;
    animation-duration: 30s;
}

@keyframes move {
    from { transform: translate(0, 0) scale(1); }
    to { transform: translate(15%, 15%) scale(1.1); }
}

/* Glassmorphism Utilities */
.z-glass {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
}

.border-bottom-glass {
    border-bottom: 1px solid var(--glass-border);
}

.border-top-glass {
    border-top: 1px solid var(--glass-border);
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-main);
    font-size: 1.2rem;
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.icon-btn:hover {
    background: var(--glass-bg-hover);
    transform: translateY(-2px);
}

/* Layout */
.app-container {
    display: flex;
    width: 95%;
    max-width: 1400px;
    height: 90vh;
    border-radius: 24px;
    box-shadow: var(--glass-shadow), 0 0 40px rgba(0, 229, 255, 0.1);
    border: 1px solid var(--glass-border);
    overflow: hidden;
    position: relative;
    background: rgba(255, 255, 255, 0.03);
}

/* Sidebar */
.sidebar {
    width: 320px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--glass-border);
}

.sidebar-header {
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--glass-border);
}

.sidebar-header h2 {
    font-weight: 600;
    font-size: 1.5rem;
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.chat-list::-webkit-scrollbar { width: 6px; }
.chat-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 10px; }

.chat-item {
    display: flex;
    align-items: center;
    padding: 15px;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.3s ease;
    margin-bottom: 5px;
}

.chat-item:hover, .chat-item.active {
    background: var(--glass-bg-hover);
}

.avatar {
    position: relative;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    margin-right: 15px;
}

.avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.status {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid #203a43;
}

.status.online { background: #00e676; }

.chat-info h3 {
    font-size: 1rem;
    font-weight: 500;
}

.chat-info p {
    font-size: 0.85rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
}

/* Main Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 25px;
}

.chat-user {
    display: flex;
    align-items: center;
}

.user-details h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.user-details p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.header-actions {
    display: flex;
    gap: 10px;
}

/* Messages */
.messages-container {
    flex: 1;
    padding: 25px;
    overflow-y: auto;
    overflow-x: hidden; /* Prevent message options from leaking */
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.messages-container::-webkit-scrollbar { width: 8px; }
.messages-container::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 10px; }

.message {
    max-width: 70%;
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.4s ease forwards;
    opacity: 0;
    transform: translateY(10px);
}

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

.message.sent {
    align-self: flex-end;
}

.message.received {
    align-self: flex-start;
}

.bubble {
    padding: 12px 18px;
    border-radius: 20px;
    font-size: 0.95rem;
    line-height: 1.5;
    word-break: break-word;
    border: 1px solid rgba(255, 255, 255, 0.05);
    transition: transform 0.2s;
}

.message.sent .bubble {
    background: var(--msg-sent);
    border-bottom-right-radius: 4px;
    box-shadow: 0 5px 15px rgba(0, 229, 255, 0.2);
}

.message.received .bubble {
    background: var(--msg-received);
    backdrop-filter: blur(10px);
    border-bottom-left-radius: 4px;
}

.msg-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 5px;
    display: flex;
    gap: 10px;
}

.message.sent .msg-meta {
    justify-content: flex-end;
}

.file-attachment {
    max-width: 250px;
    border-radius: 10px;
    margin-top: 5px;
    display: block;
}

.file-link {
    display: inline-block;
    padding: 8px 12px;
    background: rgba(0,0,0,0.2);
    border-radius: 8px;
    color: white;
    text-decoration: none;
    font-size: 0.85rem;
    margin-top: 5px;
}

.file-link i { margin-right: 5px; }

/* Input Footer */
.chat-footer {
    padding: 15px 25px;
    position: relative;
}

#message-form {
    display: flex;
    align-items: center;
    gap: 15px;
    background: rgba(0, 0, 0, 0.2);
    padding: 8px 15px;
    border-radius: 30px;
    border: 1px solid var(--glass-border);
}

.paperclip { margin: 0; }

#message-input {
    flex: 1;
    background: transparent;
    border: none;
    color: white;
    font-size: 1rem;
    outline: none;
    padding: 5px;
}

#message-input::placeholder {
    color: var(--text-muted);
}

.send-btn {
    background: linear-gradient(135deg, #00C6FF, #0072FF);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    transition: transform 0.3s;
    display: none; /* Hidden by default, toggled via JS */
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
}

.send-btn:hover {
    transform: scale(1.05);
}

/* File Preview */
#file-preview-container {
    position: absolute;
    top: -40px;
    left: 25px;
    background: rgba(0,0,0,0.6);
    padding: 5px 15px;
    border-radius: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
}

#file-preview-container.hidden {
    display: none;
}

#remove-file-btn {
    background: none;
    border: none;
    color: #ff5252;
    cursor: pointer;
}

/* Modal */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.active { display: flex; }

.modal-content {
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    width: 90%;
    max-width: 400px;
}

.modal-content h3 { margin-bottom: 20px; }

/* Auth Tabs */
.auth-tabs {
    display: flex;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    margin-bottom: 25px;
    padding: 5px;
    gap: 5px;
}

.auth-tab {
    flex: 1;
    padding: 10px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-weight: 500;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.auth-tab.active {
    background: var(--glass-bg-hover);
    color: white;
}

.auth-tab:hover:not(.active) {
    background: rgba(255, 255, 255, 0.05);
}

.modal-content input {
    width: 100%;
    padding: 12px 15px;
    border-radius: 10px;
    border: 1px solid var(--glass-border);
    background: rgba(0,0,0,0.2);
    color: white;
    outline: none;
    transition: border-color 0.3s;
}

.modal-content input:focus {
    border-color: var(--secondary);
}

/* Responsive */
@media (max-width: 768px) {
    body {
        height: 100dvh;
    }
    .app-container {
        width: 100%;
        height: 100dvh;
        border-radius: 0;
    }
    .sidebar {
        position: absolute;
        width: 100%;
        height: 100%;
        z-index: 10;
        background: rgba(15, 32, 39, 0.95);
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    .sidebar.open {
        transform: translateX(0);
    }
    #mobile-menu-btn, #close-sidebar-btn {
        display: flex !important;
    }
    .chat-footer {
        padding: 10px 15px;
    }
    #message-form {
        gap: 8px;
        padding: 5px 10px;
    }
    .icon-btn, .send-btn {
        width: 35px;
        height: 35px;
        font-size: 1rem;
    }
    .voice-message {
        width: 200px;
    }
    #recording-overlay {
        left: 5px;
        right: 5px;
        padding: 5px 10px;
    }
}

/* Permission Warning */
.permission-banner {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    background: #ff5252;
    color: white;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    font-weight: 500;
    z-index: 2000;
    animation: slideDown 0.4s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

@keyframes slideDown {
    from { transform: translateY(-100%); }
    to { transform: translateY(0); }
}

.permission-banner span { display: flex; align-items: center; gap: 8px; }

.permission-banner.hidden { display: none; }

.btn-text {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 4px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.75rem;
    transition: all 0.2s;
}

.btn-text:hover { background: rgba(255, 255, 255, 0.3); }

.unread-badge {
    background: #ff5252;
    color: white;
    font-size: 0.7rem;
    padding: 2px 7px;
    border-radius: 10px;
    margin-left: auto;
    font-weight: bold;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

/* Dropdown Menu styling */
.msg-options {
    position: absolute;
    top: 5px;
    right: 5px; /* Stay inside bubble bounds */
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-muted);
    opacity: 0;
    transition: opacity 0.3s;
    background: rgba(0,0,0,0.3);
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.message.received .msg-options {
    right: auto;
    left: 5px;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background: rgba(15, 32, 39, 0.95);
    backdrop-filter: blur(15px);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 5px 0;
    min-width: 140px;
    display: none;
    z-index: 100;
    box-shadow: var(--glass-shadow);
}

.message.received .dropdown-menu {
    right: auto;
    left: 0;
}

.dropdown-menu.show {
    display: block;
}

.dropdown-item {
    padding: 8px 15px;
    font-size: 0.85rem;
    color: white;
    cursor: pointer;
    text-align: left;
    white-space: nowrap;
}

.dropdown-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.edited-tag {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.5);
    margin-left: 5px;
}

.chat-options {
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0;
    transition: opacity 0.3s;
    color: var(--text-muted);
    padding: 10px;
    z-index: 50;
}

.chat-item:hover .chat-options {
    opacity: 1;
}

.chat-options.active-menu {
    opacity: 1;
}

.chat-options .dropdown-menu {
    right: 0;
    top: 100%;
}

/* Advanced Calling UI */
.call-card {
    width: 100%;
    max-width: 900px;
    height: 85vh;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    position: relative;
    overflow: hidden;
}

.call-view {
    flex: 1;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Audio View */
.pulse-avatar {
    width: 150px;
    height: 150px;
    border-radius: 50%;
    position: relative;
    margin-bottom: 30px;
}

.pulse-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    z-index: 2;
    position: relative;
    border: 4px solid var(--glass-border);
}

.pulse-avatar::before, .pulse-avatar::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    border-radius: 50%;
    background: var(--secondary);
    opacity: 0.5;
    animation: pulse 2s infinite;
}

.pulse-avatar::after { animation-delay: 1s; }

@keyframes pulse {
    0% { transform: scale(1); opacity: 0.5; }
    100% { transform: scale(2.2); opacity: 0; }
}

.voice-waves {
    display: flex;
    gap: 5px;
    height: 30px;
    align-items: center;
}

.voice-waves span {
    width: 4px;
    background: var(--secondary);
    border-radius: 10px;
    animation: wave 1s infinite ease-in-out;
}

@keyframes wave {
    0%, 100% { height: 10px; }
    50% { height: 30px; }
}

.voice-waves span:nth-child(2) { animation-delay: 0.2s; }
.voice-waves span:nth-child(3) { animation-delay: 0.4s; }
.voice-waves span:nth-child(4) { animation-delay: 0.6s; }

/* Video View */
.remote-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 15px;
    background: #000;
}

.local-preview {
    position: absolute;
    bottom: 100px;
    right: 30px;
    width: 180px;
    aspect-ratio: 16/9;
    border-radius: 12px;
    object-fit: cover;
    background: #222;
    border: 2px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
    z-index: 10;
}

/* Call Info & Controls */
.call-info {
    text-align: center;
    margin: 15px 0;
}

.call-timer {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--secondary);
}

.call-controls-bar {
    display: flex;
    gap: 20px;
    padding: 15px 30px;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(15px);
    border-radius: 40px;
    border: 1px solid var(--glass-border);
    margin-bottom: 10px;
    z-index: 100;
}

.call-ctrl-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    justify-content: center;
    align-items: center;
}

.call-ctrl-btn:hover { background: rgba(255, 255, 255, 0.2); transform: scale(1.1); }
.call-ctrl-btn.active { background: #ff5252; }

.call-ctrl-btn.accept-btn { background: #00e676; }
.call-ctrl-btn.end-btn { background: #ff5252; }

@media (max-width: 768px) {
    .local-preview {
        width: 120px;
        bottom: 120px;
        right: 15px;
    }
    .call-card { height: 100vh; padding: 10px; }
}
/* Restored Recording UI */
#recording-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--primary);
    border-radius: 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    z-index: 100;
}

#recording-overlay.hidden { display: none; }

.recording-status {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #ff5252;
    font-weight: 500;
}

.recording-dot {
    width: 10px;
    height: 10px;
    background: #ff5252;
    border-radius: 50%;
    animation: blink-dot 0.8s infinite alternate;
}

@keyframes blink-dot { from { opacity: 1; } to { opacity: 0.3; } }

.recording-actions {
    display: flex;
    gap: 20px;
    align-items: center;
}

#cancel-record-btn { color: #ff5252; cursor: pointer; }
#stop-record-btn { color: #00e676; cursor: pointer; }

/* Enhanced Chat Footer */
.chat-footer {
    background: rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--glass-border);
}

#message-form {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    transition: all 0.3s;
}

#message-form:focus-within {
    border-color: var(--secondary);
    box-shadow: 0 0 15px rgba(0, 229, 255, 0.1);
}

/* Custom Glass Audio Player */
.voice-message {
    width: 280px;
    margin-top: 8px;
    padding: 0;
    background: transparent;
}

.glass-audio-player {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    padding: 10px 15px;
    border-radius: 12px;
}

.player-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--secondary);
    color: #0b0e11;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.9rem;
    box-shadow: 0 0 15px rgba(0, 229, 255, 0.3);
    transition: all 0.2s;
    flex-shrink: 0;
}

.player-btn:hover { transform: scale(1.1); box-shadow: 0 0 20px rgba(0, 229, 255, 0.5); }

.player-controls {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.seek-bar {
    width: 100%;
    height: 4px;
    -webkit-appearance: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

.seek-bar::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 10px;
    height: 10px;
    background: var(--secondary);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--secondary);
}

.player-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
}

/* --- Custom Context Menu --- */
#custom-context-menu {
    position: fixed;
    z-index: 5000;
    width: 180px;
    background: rgba(15, 32, 39, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
    padding: 6px 0;
    display: none;
    transform-origin: top left;
    animation: menuZoom 0.2s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

@keyframes menuZoom {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.context-item {
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
    color: var(--text-main);
    cursor: pointer;
    transition: all 0.2s;
}

.context-item:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--secondary);
}

.context-item i {
    width: 16px;
    text-align: center;
    font-size: 0.95rem;
}

.context-item.delete {
    color: #ff5252;
}

.context-item.delete:hover {
    background: rgba(255, 82, 82, 0.1);
}

/* --- Custom Popup Modal --- */
#custom-popup-modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 9000;
    animation: fadeIn 0.3s ease;
}

#custom-popup-modal.active {
    display: flex;
}

.popup-content {
    background: rgba(15, 32, 39, 0.85);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    width: 90%;
    max-width: 400px;
    padding: 30px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

#custom-popup-modal.active .popup-content {
    transform: scale(1);
}

.popup-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.popup-header i {
    font-size: 1.5rem;
    color: var(--secondary);
}

.popup-header h3 {
    font-size: 1.3rem;
    font-weight: 600;
}

.popup-body {
    margin-bottom: 25px;
}

.popup-body p {
    color: var(--text-muted);
    font-size: 0.95rem;
    line-height: 1.5;
}

.popup-input {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    padding: 12px;
    color: white;
    font-size: 1rem;
    margin-top: 15px;
    outline: none;
    transition: border-color 0.3s;
}

.popup-input:focus {
    border-color: var(--secondary);
}

.popup-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.btn-popup {
    padding: 10px 20px;
    border-radius: 10px;
    border: none;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-popup.cancel {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

.btn-popup.confirm {
    background: var(--secondary);
    color: #000;
    box-shadow: 0 4px 15px rgba(0, 229, 255, 0.3);
}

.btn-popup.delete {
    background: #ff5252;
    color: white;
    box-shadow: 0 4px 15px rgba(255, 82, 82, 0.3);
}

.btn-popup:hover {
    transform: translateY(-2px);
    filter: brightness(1.1);
}

.btn-popup:active {
    transform: translateY(0);
}


