/* Standalone Messenger Styling */
:root {
    --bg-dark: #050505;
    --card-bg: #111;
    --border: rgba(255, 255, 255, 0.05);
    --primary: #9d4edd;
    --primary-light: #c77dff;
    --text: #ffffff;
    --text-muted: #888888;
}

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

body, html {
    height: 100vh; /* Fixed height! Solves the background scrolling issue! */
    width: 100vw;
    overflow: hidden; /* Prevents whole device scrolling */
    font-family: 'Inter', sans-serif;
    background: var(--bg-dark);
    color: var(--text);
}

.messenger-container {
    display: flex;
    height: 100%;
    width: 100%;
    background: var(--bg-dark);
}

/* ================== SIDEBAR (Chat List) ================== */
.chat-sidebar {
    width: 350px;
    background: var(--card-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100%;
    z-index: 5;
}

.sidebar-header {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    border-bottom: 1px solid var(--border);
    background: #0a0a0a;
}

.back-btn {
    color: var(--text);
    font-size: 1.5rem;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 50%;
    width: 45px;
    height: 45px;
    transition: 0.2s;
}

.back-btn:hover {
    background: rgba(157, 78, 221, 0.3);
    color: var(--primary-light);
}

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

.search-wrap {
    padding: 15px;
    position: relative;
    border-bottom: 1px solid var(--border);
}

.search-wrap i {
    position: absolute;
    left: 30px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 1.2rem;
}

.search-wrap input {
    width: 100%;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 12px 15px 12px 45px;
    color: var(--text);
    outline: none;
    transition: 0.2s;
}

.search-wrap input:focus {
    border-color: var(--primary);
    background: rgba(157, 78, 221, 0.05);
}

.chat-list {
    flex: 1;
    overflow-y: auto; /* Independent scrolling for chat list */
    padding-bottom: 20px;
}

/* Custom Scrollbar for sleekness */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(157, 78, 221, 0.5);
}

.chat-item {
    display: flex;
    padding: 15px 20px;
    gap: 15px;
    align-items: center;
    cursor: pointer;
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
    transition: 0.2s;
    position: relative;
}

.chat-item:hover {
    background: rgba(255, 255, 255, 0.03);
}

.chat-item.active {
    background: rgba(157, 78, 221, 0.15);
    border-left: 4px solid var(--primary);
}

.chat-item img {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    object-fit: cover;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.chat-info {
    flex: 1;
    overflow: hidden;
}

.chat-info h4 {
    margin-bottom: 5px;
    font-size: 1rem;
    color: #fff;
    font-weight: 600;
}

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

.unread-badge {
    background: var(--primary);
    color: #fff;
    border-radius: 12px;
    padding: 2px 10px;
    font-size: 0.75rem;
    font-weight: bold;
    box-shadow: 0 0 10px var(--primary);
}

/* ================== MAIN (Chat Window) ================== */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    background: url('https://www.transparenttextures.com/patterns/dark-matter.png') #050505;
    position: relative;
}

.chat-main-header {
    height: 80px;
    padding: 0 25px;
    display: flex;
    align-items: center;
    gap: 15px;
    background: rgba(10, 10, 10, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    z-index: 10;
}

.mobile-back-btn {
    display: none;
}

.chat-main-header img {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    border: 2px solid var(--border);
}

.active-user-info h3 {
    font-size: 1.15rem;
    font-weight: 600;
    color: #fff;
}

.active-user-info p {
    font-size: 0.8rem;
    color: var(--primary-light);
    margin-top: 2px;
}

/* The actual scrollable chat history */
.chat-messages-area {
    flex: 1;
    overflow-y: auto; /* Confined internal scroll */
    padding: 30px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.empty-state {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    text-align: center;
}

.empty-state .icon-circle {
    width: 100px;
    height: 100px;
    background: rgba(157, 78, 221, 0.1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
    box-shadow: 0 0 30px rgba(157, 78, 221, 0.2);
}

.empty-state i {
    font-size: 3.5rem;
    color: var(--primary-light);
}

.message {
    max-width: 65%;
    padding: 14px 18px;
    border-radius: 20px;
    font-size: 0.95rem;
    line-height: 1.5;
    position: relative;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    animation: slideIn 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

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

.msg-sent {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--primary), #b366ff);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.msg-received {
    align-self: flex-start;
    background: #1e1e1e;
    color: #fff;
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.msg-time {
    display: block;
    font-size: 0.7rem;
    opacity: 0.7;
    margin-top: 6px;
    text-align: right;
}

/* Message Controls (Edit/Delete) */
.message-controls {
    position: absolute;
    top: -10px;
    right: 5px;
    display: none;
    gap: 5px;
    background: #222;
    border-radius: 12px;
    padding: 3px 8px;
    border: 1px solid rgba(255,255,255,0.1);
    z-index: 10;
}

.message:hover .message-controls {
    display: flex;
}

.control-btn {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 0.9rem;
    padding: 2px;
    transition: 0.2s;
}

.control-btn:hover {
    color: var(--primary-light);
}

.control-btn.delete:hover {
    color: #ff4d4f;
}

/* Typing Indicator */
.typing-indicator {
    padding: 10px 30px;
    display: flex;
    align-items: center;
    gap: 5px;
    color: var(--text-muted);
    font-size: 0.85rem;
    position: absolute;
    bottom: 90px;
    left: 0;
    width: 100%;
    z-index: 9;
    background: linear-gradient(to top, rgba(5,5,5,0.9), transparent);
}

.typing-indicator .dot {
    width: 6px;
    height: 6px;
    background: var(--primary-light);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

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

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-5px); }
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    backdrop-filter: blur(5px);
}

.modal-content {
    background: #111;
    border: 1px solid rgba(255,255,255,0.1);
    padding: 30px;
    border-radius: 20px;
    width: 90%;
    max-width: 500px;
    position: relative;
    max-height: 85vh;
    overflow-y: auto;
}

.close-modal {
    position: absolute;
    right: 20px;
    top: 20px;
    font-size: 1.8rem;
    cursor: pointer;
    color: var(--text-muted);
}

.mini-products-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin-top: 15px;
}

.mini-product {
    background: rgba(255,255,255,0.03);
    border-radius: 12px;
    padding: 10px;
    text-align: center;
}

.mini-product img {
    width: 100%;
    height: 100px;
    object-fit: cover;
    border-radius: 8px;
    margin-bottom: 8px;
}

.mini-product h4 {
    font-size: 0.9rem;
    margin: 5px 0;
}

.mini-product p {
    color: var(--primary-light);
    font-weight: bold;
    font-size: 0.85rem;
}

/* Input typing zone */
.chat-input-area {
    padding: 20px 25px;
    background: rgba(10, 10, 10, 0.95);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border);
    display: flex;
    gap: 12px;
    align-items: center;
    z-index: 10;
}

.chat-input-area input {
    flex: 1;
    background: #1a1a1a;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 25px;
    padding: 15px 25px;
    color: #fff;
    font-size: 1rem;
    outline: none;
    transition: 0.2s;
}

.chat-input-area input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 15px rgba(157, 78, 221, 0.2);
}

.send-btn, .attach-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    transition: transform 0.2s;
}

.send-btn {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 5px 15px rgba(157, 78, 221, 0.4);
}

.send-btn:active {
    transform: scale(0.9);
}

.attach-btn {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
}

.attach-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

/* ================== MOBILE SEAMLESS UI ================== */
@media (max-width: 768px) {
    .messenger-container {
        position: relative;
    }
    .chat-sidebar {
        width: 100%;
        border-right: none;
    }
    
    /* Hide the chat window off-screen to the right */
    .chat-main {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        transform: translateX(100%);
        transition: transform 0.35s cubic-bezier(0.25, 0.8, 0.25, 1);
        z-index: 20;
    }
    
    /* Mobile Slide In Animation */
    .chat-main.active {
        transform: translateX(0);
    }
    
    .mobile-back-btn {
        display: flex;
        background: none;
        border: none;
        color: #fff;
        font-size: 2.2rem;
        cursor: pointer;
        align-items: center;
        margin-left: -15px;
        margin-right: 5px;
    }

    .message {
        max-width: 85%;
    }
    
    .chat-main-header {
        padding: 0 15px;
    }
    
    .chat-input-area {
        padding: 15px;
    }
}
