/* ========================================
   Modern Chat Application Styles
   ======================================== */

:root {
    /* Modern Gradient Colors */
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --secondary-gradient: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --accent-gradient: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    
    /* Base Colors */
    --bg-color: #0f172a;
    --bg-secondary: #1e293b;
    --accent-color: #667eea;
    --accent-hover: #7c3aed;
    --text-primary: #ffffff;
    --text-secondary: #94a3b8;
    --border-color: rgba(255, 255, 255, 0.1);
    
    /* Message Bubble Colors */
    --msg-sent-bg: linear-gradient(135deg, rgba(102, 126, 234, 0.4) 0%, rgba(118, 75, 162, 0.3) 100%);
    --msg-received-bg: rgba(30, 41, 59, 0.6);
    
    /* Shadows & Effects */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.3);
    --glow: 0 0 20px rgba(102, 126, 234, 0.3);
    
    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    
    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;
    
    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-base: 0.3s ease;
    --transition-slow: 0.5s ease;
}

/* ========================================
   Base Styles
   ======================================== */

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

body {
    font-family: 'Outfit', sans-serif;
    background: var(--bg-color);
    background-image: 
        radial-gradient(at 0% 0%, rgba(102, 126, 234, 0.1) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(118, 75, 162, 0.1) 0px, transparent 50%);
    color: var(--text-primary);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
}

/* Glass Effect */
.glass {
    background: rgba(30, 41, 59, 0.4);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

/* ========================================
   Dashboard Layout
   ======================================== */

.dashboard-container {
    display: flex;
    width: 90%;
    max-width: 1200px;
    height: 90vh;
    gap: 20px;
}

.sidebar {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-width: 280px;
    max-width: 350px;
}

.main-chat {
    flex: 3;
    display: flex;
    flex-direction: column;
}

/* Chat Window - CRITICAL for messages display */
.chat-window {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
}

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

/* ========================================
   Friends List & User Items
   ======================================== */

.user-item {
    padding: 15px;
    cursor: pointer;
    transition: all var(--transition-base);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: var(--radius-md);
    position: relative;
    overflow: hidden;
}

.user-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 3px;
    background: var(--primary-gradient);
    transform: scaleY(0);
    transition: transform var(--transition-base);
}

.user-item:hover::before,
.user-item.active::before {
    transform: scaleY(1);
}

.user-item:hover,
.user-item.active {
    background: rgba(102, 126, 234, 0.15);
    border-color: var(--accent-color);
    transform: translateX(5px);
}

/* Avatar Placeholder */
.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: var(--primary-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1.1rem;
    margin-right: 12px;
    box-shadow: var(--shadow-sm);
    position: relative;
}

.user-avatar.online::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    background: #22c55e;
    border: 2px solid var(--bg-secondary);
    border-radius: var(--radius-full);
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
}

/* ========================================
   Chat Messages
   ======================================== */

#messages-list {
    display: flex;
    flex-direction: column;
    padding: 20px;
    gap: 12px;
    overflow-y: auto;
    flex: 1;
}

.message {
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    max-width: 75%;
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    position: relative;
    animation: fadeIn 0.3s ease;
    box-shadow: var(--shadow-sm);
    transition: all var(--transition-base);
}

.message:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.message.sent {
    margin-left: auto;
    text-align: left;
    background: var(--msg-sent-bg);
    border-bottom-right-radius: 4px;
}

.message.received {
    margin-right: auto;
    background: var(--msg-received-bg);
    border-bottom-left-radius: 4px;
}

/* Message Actions */
.delete-btn, .edit-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    font-size: 0.85rem;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    opacity: 0.7;
}

.delete-btn {
    color: #ef4444;
}

.edit-btn {
    color: #3b82f6;
}

.delete-btn:hover, .edit-btn:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
}

/* Context Menu */
.msg-context-menu {
    display: none;
    position: absolute;
    top: -40px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(10px);
    border-radius: var(--radius-md);
    padding: 6px;
    gap: 6px;
    z-index: 5100;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
}

.message.menu-active {
    z-index: 5000;
}

.message.menu-active .msg-context-menu {
    display: flex;
}

.msg-context-menu button {
    background: transparent;
    border: none;
    color: white;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.9rem;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.msg-context-menu button:hover {
    background: rgba(102, 126, 234, 0.3);
    transform: scale(1.05);
}

/* Reply Preview */
.reply-preview {
    font-size: 0.8rem;
    color: var(--text-secondary);
    padding: 6px 10px;
    margin-bottom: 6px;
    border-left: 3px solid var(--accent-color);
    background: rgba(102, 126, 234, 0.1);
    border-radius: var(--radius-sm);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Reply Bar */
.reply-bar {
    display: none;
    padding: 10px 15px;
    background: rgba(102, 126, 234, 0.15);
    border-left: 3px solid var(--accent-color);
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    align-items: center;
    justify-content: space-between;
    border-radius: var(--radius-sm);
}

.reply-bar.active {
    display: flex;
}

.reply-bar .close-reply {
    cursor: pointer;
    color: #ef4444;
    font-weight: bold;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.reply-bar .close-reply:hover {
    background: rgba(239, 68, 68, 0.2);
}

/* Edited Tag */
.edited-tag {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-left: 6px;
    opacity: 0.8;
}

/* Read Receipt Checkmarks */
.msg-status {
    font-size: 0.8rem;
    margin-left: 6px;
    letter-spacing: -2px;
    font-weight: bold;
    display: inline-block;
    vertical-align: bottom;
}

.msg-status.gray {
    color: #9ca3af;
}

.msg-status.green {
    color: #22c55e;
    text-shadow: 0 0 8px rgba(34, 197, 94, 0.3);
}

/* Hidden/Locked Messages */
.message.hidden-msg {
    background-image: url('https://images.unsplash.com/photo-1441974231531-c6227db76b6e?w=400');
    background-color: #059669;
    background-size: cover;
    background-position: center;
    color: transparent;
    position: relative;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.message.hidden-msg * {
    visibility: hidden;
}

.message.hidden-msg::after {
    content: '';
    visibility: visible;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.2);
}

/* ========================================
   Typing Indicator
   ======================================== */

.typing-indicator {
    display: none;
    align-self: flex-start;
    background: var(--msg-received-bg);
    padding: 10px 14px;
    border-radius: var(--radius-lg);
    border-bottom-left-radius: 4px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
    width: fit-content;
    box-shadow: var(--shadow-sm);
}

.typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
}

.typing-dots span {
    display: inline-block;
    width: 6px;
    height: 6px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: bounce 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;
}

/* ========================================
   Chat Input Area
   ======================================== */

.chat-input-area {
    padding: 15px;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border-color);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    display: flex;
    gap: 10px;
    align-items: center;
}

.chat-input-area input {
    flex: 1;
    padding: 12px 16px;
    border-radius: var(--radius-full);
    background: rgba(30, 41, 59, 0.6);
   border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: all var(--transition-base);
}

.chat-input-area input:focus {
    background: rgba(30, 41, 59, 0.8);
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.chat-input-area button {
    padding: 12px 20px;
    border-radius: var(--radius-full);
    background: var(--primary-gradient);
    font-weight: 600;
}

/* ========================================
   Header Actions
   ======================================== */

.header-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.clear-chat-btn {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.3);
    font-size: 0.85rem;
    padding: 6px 12px;
    width: auto;
    margin: 0;
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: all var(--transition-base);
}

.clear-chat-btn:hover {
    background: rgba(239, 68, 68, 0.4);
    transform: translateY(-2px);
}

.back-btn {
    display: none;
    background: transparent;
    border: none;
    color: white;
    font-size: 1.3rem;
    margin-right: 12px;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-md);
    transition: all var(--transition-base);
}

.back-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* ========================================
   Modals
   ======================================== */

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background: var(--bg-secondary);
    padding: 30px;
    border-radius: var(--radius-lg);
    text-align: center;
    border: 1px solid var(--border-color);
    width: 90%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
}

.modal-btn {
    width: 100%;
    padding: 12px;
    margin-top: 12px;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 600;
    transition: all var(--transition-base);
}

.btn-me {
    background: #334155;
    color: white;
}

.btn-both {
    background: #ef4444;
    color: white;
}

.btn-cancel {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.modal-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* ========================================
   Buttons
   ======================================== */

button, input[type="button"], input[type="submit"] {
    font-family: 'Outfit', sans-serif;
    border: none;
    border-radius: var(--radius-md);
    padding: 0.75rem 1.5rem;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-base);
    background: var(--primary-gradient);
    color: white;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md), var(--glow);
}

button:active {
    transform: translateY(0);
}

button::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

button:active::before {
    width: 300px;
    height: 300px;
}

/* ========================================
   Input Fields
   ======================================== */

input[type="text"], 
input[type="password"], 
input[type="email"], 
textarea {
    font-family: 'Outfit', sans-serif;
    width: 100%;
    padding: 0.875rem 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: rgba(30, 41, 59, 0.5);
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: all var(--transition-base);
    outline: none;
}

input:focus, textarea:focus {
    border-color: var(--accent-color);
    background: rgba(30, 41, 59, 0.7);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

input::placeholder, textarea::placeholder {
    color: var(--text-secondary);
}

/* ========================================
   Scrollbar
   ======================================== */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(30, 41, 59, 0.3);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb {
    background: var(--primary-gradient);
    border-radius: var(--radius-full);
    transition: all var(--transition-base);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-gradient);
}

/* ========================================
   Mobile Responsive
   ======================================== */

@media (max-width: 768px) {
    body {
        overflow: hidden;
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height for mobile */
    }

    .dashboard-container {
        width: 100%;
        height: 100vh;
        height: 100dvh;
        gap: 0;
        border: none;
    }

    .chat-input-area {
        border-radius: 0;
        background: rgba(15, 23, 42, 0.95);
    }

    .sidebar.glass,
    .main-chat.glass {
        border-radius: 0;
        border: none;
    }

    .sidebar {
        width: 100%;
        display: flex;
        max-width: none;
    }

    .main-chat {
        display: none;
        width: 100%;
        position: absolute;
        top: 0;
        left: 0;
        height: 100vh;
        height: 100dvh;
        background: var(--bg-color);
        z-index: 10;
        flex-direction: column;
    }

    .view-chat .sidebar {
        display: none !important;
    }

    .view-chat .main-chat {
        display: flex !important;
        flex-direction: column !important;
    }

    .back-btn {
        display: block;
    }

    .message {
        max-width: 85%;
    }

    /* iPhone Safari specific fixes for message display */
    .chat-window {
        display: flex !important;
        flex-direction: column !important;
        flex: 1 1 0% !important; /* Explicit flex-basis for Safari */
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        min-height: 0 !important; /* Critical for Safari nested flex */
    }
    
    #messages-list {
        display: flex !important;
        flex-direction: column !important;
        padding: 20px;
        gap: 12px;
        flex: 1 1 auto;
        min-height: min-content;
    }

    /* Force visibility on iPhone */
    .view-chat .chat-window,
    .view-chat #messages-list,
    .view-chat .message {
        visibility: visible !important;
        opacity: 1 !important;
    }
}

/* ========================================
   Animations
   ======================================== */

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

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

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

/* Utility Classes */
.fade-in {
    animation: fadeIn 0.5s ease;
}

.slide-in {
    animation: slideIn 0.5s ease;
}
/* ========================================
   Screen Lock (Stealth Contact Form)
   ======================================== */
#screen-lock-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    background: var(--bg-color);
    z-index: 9999;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

#screen-lock-overlay h1 {
    margin-bottom: 20px;
    font-weight: 600;
    color: white;
}

#screen-lock-overlay p {
    color: #94a3b8;
    margin-bottom: 30px;
}

#lock-pass-input {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 15px;
    color: white;
    border-radius: 10px;
    margin-bottom: 15px;
    outline: none;
}

#screen-lock-overlay button {
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    background: var(--accent-color, #3b82f6);
    border: none;
    color: white;
    cursor: pointer;
}
