/* Chat Overlay */
.chat-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: white;
    z-index: 2000; /* Above messages overlay */
    display: none;
    overflow: hidden;
}

.chat-container {
    max-width: 500px;
    margin: 0 auto;
    background: white;
    height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Chat Header - FIXED: Tightened alignment */
.chat-header {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    padding: 15px 20px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.chat-header-content {
    display: flex;
    align-items: center;
    justify-content: flex-start; /* FIXED: Align items to start */
    gap: 12px; /* Small fixed gap from back button to profile */
}

/* Back Button */
.chat-back-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.chat-back-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

/* User Info - FIXED: Now sits tight against the back button */
.chat-user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.chat-user-avatar {
    position: relative;
}

.chat-user-avatar img {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.chat-user-status {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    background: #4cd964;
    border-radius: 50%;
    border: 2px solid white;
}

.chat-user-details {
    text-align: left;
}

.chat-user-name {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 2px;
}

.chat-user-status-text {
    font-size: 12px;
    opacity: 0.9;
}

/* Chat Messages Area - FIXED: Reduced internal gap */
.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 2px; /* FIXED: Minimal gap between same-side messages */
}

/* Message Date Divider - FIXED: Reduced margin significantly */
.message-date-divider {
    text-align: center;
    margin: 8px 0; /* FIXED: Reduced from 10px to 8px for tighter look */
    position: relative;
}

.message-date-divider span {
    background: #e0e0e0;
    color: #666;
    font-size: 12px;
    font-weight: 600;
    padding: 5px 15px;
    border-radius: 15px;
    display: inline-block;
}

/* Message Rows - FIXED: Tighter vertical spacing */
.message-row {
    display: flex;
    gap: 10px;
    max-width: 80%;
    margin-bottom: 3px; /* FIXED: Minimal vertical gap */
}

.message-row + .message-date-divider {
    margin-top: 8px; /* Controlled space before a new date */
}

.message-row.sent {
    margin-left: auto;
    flex-direction: row-reverse;
}

.message-row.received {
    margin-right: auto;
}

/* Message Bubbles */
.message-bubble {
    padding: 12px 16px;
    border-radius: 20px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
    max-width: 100%;
    position: relative;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    margin: 0;
}

.message-row.sent .message-bubble {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border-bottom-right-radius: 5px;
}

.message-row.received .message-bubble {
    background: white;
    color: #333;
    border-bottom-left-radius: 5px;
    border: 1px solid #e0e0e0;
}

/* Message Time - FIXED: Tighter alignment to bubble */
.message-time {
    font-size: 11px;
    color: #999;
    margin-top: 1px; /* FIXED: Closer to the bubble */
    display: flex;
    align-items: center;
    gap: 4px;
}

.message-row.sent .message-time {
    justify-content: flex-end;
    color: rgba(255, 255, 255, 0.7);
}

.message-status {
    color: rgba(255, 255, 255, 0.7);
    font-size: 10px;
}

.message-row.received .message-time {
    margin-left: 10px;
    color: #999;
}

/* Message Avatar (Small) */
.message-avatar-small {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    align-self: flex-end;
    margin-bottom: 15px; /* FIXED: Adjusted to align better with bubbles */
    flex-shrink: 0;
}

/* Empty Chat */
.chat-empty {
    text-align: center;
    padding: 60px 20px;
    color: #999;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.chat-empty i {
    font-size: 64px;
    margin-bottom: 20px;
    opacity: 0.3;
}

.chat-empty h3 {
    font-size: 20px;
    margin-bottom: 10px;
    color: #666;
}

.chat-empty p {
    font-size: 14px;
    color: #999;
    max-width: 300px;
    margin: 0 auto;
}

/* Chat Input Container */
.chat-input-container {
    padding: 15px 20px;
    background: white;
    border-top: 1px solid #eee;
    position: sticky;
    bottom: 0;
    z-index: 100;
}

/* FIXED: Wrapper centers the items vertically */
.chat-input-wrapper {
    display: flex;
    align-items: center; 
    gap: 10px;
    background: #f8f9fa;
    border-radius: 25px;
    padding: 4px 15px; /* FIXED: Reduced vertical padding */
    border: 2px solid #e0e0e0;
    transition: all 0.3s ease;
    min-height: 48px;
    box-sizing: border-box;
}

.chat-input-wrapper:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(138, 43, 226, 0.1);
}

/* FIXED: Changed height logic to keep placeholder centered */
.chat-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    resize: none;
    font-size: 14px;
    color: #333;
    max-height: 120px; 
    padding: 10px 0; /* FIXED: Vertical padding defines the centering */
    font-family: inherit;
    line-height: 20px; /* FIXED: Line height matches height for centering */
    min-height: 20px;
    height: auto; /* ALLOWS EXPANSION */
    overflow-y: auto;
    display: block; 
}

.chat-input::placeholder {
    color: #999;
    opacity: 1;
    line-height: 20px; /* FIXED: Ensures placeholder is vertically centered */
}

/* FIXED: Send Button remains centered */
.send-message-btn {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0;
    margin: 0; 
    align-self: center;
}

.send-message-btn:hover:not(:disabled) {
    transform: scale(1.1);
    box-shadow: 0 3px 10px rgba(138, 43, 226, 0.3);
}

.send-message-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Scrollbar Styling */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}
.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}
.chat-messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}
.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

/* Animation for new messages */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-row {
    animation: fadeInUp 0.3s ease forwards;
}

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

/* Loading State */
.chat-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: white;
}

.chat-loading i {
    font-size: 48px;
    color: var(--primary);
    animation: spin 1s linear infinite;
}

/* Responsive */
@media (max-width: 480px) {
    .chat-container {
        max-width: 100%;
    }
    .chat-header {
        padding: 15px;
    }
    .chat-messages {
        padding: 15px;
    }
    .message-bubble {
        padding: 10px 14px;
        font-size: 13px;
    }
    .message-row {
        max-width: 85%;
    }
    .chat-input-container {
        padding: 12px 15px;
    }
    .chat-user-avatar img {
        width: 40px;
        height: 40px;
    }
}

