:root {
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --sidebar-bg: #0b1120;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --msg-sent: #0ea5e9;
    --msg-received: #334155;
    --border: #334155;
    --danger: #ef4444;
    --success: #10b981;
    --border-radius-lg: 16px;
    --border-radius-sm: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

#app-container {
    width: 100%;
    max-width: 1200px;
    height: 100vh;
    background-color: var(--bg-color);
    position: relative;
    overflow: hidden;
}

@media (min-width: 1200px) {
    #app-container {
        height: 90vh;
        border-radius: var(--border-radius-lg);
        border: 1px solid var(--border);
        box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.25);
    }
}

.view { display: none; height: 100%; width: 100%; }
.view.active { display: flex; }
.hidden { display: none !important; }

/* Buttons & Utils */
.icon-btn {
    background: none; border: none; color: var(--text-secondary);
    cursor: pointer; padding: 0.5rem; border-radius: 50%;
    transition: all 0.2s; display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { color: var(--accent); background: rgba(59, 130, 246, 0.1); }
.icon-btn.sm { padding: 0.25rem; }

.btn {
    padding: 0.5rem 1rem; background-color: var(--accent); color: white;
    border: none; border-radius: var(--border-radius-sm); cursor: pointer;
    font-weight: 500; transition: background 0.2s;
}
.btn:hover { background-color: var(--accent-hover); }
.btn.outline { background: transparent; border: 1px solid var(--accent); color: var(--accent); }
.btn.outline:hover { background: rgba(59, 130, 246, 0.1); }
.btn.danger { background-color: transparent; border: 1px solid var(--danger); color: var(--danger); font-size: 0.7rem; padding: 2px 6px; border-radius: 4px; }
.btn.danger:hover { background-color: rgba(239, 68, 68, 0.1); }


/* Auth Screen */
#auth-screen { justify-content: center; align-items: center; }
.auth-card {
    background-color: var(--card-bg); padding: 2.5rem; border-radius: var(--border-radius-lg);
    border: 1px solid var(--border); width: 90%; max-width: 400px;
}
.auth-card h1 { font-size: 1.75rem; margin-bottom: 0.5rem; }
.auth-card p { color: var(--text-secondary); margin-bottom: 2rem; }
.auth-card input {
    width: 100%; padding: 0.75rem; background: var(--bg-color); border: 1px solid var(--border);
    border-radius: var(--border-radius-sm); color: white; margin-bottom: 1rem; outline: none;
}
.auth-card input:focus { border-color: var(--accent); }
.auth-card button {
    width: 100%; padding: 0.75rem; background: var(--accent); color: white; border: none;
    border-radius: var(--border-radius-sm); font-weight: 600; cursor: pointer; margin-bottom: 1rem;
}
.auth-toggle { text-align: center; font-size: 0.9rem; color: var(--text-secondary); }
.auth-toggle a { color: var(--accent); text-decoration: none; }
.error-msg { color: var(--danger); font-size: 0.85rem; margin-top: 1rem; text-align: center; }
.success-msg { color: var(--success); font-size: 0.85rem; margin-top: 1rem; text-align: center; }

/* Main App */
.sidebar {
    width: 300px; background-color: var(--sidebar-bg); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; height: 100%; transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative; z-index: 10;
}
.sidebar.collapsed { width: 72px; }
.sidebar.collapsed .sidebar-title,
.sidebar.collapsed .section-header h3,
.sidebar.collapsed .section-header .icon-btn,
.sidebar.collapsed .list li span:first-child { display: none; }
.sidebar.collapsed .sidebar-header { justify-content: center; padding: 1.5rem 0.5rem; }
.sidebar.collapsed .sidebar-header > :not(#toggle-sidebar-btn) { display: none; }
.sidebar.collapsed .list li { justify-content: center; padding: 0.75rem 0.5rem; }
.sidebar.collapsed .list li button { display: none; }
.sidebar.collapsed .sidebar-section { padding: 1rem 0.5rem; }
.sidebar-header {
    padding: 1.5rem 1rem; border-bottom: 1px solid var(--border); display: flex;
    justify-content: space-between; align-items: center;
}
.sidebar-header h2 { font-size: 1.25rem; font-weight: 600; }
.sidebar-section { padding: 1rem; border-bottom: 1px solid var(--border); }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; }
.section-header h3 { font-size: 0.85rem; text-transform: uppercase; color: var(--text-secondary); letter-spacing: 0.05em; }

input#friend-search-input {
    width: 100%; padding: 0.5rem; background: var(--bg-color); border: 1px solid var(--border);
    border-radius: 4px; color: white; font-size: 0.85rem; margin-bottom: 0.5rem;
}

.list { list-style: none; display: flex; flex-direction: column; gap: 0.25rem; }
.list li {
    padding: 0.75rem; border-radius: var(--border-radius-sm); cursor: pointer;
    transition: background 0.2s; display: flex; justify-content: space-between; align-items: center;
}
.list li:hover { background-color: var(--card-bg); }
.list li.active { background-color: rgba(59, 130, 246, 0.15); color: var(--accent); }

.chat-area { flex: 1; display: flex; flex-direction: column; background-color: var(--bg-color); height: 100%; overflow: hidden; }
.chat-header { padding: 1.5rem; background-color: var(--card-bg); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.chat-messages { flex: 1; overflow-y: auto; padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.no-chat-selected { margin: auto; color: var(--text-secondary); }

/* Messages */
.message { display: flex; flex-direction: column; max-width: 75%; animation: slideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1); position: relative; }
@keyframes slideIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.message.sent { align-self: flex-end; }
.message.received { align-self: flex-start; }
.message.disappeared .message-content { background: repeating-linear-gradient(45deg, transparent, transparent 10px, rgba(255,255,255,0.05) 10px, rgba(255,255,255,0.05) 20px); border: 1px dashed var(--border); color: var(--text-secondary); font-style: italic; }

.message-content { padding: 0.75rem 1rem; border-radius: var(--border-radius-lg); font-size: 0.95rem; line-height: 1.4; word-break: break-word; }
.message.sent .message-content { background-color: var(--msg-sent); border-bottom-right-radius: 4px; }
.message.received .message-content { background-color: var(--msg-received); border-bottom-left-radius: 4px; }

.message-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.25rem; font-size: 0.75rem; }
.message.sent .message-header { color: rgba(255, 255, 255, 0.8); }
.message.received .message-header { color: var(--text-secondary); }

.view-once-placeholder {
    padding: 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px dashed var(--border);
    border-radius: var(--border-radius-sm);
    text-align: center;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--accent);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: center;
    transition: background 0.2s;
}

.view-once-placeholder:hover {
    background: rgba(255, 255, 255, 0.1);
}

.view-once-placeholder svg {
    opacity: 0.7;
}

.message-actions { opacity: 0.8; transition: opacity 0.2s; margin-left: 0.5rem; display: inline-flex; align-items: center; }
.message:hover .message-actions { opacity: 1; }

.chat-input-area { padding: 1rem 1.5rem; background-color: var(--card-bg); border-top: 1px solid var(--border); display: flex; gap: 0.75rem; align-items: center; flex-shrink: 0; }
.chat-input-area input { flex: 1; background-color: var(--bg-color); border: 1px solid var(--border); border-radius: 20px; padding: 0.75rem 1.25rem; color: white; outline: none; }
.chat-input-area input:focus { border-color: var(--accent); }

/* Mobile Utilities & Transitions */
.mobile-only { display: none; }

@media (max-width: 768px) {
    .mobile-only { display: flex; }
    
    #main-screen { position: relative; height: 100vh; overflow: hidden; }
    
    .sidebar {
        width: 100%;
        position: absolute;
        inset: 0;
        z-index: 20;
        transition: transform 0.3s ease;
    }
    
    .chat-area {
        width: 100%;
        position: absolute;
        inset: 0;
        z-index: 10;
        display: flex;
        flex-direction: column;
        height: 100%;
        overflow: hidden;
    }
    
    /* When a chat is active on mobile, hide the sidebar */
    #main-screen.mobile-chat-active .sidebar {
        transform: translateX(-100%);
    }
    
    .sidebar.collapsed { width: 100%; } /* No collapsing on mobile */
    .sidebar.collapsed .sidebar-title,
    .sidebar.collapsed .section-header h3,
    .sidebar.collapsed .list li span:first-child { display: block; }
    
    /* Compact Mobile Chat UI */
    .chat-header { padding: 0.75rem 1rem; }
    .chat-header h2 { font-size: 1.1rem; }
    
    .chat-messages { 
        padding: 0.75rem; 
        gap: 0.5rem; 
        flex: 1; 
        overflow-y: auto; 
    }
    
    .message { max-width: 90%; }
    .message-content { padding: 0.5rem 0.75rem; font-size: 0.9rem; }
    .sender-name { font-size: 0.7rem; }
    .message-time { font-size: 0.65rem; }
    
    .chat-input-area { padding: 0.5rem 0.75rem; gap: 0.5rem; }
    .chat-input-area input { padding: 0.5rem 1rem; font-size: 16px; }
    
    .auth-input, .auth-card input { font-size: 16px; }
    
    .typing-indicator { padding: 0.25rem 0.75rem; font-size: 0.75rem; }
    
    .reply-preview { padding: 0.4rem 0.75rem; font-size: 0.8rem; }
}

/* Admin Dashboard */
#admin-screen { flex-direction: column; background: var(--bg-color); overflow-y: auto;}
.admin-header { padding: 1.5rem 2rem; background: var(--card-bg); border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.admin-content { padding: 2rem; display: flex; flex-direction: column; gap: 2rem; max-width: 1000px; margin: 0 auto; width: 100%; }
.admin-section { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--border-radius-lg); padding: 1.5rem; }
.admin-section h3 { margin-bottom: 1rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--border); }

.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th, .admin-table td { padding: 0.75rem; text-align: left; border-bottom: 1px solid var(--border); }
.admin-table th { color: var(--text-secondary); font-size: 0.85rem; text-transform: uppercase; font-weight: 600; }
.status-badge { padding: 2px 8px; border-radius: 12px; font-size: 0.75rem; font-weight: 600; }
.status-badge.active { background: rgba(16, 185, 129, 0.1); color: var(--success); }
.status-badge.pending { background: rgba(239, 68, 68, 0.1); color: var(--danger); }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; justify-content: center; align-items: center; z-index: 100; }
.modal-content { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--border-radius-lg); width: 90%; max-width: 600px; max-height: 80vh; display: flex; flex-direction: column; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5); }
.modal-header { padding: 1.5rem; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 1.5rem; overflow-y: auto; flex: 1; display:flex; flex-direction:column; gap:1rem;}

/* Profile */
.profile-content { max-width: 600px; }
.profile-section { display: flex; flex-direction: column; gap: 0.5rem; }
.profile-pic-container { display: flex; align-items: center; justify-content: center; width: 100px; height: 100px; border-radius: 50%; background: var(--bg-color); border: 1px solid var(--border); overflow: hidden; margin-bottom: 1rem; }
.profile-pic-container img { width: 100%; height: 100%; object-fit: cover; }
.pic-placeholder { color: var(--text-secondary); font-size: 0.75rem; text-align: center; }
.auth-input { width: 100%; padding: 0.75rem; background: var(--bg-color); border: 1px solid var(--border); border-radius: var(--border-radius-sm); color: white; margin-bottom: 0.5rem; outline: none; }
.auth-input:focus { border-color: var(--accent); }
.danger-zone { border-color: var(--danger); }
.mb-1 { margin-bottom: 0.5rem; }
.mt-1 { margin-top: 0.5rem; }
.text-secondary { color: var(--text-secondary); }
.text-sm { font-size: 0.85rem; }
.sidebar-avatar { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; margin-left: auto; margin-right: 10px; border: 1px solid var(--border); }

.typing-indicator {
    padding: 0.5rem 1.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-style: italic;
    background: transparent;
    min-height: 1.5rem;
}

.typing-indicator span {
    display: inline-block;
    animation: typing-dots 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-dots {
    0%, 20% { opacity: 0; transform: translateY(0); }
    50% { opacity: 1; transform: translateY(-2px); }
    80%, 100% { opacity: 0; transform: translateY(0); }
}

.message-image {
    max-width: 100%;
    max-height: 300px;
    border-radius: var(--border-radius-sm);
    margin-top: 0.5rem;
    display: block;
    cursor: pointer;
    transition: opacity 0.2s;
}

.message-image:hover {
    opacity: 0.9;
}

/* Admin Specific */
.admin-user-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-top: 1rem;
}

.admin-user-card {
    transition: transform 0.2s, box-shadow 0.2s;
}

.admin-user-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
}

.admin-img-preview {
    max-width: 100px;
    max-height: 100px;
    border-radius: 4px;
    margin-top: 0.5rem;
    cursor: pointer;
    border: 1px solid var(--border);
}

.admin-full-img-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.9);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.admin-full-img-overlay img {
    max-width: 90%;
    max-height: 90%;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
}

.admin-full-img-overlay .close-overlay {
    position: absolute;
    top: 20px;
    right: 30px;
    color: white;
    font-size: 40px;
    cursor: pointer;
}

/* App Full-screen image overlay */
.full-img-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.95);
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.full-img-overlay.hidden {
    display: none;
}

.full-img-container {
    position: relative;
    max-width: 90%;
    max-height: 90%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.full-img-overlay img {
    max-width: 100%;
    max-height: 85vh;
    box-shadow: 0 0 30px rgba(0,0,0,0.8);
    border-radius: 4px;
}

.full-img-overlay .close-overlay {
    position: absolute;
    top: 20px;
    right: 30px;
    color: white;
    font-size: 40px;
    cursor: pointer;
    z-index: 3001;
    line-height: 1;
}

.full-img-timer {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    margin-top: 15px;
    overflow: hidden;
}

.full-img-timer-bar {
    height: 100%;
    background: var(--accent);
    width: 100%;
    /* Transition will be set dynamically via JS */
}

.full-img-timer.hidden {
    display: none;
}

/* Replies */
.reply-preview {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    padding: 0.5rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
}

.reply-preview-content {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-left: 3px solid var(--accent);
    padding-left: 0.5rem;
    color: var(--text-secondary);
}

.replied-to-box {
    background: rgba(0,0,0,0.05);
    border-left: 3px solid var(--accent);
    padding: 0.25rem 0.5rem;
    margin-bottom: 0.25rem;
    font-size: 0.75rem;
    border-radius: 4px;
    cursor: pointer;
    opacity: 0.8;
}

.dark-mode .replied-to-box {
    background: rgba(255,255,255,0.1);
}

.replied-to-box .reply-sender {
    font-weight: 600;
    color: var(--accent);
    display: block;
}

.message-item {
    position: relative;
}

.reply-btn {
    opacity: 0;
    position: absolute;
    right: -30px;
    top: 50%;
    transform: translateY(-50%);
    transition: opacity 0.2s;
    cursor: pointer;
    background: none;
    border: none;
    padding: 5px;
    color: var(--text-secondary);
}

.message-item:hover .reply-btn {
    opacity: 1;
}

.sent .reply-btn {
    left: -30px;
    right: auto;
}

/* Reactions */
.reaction-picker {
    position: absolute;
    bottom: 100%;
    left: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 5px 10px;
    display: flex;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
    transform: translateY(10px);
}

.message-bubble:hover .reaction-picker {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.reaction-option {
    cursor: pointer;
    font-size: 1.2rem;
    transition: transform 0.1s;
}

.reaction-option:hover {
    transform: scale(1.3);
}

.reaction-option {
    cursor: pointer;
}

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

.reaction-badge {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2px 6px;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
}

.reaction-badge.active {
    background: var(--accent-light);
    border-color: var(--accent);
}

.reaction-count {
    font-weight: 600;
    color: var(--text-secondary);
}

/* Adjust message bubble for reactions */
.message-bubble {
    display: inline-block;
    max-width: 100%;
    position: relative;
}
