/**
 * Tunbridge Wellness - Direct Messaging Component Styles
 * Palette: Forest Green (#2D3E33), Sage (#4A7B72), Sand/Linen (#FBFBF9, #E8E2D6), Plum (#6C536D)
 */

.dm-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    margin: 0 auto;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: #2D3E33;
}

.dm-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    grid-template-rows: minmax(0, 1fr);
    background: #FFFFFF;
    border: 1px solid #E8E2D6;
    border-radius: 16px;
    height: min(720px, calc(100dvh - 180px));
    min-height: 520px;
    box-shadow: 0 10px 30px rgba(45, 62, 51, 0.05);
    overflow: hidden;
    position: relative;
}

/* -------------------------------------------------------------
   Left Sidebar: Thread List
------------------------------------------------------------- */
.dm-sidebar {
    background: #FBFBF9;
    border-right: 1px solid #E8E2D6;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.dm-sidebar-header {
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid #E8E2D6;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #FFFFFF;
}

.dm-sidebar-header h3 {
    margin: 0;
    font-size: 1.15rem;
    font-family: 'DM Serif Display', Georgia, serif;
    color: #2D3E33;
    letter-spacing: -0.01em;
}

.dm-unread-badge-total {
    background: #4A7B72;
    color: #FFFFFF;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    line-height: 1;
}

.dm-new-msg-btn:hover {
    background: #5B4158 !important;
    transform: translateY(-1px);
}

.dm-new-msg-btn:active {
    transform: translateY(0);
}

.dm-empty-start-btn:hover {
    background: #5B4158 !important;
    transform: translateY(-1px);
}

.dm-modal-close:hover {
    color: #2D3E33 !important;
    background: #EAE5DE !important;
}

.dm-thread-list {
    flex: 1;
    overflow-y: auto;
    list-style: none;
    margin: 0;
    padding: 0.5rem 0;
}

.dm-thread-list::-webkit-scrollbar {
    width: 6px;
}
.dm-thread-list::-webkit-scrollbar-thumb {
    background: #D9D2C5;
    border-radius: 3px;
}

.dm-thread-item {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.85rem 1.15rem;
    cursor: pointer;
    transition: background 0.15s ease, border-left-color 0.15s ease;
    border-left: 3px solid transparent;
    position: relative;
    user-select: none;
}

.dm-thread-item:hover {
    background: #F4F1EA;
}

.dm-thread-item.active {
    background: #EBF3EE;
    border-left-color: #2D3E33;
}

.dm-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #2D3E33;
    color: #FFFFFF;
    font-weight: 600;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: 2px solid #E8E2D6;
    overflow: hidden;
}

.dm-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.dm-avatar.concierge-avatar {
    background: linear-gradient(135deg, #4A7B72, #2D3E33);
}

.dm-thread-details {
    flex: 1;
    min-width: 0;
}

.dm-thread-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.25rem;
}

.dm-thread-name {
    font-size: 0.92rem;
    font-weight: 600;
    color: #2D3E33;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dm-thread-role {
    font-size: 0.72rem;
    color: #4A7B72;
    background: rgba(74, 123, 114, 0.12);
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
    margin-left: 0.35rem;
    font-weight: 500;
    vertical-align: middle;
}

.dm-thread-role.dm-enquiry-badge {
    background: #DCFCE7;
    color: #15803D;
    font-weight: 600;
    border: 1px solid rgba(21, 128, 61, 0.15);
}

.dm-thread-time {
    font-size: 0.75rem;
    color: #8C827A;
    white-space: nowrap;
    margin-left: 0.5rem;
}

.dm-thread-delete-btn {
    background: none;
    border: none;
    padding: 2px 4px;
    cursor: pointer;
    color: #8C827A;
    opacity: 0;
    transition: opacity 0.15s ease, color 0.15s ease, background 0.15s ease;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.dm-thread-item:hover .dm-thread-delete-btn,
.dm-thread-item:focus-within .dm-thread-delete-btn {
    opacity: 0.6;
}

.dm-thread-delete-btn:hover {
    opacity: 1 !important;
    color: #DC2626 !important;
    background: rgba(220, 38, 38, 0.08) !important;
}

.dm-thread-delete-btn:focus-visible {
    opacity: 1 !important;
    outline: 2px solid #6C536D;
}

.dm-thread-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.dm-thread-snippet {
    font-size: 0.82rem;
    color: #6B7280;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.dm-thread-item.has-unread .dm-thread-snippet {
    color: #2D3E33;
    font-weight: 600;
}

.dm-unread-badge {
    background: #4A7B72;
    color: #FFFFFF;
    font-size: 0.72rem;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 0.5rem;
    flex-shrink: 0;
}

/* -------------------------------------------------------------
   Right Column: Active Chat Area
------------------------------------------------------------- */
.dm-main {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    background: #FFFFFF;
    position: relative;
    min-width: 0;
}

#dm-active-chat {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

.dm-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 2.5rem 1.5rem;
    text-align: center;
    color: #8C827A;
}

.dm-empty-state-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #F4F1EA;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.15rem;
    color: #4A7B72;
    flex-shrink: 0;
}

.dm-empty-state h4 {
    margin: 0 0 0.5rem;
    font-family: 'DM Serif Display', Georgia, serif;
    font-size: 1.35rem;
    color: #2D3E33;
}

.dm-empty-state p {
    margin: 0;
    font-size: 0.92rem;
    max-width: 440px;
    line-height: 1.55;
    color: #5C635E;
}

/* Empty State Actions & Buttons */
.dm-empty-state-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.dm-empty-state-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.65rem 1.25rem;
    background: var(--forest, #6C536D);
    color: #FFFFFF !important;
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s ease;
    border: 1px solid var(--forest, #6C536D);
    cursor: pointer;
    font-family: inherit;
    line-height: 1.35;
}

.dm-empty-state-btn:hover {
    background: var(--forest-mid, #5D465F);
    border-color: var(--forest-mid, #5D465F);
    color: #FFFFFF !important;
    transform: translateY(-1px);
}

.dm-empty-state-btn--secondary {
    background: #FFFFFF;
    color: var(--forest, #6C536D) !important;
    border: 1px solid #D5CEC0;
}

.dm-empty-state-btn--secondary:hover {
    background: #F4EFE6;
    border-color: var(--forest, #6C536D);
    color: var(--forest, #6C536D) !important;
    transform: translateY(-1px);
}

/* Chat Header */
.dm-chat-header {
    padding: 0.9rem 1.25rem;
    border-bottom: 1px solid #E8E2D6;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #FFFFFF;
    flex-shrink: 0;
}

.dm-chat-recipient-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.dm-back-btn {
    display: none;
    background: none;
    border: none;
    color: #2D3E33;
    cursor: pointer;
    padding: 0.4rem;
    margin-right: 0.25rem;
    border-radius: 6px;
}
.dm-back-btn:hover {
    background: #F4F1EA;
}

.dm-chat-recipient-name {
    font-size: 1rem;
    font-weight: 600;
    color: #2D3E33;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.dm-chat-status {
    font-size: 0.78rem;
    color: #4A7B72;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-top: 0.15rem;
}

.dm-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #10B981;
}

.dm-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.dm-header-delete-btn {
    background: none;
    border: 1px solid #E8E2D6;
    border-radius: 6px;
    padding: 0.35rem 0.65rem;
    color: #8C827A;
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    transition: all 0.15s ease;
    font-family: inherit;
}

.dm-header-delete-btn:hover {
    color: #DC2626 !important;
    border-color: #FECACA !important;
    background: #FEF2F2 !important;
}

.dm-action-link {
    font-size: 0.82rem;
    color: #4A7B72;
    text-decoration: none;
    font-weight: 500;
    padding: 0.35rem 0.75rem;
    border-radius: 6px;
    border: 1px solid #E8E2D6;
    transition: background 0.15s ease;
}
.dm-action-link:hover {
    background: #F4F1EA;
    color: #2D3E33;
}

/* Chat Message Stream */
.dm-message-stream,
#dm-message-stream,
#messagesContainer,
.messages-feed,
.messages-list {
    flex: 1 1 auto;
    overflow-y: auto !important;
    overflow-x: hidden;
    min-height: 0;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    background: #FAF8F5;
}

.dm-message-stream::-webkit-scrollbar {
    width: 6px;
}
.dm-message-stream::-webkit-scrollbar-thumb {
    background: #D9D2C5;
    border-radius: 3px;
}

.dm-message-group {
    display: flex;
    flex-direction: column;
    max-width: 75%;
}

.dm-message-group.outgoing {
    align-self: flex-end;
    align-items: flex-end;
}

.dm-message-group.incoming {
    align-self: flex-start;
    align-items: flex-start;
}

.dm-message-sender-name {
    font-size: 0.75rem;
    font-weight: 600;
    color: #6B7280;
    margin-bottom: 0.25rem;
    padding-left: 0.25rem;
}

.dm-message-bubble {
    padding: 0.85rem 1.15rem;
    font-size: 0.92rem;
    line-height: 1.5;
    word-break: break-word;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.dm-message-group.outgoing .dm-message-bubble {
    background: #2D3E33;
    color: #FFFFFF;
    border-radius: 16px 16px 4px 16px;
}

.dm-message-group.incoming .dm-message-bubble {
    background: #FFFFFF;
    color: #2D3E33;
    border: 1px solid #E8E2D6;
    border-radius: 16px 16px 16px 4px;
}

.dm-message-meta {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.72rem;
    color: #8C827A;
    margin-top: 0.25rem;
    padding: 0 0.25rem;
}

.dm-read-status {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

.dm-read-status.read {
    color: #4A7B72;
    font-weight: 500;
}

.dm-delete-msg-btn {
    background: none;
    border: none;
    padding: 2px 4px;
    cursor: pointer;
    color: #8C827A;
    opacity: 0.5;
    transition: opacity 0.15s ease, color 0.15s ease, background 0.15s ease;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    margin-left: 0.2rem;
}

.dm-message-group:hover .dm-delete-msg-btn {
    opacity: 0.85;
}

.dm-delete-msg-btn:hover {
    opacity: 1 !important;
    color: #DC2626 !important;
    background: rgba(220, 38, 38, 0.08) !important;
}

.dm-delete-msg-btn:focus-visible {
    outline: 2px solid #6C536D;
    outline-offset: 1px;
    opacity: 1;
}

/* Chat Composer */
.dm-composer-wrap {
    padding: 1rem 1.25rem;
    background: #FFFFFF;
    border-top: 1px solid #E8E2D6;
    flex-shrink: 0;
}

.dm-composer-form {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    background: #FBFBF9;
    border: 1px solid #D9D2C5;
    border-radius: 24px;
    padding: 0.4rem 0.6rem 0.4rem 1rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.dm-composer-form:focus-within {
    border-color: #2D3E33;
    box-shadow: 0 0 0 3px rgba(45, 62, 51, 0.1);
    background: #FFFFFF;
}

.dm-input {
    flex: 1;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 0.92rem;
    line-height: 1.45;
    color: #2D3E33;
    resize: none;
    padding: 0.4rem 0;
    max-height: 120px;
    min-height: 24px;
    outline: none;
}

.dm-input::placeholder {
    color: #9CA3AF;
}

.dm-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #2D3E33;
    color: #FFFFFF;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, transform 0.1s ease;
    flex-shrink: 0;
}

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

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

.dm-send-btn:disabled {
    background: #D1D5DB;
    cursor: not-allowed;
    transform: none;
}

.dm-composer-hint {
    margin: 0.4rem 0 0 0.5rem;
    font-size: 0.72rem;
    color: #9CA3AF;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

/* -------------------------------------------------------------
   Responsive Mobile Behavior (< 768px)
------------------------------------------------------------- */
@media (max-width: 768px) {
    .dm-layout {
        grid-template-columns: 1fr;
        height: calc(100dvh - 140px);
        min-height: 480px;
    }

    .dm-thread-delete-btn {
        opacity: 0.7; /* Always visible on mobile/touch */
    }

    .dm-sidebar {
        display: flex;
    }

    .dm-main {
        display: none;
    }

    /* Active thread slide in */
    .dm-layout.thread-active .dm-sidebar {
        display: none;
    }

    .dm-layout.thread-active .dm-main {
        display: flex;
    }

    .dm-back-btn {
        display: inline-flex;
    }

    .dm-message-group {
        max-width: 88%;
    }
}
