/* ===================================
   Messages Page Styles
   =================================== */

.messages-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 0;
    height: calc(100vh - 11rem);
    min-height: 420px;
    max-height: calc(100vh - 11rem);
    background: var(--dark-card-soft);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.conversations-panel {
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    overflow: hidden;
}

.conversations-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    background: #fff;
}

.conversations-header h2 {
    margin: 0 0 10px;
    font-size: 0.95rem;
    font-weight: 600;
}

.conversations-search input {
    width: 100%;
}

.conversations-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.conversation-item {
    display: flex;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.15s ease;
}

.conversation-item:hover,
.conversation-item.active {
    background: rgba(34, 197, 94, 0.08);
}

.conversation-item.unread {
    background: rgba(59, 130, 246, 0.06);
}

.conversation-avatar {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: rgba(34, 197, 94, 0.15);
    color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-weight: 600;
    font-size: 0.85rem;
}

.conversation-meta {
    flex: 1;
    min-width: 0;
}

.conversation-meta-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.conversation-meta-top strong {
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-meta-top time {
    font-size: 0.75rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

.conversation-preview {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-role {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.unread-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary-color);
    flex-shrink: 0;
    margin-top: 6px;
}

.chat-panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    overflow: hidden;
}

.messages-layout--chat {
    border-radius: 14px;
}

.chat-header {
    padding: 12px 16px;
    border-bottom: 1px solid #eef2f6;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    background: #fff;
}

.chat-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: linear-gradient(145deg, #3b82f6 0%, #1d4ed8 100%);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-weight: 600;
    font-size: 0.82rem;
}

.chat-header h3 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: #0f172a;
}

.chat-header small {
    color: #64748b;
    font-size: 0.78rem;
}

.chat-order-bar {
    flex-shrink: 0;
    padding: 10px 16px;
    background: #fff;
    border-bottom: 1px solid #eef2f6;
}

.chat-order-bar-inner {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.chat-order-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: #64748b;
    flex-shrink: 0;
}

.chat-order-select {
    flex: 1;
    min-width: 140px;
    max-width: 280px;
    font-size: 0.82rem;
    padding: 8px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #f8fafc;
    color: #334155;
}

.chat-order-send-card {
    border: none;
    background: #eff6ff;
    color: #1d4ed8;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 8px 14px;
    border-radius: 999px;
    cursor: pointer;
    font-family: inherit;
}

.chat-order-send-card:hover {
    background: #dbeafe;
}

.conversation-order-count {
    display: inline-block;
    margin-top: 2px;
    margin-right: 6px;
    font-size: 0.7rem;
    font-weight: 600;
    color: #475569;
    background: #f1f5f9;
    padding: 2px 8px;
    border-radius: 999px;
}

.message-order-tag {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 6px;
    margin-bottom: 6px;
    background: rgba(15, 23, 42, 0.08);
    color: #475569;
}

.message-bubble.sent .message-order-tag {
    background: rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.95);
}

.chat-messages {
    flex: 1;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
    background: #f4f6f9;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 99px;
}

.msg-row {
    display: flex;
    width: 100%;
    animation: msg-fade-in 0.2s ease-out;
}

@keyframes msg-fade-in {
    from {
        opacity: 0;
        transform: translateY(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.msg-row.is-sent {
    justify-content: flex-end;
}

.msg-row.is-received {
    justify-content: flex-start;
}

.msg-system {
    align-self: center;
    max-width: 92%;
    text-align: center;
    font-size: 0.72rem;
    color: #64748b;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 999px;
    padding: 6px 14px;
    margin: 4px auto 8px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}

.chat-empty--inline {
    flex: 1;
    min-height: 120px;
    padding: 24px;
}

.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    padding: 48px;
}

.chat-empty i {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.4;
}

.message-bubble {
    max-width: min(82%, 380px);
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.875rem;
    line-height: 1.55;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}

.message-text {
    white-space: pre-wrap;
    word-break: break-word;
}

.message-bubble.sent {
    background: #2563eb;
    color: #fff;
    border-bottom-right-radius: 5px;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.2);
}

.message-bubble.received {
    background: #fff;
    color: #334155;
    border: none;
    border-bottom-left-radius: 5px;
}

.message-bubble time {
    display: block;
    margin-top: 6px;
    font-size: 0.68rem;
    opacity: 0.82;
}

.message-bubble.sent time {
    color: rgba(255, 255, 255, 0.82);
    text-align: right;
}

.message-bubble.received time {
    color: #94a3b8;
}

.chat-compose-wrap {
    flex-shrink: 0;
    padding: 12px 14px 14px;
    background: #fff;
    border-top: 1px solid #eef2f6;
}

.chat-compose {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 6px 6px 6px 14px;
    background: #f4f6f9;
    border-radius: 999px;
    border: 1px solid transparent;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.chat-compose:focus-within {
    border-color: #bfdbfe;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    background: #fff;
}

.chat-compose-input {
    flex: 1;
    min-width: 0;
    min-height: 38px;
    max-height: 120px;
    padding: 9px 0;
    border: none;
    background: transparent;
    resize: none;
    font-family: inherit;
    font-size: 0.875rem;
    line-height: 1.45;
    color: #1e293b;
}

.chat-compose-input:focus {
    outline: none;
}

.chat-compose-input::placeholder {
    color: #94a3b8;
}

.chat-compose-send {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: #2563eb;
    color: #fff;
    cursor: pointer;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    transition: transform 0.12s ease, opacity 0.15s ease;
}

.chat-compose-send:hover:not(:disabled) {
    opacity: 0.92;
    transform: scale(1.04);
}

.header-messages {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    transition: background 0.15s, color 0.15s;
}

.header-messages:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--primary-color);
}

.header-messages .badge {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: #ef4444;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.activity-filters {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.activity-filter-btn {
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.15s;
}

.activity-filter-btn:hover,
.activity-filter-btn.active {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: rgba(34, 197, 94, 0.08);
}

.conversation-tag-social {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    background: #ede9fe;
    color: #5b21b6;
    margin-right: 4px;
}

.conversation-task-tag {
    display: inline-block;
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 4px;
    background: #f1f5f9;
    color: #64748b;
}

.msg-chat-header-text {
    flex: 1;
    min-width: 0;
}

.msg-order-scope {
    display: block;
    margin-top: 4px;
    color: #64748b;
    font-size: 0.75rem;
}

.msg-action-link {
    flex-shrink: 0;
    align-self: center;
    font-size: 0.78rem;
    font-weight: 500;
    color: #2563eb;
    text-decoration: none;
    padding: 7px 12px;
    border-radius: 999px;
    background: #eff6ff;
    border: 1px solid #dbeafe;
    transition: background 0.15s ease;
}

.msg-action-link:hover {
    background: #dbeafe;
    color: #1d4ed8;
}

@media (max-width: 992px) {
    .messages-layout {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(200px, 34vh) minmax(0, 1fr);
        height: calc(100vh - 10rem);
        max-height: calc(100vh - 10rem);
    }

    .conversations-panel {
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        max-height: none;
        height: auto;
    }

    .chat-panel {
        min-height: 0;
    }

    .chat-panel.hidden-mobile {
        display: none;
    }
}
