:root {
    --msg-bg: #ffffff;
    --msg-sidebar: #f8f9fa;
    --msg-active: #e9ecef;
    --msg-primary: #000000;
    --msg-text-muted: #6c757d;
    --msg-border: rgba(0,0,0,0.08);
    --msg-shadow: 0 10px 30px rgba(0,0,0,0.05);
}

/* --- CORRECTIONS ULTIMES FRYNZY --- */
.status-online, .status-dot.status-online { background-color: #2ecc71 !important; }
.status-busy, .status-dot.status-busy { background-color: #e74c3c !important; }
.status-away, .status-dot.status-away { background-color: #f1c40f !important; }
.status-offline, .status-dot.status-offline { background-color: #95a5a6 !important; }

.msg-status-input {
    color: #000000 !important;
    background: transparent !important;
    border: none !important;
    outline: none !important;
    width: 100% !important;
}

.msg-emoji-quick-picker {
    position: fixed;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 5px 10px;
    display: flex;
    gap: 8px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    z-index: 9999;
}
.msg-emoji-quick-picker span {
    cursor: pointer;
    font-size: 1.2rem;
}

/* Custom Context Menu Frynzy */
.msg-custom-context-menu {
    position: fixed;
    background: #ffffff;
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
    z-index: 10000 !important;
    min-width: 180px;
    padding: 6px;
    animation: menuFadeIn 0.2s ease;
}
@keyframes menuFadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}
.context-menu-item {
    padding: 10px 15px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    border-radius: 8px;
    font-size: 0.9rem;
    color: #333;
    transition: 0.2s;
}
.context-menu-item:hover {
    background: #f5f5f5;
}
.context-menu-item i {
    width: 16px;
    text-align: center;
    opacity: 0.6;
}
.context-menu-item.delete {
    color: #e74c3c;
}
.context-menu-item.delete:hover {
    background: #fdf2f2;
}

.messaging-section {
    display: none; /* Hidden by default */
    background: #fdfdfd;
    height: calc(100vh - 70px); /* Height minus navbar */
    padding-left: 85px; /* Offset for the floating sidebar */
    overflow: hidden;
    color: #1a1a1a;
    position: relative;
    z-index: 50;
}



.msg-container {
    display: flex;
    height: 100%;
    width: 100%;
}

/* Sidebar / Contact List */
.msg-sidebar {
    width: 380px;
    border-right: 1px solid rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    background: rgba(248, 249, 250, 0.8);
    backdrop-filter: blur(20px);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    z-index: 10;
}

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

.msg-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
}

.msg-header-icons {
    display: flex;
    gap: 15px;
    color: var(--msg-text-muted);
    align-items: center;
}

.msg-header-icons i {
    cursor: pointer;
    transition: 0.2s;
}

.msg-header-icons i:hover {
    color: var(--msg-primary);
}

.msg-more-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.msg-context-menu {
    position: absolute;
    top: 100%;
    right: 0;
    width: 250px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(0,0,0,0.05);
    border-radius: 12px;
    box-shadow: 0 15px 40px rgba(0,0,0,0.1);
    padding: 8px;
    z-index: 1000;
    display: none;
    transform-origin: top right;
    animation: menuScaleIn 0.3s cubic-bezier(0.165, 0.84, 0.44, 1) forwards;
}

@keyframes menuScaleIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(-10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.msg-context-menu.active {
    display: block;
}

.msg-context-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 15px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.msg-context-item:hover {
    background: rgba(0,0,0,0.03);
}

.msg-context-item i {
    width: 20px;
    text-align: center;
    font-size: 1rem;
    color: var(--msg-text-muted);
}

.msg-context-item span {
    font-size: 0.9rem;
    font-weight: 600;
    color: #1a1a1a;
}

.msg-context-divider {
    height: 1px;
    background: rgba(0,0,0,0.05);
    margin: 8px 0;
}

.msg-user-bar {
    padding: 15px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--msg-border);
}

.msg-user-bar img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #fff;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.msg-user-bar span {
    font-weight: 600;
    font-size: 0.95rem;
}

.msg-filter-bar {
    padding: 10px 20px;
    display: flex;
    gap: 10px;
}

.filter-chip {
    padding: 6px 15px;
    border-radius: 20px;
    background: #fff;
    border: 1px solid var(--msg-border);
    font-size: 0.85rem;
    cursor: pointer;
    transition: 0.2s;
}

.filter-chip.active {
    background: var(--msg-primary);
    color: #fff;
    border-color: var(--msg-primary);
}

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

.msg-item {
    padding: 20px;
    border-radius: 24px; /* More curved as requested */
    display: flex;
    gap: 15px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin-bottom: 15px;
    background: #ffffff;
    border: 1px solid rgba(0,0,0,0.03);
    box-shadow: 0 4px 15px rgba(0,0,0,0.02);
}

.msg-item:hover {
    background: #ffffff;
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 12px 30px rgba(0,0,0,0.06);
    border-color: rgba(0,0,0,0.08);
}

.msg-item.active {
    background: #ffffff;
    border-color: #ff4545; /* Red accent for active */
    box-shadow: 0 15px 35px rgba(255, 69, 69, 0.1);
}

.msg-item-avatar {
    position: relative;
}

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

.msg-item-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.msg-item-top {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

.msg-item-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.msg-item-time {
    font-size: 0.75rem;
    color: var(--msg-text-muted);
}

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

/* Chat View */
.msg-chat-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #fff;
    position: relative;
}

.msg-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 40px;
    position: relative;
    z-index: 10;
    color: var(--msg-text-muted);
}

.msg-empty-state h3, .msg-empty-state p {
    text-shadow: 0 1px 15px rgba(255,255,255,0.8), 0 2px 5px rgba(0,0,0,0.2);
}

.msg-empty-icon i {
    filter: drop-shadow(0 4px 15px rgba(0,0,0,0.1));
}

.msg-empty-icon {
    font-size: 5rem;
    margin-bottom: 20px;
    color: #f1f3f5;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-15px); }
}

.msg-empty-state h3 {
    color: #333;
    margin-bottom: 10px;
}

/* Empty Conversation Placeholder */
.msg-empty-chat {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    opacity: 0.8;
    text-align: center;
}

.msg-empty-chat-icon {
    font-size: 3rem;
    color: #e9ecef;
    margin-bottom: 15px;
}

.msg-empty-chat p {
    font-size: 1.1rem;
    margin: 5px 0;
    color: #1a1a1a;
}

.msg-empty-chat-hint {
    font-size: 0.85rem;
    color: var(--msg-text-muted);
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .msg-sidebar {
        width: 100%;
    }
    .msg-chat-view {
        display: none; /* Hide chat view on mobile list view */
    }
    .messaging-section {
        display: none; /* Hide unless active */
        height: 100vh;
        z-index: 10001 !important; /* Force front */
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        padding-left: 0;
        background: #fff;
    }

    .messaging-section[style*="display: block"] {
        display: flex !important;
    }

    /* Mobile active state */
    .messaging-section.chat-active .msg-sidebar {
        display: none;
    }
    .messaging-section.chat-active .msg-chat-view {
        display: flex;
    }
}

/* Chat Header */
.msg-chat-header {
    padding: 15px 25px;
    background: #fff;
    border-bottom: 1px solid var(--msg-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
}

.msg-header-profile-card {
    display: flex;
    align-items: center;
    gap: 15px;
    background: rgba(0,0,0,0.02); /* Light clear rectangle */
    padding: 8px 15px;
    border-radius: 15px;
    border: 1px solid rgba(0,0,0,0.03);
}

.msg-header-avatar-container {
    position: relative;
    width: 45px;
    height: 45px;
}

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

.online-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    background: #2dcc70;
    border: 2px solid #fff;
    border-radius: 50%;
    display: none; /* Shown via JS */
}

.msg-header-info h4 {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
}

.msg-header-info span {
    font-size: 0.75rem;
    color: var(--msg-text-muted);
}

.back-btn {
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--msg-text-muted);
    transition: 0.2s;
}

.back-btn:hover {
    color: var(--msg-primary);
    transform: translateX(3px);
}

/* History & Bubbles */
.msg-chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 25px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    background: transparent; /* Changed from #fafafa for ThemeEngine support */
}

.message-bubble {
    max-width: 75%;
    padding: 12px 18px;
    border-radius: 20px;
    font-size: 0.95rem;
    line-height: 1.4;
    position: relative;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.message-bubble.received {
    align-self: flex-start;
    background: #f1f3f5;
    color: #1a1a1a;
    border-bottom-left-radius: 4px;
}

.message-bubble.sent {
    align-self: flex-end !important;
    background: #000000;
    color: #ffffff;
    border-bottom-right-radius: 4px;
    margin-left: auto; /* Force right alignment */
}

.message-media {
    margin-bottom: 8px;
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
}

.message-media img {
    width: 100%;
    border-radius: 12px;
    cursor: pointer;
    transition: 0.3s;
}

.message-media img:hover {
    transform: scale(1.02);
}

/* Footer & Input */
.msg-chat-footer {
    padding: 15px 25px;
    background: #fff;
    border-top: 1px solid var(--msg-border);
}

.msg-input-container {
    display: flex;
    align-items: center;
    gap: 15px;
}

.plus-btn {
    font-size: 1.4rem;
    color: var(--msg-text-muted);
    cursor: pointer;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.plus-btn:hover {
    color: var(--msg-primary);
    transform: rotate(90deg);
}

.msg-input-wrapper {
    flex: 1;
    background: #f1f3f5;
    border-radius: 25px;
    padding: 5px 20px;
}

.msg-input-wrapper input {
    width: 100%;
    border: none;
    background: transparent;
    padding: 10px 0;
    font-family: inherit;
    font-size: 0.95rem;
    color: #000 !important; /* Force black text on light bg */
    cursor: text !important;
}

.msg-input-container {
    cursor: text;
}

.msg-input-wrapper input:focus {
    outline: none;
}

.msg-action-btn {
    width: 45px;
    height: 45px;
    background: #000;
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: 0.2s;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

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

/* Preview Bar */
.msg-preview-bar {
    padding: 15px 25px;
    display: flex;
    gap: 12px;
    background: #fff;
    border-top: 1px solid var(--msg-border);
    overflow-x: auto;
}

.preview-item {
    position: relative;
    width: 80px;
    height: 80px;
    flex-shrink: 0;
}

.preview-item img {
    width: 100%;
    height: 100%;
    border-radius: 12px;
    object-fit: cover;
    border: 2px solid var(--msg-border);
}

.preview-remove {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #ff4545;
    color: #fff;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    cursor: pointer;
    border: 2px solid #fff;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

/* Plus Menu Overlay */
.msg-plus-menu {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: none;
    align-items: flex-end;
}

.msg-plus-menu.active {
    display: flex;
}

.plus-menu-content {
    background: #fff;
    width: 100%;
    border-radius: 30px 30px 0 0;
    padding: 30px;
    z-index: 1002;
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
}

.msg-plus-menu.active .plus-menu-content {
    transform: translateY(0);
}

.plus-menu-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    z-index: 1001;
}

.plus-menu-section {
    margin-bottom: 25px;
}

.plus-menu-section h4 {
    margin: 0 0 15px 0;
    font-size: 0.9rem;
    color: var(--msg-text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.plus-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
}

.plus-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: 0.2s;
}

.plus-item i {
    width: 55px;
    height: 55px;
    background: #f8f9fa;
    border-radius: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    color: #333;
    transition: 0.2s;
}

.plus-item:hover i {
    background: #000;
    color: #fff;
    transform: translateY(-5px);
}

.plus-item span {
    font-size: 0.75rem;
    font-weight: 600;
    text-align: center;
}

/* Lightbox */
.msg-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.9);
    backdrop-filter: blur(10px);
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
}

.msg-lightbox img {
    max-width: 90%;
    max-height: 90%;
    border-radius: 15px;
    box-shadow: 0 0 50px rgba(0,0,0,0.5);
    animation: zoomIn 0.3s ease;
}

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

.lightbox-close {
    position: absolute;
    top: 30px;
    right: 30px;
    color: #fff;
    font-size: 2rem;
    cursor: pointer;
}

/* Date Separator */
.msg-date-separator {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 20px 0;
    position: relative;
}

.msg-date-separator::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 1px;
    background: rgba(0,0,0,0.05);
    z-index: 1;
}

.msg-date-separator span {
    background: var(--msg-sidebar); /* Fallback to sidebar bg */
    padding: 5px 15px;
    font-size: 0.75rem;
    color: var(--msg-text-muted);
    font-weight: 600;
    border-radius: 20px;
    z-index: 2;
    text-transform: capitalize;
}

/* Message Metadata (Time & Status) */
.msg-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 5px;
    margin-top: 5px;
    font-size: 0.65rem;
}

.sent .msg-meta {
    color: rgba(255,255,255,0.7);
}

.received .msg-meta {
    color: var(--msg-text-muted);
}

.status-icon {
    font-size: 0.75rem;
}

.status-read {
    color: #ff4545 !important;
}

.msg-text-content {
    word-wrap: break-word;
}
