/* Conversations - Chat list, message bubbles, mobile */

/* â”€â”€ Conversations Redesign â”€â”€ */

/* Page chrome */
.conv-page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}
.conv-page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
    margin: 0;
    line-height: 1.2;
}
.conv-page-subtitle {
    font-size: 0.8125rem;
    color: var(--gray-500);
    margin: 0.125rem 0 0;
}
.conv-count {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-500);
    background: var(--gray-100);
    padding: 0.25rem 0.625rem;
    border-radius: 20px;
    flex-shrink: 0;
}

/* Search */
.conv-search-wrap {
    position: relative;
    margin-bottom: 1rem;
    max-width: 360px;
}
.conv-search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 15px;
    height: 15px;
    color: var(--gray-400);
    pointer-events: none;
}
.conv-search-input {
    width: 100%;
    padding: 0.5rem 0.75rem 0.5rem 2.25rem;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    font-size: 0.8125rem;
    background: white;
    color: var(--gray-900);
    transition: border-color 0.15s;
}
.conv-search-input:focus {
    outline: none;
    border-color: var(--blue-500);
}

/* Layout */
.conv-layout {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 0;
    height: calc(100vh - 12rem);
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 12px;
    overflow: hidden;
}

/* Conversation list */
.conv-list {
    border-right: 1px solid var(--gray-200);
    overflow-y: auto;
    background: white;
}
.conv-list::-webkit-scrollbar { width: 4px; }
.conv-list::-webkit-scrollbar-track { background: transparent; }
.conv-list::-webkit-scrollbar-thumb { background: var(--gray-200); border-radius: 2px; }

.conv-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--gray-100);
    transition: background 0.1s;
}
.conv-item:hover { background: var(--gray-50); }
.conv-item.active { background: var(--color-primary-50); }
.conv-item.unread .conv-item-name { font-weight: 700; }
.conv-item.unread .conv-item-preview { color: var(--gray-700); font-weight: 500; }

.conv-item-avatar {
    position: relative;
    flex-shrink: 0;
}
.conv-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.8125rem;
    flex-shrink: 0;
}
.conv-avatar-sm {
    width: 32px;
    height: 32px;
    font-size: 0.75rem;
}
.conv-unread-dot {
    position: absolute;
    top: 0;
    right: 0;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--blue-600);
    border: 2px solid white;
}

.conv-item-body {
    flex: 1;
    min-width: 0;
}
.conv-item-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 2px;
}
.conv-item-name {
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--gray-900);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.conv-item-time {
    font-size: 0.75rem;
    color: var(--gray-400);
    white-space: nowrap;
    flex-shrink: 0;
}
.conv-item-preview {
    font-size: 0.8125rem;
    color: var(--gray-500);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.conv-load-more { padding: 0.75rem; text-align: center; }
.conv-load-more-btn {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 500;
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    background: white;
    color: var(--gray-600);
    cursor: pointer;
}

/* Chat pane */
.conv-chat {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: white;
}
.conv-chat .chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    background: var(--gray-50);
}
.conv-chat .chat-messages::-webkit-scrollbar { width: 4px; }
.conv-chat .chat-messages::-webkit-scrollbar-track { background: transparent; }
.conv-chat .chat-messages::-webkit-scrollbar-thumb { background: var(--gray-200); border-radius: 2px; }

/* Chat header */
.conv-chat-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--gray-200);
    background: white;
}
.conv-back-btn {
    display: none;
    border: none;
    background: none;
    padding: 0.25rem;
    cursor: pointer;
    color: var(--gray-500);
    border-radius: 6px;
}
.conv-back-btn:hover { background: var(--gray-100); }
.conv-chat-header-info {
    flex: 1;
    min-width: 0;
}
.conv-chat-header-name {
    display: block;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--gray-900);
}
.conv-chat-header-sub {
    display: block;
    font-size: 0.75rem;
    color: var(--gray-500);
    margin-top: 1px;
}
.conv-header-action {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    background: white;
    color: var(--gray-500);
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.15s;
}
.conv-header-action:hover { background: var(--gray-50); color: var(--gray-700); }

/* Session selector bar */
.conv-session-bar {
    padding: 0.375rem 1rem;
    border-bottom: 1px solid var(--gray-100);
    background: white;
    min-height: 28px;
}
.conv-session-single {
    font-size: 0.75rem;
    color: var(--gray-400);
    padding: 0.125rem 0;
}
.conv-session-tabs {
    display: flex;
    gap: 0.375rem;
    overflow-x: auto;
    padding: 0.125rem 0;
}
.conv-session-tab {
    padding: 0.25rem 0.625rem;
    font-size: 0.6875rem;
    font-weight: 500;
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    background: white;
    color: var(--gray-600);
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: all 0.15s;
}
.conv-session-tab.active {
    background: var(--gray-900);
    color: white;
    border-color: var(--gray-900);
}
.conv-session-tab:hover:not(.active) { border-color: var(--gray-300); }

/* Read-only footer */
.conv-read-only-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0.5rem 1rem;
    border-top: 1px solid var(--gray-100);
    background: white;
    font-size: 0.6875rem;
    color: var(--gray-400);
}

/* â”€â”€ Message bubbles â”€â”€ */

.conv-date-sep {
    display: flex;
    justify-content: center;
    padding: 0.75rem 0 0.5rem;
}
.conv-date-sep span {
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--gray-400);
    background: white;
    padding: 0.125rem 0.625rem;
    border-radius: 20px;
    border: 1px solid var(--gray-200);
}

.conv-sender-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-400);
    margin: 0.75rem 0 0.25rem;
    padding: 0 2px;
}
.conv-sender-ai { text-align: right; }
.conv-sender-customer { text-align: left; }

.conv-bubble-wrap {
    display: flex;
    flex-direction: column;
    max-width: 75%;
}
.conv-wrap-ai { align-self: flex-end; align-items: flex-end; }
.conv-wrap-customer { align-self: flex-start; align-items: flex-start; }

.conv-bubble {
    padding: 0.625rem 0.875rem;
    font-size: 0.875rem;
    line-height: 1.55;
    word-break: break-word;
}
.conv-bubble-first { margin-top: 0.125rem; }
.conv-bubble-cont { margin-top: 2px; }

.conv-bubble-ai {
    background: var(--color-primary-50);
    color: var(--gray-800);
    border-radius: 12px 12px 4px 12px;
}
.conv-bubble-ai.conv-bubble-cont {
    border-radius: 12px 4px 4px 12px;
}

.conv-bubble-customer {
    background: white;
    color: var(--gray-800);
    border: 1px solid var(--gray-200);
    border-radius: 12px 12px 12px 4px;
}
.conv-bubble-customer.conv-bubble-cont {
    border-radius: 4px 12px 12px 4px;
}

.conv-bubble-text p { margin: 0 0 0.25rem; }
.conv-bubble-text p:last-child { margin-bottom: 0; }

.conv-bubble-time {
    font-size: 0.6875rem;
    color: var(--gray-400);
    margin-top: 0.25rem;
}

/* Rich content cards */
.conv-rich-confirm {
    margin-top: 0.5rem;
    padding: 0.625rem 0.75rem;
    background: var(--color-primary-50);
    border: 1px solid var(--color-primary-100);
    border-radius: 8px;
}
.conv-rich-confirm-title {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-primary-700);
}
.conv-rich-confirm-time {
    font-size: 0.8125rem;
    color: var(--gray-700);
    font-weight: 500;
    margin-top: 0.25rem;
}

.conv-status-pill {
    text-align: center;
    padding: 0.75rem 0;
}
.conv-status-pill > span,
.conv-status-pill {
    font-size: 0.6875rem;
    color: var(--gray-500);
}
.conv-status-done {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    font-weight: 500;
    color: var(--color-primary-700);
}

/* Empty states & loading */
.conv-empty-state {
    text-align: center;
    padding: 4rem 2rem;
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 12px;
}
.conv-empty-state h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-900);
    margin: 0 0 0.375rem;
}
.conv-empty-state p {
    font-size: 0.875rem;
    color: var(--gray-500);
    margin: 0 0 1rem;
    max-width: 340px;
    margin-left: auto;
    margin-right: auto;
}
.conv-empty-chat {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 2rem;
    color: var(--gray-500);
    text-align: center;
    flex: 1;
}
.conv-empty-chat p {
    font-size: 0.875rem;
    margin: 0.5rem 0 0;
    color: var(--gray-500);
}
.conv-empty-icon {
    width: 32px;
    height: 32px;
    color: var(--gray-300);
}
.conv-empty-btn {
    margin-top: 0.75rem;
    padding: 0.5rem 1rem;
    font-size: 0.8125rem;
    font-weight: 500;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    background: white;
    color: var(--gray-700);
    cursor: pointer;
}
.conv-empty-btn:hover { background: var(--gray-50); }

.conv-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 2rem;
    color: var(--gray-400);
    font-size: 0.8125rem;
}
.conv-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--gray-200);
    border-top-color: var(--gray-500);
    border-radius: 50%;
    animation: conv-spin 0.8s linear infinite;
}
@keyframes conv-spin { to { transform: rotate(360deg); } }

/* â”€â”€ Mobile â”€â”€ */
@media (max-width: 768px) {
    .conv-page-header { margin-bottom: 0.75rem; }
    .conv-page-title { font-size: 1.25rem; }
    .conv-search-wrap { max-width: 100%; }

    .conv-layout {
        grid-template-columns: 1fr;
        height: calc(100dvh - 14rem - 4.5rem);
        border-radius: 10px;
    }
    .conv-list {
        border-right: none;
        min-height: 0;
    }

    /* â”€â”€ Instagram-style full-screen chat overlay â”€â”€ */
    .conv-chat {
        display: flex;
        position: fixed;
        inset: 0;
        z-index: 950;
        background: white;
        flex-direction: column;
        transform: translateX(100%);
        visibility: hidden;
        transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1),
                    visibility 0.25s;
        /* Override grid placement */
        grid-column: 1;
        grid-row: 1;
    }
    .conv-chat.mobile-show {
        transform: translateX(0);
        visibility: visible;
    }
    .conv-back-btn { display: flex; }

    .conv-item { padding: 0.75rem; }
    .conv-bubble-wrap { max-width: 85%; }
    .conv-chat .chat-messages {
        padding: 1rem;
        padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    }
    .conv-chat .conv-read-only-footer {
        padding-bottom: calc(0.5rem + env(safe-area-inset-bottom, 0px));
    }
}

@media (max-width: 480px) {
    .conv-layout {
        height: calc(100dvh - 13.5rem - 4.5rem);
    }
    .conv-bubble-wrap { max-width: 92%; }
    .conv-avatar { width: 40px; height: 40px; font-size: 0.75rem; }
    .conv-item-name { font-size: 0.875rem; }
    .conv-item-preview { font-size: 0.8125rem; }
    .conv-bubble { font-size: 0.875rem; padding: 0.5rem 0.75rem; }
    .conv-chat-header { padding: 0.75rem; }
    .conv-search-input { font-size: 16px; /* prevents iOS zoom on focus */ }
}

/* Professional Conversation Styles */
.conversation-layout {
    display: grid;
    grid-template-columns: 350px 1fr;
    gap: 1.25rem;
    height: calc(100vh - 4rem);
}

.conversation-list {
    background: white;
    border-radius: var(--radius-lg);
    border: 1px solid var(--gray-200);
    overflow-y: auto;
    box-shadow: var(--shadow-sm);
}

.conversation-item {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--gray-200);
    cursor: pointer;
    transition: all var(--transition-base);
    position: relative;
}

.conversation-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--blue-600);
    transform: scaleX(0);
    transition: transform var(--transition-base);
}

.conversation-item:hover {
    background: var(--gray-50);
}

.conversation-item:hover::before {
    transform: scaleX(1);
}

.conversation-item.active {
    background: linear-gradient(90deg, var(--blue-50) 0%, white 100%);
    border-left: 3px solid var(--blue-600);
}

.conversation-item.active::before {
    transform: scaleX(1);
}

.conversation-chat {
    background: white;
    border-radius: var(--radius-lg);
    border: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-sm);
}

.chat-header {
    padding: 1.25rem 1.75rem;
    border-bottom: 1px solid var(--gray-200);
    background: linear-gradient(180deg, white 0%, var(--gray-50) 100%);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.75rem;
    background: linear-gradient(180deg, var(--gray-50) 0%, white 50%);
}

/* Smooth scrollbar for messages */
.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: var(--gray-100);
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--gray-400);
}

.message {
    margin-bottom: 1.25rem;
    animation: messageSlide var(--transition-base);
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-bubble {
    max-width: 70%;
    padding: 0.875rem 1.125rem;
    border-radius: var(--radius-lg);
    font-size: 0.9375rem;
    line-height: 1.5;
    box-shadow: var(--shadow-xs);
    position: relative;
}

.message.incoming .message-bubble {
    background: white;
    color: var(--gray-900);
    border: 1px solid var(--gray-200);
    border-bottom-left-radius: 4px;
}

.message.outgoing {
    display: flex;
    justify-content: flex-end;
}

.message.outgoing .message-bubble {
    background: linear-gradient(135deg, var(--blue-600) 0%, var(--blue-700) 100%);
    color: white;
    box-shadow: var(--shadow-md);
    border-bottom-right-radius: 4px;
}

/* AI Message Styling â€” subtle, professional */
.message.ai-message .message-bubble {
    background: var(--color-neutral-100);
    color: var(--color-neutral-800);
    border: 1px solid var(--color-neutral-200);
    box-shadow: var(--shadow-sm);
    position: relative;
}

.message.ai-message .message-sender {
    color: var(--color-primary-600);
    font-weight: 600;
    font-size: 0.75rem;
    letter-spacing: 0.02em;
}

.chat-input {
    padding: 1.25rem 1.75rem;
    border-top: 1px solid var(--gray-200);
    background: white;
}

.quick-replies {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.875rem;
    flex-wrap: wrap;
}
