/* 
 * SUPER STRONG CSS FIX - Replace your chat-style.css with this
 * File: assets/chat-style.css
 * Version: 1.0.2 - FORCE DISPLAY FIX
 */

:root {
    --primary-color: #e63946;
    --white: #ffffff;
    --text-dark: #1d3557;
    --text-light: #8b92a5;
    --bg-light: #f8f9fa;
    --border-color: #e0e0e0;
    --shadow: 0 2px 10px rgba(0,0,0,0.08);
    --message-sent: #e63946;
    --message-received: #f1f3f5;
}

.chat-container {
    max-width: 100%;
    margin: 0 auto;
    height: calc(100vh - 70px);
    display: flex;
    background: var(--white);
    position: relative;
    overflow: hidden;
    border-radius: 10px;
}

/* Chat Sidebar */
.chat-sidebar {
    width: 100%;
    background: var(--white);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    z-index: 10;
    transition: transform 0.3s ease;
}

.chat-sidebar.hidden {
    transform: translateX(-100%);
}

.chat-sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: var(--white);
}

.chat-sidebar-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
}

.btn-close-sidebar {
    display: none;
    background: none;
    border: none;
    color: var(--white);
    cursor: pointer;
    padding: 5px;
}

/* Recent Chats List */
.recent-chats-list {
    flex: 1;
    overflow-y: auto;
}

.chat-item {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    color: var(--text-dark);
    background: var(--white);
}

.chat-item:hover {
    background: var(--bg-light);
}

.chat-item.active {
    background: rgba(230, 57, 70, 0.05);
    border-left: 3px solid var(--primary-color);
}

.chat-item-photo {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    margin-right: 15px;
    flex-shrink: 0;
    overflow: hidden;
}

.chat-item-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-item-photo .photo-placeholder {
    width: 100%;
    height: 100%;
    background: var(--primary-color);
    color: var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 700;
}

.chat-item-info {
    flex: 1;
    min-width: 0;
}

.chat-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}

.chat-item-name {
    font-weight: 600;
    font-size: 15px;
    color: var(--text-dark);
}

.chat-item-time {
    font-size: 12px;
    color: var(--text-light);
}

.chat-item-last-message {
    font-size: 14px;
    color: var(--text-light);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-item-unread {
    background: var(--primary-color);
    color: var(--white);
    font-size: 11px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 12px;
    min-width: 20px;
    text-align: center;
}

/* Chat Box */
.chat-box {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #fafbfc;
    position: relative;
}

/* Show chat box when active */
.chat-box.active {
    display: flex;
}

/* Hide sidebar on mobile when chat is active */
@media (max-width: 767px) {
    .chat-sidebar.hidden {
        display: none;
    }
    
    .chat-box {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        display: none;
    }
    
    .chat-box.active {
        display: flex !important;
        position: relative;
    }
    
    /* When no user selected, show sidebar */
    .chat-container:not(:has(.chat-box.active)) .chat-sidebar {
        display: flex;
    }
}

/* Chat Header */
.chat-header {
    background: var(--white);
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 15px;
    box-shadow: var(--shadow);
}

.btn-back-to-list {
    display: flex;
    background: none;
    border: none;
    color: var(--text-dark);
    cursor: pointer;
    padding: 5px;
}

.chat-user-info {
    display: flex;
    align-items: center;
    flex: 1;
    gap: 12px;
}

.chat-user-photo {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
}

.chat-user-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-user-photo .photo-placeholder {
    width: 100%;
    height: 100%;
    background: var(--primary-color);
    color: var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
}

.chat-user-details h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-dark);
}

.chat-user-details p {
    margin: 0;
    font-size: 13px;
    color: var(--text-light);
}

.btn-view-profile-mini {
    background: none;
    border: none;
    color: var(--primary-color);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.3s ease;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-view-profile-mini:hover {
    background: rgba(230, 57, 70, 0.1);
}

/* Messages Area - SUPER STRONG RULES */
div.chat-container div.chat-box div.messages-area {
    flex: 1 1 auto !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    padding: 20px !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 15px !important;
    min-height: 0 !important;
    background: #fafbfc !important;
}

/* CRITICAL: Force message display - Override any theme styles */
div.chat-container div.messages-area div.message,
.chat-container .messages-area .message,
#messages-area .message,
.message {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    gap: 10px !important;
    max-width: 75% !important;
    width: fit-content !important;
    animation: fadeIn 0.3s ease !important;
    position: relative !important;
}

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

/* Force sent message alignment */
div.chat-container div.messages-area div.message.sent,
.chat-container .messages-area .message.sent,
#messages-area .message.sent,
.message.sent {
    align-self: flex-end !important;
    flex-direction: row-reverse !important;
    margin-left: auto !important;
    margin-right: 0 !important;
}

/* Force received message alignment */
div.chat-container div.messages-area div.message.received,
.chat-container .messages-area .message.received,
#messages-area .message.received,
.message.received {
    align-self: flex-start !important;
    margin-right: auto !important;
    margin-left: 0 !important;
}

/* Message content box */
div.message div.message-content,
.message .message-content,
.message-content {
    background: var(--message-received) !important;
    padding: 12px 16px !important;
    border-radius: 18px !important;
    word-wrap: break-word !important;
    word-break: break-word !important;
    max-width: 100% !important;
    display: block !important;
    visibility: visible !important;
}

div.message.sent div.message-content,
.message.sent .message-content {
    background: var(--message-sent) !important;
    color: var(--white) !important;
    border-bottom-right-radius: 4px !important;
}

div.message.received div.message-content,
.message.received .message-content {
    background: var(--message-received) !important;
    border-bottom-left-radius: 4px !important;
}

/* Message text - FORCE VISIBILITY */
div.message div.message-content p.message-text,
.message .message-content .message-text,
.message-text {
    font-size: 15px !important;
    line-height: 1.4 !important;
    margin: 0 !important;
    color: var(--text-dark) !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

div.message.sent div.message-content p.message-text,
div.message.sent .message-content .message-text,
.message.sent .message-text {
    color: var(--white) !important;
}

div.message.received div.message-content p.message-text,
div.message.received .message-content .message-text,
.message.received .message-text {
    color: var(--text-dark) !important;
}

/* Message time */
div.message div.message-content div.message-time,
.message .message-content .message-time,
.message-time {
    font-size: 11px !important;
    opacity: 0.7 !important;
    margin-top: 5px !important;
    color: inherit !important;
    display: block !important;
}

/* Message Input */
.message-input-area {
    background: var(--white);
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

#message-input {
    flex: 1;
    padding: 12px 15px;
    border: 2px solid var(--border-color);
    border-radius: 25px;
    font-size: 15px;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    outline: none;
    transition: all 0.3s ease;
}

#message-input:focus {
    border-color: var(--primary-color);
}

.btn-send {
    width: 45px;
    height: 45px;
    background: var(--primary-color);
    border: none;
    border-radius: 50%;
    color: var(--white);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

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

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

/* No Chat Selected */
.no-chat-selected {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 40px 20px;
    color: var(--text-light);
}

.no-chat-selected svg {
    margin-bottom: 20px;
    opacity: 0.3;
}

.no-chat-selected h3 {
    font-size: 20px;
    color: var(--text-dark);
    margin: 0 0 10px 0;
}

.no-chat-selected p {
    font-size: 15px;
    margin: 0;
}

.no-messages {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 40px 20px;
    color: var(--text-light);
}

/* Loading States */
.loading-chats,
.loading-messages {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: var(--text-light);
}

.loader {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Tablet & Desktop */
@media (min-width: 768px) {
    .chat-container {
        max-width: 1200px;
        height: calc(100vh - 100px);
        border-radius: 15px;
        overflow: hidden;
        box-shadow: var(--shadow);
        margin: 20px auto;
    }
    
    .chat-sidebar {
        width: 350px;
        position: relative;
        transform: translateX(0) !important;
    }
    
    .btn-close-sidebar,
    .btn-back-to-list {
        display: none;
    }
    
    .message {
        max-width: 60% !important;
    }
}

/* Scrollbar Styling */
.recent-chats-list::-webkit-scrollbar,
.messages-area::-webkit-scrollbar {
    width: 6px;
}

.recent-chats-list::-webkit-scrollbar-thumb,
.messages-area::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.recent-chats-list::-webkit-scrollbar-thumb:hover,
.messages-area::-webkit-scrollbar-thumb:hover {
    background: #ccc;
}