/* Dashboard Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

.dashboard-container {
    max-width: 1200px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.dashboard-header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    padding: 1rem 2rem;
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
}

.dashboard-header h1 {
    color: #4a5568;
    font-size: 1.8rem;
    font-weight: 600;
}

.dashboard-header h1 i {
    margin-right: 0.5rem;
    color: #667eea;
}

.header-nav {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.btn { display:flex; align-items:center; gap:0.5rem; padding:0.5rem 1rem; border-radius:8px; font-weight:500; text-decoration:none; border:none; cursor:pointer; }
.btn.primary { background:#667eea; color:#fff; }
.btn.danger { background:#ef4444; color:#fff; }
.btn.light { background:#edf2f7; color:#2d3748; }
.btn:hover { filter: brightness(0.97); transform: translateY(-1px); transition: all .2s ease; }

.refresh-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: #48bb78;
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.refresh-btn:hover {
    background: #38a169;
    transform: translateY(-1px);
}

/* Main Content */
.dashboard-main {
    flex: 1;
    padding: 2rem;
    display: flex;
    gap: 2rem;
    flex-direction: column;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 0;
    border-bottom: 1px solid #e2e8f0;
    align-items: flex-end;
}

.tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: #f7fafc;
    color: #4a5568;
    border: 1px solid #e2e8f0;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    margin-bottom: -1px; /* sit on the tabs bottom border */
}

.tab-btn.active {
    background: #ffffff;
    color: #2d3748;
    border-color: #cbd5e0;
    border-bottom-color: #ffffff; /* connect with content */
    position: relative;
    z-index: 1;
}

.tab-btn:hover {
    background: #ffffff;
}

/* Conversations Section */
.conversations-section {
    flex: 1;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* KPI Cards */
.kpi-section { display:flex; gap:1rem; }
.kpi-card { flex:1; background: rgba(255, 255, 255, 0.95); border-radius: 16px; padding: 1rem; display:flex; align-items:center; gap:1rem; box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08); }
.kpi-icon { width:56px; height:56px; border-radius:50%; display:flex; align-items:center; justify-content:center; color:#fff; font-size:1.2rem; }
.kpi-icon.purple { background:#7c3aed; }
.kpi-icon.indigo { background:#4f46e5; }
.kpi-icon.blue { background:#2563eb; }
.kpi-value { font-size:1.75rem; font-weight:700; color:#2d3748; }
.kpi-label { color:#718096; font-size:0.9rem; }

.section-actions { display:flex; align-items:center; gap:1rem; }
.search-box { position:relative; }
.search-box input { padding:0.5rem 2rem 0.5rem 0.75rem; border:1px solid #e2e8f0; border-radius:8px; outline:none; }
.search-box i { position:absolute; right:8px; top:50%; transform: translateY(-50%); color:#718096; }

/* Analysis Section */
.analysis-section {
    flex: 1;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
}

.analysis-table-wrapper {
    width: 100%;
    overflow-x: auto;
}

.analysis-table {
    width: 100%;
    border-collapse: collapse;
}

.analysis-table th,
.analysis-table td {
    text-align: left;
    padding: 0.75rem;
    border-bottom: 1px solid #e2e8f0;
    font-size: 0.9rem;
}

.analysis-table thead th {
    background: #f7fafc;
    position: sticky;
    top: 0;
    z-index: 1;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid #e2e8f0;
}

.section-header h2 {
    color: #2d3748;
    font-size: 1.5rem;
    font-weight: 600;
}

.conversation-stats {
    color: #718096;
    font-size: 0.9rem;
}

.conversations-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Conversation Item */
.conversation-item {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 1.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.conversation-item:hover {
    border-color: #667eea;
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.15);
}

.conversation-item.active {
    border-color: #667eea;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.conversation-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.5rem;
}

.conversation-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.conversation-id {
    font-weight: 600;
    font-size: 0.9rem;
    color: #4a5568;
}

.conversation-item.active .conversation-id {
    color: white;
}

.conversation-date {
    font-size: 0.8rem;
    color: #718096;
}

.conversation-item.active .conversation-date {
    color: rgba(255, 255, 255, 0.8);
}

.conversation-preview {
    margin-bottom: 0.5rem;
}

.conversation-preview h4 {
    font-size: 1rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
    color: #2d3748;
}

.conversation-item.active .conversation-preview h4 {
    color: white;
}

.conversation-preview p {
    font-size: 0.9rem;
    color: #718096;
    line-height: 1.4;
}

.conversation-item.active .conversation-preview p {
    color: rgba(255, 255, 255, 0.9);
}

.conversation-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: #a0aec0;
}

.conversation-item.active .conversation-meta {
    color: rgba(255, 255, 255, 0.7);
}

.message-count {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* Analyze Button */
.analyze-btn {
    background: #3182ce;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
}

.analyze-btn:hover {
    background: #2c5aa0;
    opacity: 1;
    transform: translateY(-1px);
}

.analyze-btn:active {
    transform: translateY(0);
}

.analyze-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.conversation-item:hover .analyze-btn {
    opacity: 1;
}

/* Lead Quality Badge */
.lead-quality-badge {
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.lead-quality-badge.good {
    background: #c6f6d5;
    color: #22543d;
    border: 1px solid #9ae6b4;
}

.lead-quality-badge.ok {
    background: #fef5e7;
    color: #744210;
    border: 1px solid #f6e05e;
}

.lead-quality-badge.spam {
    background: #fed7d7;
    color: #742a2a;
    border: 1px solid #feb2b2;
}

/* Delete Button */
.delete-btn {
    background: #e53e3e;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
}

.delete-btn:hover {
    background: #c53030;
    opacity: 1;
    transform: translateY(-1px);
}

.delete-btn:active {
    transform: translateY(0);
}

.conversation-item:hover .delete-btn {
    opacity: 1;
}

/* Conversation Detail */
.conversation-detail {
    flex: 1;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.detail-header { display: grid; grid-template-columns: 1fr auto auto; gap: 0.5rem; align-items: center; margin-bottom: 1rem; padding-bottom: 0.75rem; border-bottom: 2px solid #e2e8f0; }
.close-btn { background:#ef4444; color:#fff; border:none; border-radius:8px; padding:0.35rem 0.6rem; cursor:pointer; }

.back-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: #e2e8f0;
    color: #4a5568;
    border: none;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.back-btn:hover {
    background: #cbd5e0;
    transform: translateY(-1px);
}

.detail-header h3 {
    color: #2d3748;
    font-size: 1.3rem;
    font-weight: 600;
}

.conversation-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.25rem;
    font-size: 0.9rem;
    color: #718096;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding-right: 0.5rem;
}

/* Message Styles */
.message {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    border-radius: 12px;
    max-width: 80%;
}

.message.user-message {
    align-self: flex-end;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    flex-direction: row-reverse;
}

.message.bot-message {
    align-self: flex-start;
    background: #f7fafc;
    color: #2d3748;
    border: 1px solid #e2e8f0;
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.user-message .message-avatar {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.bot-message .message-avatar {
    background: #667eea;
    color: white;
}

.message-content {
    flex: 1;
}

.message-content p {
    margin-bottom: 0.5rem;
    line-height: 1.5;
}

.message-time {
    font-size: 0.75rem;
    opacity: 0.7;
}

/* Loading State */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    color: #718096;
}

.loading-state i {
    font-size: 2rem;
    margin-bottom: 1rem;
    color: #667eea;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    text-align: center;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
}

.empty-state i {
    font-size: 4rem;
    color: #cbd5e0;
    margin-bottom: 1.5rem;
}

.empty-state h3 {
    color: #4a5568;
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.empty-state p {
    color: #718096;
    margin-bottom: 2rem;
    max-width: 400px;
}

.cta-button {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.cta-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3);
}

/* Responsive Design */
@media (max-width: 768px) {
    .dashboard-main {
        flex-direction: column;
        padding: 1rem;
    }
    
    .conversations-section,
    .conversation-detail {
        max-height: none;
    }
    
    .header-content {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }
    
    .header-nav {
        justify-content: center;
    }
    
    .message {
        max-width: 95%;
    }
}

/* Lead Analysis Display */
.lead-analysis-display {
    margin-top: 1rem;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid #3182ce;
}

.analysis-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #e2e8f0;
}

.analysis-header h4 {
    color: #2d3748;
    font-size: 0.9rem;
    font-weight: 600;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.analysis-header h4 i {
    color: #3182ce;
}

.analysis-content {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.analysis-item {
    font-size: 0.85rem;
    line-height: 1.4;
    color: #4a5568;
}

.analysis-item strong {
    color: #2d3748;
    font-weight: 600;
    margin-right: 0.5rem;
}

/* Success and Error Messages */
/* Toast notifications */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 9999;
}

.toast {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    font-weight: 500;
    background: white;
    border: 1px solid #e2e8f0;
    animation: toastIn 200ms ease-out;
    transition: transform 200ms ease, opacity 200ms ease;
}

.toast.hide {
    opacity: 0;
    transform: translateY(-6px);
}

.toast-success {
    border-left: 4px solid #38a169;
}

.toast-error {
    border-left: 4px solid #e53e3e;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

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

/* Scrollbar Styling */
.conversations-list::-webkit-scrollbar,
.messages-container::-webkit-scrollbar {
    width: 6px;
}

.conversations-list::-webkit-scrollbar-track,
.messages-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.conversations-list::-webkit-scrollbar-thumb,
.messages-container::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.conversations-list::-webkit-scrollbar-thumb:hover,
.messages-container::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}
