/* Batch C message workspace enhancements. */

#messages-contacts.batch-c-message-contacts {
    display: flex;
    flex-direction: column;
    width: 340px;
    min-width: 300px;
    background: #fff;
}

.message-filter-bar {
    position: sticky;
    top: 0;
    z-index: 3;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 12px;
    border-bottom: 1px solid #d8e0ea;
    background: #fff;
}

.message-filter-button {
    min-height: 32px;
    padding: 5px 9px;
    border: 1px solid #c7d2e1;
    border-radius: 6px;
    background: #fff;
    color: #334155;
    font: inherit;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
}

.message-filter-button:hover {
    border-color: #2563eb;
    color: #1d4ed8;
}

.message-filter-button[aria-pressed="true"] {
    border-color: #1d4ed8;
    background: #e8f0ff;
    color: #1d4ed8;
}

#messages-contacts > .contact-item {
    min-height: 116px;
    padding: 13px 12px;
    align-items: flex-start;
    border-left: 3px solid transparent;
}

#messages-contacts > .contact-item.has-unread {
    border-left-color: #2563eb;
    background: #f7faff;
}

#messages-contacts > .contact-item.needs-reply:not(.active) {
    background: #fffaf0;
}

#messages-contacts > .contact-item[hidden] {
    display: none;
}

#messages-contacts .contact-info {
    min-width: 0;
    flex: 1;
}

.batch-c-contact-heading,
.batch-c-contact-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.batch-c-contact-heading .contact-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #0f172a;
    font-size: 0.9rem;
    font-weight: 800;
}

.message-unread-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 999px;
    background: #1d4ed8;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 800;
}

.batch-c-contact-preview {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 7px;
    align-items: center;
    margin-top: 7px;
}

.batch-c-contact-preview .contact-preview {
    overflow: hidden;
    color: #475569;
    font-size: 0.77rem;
    line-height: 1.45;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.message-direction {
    font-size: 0.69rem;
    font-weight: 800;
    white-space: nowrap;
}

.message-direction.is-inbound {
    color: #b45309;
}

.message-direction.is-outbound {
    color: #1d4ed8;
}

.message-direction.is-none {
    color: #64748b;
}

.batch-c-contact-meta {
    margin-top: 9px;
}

.batch-c-contact-meta time {
    color: #64748b;
    font-size: 0.7rem;
    white-space: nowrap;
}

.message-stage-badge {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    max-width: 170px;
    padding: 2px 7px;
    overflow: hidden;
    border-radius: 4px;
    font-size: 0.68rem;
    font-weight: 800;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.message-stage-badge.is-active {
    background: #e8f0ff;
    color: #1d4ed8;
}

.message-stage-badge.is-terminal {
    background: #e2e8f0;
    color: #475569;
}

.batch-c-conversation {
    display: flex;
    flex-direction: column;
    gap: 8px !important;
    background: #f1f5f9;
}

.batch-c-conversation .message-date-separator {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    margin: 9px 0;
    color: #64748b;
    font-size: 0.72rem;
    font-weight: 700;
    text-align: center;
}

.batch-c-conversation .message-date-separator::before,
.batch-c-conversation .message-date-separator::after {
    content: '';
    flex: 1;
    height: 1px;
    background: #cbd5e1;
}

.batch-c-conversation .batch-c-message {
    width: fit-content;
    max-width: min(76%, 680px);
    margin: 0 0 6px;
}

.batch-c-conversation .batch-c-message.msg-sent {
    align-self: flex-end;
    align-items: flex-end;
}

.batch-c-conversation .batch-c-message.msg-received {
    align-self: flex-start;
    align-items: flex-start;
}

.batch-c-conversation .msg-header {
    display: flex;
    gap: 8px;
    align-items: center;
    margin: 0 3px 4px;
}

.batch-c-conversation .msg-name {
    color: #334155;
    font-size: 0.72rem;
    font-weight: 800;
}

.batch-c-conversation .msg-time {
    color: #64748b;
    font-size: 0.68rem;
}

.batch-c-conversation .msg-bubble {
    padding: 10px 13px;
    border: 1px solid transparent;
    border-radius: 7px;
    box-shadow: 0 1px 2px rgb(15 23 42 / 8%);
    font-size: 0.86rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

.batch-c-conversation .msg-sent .msg-bubble {
    border-color: #1d4ed8;
    background: #2563eb;
    color: #fff;
}

.batch-c-conversation .msg-received .msg-bubble {
    border-color: #d8e0ea;
    background: #fff;
    color: #172033;
}

.message-delivery {
    display: flex;
    gap: 8px;
    align-items: center;
    min-height: 20px;
    margin: 3px 3px 0;
    color: #64748b;
    font-size: 0.67rem;
    font-weight: 700;
}

.message-delivery.is-failed {
    color: #b91c1c;
}

.message-retry-button {
    padding: 1px 5px;
    border: 0;
    border-bottom: 1px solid currentcolor;
    background: transparent;
    color: #b91c1c;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
}

.message-load-error {
    margin: auto;
    padding: 20px;
    color: #b91c1c;
    text-align: center;
}

#btn-send-message:disabled,
#btn-workspace-send-msg:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.message-template-choice-overlay {
    position: fixed;
    inset: 0;
    z-index: 10020;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgb(15 23 42 / 48%);
}

.message-template-choice-overlay[hidden] {
    display: none;
}

.message-template-choice-dialog {
    width: min(440px, 100%);
    padding: 22px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 18px 50px rgb(15 23 42 / 22%);
}

.message-template-choice-dialog h2 {
    margin: 0;
    color: #0f172a;
    font-size: 1.05rem;
}

.message-template-choice-dialog p {
    margin: 8px 0 18px;
    color: #475569;
    font-size: 0.86rem;
}

.message-template-choice-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.message-template-choice-actions .btn {
    min-height: 38px;
}

@media (max-width: 767px) {
    #messages-contacts.batch-c-message-contacts {
        width: 100%;
        min-width: 0;
        max-height: 42vh;
    }

    .messages-container {
        flex-direction: column;
    }

    .batch-c-conversation .batch-c-message {
        max-width: 88%;
    }

    .message-template-choice-actions {
        display: grid;
        grid-template-columns: 1fr;
    }
}
