/**
 * NxSpot Relationship System — Global Messages View styles
 * Scoped under .nxspot-rel-msg- prefix. Operational scan-focused layout.
 * Row is the primary interaction — no per-row action chips on the list view.
 */

/* ===== Page header ===== */
.nxspot-rel-page #nxspot-rel-messages-app .nxspot-rel-msg-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 4px;
}
.nxspot-rel-page #nxspot-rel-messages-app .nxspot-rel-msg-header h1 {
    margin: 0;
}
.nxspot-rel-msg-unread-pill {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: 999px;
    background: #fef3e2;
    color: #a8741a;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
}
.nxspot-rel-msg-subtitle {
    font-size: 13px;
    color: #888;
    margin: 0 0 18px 0;
}

/* ===== Filter Tabs ===== */
.nxspot-rel-msg-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 18px;
    overflow-x: auto;
    padding-bottom: 4px;
}
.nxspot-rel-msg-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid #e8e0d6;
    border-radius: 999px;
    background: #fff;
    color: #555;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    line-height: 1.4;
}
.nxspot-rel-msg-tab:hover {
    background: #faf6f0;
    color: #333333;
}
.nxspot-rel-msg-tab--active {
    background: #ff9600;
    border-color: #ff9600;
    color: #fff;
}
.nxspot-rel-msg-tab--active:hover {
    background: #e69612;
    color: #fff;
}
.nxspot-rel-msg-tab__count {
    font-size: 11px;
    font-weight: 500;
    opacity: 0.75;
}
.nxspot-rel-msg-tab--active .nxspot-rel-msg-tab__count {
    opacity: 0.9;
}
.nxspot-rel-msg-tab__count:empty {
    display: none;
}

/* ===== Conversation List ===== */
.nxspot-rel-msg-list {
    display: flex;
    flex-direction: column;
    gap: 0;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid #f0e8dc;
    background: #fff;
}

/* ===== Conversation Row ===== */
.nxspot-rel-msg-row {
    display: flex;
    gap: 14px;
    align-items: flex-start;
    padding: 14px 16px;
    border-bottom: 1px solid #f5f0e8;
    background: #fff;
    cursor: pointer;
    transition: background 0.15s ease;
    position: relative;
    text-decoration: none;
    color: inherit;
}
.nxspot-rel-msg-row:last-child {
    border-bottom: none;
}
.nxspot-rel-msg-row:hover {
    background: #fdf8f1;
}
.nxspot-rel-msg-row:focus-visible {
    outline: 2px solid #ff9600;
    outline-offset: -2px;
}

/* Unread row emphasis — stronger background + left border accent */
.nxspot-rel-msg-row--unread {
    background: #fff8ea;
    border-left: 3px solid #ff9600;
    padding-left: 13px;
}
.nxspot-rel-msg-row--unread:hover {
    background: #fef0d3;
}

/* ===== Avatar ===== */
.nxspot-rel-msg-row__avatar {
    flex: 0 0 auto;
    position: relative;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    overflow: visible;
    background: #ff9600;
    display: flex;
    align-items: center;
    justify-content: center;
}
.nxspot-rel-msg-row__avatar-img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}
.nxspot-rel-msg-row__avatar-initials {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 600;
    font-size: 15px;
    background: #ff9600;
}
.nxspot-rel-msg-row__unread-dot {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 11px;
    height: 11px;
    background: #ff9600;
    border: 2px solid #fff;
    border-radius: 50%;
    pointer-events: none;
}

/* ===== Main column ===== */
.nxspot-rel-msg-row__main {
    flex: 1 1 auto;
    min-width: 0;
}
.nxspot-rel-msg-row__top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 4px;
}
.nxspot-rel-msg-row__name-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1 1 auto;
}
.nxspot-rel-msg-row__name {
    font-size: 15px;
    color: #333333;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.nxspot-rel-msg-row--unread .nxspot-rel-msg-row__name {
    font-weight: 700;
}
.nxspot-rel-msg-row__time {
    flex: 0 0 auto;
    font-size: 12px;
    color: #999;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.nxspot-rel-msg-row--unread .nxspot-rel-msg-row__time {
    color: #ff9600;
    font-weight: 600;
}

/* ===== Channel icon (inline before preview) ===== */
.nxspot-rel-msg-row__channel {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    flex: 0 0 auto;
    color: #999;
}
.nxspot-rel-msg-row__channel svg {
    display: block;
}
.nxspot-rel-msg-row--unread .nxspot-rel-msg-row__channel {
    color: #ff9600;
}

/* ===== Preview line ===== */
.nxspot-rel-msg-row__preview-line {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    margin-bottom: 6px;
}
.nxspot-rel-msg-row__preview {
    font-size: 13px;
    color: #666;
    line-height: 1.45;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    white-space: nowrap;
    text-overflow: ellipsis;
    flex: 1 1 auto;
    min-width: 0;
}
.nxspot-rel-msg-row__preview-actor {
    font-weight: 600;
    color: #555;
}
.nxspot-rel-msg-row--unread .nxspot-rel-msg-row__preview {
    color: #333333;
    font-weight: 500;
}
.nxspot-rel-msg-row--unread .nxspot-rel-msg-row__preview-actor {
    color: #333333;
    font-weight: 700;
}
.nxspot-rel-msg-row__preview-failed {
    color: #d32f2f;
    font-weight: 500;
}

/* ===== Meta row (state + awaiting-reply pills) ===== */
.nxspot-rel-msg-row__meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}
.nxspot-rel-msg-row__state {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.4;
    white-space: nowrap;
}
.nxspot-rel-msg-row__state--new,
.nxspot-rel-msg-row__state--new_connection {
    background: #e3f2fd;
    color: #1565c0;
}
.nxspot-rel-msg-row__state--conversation_started {
    background: #f5f0e8;
    color: #8a6d3b;
}
.nxspot-rel-msg-row__state--engaged {
    background: #e8f5e9;
    color: #2e7d32;
}
.nxspot-rel-msg-row__state--at_risk {
    background: #fff4e5;
    color: #c77700;
}
.nxspot-rel-msg-row__state--converted {
    background: #f1f1f1;
    color: #666;
}
.nxspot-rel-msg-row__awaiting {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 500;
    background: #fff4e5;
    color: #c77700;
    line-height: 1.4;
    white-space: nowrap;
}
.nxspot-rel-msg-row__awaiting svg {
    flex: 0 0 auto;
}

/* ===== Empty + footer ===== */
.nxspot-rel-msg-empty {
    padding: 60px 24px;
    text-align: center;
}
.nxspot-rel-msg-empty h3 {
    margin: 14px 0 6px;
    font-size: 18px;
    color: #333333;
}
.nxspot-rel-msg-empty p {
    color: #888;
    font-size: 14px;
    margin: 0;
}
.nxspot-rel-msg-footer {
    display: flex;
    justify-content: center;
    padding: 16px 0;
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
    .nxspot-rel-msg-row {
        padding: 12px 14px;
        gap: 12px;
    }
    .nxspot-rel-msg-row__avatar {
        width: 40px;
        height: 40px;
    }
    .nxspot-rel-msg-row__name {
        font-size: 14px;
    }
    .nxspot-rel-msg-row__preview {
        font-size: 12.5px;
    }
}

/* =============================================================
   CONVERSATION VIEW (?view=conversation&contact_id=X)
   ============================================================= */

.nxspot-rel-conv-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    background: #fff;
    border: 1px solid #f0e8dc;
    border-radius: 12px;
    margin-bottom: 14px;
}
.nxspot-rel-conv-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #faf6f0;
    color: #333333;
    border: none;
    cursor: pointer;
    flex: 0 0 auto;
    text-decoration: none;
    transition: background 0.15s ease;
}
.nxspot-rel-conv-back:hover {
    background: #f0e8dc;
}
.nxspot-rel-conv-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #ff9600;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 15px;
    flex: 0 0 auto;
    overflow: hidden;
}
.nxspot-rel-conv-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.nxspot-rel-conv-identity {
    flex: 1 1 auto;
    min-width: 0;
}
.nxspot-rel-conv-name {
    font-size: 16px;
    font-weight: 600;
    color: #333333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.nxspot-rel-conv-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
    align-items: center;
}

.nxspot-rel-conv-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 18px;
}
.nxspot-rel-conv-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid #e8e0d6;
    border-radius: 999px;
    background: #fff;
    color: #333333;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}
.nxspot-rel-conv-action:hover:not([disabled]) {
    background: #fdf8f1;
    border-color: #ff9600;
}
.nxspot-rel-conv-action--primary {
    background: #ff9600;
    border-color: #ff9600;
    color: #fff;
}
.nxspot-rel-conv-action--primary:hover:not([disabled]) {
    background: #e69612;
    border-color: #e69612;
    color: #fff;
}
.nxspot-rel-conv-action[disabled] {
    opacity: 0.45;
    cursor: not-allowed;
}
.nxspot-rel-conv-action svg {
    flex: 0 0 auto;
}

.nxspot-rel-conv-thread {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 18px;
    background: #fff;
    border: 1px solid #f0e8dc;
    border-radius: 12px;
    min-height: 200px;
}
.nxspot-rel-conv-empty {
    text-align: center;
    color: #888;
    padding: 30px 16px;
    font-size: 14px;
}

.nxspot-rel-conv-item {
    display: flex;
    flex-direction: column;
    max-width: 78%;
}
.nxspot-rel-conv-item--inbound {
    align-self: flex-start;
}
.nxspot-rel-conv-item--outbound {
    align-self: flex-end;
    align-items: flex-end;
}
.nxspot-rel-conv-item--system {
    align-self: center;
    max-width: 100%;
    width: 100%;
    align-items: center;
}

.nxspot-rel-conv-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.45;
    word-break: break-word;
    white-space: pre-wrap;
}
.nxspot-rel-conv-item--inbound .nxspot-rel-conv-bubble {
    background: #f5f0e8;
    color: #333333;
    border-bottom-left-radius: 4px;
}
.nxspot-rel-conv-item--outbound .nxspot-rel-conv-bubble {
    background: #ff9600;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.nxspot-rel-conv-item--failed .nxspot-rel-conv-bubble {
    background: #fff;
    color: #d32f2f;
    border: 1px solid #f8d7da;
    border-radius: 10px;
    font-size: 13px;
    text-align: center;
}

.nxspot-rel-conv-bubble-meta {
    margin-top: 4px;
    font-size: 11px;
    color: #999;
    display: flex;
    align-items: center;
    gap: 6px;
}
.nxspot-rel-conv-item--outbound .nxspot-rel-conv-bubble-meta {
    flex-direction: row-reverse;
}
.nxspot-rel-conv-bubble-channel {
    display: inline-flex;
    align-items: center;
    color: #999;
}
.nxspot-rel-conv-bubble-channel svg {
    display: block;
}

.nxspot-rel-conv-load-older {
    align-self: center;
    background: none;
    border: 1px solid #e8e0d6;
    color: #555;
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 12px;
    cursor: pointer;
}
.nxspot-rel-conv-load-older:hover {
    background: #faf6f0;
}

@media (max-width: 640px) {
    .nxspot-rel-conv-item {
        max-width: 88%;
    }
}

/* Attention condition — sits alongside the relationship state, never replaces it.
   Relationship state, communication state and operational attention are separate
   concepts and are shown separately. */
.nxspot-rel-msg-row__attention-condition {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
    background: #fdecea;
    color: #c0392b;
}
