/* ==========================================================================
   MxChat Transcripts Page Styles - v2.0
   Uses admin-sidebar.css for core layout/navigation styles
   ========================================================================== */

/* ==========================================================================
   Stats Grid
   ========================================================================== */
.mxch-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--mxch-spacing-lg);
    margin-bottom: var(--mxch-spacing-xl);
}

.mxch-stat-card {
    background: var(--mxch-card-bg);
    border: 1px solid var(--mxch-card-border);
    border-radius: var(--mxch-radius-lg);
    padding: var(--mxch-spacing-lg);
    display: flex;
    align-items: center;
    gap: var(--mxch-spacing-md);
    transition: all var(--mxch-transition);
}

.mxch-stat-card:hover {
    box-shadow: var(--mxch-card-shadow-hover);
    transform: translateY(-2px);
}

.mxch-stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--mxch-radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.mxch-stat-icon svg {
    width: 24px;
    height: 24px;
}

.mxch-stat-icon-primary {
    background: rgba(120, 115, 245, 0.1);
    color: var(--mxch-primary);
}

.mxch-stat-icon-success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--mxch-success);
}

.mxch-stat-icon-info {
    background: rgba(59, 130, 246, 0.1);
    color: var(--mxch-info);
}

.mxch-stat-icon-warning {
    background: rgba(245, 158, 11, 0.1);
    color: var(--mxch-warning);
}

.mxch-stat-content {
    display: flex;
    flex-direction: column;
}

.mxch-stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--mxch-text-primary);
    line-height: 1.2;
}

.mxch-stat-label {
    font-size: 13px;
    color: var(--mxch-text-secondary);
    margin-top: 2px;
}

.mxch-stat-sublabel {
    font-size: 11px;
    color: var(--mxch-text-muted);
    margin-top: 4px;
}

/* ==========================================================================
   Cards Row Layout
   ========================================================================== */
.mxch-cards-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: var(--mxch-spacing-lg);
    margin-bottom: var(--mxch-spacing-xl);
}

.mxch-card-flex {
    display: flex;
    flex-direction: column;
}

/* ==========================================================================
   Activity Stats
   ========================================================================== */
.mxch-activity-stats {
    display: flex;
    flex-direction: column;
    gap: var(--mxch-spacing-md);
}

.mxch-activity-item {
    display: flex;
    align-items: center;
    gap: var(--mxch-spacing-md);
    padding: var(--mxch-spacing-sm);
    background: #f8fafc;
    border-radius: var(--mxch-radius-md);
}

.mxch-activity-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--mxch-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.mxch-activity-today {
    background: rgba(16, 185, 129, 0.1);
    color: var(--mxch-success);
}

.mxch-activity-week {
    background: rgba(59, 130, 246, 0.1);
    color: var(--mxch-info);
}

.mxch-activity-month {
    background: rgba(120, 115, 245, 0.1);
    color: var(--mxch-primary);
}

.mxch-activity-content {
    display: flex;
    flex-direction: column;
}

.mxch-activity-value {
    font-size: 20px;
    font-weight: 700;
    color: var(--mxch-text-primary);
}

.mxch-activity-label {
    font-size: 12px;
    color: var(--mxch-text-secondary);
}

/* ==========================================================================
   Insights List
   ========================================================================== */
.mxch-insights-list {
    display: flex;
    flex-direction: column;
    gap: var(--mxch-spacing-sm);
}

.mxch-insight-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--mxch-spacing-sm) 0;
    border-bottom: 1px solid var(--mxch-card-border);
}

.mxch-insight-item:last-child {
    border-bottom: none;
}

.mxch-insight-label {
    font-size: 13px;
    color: var(--mxch-text-secondary);
}

.mxch-insight-value {
    font-size: 14px;
    font-weight: 600;
    color: var(--mxch-text-primary);
}

/* Status Badges */
.mxch-status-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.mxch-status-active {
    background: rgba(16, 185, 129, 0.1);
    color: var(--mxch-success);
}

.mxch-status-moderate {
    background: rgba(245, 158, 11, 0.1);
    color: var(--mxch-warning);
}

.mxch-status-quiet {
    background: rgba(100, 116, 139, 0.1);
    color: var(--mxch-text-muted);
}

/* ==========================================================================
   Activity Chart
   ========================================================================== */
.mxch-activity-chart-card .mxch-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--mxch-spacing-sm);
}

.mxch-chart-legend {
    display: flex;
    align-items: center;
    gap: var(--mxch-spacing-lg);
}

.mxch-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 500;
    color: var(--mxch-text-secondary);
}

.mxch-legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.mxch-legend-chats .mxch-legend-dot {
    background: #667eea;
}

.mxch-legend-messages .mxch-legend-dot {
    background: #764ba2;
}

.mxch-chart-container {
    background: #f9fafb;
    border-radius: var(--mxch-radius-md);
    padding: var(--mxch-spacing-lg);
    border: 1px solid #e5e7eb;
}

#mxchat-activity-chart {
    max-height: 280px;
    width: 100% !important;
    height: 280px !important;
}

/* ==========================================================================
   Quick Actions
   ========================================================================== */
.mxch-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--mxch-spacing-md);
}

.mxch-quick-action-btn {
    display: flex;
    align-items: center;
    gap: var(--mxch-spacing-sm);
    padding: var(--mxch-spacing-md) var(--mxch-spacing-lg);
    background: #f8fafc;
    border: 1px solid var(--mxch-card-border);
    border-radius: var(--mxch-radius-md);
    color: var(--mxch-text-primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--mxch-transition-fast);
}

.mxch-quick-action-btn:hover {
    background: var(--mxch-primary);
    border-color: var(--mxch-primary);
    color: white;
}

.mxch-quick-action-btn svg {
    flex-shrink: 0;
}

/* ==========================================================================
   Transcripts Controls
   ========================================================================== */
.mxch-transcripts-controls {
    display: flex;
    flex-wrap: wrap;
    gap: var(--mxch-spacing-md);
    align-items: center;
    justify-content: space-between;
}

.mxch-search-wrapper {
    display: flex;
    align-items: center;
    gap: var(--mxch-spacing-sm);
    flex: 1;
    max-width: 400px;
    position: relative;
}

.mxch-search-wrapper svg {
    position: absolute;
    left: 12px;
    color: var(--mxch-text-muted);
    pointer-events: none;
}

.mxch-search-wrapper .mxch-input {
    padding-left: 40px;
}

.mxch-controls-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--mxch-spacing-sm);
}

/* Danger Button */
.mxch-btn-danger {
    background: white;
    color: var(--mxch-error);
    border: 1px solid var(--mxch-error);
}

.mxch-btn-danger:hover:not(:disabled) {
    background: var(--mxch-error);
    color: white;
}

.mxch-btn-danger:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ==========================================================================
   Split Panel Layout - Chat List + Conversation View
   ========================================================================== */

/* Override parent content padding and scrolling for split panel view */
.mxch-content:has(#all-chats.mxch-section.active) {
    padding: 0 !important;
    overflow: hidden !important; /* Prevent content area from scrolling */
    height: 100%;
}

#all-chats.mxch-section {
    padding: 0;
    margin: 0;
    height: 100%;
    overflow: hidden;
}

.mxch-split-panel {
    display: flex;
    height: 100%;
    background: #fff;
    border: none;
    border-radius: 0;
    overflow: hidden;
}

/* Hide the expand button - not needed */
.mxch-panel-expand {
    display: none;
}

/* Left Panel - Chat List */
.mxch-chat-list-panel {
    width: 340px;
    min-width: 280px;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #e5e7eb;
    background: #fff;
    min-height: 0; /* Important: allows flex child to shrink below content size */
    overflow: hidden;
}

/* Bulk Actions Toolbar */
.mxch-bulk-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: #f8fafc;
    border-bottom: 1px solid #e5e7eb;
}

.mxch-bulk-select-all {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #6b7280;
    cursor: pointer;
}

.mxch-bulk-select-all input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: #3b82f6;
}

.mxch-bulk-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
}

.mxch-bulk-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 500;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    color: #374151;
    cursor: pointer;
    transition: all 0.15s;
}

.mxch-bulk-btn:hover {
    background: #f3f4f6;
    border-color: #d1d5db;
}

.mxch-bulk-btn.mxch-bulk-delete {
    color: #dc2626;
    border-color: #fecaca;
}

.mxch-bulk-btn.mxch-bulk-delete:hover {
    background: #fef2f2;
    border-color: #fca5a5;
}

.mxch-bulk-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.mxch-selected-count {
    font-size: 11px;
    color: #3b82f6;
    font-weight: 600;
    padding: 2px 8px;
    background: #eff6ff;
    border-radius: 10px;
    display: none;
}

.mxch-selected-count.has-selection {
    display: inline-block;
}

.mxch-panel-header {
    padding: 0;
    border-bottom: 1px solid #e5e7eb;
}

.mxch-panel-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-bottom: 1px solid #f3f4f6;
}

.mxch-panel-count {
    font-size: 12px;
    font-weight: 600;
    color: #374151;
}

.mxch-panel-actions {
    display: flex;
    gap: 4px;
}

.mxch-icon-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: #6b7280;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.mxch-icon-btn:hover {
    background: #f3f4f6;
    color: #374151;
}

.mxch-icon-btn.spinning svg {
    animation: spin 0.5s linear;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.mxch-search-wrapper {
    position: relative;
    background: #fff;
}

.mxch-search-wrapper svg {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: #9ca3af;
    pointer-events: none;
    width: 14px;
    height: 14px;
    z-index: 1;
}

.mxch-search-input {
    width: 100%;
    padding: 10px 12px 10px 32px;
    border: none;
    border-radius: 0;
    font-size: 13px;
    background: #fff;
    transition: all 0.15s;
    box-sizing: border-box;
}

.mxch-search-input:focus {
    outline: none;
    background: #fff;
    box-shadow: none;
}

.mxch-search-input::placeholder {
    color: #9ca3af;
}

/* Chat List */
.mxch-chat-list {
    flex: 1;
    overflow-y: auto;
}

.mxch-chat-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    cursor: pointer;
    border-bottom: 1px solid #f3f4f6;
    transition: background 0.15s;
    position: relative;
}

.mxch-chat-item:hover {
    background: #f9fafb;
}

.mxch-chat-item.active {
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
    border-left: 3px solid #3b82f6;
    padding-left: 9px;
}

.mxch-chat-item.selected {
    background: #eff6ff;
}

/* Checkbox for chat items */
.mxch-chat-checkbox {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    cursor: pointer;
    accent-color: #3b82f6;
    opacity: 0;
    transition: opacity 0.15s;
}

.mxch-chat-item:hover .mxch-chat-checkbox,
.mxch-chat-item.selected .mxch-chat-checkbox,
.mxch-chat-list.selection-mode .mxch-chat-checkbox {
    opacity: 1;
}

/* Always show checkboxes on mobile/touch devices since hover doesn't work */
@media screen and (max-width: 782px) {
    .mxch-chat-checkbox {
        opacity: 0.4;  /* Subtle but visible */
    }

    .mxch-chat-item.selected .mxch-chat-checkbox,
    .mxch-chat-list.selection-mode .mxch-chat-checkbox {
        opacity: 1;
    }
}

/* Avatar hidden - cleaner look */
.mxch-chat-avatar {
    display: none;
}

.mxch-chat-info {
    flex: 1;
    min-width: 0;
}

.mxch-chat-name {
    font-size: 14px;
    font-weight: 600;
    color: #111827;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mxch-chat-preview {
    font-size: 12px;
    color: #6b7280;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.mxch-chat-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    flex-shrink: 0;
}

.mxch-chat-time {
    font-size: 11px;
    color: #9ca3af;
}

.mxch-chat-count {
    font-size: 11px;
    font-weight: 600;
    color: #6b7280;
    background: #f3f4f6;
    padding: 2px 8px;
    border-radius: 10px;
}

.mxch-list-loading,
.mxch-list-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: #9ca3af;
    font-size: 13px;
}

.mxch-panel-footer {
    padding: 8px 12px;
    border-top: 1px solid #e5e7eb;
    background: #f9fafb;
}

.mxch-pagination-btns {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.mxch-page-btn {
    width: 32px;
    height: 32px;
    border: 1px solid #e5e7eb;
    background: #fff;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: #374151;
    transition: all 0.15s;
}

.mxch-page-btn:hover {
    background: #f3f4f6;
    border-color: #d1d5db;
}

.mxch-page-info {
    font-size: 12px;
    color: #6b7280;
}

/* Expand Button */
.mxch-panel-expand {
    width: 24px;
    background: #f9fafb;
    border: none;
    border-left: 1px solid #e5e7eb;
    border-right: 1px solid #e5e7eb;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
    transition: all 0.15s;
}

.mxch-panel-expand:hover {
    background: #f3f4f6;
    color: #374151;
}

/* Right Panel - Conversation View */
.mxch-conversation-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #f9fafb;
    min-height: 0; /* Important: allows flex child to shrink below content size */
    overflow: hidden;
}

/* Empty State */
.mxch-conversation-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
    text-align: center;
    padding: 40px;
}

.mxch-empty-icon {
    margin-bottom: 16px;
    opacity: 0.5;
}

.mxch-conversation-empty h3 {
    font-size: 16px;
    font-weight: 600;
    color: #6b7280;
    margin: 0 0 8px 0;
}

.mxch-conversation-empty p {
    font-size: 13px;
    margin: 0;
}

/* Conversation Content */
.mxch-conversation-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0; /* Important: allows flex child to shrink below content size */
    overflow: hidden;
}

.mxch-conversation-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
}

.mxch-user-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.mxch-user-avatar span {
    color: #fff;
    font-size: 15px;
    font-weight: 600;
}

.mxch-user-info {
    flex: 1;
    min-width: 0; /* Allow flex item to shrink below content size */
    overflow: hidden;
}

.mxch-user-name {
    font-size: 15px;
    font-weight: 600;
    color: #111827;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mxch-user-meta {
    font-size: 12px;
    color: #6b7280;
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mxch-details-toggle {
    width: 36px;
    height: 36px;
    border: 1px solid #e5e7eb;
    background: #fff;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6b7280;
    transition: all 0.15s;
}

.mxch-details-toggle:hover,
.mxch-details-toggle.active {
    background: #f3f4f6;
    color: #374151;
}

/* Details Drawer */
.mxch-details-drawer {
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    padding: 16px 20px;
}

.mxch-details-section {
    margin-bottom: 16px;
}

.mxch-details-section:last-child {
    margin-bottom: 0;
}

.mxch-details-section h4 {
    font-size: 11px;
    font-weight: 600;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0 0 10px 0;
}

.mxch-detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    font-size: 13px;
}

.mxch-detail-label {
    color: #6b7280;
}

.mxch-detail-value {
    color: #111827;
    font-weight: 500;
}

.mxch-detail-value a {
    color: #3b82f6;
    text-decoration: none;
}

.mxch-detail-value a:hover {
    text-decoration: underline;
}

.mxch-clicked-links {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.mxch-clicked-link {
    font-size: 12px;
    color: #3b82f6;
    text-decoration: none;
    padding: 6px 10px;
    background: #eff6ff;
    border-radius: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mxch-clicked-link:hover {
    background: #dbeafe;
}

.mxch-details-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid #f3f4f6;
}

.mxch-btn-sm {
    padding: 8px 12px;
    font-size: 12px;
}

/* Translate Controls */
.mxch-translate-section {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #f3f4f6;
}

.mxch-translate-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.mxch-translate-select {
    padding: 6px 10px;
    font-size: 12px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: #fff;
    color: #374151;
    cursor: pointer;
    min-width: 100px;
}

.mxch-translate-select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

#mxch-translate-btn,
#mxch-show-original-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

#mxch-translate-btn svg,
#mxch-show-original-btn svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

#mxch-translate-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.mxch-translate-spinner {
    animation: spin 1s linear infinite;
}

@keyframes mxch-translate-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Translated message indicator */
.mxch-message-bubble.translated {
    position: relative;
}

.mxch-message-bubble.translated::after {
    content: '';
    position: absolute;
    top: 6px;
    right: 6px;
    width: 6px;
    height: 6px;
    background: #3b82f6;
    border-radius: 50%;
    opacity: 0.6;
}

/* Messages Area */
.mxch-messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

/* Mobile back button - hidden by default on desktop */
.mxch-mobile-back-btn {
    display: none;
}

.mxch-messages-loading,
.mxch-messages-error {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: #9ca3af;
    font-size: 13px;
}

/* Message Styles */
.mxch-message {
    margin-bottom: 20px;
}

.mxch-message:last-child {
    margin-bottom: 0;
}

/* User Message */
.mxch-message-user {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.mxch-message-user .mxch-message-row {
    max-width: 70%;
    min-width: 120px;
}

.mxch-message-user .mxch-message-bubble {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: #fff;
    padding: 12px 16px;
    border-radius: 18px 18px 4px 18px;
    font-size: 14px;
    line-height: 1.5;
    min-width: 80px;
}

.mxch-message-user .mxch-message-bubble a {
    color: #bfdbfe;
    text-decoration: underline;
}

.mxch-message-user .mxch-message-time {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 4px;
}

/* Bot Message */
.mxch-message-bot {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.mxch-message-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
}

.mxch-bot-label {
    font-size: 11px;
    font-weight: 600;
    color: #059669;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.mxch-rag-link {
    font-size: 11px;
    color: #3b82f6;
    text-decoration: none;
    font-weight: 500;
    padding: 2px 8px;
    background: #eff6ff;
    border-radius: 4px;
    transition: all 0.15s;
}

.mxch-rag-link:hover {
    background: #dbeafe;
}

.mxch-message-bot .mxch-message-row {
    max-width: 80%;
    min-width: 150px;
}

.mxch-message-bot .mxch-message-bubble {
    background: #fff;
    border: 1px solid #e5e7eb;
    color: #374151;
    padding: 12px 16px;
    border-radius: 18px 18px 18px 4px;
    font-size: 14px;
    line-height: 1.5;
    min-width: 100px;
}

.mxch-message-bot .mxch-message-bubble a {
    color: #3b82f6;
}

.mxch-message-bot .mxch-message-time {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 4px;
}

/* Message Content Styles */
.mxch-message-bubble p {
    margin: 0 0 10px 0;
}

.mxch-message-bubble p:last-child {
    margin-bottom: 0;
}

.mxch-message-bubble ul,
.mxch-message-bubble ol {
    margin: 10px 0;
    padding-left: 20px;
}

.mxch-message-bubble li {
    margin: 4px 0;
}

.mxch-message-bubble code {
    background: rgba(0, 0, 0, 0.08);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.9em;
}

.mxch-message-user .mxch-message-bubble code {
    background: rgba(255, 255, 255, 0.2);
}

.mxch-message-bubble pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 12px 14px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 10px 0;
    font-size: 13px;
}

.mxch-message-bubble pre code {
    background: none;
    padding: 0;
    color: inherit;
}

/* Scrollbar Styling */
.mxch-chat-list::-webkit-scrollbar,
.mxch-messages-area::-webkit-scrollbar {
    width: 6px;
}

.mxch-chat-list::-webkit-scrollbar-track,
.mxch-messages-area::-webkit-scrollbar-track {
    background: transparent;
}

.mxch-chat-list::-webkit-scrollbar-thumb,
.mxch-messages-area::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.mxch-chat-list::-webkit-scrollbar-thumb:hover,
.mxch-messages-area::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* Responsive Split Panel - Tablet */
@media screen and (max-width: 900px) and (min-width: 783px) {
    #all-chats.mxch-section {
        padding: 0;
    }

    .mxch-split-panel {
        flex-direction: column;
        height: auto;
    }

    .mxch-chat-list-panel {
        width: 100%;
        max-width: none;
        height: 350px;
        border-right: none;
        border-bottom: 1px solid #e5e7eb;
    }

    .mxch-panel-expand {
        display: none;
    }

    .mxch-conversation-panel {
        min-height: 400px;
    }

    .mxch-bulk-toolbar {
        flex-wrap: wrap;
    }

    .mxch-bulk-btn span {
        display: none;
    }
}

/* ==========================================================================
   Mobile Split Panel - Full Screen Panels
   ========================================================================== */
@media screen and (max-width: 782px) {
    #all-chats.mxch-section {
        padding: 0;
        /* Mobile viewport height with fallbacks for browser address bar */
        /* 1. Fallback: standard vh (may be cut off by browser chrome) */
        height: calc(100vh - 46px - 32px);
        /* 2. Better: dvh (dynamic viewport height) for modern browsers */
        height: calc(100dvh - 46px - 32px);
        /* 3. Best: JS-calculated actual viewport via CSS custom property */
        height: calc(var(--mxch-mobile-vh, 100vh) - 46px - 32px);
        overflow: hidden;
    }

    .mxch-split-panel {
        height: 100%;
        position: relative;
    }

    /* Chat List - Full screen on mobile */
    .mxch-chat-list-panel {
        width: 100%;
        max-width: none;
        height: 100%;
        border-right: none;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 10;
        transition: transform 0.3s ease;
    }

    .mxch-chat-list-panel.panel-hidden {
        transform: translateX(-100%);
    }

    .mxch-chat-list {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Conversation Panel - Slide over from right */
    .mxch-conversation-panel {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 20;
        transform: translateX(100%);
        transition: transform 0.3s ease;
        min-height: 0;
        height: 100%;
        display: flex;
        flex-direction: column;
    }

    .mxch-conversation-panel.panel-active {
        transform: translateX(0);
    }

    /* Mobile back button in conversation header */
    .mxch-mobile-back-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        background: #f3f4f6;
        border: none;
        border-radius: 8px;
        color: #374151;
        cursor: pointer;
        margin-right: 8px;
        flex-shrink: 0;
    }

    .mxch-mobile-back-btn:hover {
        background: #e5e7eb;
    }

    /* Ensure conversation content scrolls properly */
    .mxch-conversation-content {
        flex: 1;
        display: flex;
        flex-direction: column;
        min-height: 0;
        overflow: hidden;
    }

    /* Messages area scroll fix for mobile */
    .mxch-messages-area {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 16px;
        padding-bottom: 24px; /* Extra padding at bottom for visibility */
    }

    /* Hide expand button on mobile */
    .mxch-panel-expand {
        display: none;
    }

    /* Adjust bulk toolbar for mobile */
    .mxch-bulk-toolbar {
        flex-wrap: wrap;
        gap: 6px;
        padding: 8px 10px;
    }

    .mxch-bulk-btn span {
        display: none;
    }

    /* Make chat items more tappable */
    .mxch-chat-item {
        padding: 14px 12px;
    }

    /* Adjust conversation header for mobile */
    .mxch-conversation-header {
        padding: 12px 16px;
        flex-shrink: 0;
    }

    /* Details drawer adjustments */
    .mxch-details-drawer {
        max-height: 200px;
        overflow-y: auto;
        flex-shrink: 0;
    }

    /* Conversation empty state on mobile */
    .mxch-conversation-empty {
        display: none;
    }
}

/* ==========================================================================
   Pagination
   ========================================================================== */
.mxch-pagination {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    margin-top: var(--mxch-spacing-lg);
    padding: var(--mxch-spacing-md);
    background: var(--mxch-card-bg);
    border: 1px solid var(--mxch-card-border);
    border-radius: var(--mxch-radius-md);
}

.mxch-pagination-info {
    font-size: 13px;
    color: var(--mxch-text-secondary);
}

.mxch-pagination-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.mxch-pagination-btn {
    padding: 6px 12px;
    background: #f8fafc;
    border: 1px solid var(--mxch-card-border);
    border-radius: var(--mxch-radius-sm);
    color: var(--mxch-text-primary);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--mxch-transition-fast);
}

.mxch-pagination-btn:hover {
    background: #e2e8f0;
}

.mxch-pagination-btn.active {
    background: var(--mxch-primary);
    border-color: var(--mxch-primary);
    color: white;
}

.mxch-pagination-ellipsis {
    padding: 6px 8px;
    color: var(--mxch-text-muted);
}

/* ==========================================================================
   No Results
   ========================================================================== */
.mxch-no-results {
    text-align: center;
    padding: var(--mxch-spacing-xl) var(--mxch-spacing-lg);
    color: var(--mxch-text-muted);
    background: #f9fafb;
    border: 2px dashed var(--mxch-card-border);
    border-radius: var(--mxch-radius-lg);
}

.mxch-no-results svg {
    width: 48px;
    height: 48px;
    margin-bottom: var(--mxch-spacing-md);
    opacity: 0.5;
}

.mxch-no-results h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--mxch-text-secondary);
    margin: 0 0 var(--mxch-spacing-xs) 0;
}

.mxch-no-results p {
    font-size: 14px;
    margin: 0;
}

/* ==========================================================================
   Toggle Row
   ========================================================================== */
.mxch-toggle-row {
    display: flex;
    align-items: center;
    gap: var(--mxch-spacing-sm);
}

.mxch-toggle-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--mxch-text-primary);
}

/* ==========================================================================
   Modal Styles
   ========================================================================== */
.mxch-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100000;
    animation: mxchFadeIn 0.2s ease;
}

.mxch-modal-content {
    background: white;
    border-radius: var(--mxch-radius-lg);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    animation: mxchSlideIn 0.2s ease;
}

@keyframes mxchSlideIn {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.mxch-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--mxch-spacing-md) var(--mxch-spacing-lg);
    border-bottom: 1px solid var(--mxch-card-border);
}

.mxch-modal-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--mxch-text-primary);
    margin: 0;
}

.mxch-modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    font-size: 24px;
    color: var(--mxch-text-muted);
    cursor: pointer;
    border-radius: var(--mxch-radius-sm);
    transition: all var(--mxch-transition-fast);
}

.mxch-modal-close:hover {
    background: #f1f5f9;
    color: var(--mxch-text-primary);
}

.mxch-modal-body {
    flex: 1;
    padding: var(--mxch-spacing-lg);
    overflow-y: auto;
}

/* RAG Context Styles */
.mxch-rag-summary {
    display: flex;
    flex-wrap: wrap;
    gap: var(--mxch-spacing-md);
    padding: var(--mxch-spacing-md);
    background: #f8fafc;
    border-radius: var(--mxch-radius-md);
    margin-bottom: var(--mxch-spacing-lg);
}

.mxch-rag-summary-item {
    font-size: 13px;
}

.mxch-rag-label {
    color: var(--mxch-text-secondary);
}

.mxch-rag-value {
    font-weight: 600;
    color: var(--mxch-text-primary);
}

.mxch-rag-matches h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--mxch-text-primary);
    margin: 0 0 var(--mxch-spacing-md) 0;
}

.mxch-rag-match-card {
    border: 1px solid var(--mxch-card-border);
    border-radius: var(--mxch-radius-md);
    padding: var(--mxch-spacing-md);
    margin-bottom: var(--mxch-spacing-sm);
}

.mxch-rag-match-used {
    border-color: rgba(16, 185, 129, 0.3);
    background: rgba(16, 185, 129, 0.05);
}

.mxch-rag-match-below {
    border-color: var(--mxch-card-border);
    background: #fafafa;
}

.mxch-rag-match-header {
    display: flex;
    align-items: center;
    gap: var(--mxch-spacing-sm);
    margin-bottom: var(--mxch-spacing-sm);
}

.mxch-rag-match-score {
    font-size: 14px;
    font-weight: 700;
    color: var(--mxch-primary);
}

.mxch-rag-chunk-badge {
    font-size: 11px;
    padding: 2px 8px;
    background: rgba(120, 115, 245, 0.1);
    color: var(--mxch-primary);
    border-radius: 10px;
}

.mxch-rag-match-status {
    margin-left: auto;
    font-size: 12px;
    font-weight: 500;
}

.mxch-rag-match-status.status-used {
    color: var(--mxch-success);
}

.mxch-rag-match-status.status-below {
    color: var(--mxch-text-muted);
}

.mxch-rag-match-source {
    font-size: 13px;
    color: var(--mxch-text-secondary);
    word-break: break-all;
}

.mxch-rag-match-source a {
    color: var(--mxch-primary);
    text-decoration: none;
}

.mxch-rag-match-source a:hover {
    text-decoration: underline;
}

/* Context Modal Tabs */
.mxch-context-tabs {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: #f1f5f9;
    border-radius: var(--mxch-radius-md);
    margin-bottom: var(--mxch-spacing-md);
}

.mxch-context-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    border: none;
    background: transparent;
    border-radius: var(--mxch-radius-sm);
    font-size: 13px;
    font-weight: 500;
    color: var(--mxch-text-secondary);
    cursor: pointer;
    transition: all var(--mxch-transition-fast);
}

.mxch-context-tab:hover {
    color: var(--mxch-text-primary);
    background: rgba(255, 255, 255, 0.5);
}

.mxch-context-tab.active {
    background: white;
    color: var(--mxch-primary);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.mxch-context-tab svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.mxch-tab-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: rgba(120, 115, 245, 0.1);
    color: var(--mxch-primary);
    font-size: 11px;
    font-weight: 600;
    border-radius: 10px;
}

.mxch-context-tab.active .mxch-tab-badge {
    background: var(--mxch-primary);
    color: white;
}

.mxch-tab-content {
    min-height: 200px;
}

/* Action Specific Styles */
.mxch-action-triggered {
    border-color: rgba(245, 158, 11, 0.4);
    background: rgba(245, 158, 11, 0.08);
}

.mxch-action-threshold-badge {
    font-size: 11px;
    padding: 2px 8px;
    background: rgba(100, 116, 139, 0.1);
    color: var(--mxch-text-secondary);
    border-radius: 10px;
}

.mxch-rag-match-status.status-triggered {
    color: #f59e0b;
    font-weight: 600;
}

.mxch-action-details {
    margin-top: var(--mxch-spacing-sm);
}

.mxch-action-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--mxch-text-primary);
    margin-bottom: 4px;
}

.mxch-action-callback {
    font-size: 12px;
    color: var(--mxch-text-muted);
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
}

.mxch-action-callback-label {
    color: var(--mxch-text-secondary);
    font-family: inherit;
}

/* Action Score Bar Visualization */
.mxch-action-score-bar {
    position: relative;
    height: 6px;
    background: #e2e8f0;
    border-radius: 3px;
    margin-top: var(--mxch-spacing-sm);
    overflow: visible;
}

.mxch-action-score-fill {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    background: linear-gradient(90deg, #7873f5, #a5a1fa);
    border-radius: 3px;
    transition: width 0.3s ease;
}

.mxch-action-triggered .mxch-action-score-fill {
    background: linear-gradient(90deg, #f59e0b, #fbbf24);
}

.mxch-action-threshold-marker {
    position: absolute;
    top: -4px;
    width: 2px;
    height: 14px;
    background: #ef4444;
    border-radius: 1px;
    transform: translateX(-50%);
}

.mxch-action-threshold-marker::after {
    content: '';
    position: absolute;
    top: -3px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 4px solid #ef4444;
}

/* No Results State */
.mxch-no-results {
    text-align: center;
    padding: var(--mxch-spacing-xl);
    color: var(--mxch-text-secondary);
}

.mxch-no-results p {
    margin: 0;
}

/* ==========================================================================
   Responsive Adjustments
   ========================================================================== */
@media screen and (max-width: 768px) {
    .mxch-stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .mxch-stat-card {
        padding: var(--mxch-spacing-md);
    }

    .mxch-stat-value {
        font-size: 22px;
    }

    .mxch-cards-row {
        grid-template-columns: 1fr;
    }

    .mxch-transcripts-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .mxch-search-wrapper {
        max-width: none;
    }

    .mxch-controls-actions {
        justify-content: flex-end;
    }

    .mxch-session-header {
        flex-direction: column;
        gap: var(--mxch-spacing-sm);
    }

    .mxch-session-actions {
        opacity: 1;
        align-self: flex-end;
    }

    .mxch-pagination {
        flex-direction: column;
        gap: var(--mxch-spacing-md);
        align-items: flex-start;
    }

    .mxch-quick-actions {
        flex-direction: column;
    }

    .mxch-quick-action-btn {
        width: 100%;
        justify-content: center;
    }

    /* Chart responsive */
    .mxch-activity-chart-card .mxch-card-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .mxch-chart-legend {
        margin-top: var(--mxch-spacing-xs);
    }

    #mxchat-activity-chart {
        height: 220px !important;
    }
}

@media screen and (max-width: 480px) {
    .mxch-stats-grid {
        grid-template-columns: 1fr;
    }

    .mxch-controls-actions {
        flex-direction: column;
        width: 100%;
    }

    .mxch-controls-actions .mxch-btn {
        width: 100%;
        justify-content: center;
    }

    .mxch-controls-actions form {
        width: 100%;
    }
}

/* Product Card in Transcripts */
.mxch-message-bubble .mxchat-product-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 8px 0;
    padding: 12px;
    border-radius: 8px;
    background: #f9f9f9;
    border: 1px solid #e5e5e5;
    max-width: 280px;
}

.mxch-message-bubble .mxchat-product-card a.mxchat-product-link {
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.mxch-message-bubble .mxchat-product-card img.mxchat-product-image {
    max-width: 100%;
    height: auto;
    max-height: 180px;
    object-fit: contain;
    margin-bottom: 8px;
    border-radius: 6px;
}

.mxch-message-bubble .mxchat-product-card h3.mxchat-product-name {
    font-size: 14px;
    font-weight: 600;
    margin: 4px 0;
    text-align: center;
    color: #1a1a1a;
}

.mxch-message-bubble .mxchat-product-card .mxchat-product-price {
    color: #2e7d32;
    font-weight: 600;
    font-size: 15px;
    margin: 4px 0 8px;
}

.mxch-message-bubble .mxchat-product-card .mxchat-add-to-cart-button {
    background-color: #212121;
    color: #fff;
    padding: 7px 16px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    cursor: default;
    opacity: 0.6;
}

.mxch-message-bubble .mxchat-product-card select {
    width: 100%;
    padding: 6px 8px;
    margin: 4px 0;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
}

/* Featured Products in Transcripts */
.mxch-message-bubble .mxchat-featured-products {
    margin: 8px 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.4;
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 0;
}

.mxch-message-bubble .mxchat-featured-item {
    padding: 10px 0;
    border-bottom: 1px solid #e5e5e5;
    margin: 0;
}

.mxch-message-bubble .mxchat-featured-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.mxch-message-bubble .mxchat-featured-item:first-child {
    padding-top: 0;
}

.mxch-message-bubble .mxchat-featured-item-top {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.mxch-message-bubble .mxchat-featured-item-image {
    flex-shrink: 0;
    width: 70px;
    height: 70px;
    overflow: hidden;
    border-radius: 8px;
    background: #f1f1f1;
}

.mxch-message-bubble .mxchat-featured-item-image a {
    display: block;
    width: 70px;
    height: 70px;
    text-decoration: none;
}

.mxch-message-bubble .mxchat-featured-item-image img {
    width: 70px;
    height: 70px;
    object-fit: cover;
    border-radius: 8px;
    display: block;
}

.mxch-message-bubble .mxchat-featured-item-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    justify-content: center;
}

.mxch-message-bubble .mxchat-featured-item-title,
.mxch-message-bubble a.mxchat-featured-item-title {
    font-size: 13px;
    font-weight: 600;
    color: #1a1a1a;
    text-decoration: none;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin: 0;
    padding: 0;
}

.mxch-message-bubble a.mxchat-featured-item-title:hover {
    opacity: 0.8;
}

.mxch-message-bubble .mxchat-featured-item-price {
    font-weight: 700;
    font-size: 13px;
    color: #2e7d32;
    margin: 0;
}

.mxch-message-bubble .mxchat-featured-item-price del {
    opacity: 0.6;
    font-weight: 400;
    font-size: 0.85em;
    margin-right: 4px;
}

.mxch-message-bubble .mxchat-featured-item-price ins {
    text-decoration: none;
    background: none;
}

.mxch-message-bubble .mxchat-featured-item-actions {
    display: flex;
    flex-direction: row;
    gap: 8px;
    margin: 0;
    padding: 0;
}

.mxch-message-bubble .mxchat-featured-btn-details,
.mxch-message-bubble a.mxchat-featured-btn-details {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 7px 10px;
    font-size: 12px;
    font-weight: 500;
    border-radius: 6px;
    text-decoration: none;
    border: 1px solid #ddd;
    background: transparent;
    color: #1a1a1a;
    text-align: center;
    line-height: 1.2;
}

.mxch-message-bubble .mxchat-featured-btn-cart,
.mxch-message-bubble button.mxchat-featured-btn-cart {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 7px 10px;
    font-size: 12px;
    font-weight: 500;
    border-radius: 6px;
    border: none;
    background: #212121;
    color: #fff;
    cursor: default;
    opacity: 0.6;
    line-height: 1.2;
}
