/* ==========================================================================
   Messaging - Shared styles for patient and doctor messaging
   ========================================================================== */

/* ------------------------------------------------------------------
   Badge (hamburger menu + doctor navbar)
   ------------------------------------------------------------------ */
.nav-menu-badge,
.messages-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    font-size: 0.7rem;
    font-weight: 700;
    color: #fff;
    background-color: #dc3545;
    border-radius: 10px;
    margin-left: auto;
}

/* ------------------------------------------------------------------
   Patient overlay (full-screen, same pattern as diary-overlay)
   ------------------------------------------------------------------ */
.messaging-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--gray-50, #f9fafb);
    z-index: 1050;
    display: flex;
    flex-direction: column;
    animation: msgSlideIn 0.3s var(--ease-out, ease-out);
}

.messaging-overlay.closing {
    animation: msgSlideOut 0.3s ease-in forwards;
}

@keyframes msgSlideIn {
    from { transform: translateX(100%); }
    to   { transform: translateX(0); }
}

@keyframes msgSlideOut {
    from { transform: translateX(0); }
    to   { transform: translateX(100%); }
}

/* Header */
.messaging-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: #fff;
    border-bottom: 1px solid var(--gray-200, #e5e7eb);
    box-shadow: var(--shadow-xs, 0 1px 2px 0 rgba(0, 0, 0, 0.05));
    flex-shrink: 0;
}

.messaging-header-info {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.messaging-doctor-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background-color: var(--primary-color, #8B0000);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 600;
    flex-shrink: 0;
}

.messaging-header .messaging-title {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.2;
}

.messaging-header .messaging-subtitle {
    font-size: 0.75rem;
    line-height: 1.2;
}

.messaging-header .close-btn {
    border: none;
    background: none;
    font-size: 1.25rem;
    color: #6c757d;
    padding: 0.25rem;
    cursor: pointer;
    line-height: 1;
}

.messaging-header .close-btn:hover {
    color: #333;
}

/* Messages area */
.messaging-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* Load more button */
.messaging-load-more {
    text-align: center;
    padding: 0.5rem;
}

.messaging-load-more button {
    border: none;
    background: none;
    color: var(--primary-color, #8B0000);
    font-size: 0.85rem;
    cursor: pointer;
    padding: 0.25rem 0.75rem;
}

.messaging-load-more button:hover {
    text-decoration: underline;
}

/* Empty state */
.messaging-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: #6c757d;
    font-size: 0.9rem;
    text-align: center;
    padding: 2rem;
}

/* Input area */
.messaging-input-area {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: #fff;
    border-top: 1px solid var(--gray-200, #e5e7eb);
    flex-shrink: 0;
}

.messaging-input-area textarea {
    flex: 1;
    border: 1px solid #dee2e6;
    border-radius: 1.25rem;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    resize: none;
    max-height: 120px;
    line-height: 1.4;
    outline: none;
    font-family: inherit;
}

.messaging-input-area textarea:focus {
    border-color: var(--primary-color, #8B0000);
    box-shadow: 0 0 0 2px rgba(139, 0, 0, 0.1);
}

.messaging-input-area .send-msg-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background-color: var(--primary-color, #8B0000);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color 0.15s;
}

.messaging-input-area .send-msg-btn:hover {
    background-color: #6b0000;
}

.messaging-input-area .send-msg-btn:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

/* ------------------------------------------------------------------
   Message bubbles (shared)
   ------------------------------------------------------------------ */
.message-bubble {
    max-width: 80%;
    padding: 0.5rem 0.875rem;
    border-radius: 1rem;
    font-size: 0.9rem;
    line-height: 1.45;
    word-wrap: break-word;
    position: relative;
}

.message-bubble .msg-time {
    display: block;
    font-size: 0.7rem;
    color: rgba(0, 0, 0, 0.4);
    margin-top: 0.2rem;
    text-align: right;
}

.message-bubble.sent {
    align-self: flex-end;
    background-color: var(--primary-color, #8B0000);
    color: #fff;
    border-bottom-right-radius: 0.25rem;
}

.message-bubble.sent .msg-time {
    color: rgba(255, 255, 255, 0.6);
}

.message-bubble.received {
    align-self: flex-start;
    background-color: #fff;
    color: #333;
    border: 1px solid #e9ecef;
    border-bottom-left-radius: 0.25rem;
}

/* Date separator */
.message-date-separator {
    text-align: center;
    padding: 0.5rem 0;
    font-size: 0.75rem;
    color: #6c757d;
    font-weight: 500;
}

/* ------------------------------------------------------------------
   Doctor messaging section (inside doctor-main)
   ------------------------------------------------------------------ */
.doctor-messages-section {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* Split layout: conversation list + thread */
.doctor-messages-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Left: conversation list */
.doctor-conversations-list {
    width: 280px;
    border-right: 1px solid #dee2e6;
    overflow-y: auto;
    flex-shrink: 0;
    background: #fff;
}

.conversation-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background-color 0.15s;
}

.conversation-item:hover {
    background-color: #f8f9fa;
}

.conversation-item.active {
    background-color: #e8f0fe;
    border-left: 3px solid var(--doctor-primary, #0056B3);
}

.conversation-item .conv-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--doctor-primary, #0056B3);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 600;
    flex-shrink: 0;
}

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

.conversation-item .conv-name {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 0.1rem;
}

.conversation-item .conv-preview {
    font-size: 0.8rem;
    color: #6c757d;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-item .conv-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.25rem;
    flex-shrink: 0;
}

.conversation-item .conv-time {
    font-size: 0.7rem;
    color: #6c757d;
}

.conversation-item .conv-unread {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    font-size: 0.7rem;
    font-weight: 700;
    color: #fff;
    background-color: #dc3545;
    border-radius: 10px;
}

/* Right: active thread */
.doctor-messages-thread {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.doctor-messages-thread .thread-header {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #dee2e6;
    background: #fff;
}

.doctor-messages-thread .thread-header h6 {
    margin: 0;
    font-weight: 600;
}

.doctor-messages-thread .thread-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.doctor-messages-thread .thread-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: #6c757d;
    font-size: 0.9rem;
}

/* Doctor input area */
.doctor-messages-thread .messaging-input-area .send-msg-btn {
    background-color: var(--doctor-primary, #0056B3);
}

.doctor-messages-thread .messaging-input-area .send-msg-btn:hover {
    background-color: #004494;
}

.doctor-messages-thread .messaging-input-area textarea:focus {
    border-color: var(--doctor-primary, #0056B3);
    box-shadow: 0 0 0 2px rgba(0, 86, 179, 0.1);
}

/* Doctor sent bubbles override */
.doctor-messages-section .message-bubble.sent {
    background-color: var(--doctor-primary, #0056B3);
}

/* Empty state for conversation selection */
.doctor-thread-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: #6c757d;
    text-align: center;
    padding: 2rem;
}

.doctor-thread-placeholder i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.4;
}

/* Doctor navbar messages button */
.btn-messages {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    background: none;
    border: 1px solid #0056B3;
    color: #0056B3;
    border-radius: 0.375rem;
    padding: 0.25rem 0.625rem;
    font-size: 0.85rem;
    cursor: pointer;
    position: relative;
    transition: all 0.15s;
}

.btn-messages:hover {
    background-color: #0056B3;
    color: #fff;
}

.btn-messages .messages-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 18px;
    height: 18px;
    font-size: 0.65rem;
}

/* ------------------------------------------------------------------
   New conversation button + Patient picker
   ------------------------------------------------------------------ */
.new-conversation-btn-wrapper {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #dee2e6;
}

.new-conversation-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border: 1px dashed var(--doctor-primary, #0056B3);
    border-radius: 0.5rem;
    background: none;
    color: var(--doctor-primary, #0056B3);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s;
}

.new-conversation-btn:hover {
    background-color: var(--doctor-primary, #0056B3);
    color: #fff;
}

.patient-picker-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #dee2e6;
    background: #fff;
    font-weight: 600;
    font-size: 0.95rem;
}

.patient-picker-back-btn {
    border: none;
    background: none;
    padding: 0.25rem;
    font-size: 1.1rem;
    color: var(--doctor-primary, #0056B3);
    cursor: pointer;
    line-height: 1;
}

.patient-picker-back-btn:hover {
    color: #004494;
}

.patient-picker-search-wrapper {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #f0f0f0;
}

.patient-picker-search {
    width: 100%;
    padding: 0.45rem 0.75rem;
    border: 1px solid #dee2e6;
    border-radius: 1.25rem;
    font-size: 0.85rem;
    outline: none;
    font-family: inherit;
}

.patient-picker-search:focus {
    border-color: var(--doctor-primary, #0056B3);
    box-shadow: 0 0 0 2px rgba(0, 86, 179, 0.1);
}

.patient-picker-list {
    overflow-y: auto;
    flex: 1;
}

.patient-picker-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background-color 0.15s;
}

.patient-picker-item:hover {
    background-color: #f8f9fa;
}

.patient-picker-item .conv-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--doctor-primary, #0056B3);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 600;
    flex-shrink: 0;
}

.patient-picker-item .conv-info {
    flex: 1;
    min-width: 0;
}

.patient-picker-item .conv-name {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 0.1rem;
}

.patient-picker-item .conv-preview {
    font-size: 0.8rem;
    color: #6c757d;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ------------------------------------------------------------------
   Responsive
   ------------------------------------------------------------------ */
@media (max-width: 768px) {
    .doctor-conversations-list {
        width: 100%;
        border-right: none;
    }

    .doctor-messages-layout {
        flex-direction: column;
    }

    /* Show only one pane at a time on mobile */
    .doctor-messages-layout.thread-active .doctor-conversations-list {
        display: none;
    }

    .doctor-messages-layout:not(.thread-active) .doctor-messages-thread {
        display: none;
    }

    /* Thread back button for mobile */
    .thread-back-btn {
        display: inline-flex;
    }

    .message-bubble {
        max-width: 88%;
    }
}

@media (min-width: 769px) {
    .thread-back-btn {
        display: none;
    }
}
