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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: #f5f7fa;
    padding: 20px;
}

.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    border-bottom: 2px solid #e0e0e0;
}

.tab {
    padding: 12px 24px;
    background: white;
    border: none;
    border-radius: 8px 8px 0 0;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    color: #7f8c8d;
    transition: all 0.3s ease;
}

.tab:hover {
    color: #3498db;
    background: #f8f9fa;
}

.tab.active {
    color: #3498db;
    background: white;
    border-bottom: 3px solid #3498db;
    margin-bottom: -2px;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

h1 {
    color: #2c3e50;
    margin-bottom: 10px;
}

.subtitle {
    color: #7f8c8d;
    margin-bottom: 30px;
}

.filters {
    background: white;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.filters select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-right: 10px;
    font-size: 14px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: white;
    padding: 24px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.stat-value {
    font-size: 36px;
    font-weight: bold;
    color: #3498db;
    margin: 10px 0;
}

.stat-label {
    color: #7f8c8d;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.section {
    background: white;
    padding: 24px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin-bottom: 20px;
}

.section h2 {
    color: #2c3e50;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #ecf0f1;
}

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

th, td {
    text-align: left;
    padding: 12px;
    border-bottom: 1px solid #ecf0f1;
}

th {
    background: #f8f9fa;
    color: #2c3e50;
    font-weight: 600;
}

tr:hover {
    background: #f8f9fa;
}

.event-type {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

.event-message_sent { background: #e3f2fd; color: #1976d2; }
.event-message_received { background: #f3e5f5; color: #7b1fa2; }
.event-product_mentioned { background: #e8f5e9; color: #388e3c; }

.loading {
    text-align: center;
    padding: 40px;
    color: #7f8c8d;
}

.refresh-btn {
    background: #3498db;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.refresh-btn:hover {
    background: #2980b9;
}

.auto-refresh {
    color: #7f8c8d;
    font-size: 12px;
    margin-left: 10px;
}

/* Funnel Visualization Styles */
.funnel-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    max-width: 500px;
    margin: 0 auto;
}

.funnel-stage {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0;
    transition: all 0.3s ease;
    cursor: pointer;
}

.funnel-stage:hover {
    filter: brightness(1.1);
    transform: scale(1.02);
}

.funnel-bar {
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
    position: relative;
    clip-path: polygon(0% 0%, 100% 0%, 95% 100%, 5% 100%);
    transition: all 0.3s ease;
}

.funnel-stage:last-child .funnel-bar {
    clip-path: polygon(5% 0%, 95% 0%, 90% 100%, 10% 100%);
}

.funnel-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.funnel-label {
    font-size: 14px;
    font-weight: 600;
}

.funnel-count {
    font-size: 22px;
    font-weight: 700;
}

.funnel-dropoff {
    position: absolute;
    right: -100px;
    font-size: 12px;
    color: #e74c3c;
    font-weight: 500;
    background: #fff3f3;
    padding: 4px 8px;
    border-radius: 4px;
    white-space: nowrap;
}

.funnel-rate {
    position: absolute;
    left: -100px;
    font-size: 12px;
    color: #27ae60;
    font-weight: 500;
    background: #f0fff4;
    padding: 4px 8px;
    border-radius: 4px;
    white-space: nowrap;
}

.funnel-arrow {
    font-size: 20px;
    color: #bdc3c7;
    margin: 2px 0;
}

.funnel-empty {
    text-align: center;
    color: #7f8c8d;
    padding: 40px;
}

/* Live View Styles */
.live-session-card {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 15px;
    transition: all 0.3s ease;
}

.live-session-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.live-session-card.status-active {
    border-left: 4px solid #27ae60;
}

.live-session-card.status-idle {
    border-left: 4px solid #f39c12;
}

.live-session-card.status-left {
    border-left: 4px solid #e74c3c;
    opacity: 0.6;
}

.live-session-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.live-session-id {
    font-family: monospace;
    font-size: 12px;
    color: #7f8c8d;
}

.live-session-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 12px;
}

.live-session-status.active {
    background: #d5f5e3;
    color: #27ae60;
}

.live-session-status.idle {
    background: #fef9e7;
    color: #f39c12;
}

.live-session-status.left {
    background: #fadbd8;
    color: #e74c3c;
}

.live-session-funnel {
    display: flex;
    gap: 5px;
    margin: 10px 0;
}

.live-funnel-step {
    flex: 1;
    height: 6px;
    background: #ecf0f1;
    border-radius: 3px;
}

.live-funnel-step.completed {
    background: linear-gradient(90deg, #3498db, #2ecc71);
}

.live-session-page {
    font-size: 12px;
    color: #555;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.live-event-item {
    display: flex;
    gap: 10px;
    padding: 8px;
    background: #f8f9fa;
    border-radius: 4px;
    align-items: flex-start;
}

.live-event-time {
    color: #7f8c8d;
    font-size: 11px;
    white-space: nowrap;
}

.live-event-type {
    font-weight: 600;
    min-width: 120px;
}

.live-event-type.page_view { color: #3498db; }
.live-event-type.product_viewed { color: #9b59b6; }
.live-event-type.add_to_cart { color: #e67e22; }
.live-event-type.checkout_initiated { color: #1abc9c; }
.live-event-type.purchase_completed { color: #27ae60; }

.live-event-details {
    color: #555;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

.live-pulse {
    animation: pulse 2s infinite;
}

/* Session Explorer Styles */
.session-explorer-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    font-family: monospace;
}

.session-explorer-btn {
    padding: 12px 24px;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
}

.session-explorer-btn:hover {
    background: #2980b9;
}

/* Timeline Styles */
.timeline-event {
    display: flex;
    gap: 15px;
    padding: 12px;
    border-left: 3px solid #ddd;
    margin-left: 10px;
    transition: all 0.2s ease;
}

.timeline-event:hover {
    background: #f8f9fa;
}

.timeline-event.chatbot {
    border-left-color: #9b59b6;
}

.timeline-event.tracker {
    border-left-color: #3498db;
}

.timeline-time {
    color: #7f8c8d;
    font-size: 12px;
    white-space: nowrap;
    min-width: 140px;
}

.timeline-content {
    flex: 1;
}

.timeline-type {
    font-weight: 600;
    margin-bottom: 4px;
}

.timeline-details {
    font-size: 13px;
    color: #555;
}

/* Marketing Intelligence Styles */
.mi-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    margin-bottom: 20px;
}

.mi-header h2 {
    color: white;
    border: none;
    margin: 0;
    padding: 0;
}

.mi-sync-btn {
    background: rgba(255,255,255,0.2);
    color: white;
    border: 2px solid white;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
}

.mi-sync-btn:hover {
    background: rgba(255,255,255,0.3);
}

.lift-positive { color: #27ae60; }
.lift-negative { color: #e74c3c; }
.lift-neutral { color: #666; }

/* Attribution Tags */
.attribution-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}

.attribution-tag.chatbot-direct {
    background: #667eea22;
    color: #667eea;
}

.attribution-tag.chatbot-assisted {
    background: #764ba222;
    color: #764ba2;
}

.attribution-tag.organic {
    background: #95a5a622;
    color: #666;
}

/* Responsive Design */
@media (max-width: 768px) {
    .tabs {
        flex-wrap: wrap;
    }
    
    .tab {
        padding: 10px 16px;
        font-size: 13px;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .section {
        padding: 16px;
    }
}

@media (max-width: 480px) {
    body {
        padding: 10px;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .stat-value {
        font-size: 28px;
    }
}

/* ===== Widget Chat Styles ===== */
/* CSS Variables from Widget */
:root {
    --widget-primary-color: #667eea;
    --widget-secondary-color: #764ba2;
    --widget-gradient: linear-gradient(135deg, var(--widget-primary-color) 0%, var(--widget-secondary-color) 100%);
    --widget-text-color: #2d3748;
    --widget-border-radius: 16px;
    --widget-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* Chat Messages Container */
.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 20px;
    max-height: 600px;
    overflow-y: auto;
}

.message-content ul {
        padding-left: 30px;
    margin: 10px 0;
}

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

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--widget-primary-color);
    border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--widget-secondary-color);
}

/* Message Container */
.message {
    display: flex;
    gap: 12px;
    animation: fadeInUp 0.3s ease-out;
    align-items: flex-start;
}

.message.user {
    flex-direction: row-reverse;
}

.message.assistant {
    flex-direction: row;
}

/* Message Avatar */
.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.message.user .message-avatar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.message.assistant .message-avatar {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
}

/* Message Content Wrapper */
.message-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 75%;
    word-wrap: break-word;
}

.message.user .message-content {
    align-items: flex-end;
}

.message.assistant .message-content {
    align-items: flex-start;
}

/* Message Bubble */
.message-bubble {
    padding: 12px 16px;
    border-radius: var(--widget-border-radius);
    line-height: 1.5;
    font-size: 14px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

.message.user .message-bubble {
    background: var(--widget-gradient);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
    background: #f7fafc;
    color: var(--widget-text-color);
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
}

/* Message Time */
.message-time {
    font-size: 11px;
    color: #a0aec0;
    padding: 0 4px;
}

/* Product Cards in Messages */
.message-bubble .singleProduct {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px;
    margin: 12px 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
}

.message-bubble .singleProduct:hover {
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
    transform: translateY(-2px);
}

.message-bubble .singleProduct h3 {
    font-size: 16px;
    color: #2d3748;
    margin: 0 0 8px 0;
    font-weight: 600;
}

.message-bubble .singleProduct .product-price {
    font-size: 18px;
    font-weight: bold;
    color: var(--widget-primary-color);
    margin: 8px 0;
}

.message-bubble .viewDetails,
.message-bubble .add_to_cart_button {
    display: inline-block;
    padding: 8px 16px;
    margin: 4px 4px 0 0;
    border-radius: 8px;
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease;
    border: none;
    cursor: pointer;
}

.message-bubble .viewDetails {
    background: #f7fafc;
    color: var(--widget-primary-color);
    border: 1px solid var(--widget-primary-color);
}

.message-bubble .viewDetails:hover {
    background: var(--widget-primary-color);
    color: white;
}

.message-bubble .add_to_cart_button {
    background: var(--widget-gradient);
    color: white;
}

.message-bubble .add_to_cart_button:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Session Modal Overrides */
#sessionModal .chat-messages {
    background: #ffffff;
    border-radius: 8px;
    margin: 20px 0;
}

#sessionModal h2 {
    color: var(--widget-text-color);
    font-size: 24px;
    margin-bottom: 10px;
}

/* Info Icon & Help Modal */
.info-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    margin-left: 8px;
    transition: all 0.2s ease;
    vertical-align: middle;
    font-style: normal;
}

.info-icon:hover {
    transform: scale(1.15);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
}

.section h2 .info-icon {
    font-size: 11px;
    width: 18px;
    height: 18px;
}

/* Info Modal */
#infoModal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 2000;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

.info-modal-content {
    background: white;
    max-width: 550px;
    margin: 80px auto;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: slideIn 0.3s ease;
    overflow: hidden;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

.info-modal-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 24px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.info-modal-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}

.info-modal-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.info-modal-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.info-modal-body {
    padding: 30px;
    overflow-y: auto;
    flex: 1;
}

.info-modal-body p {
    color: #4a5568;
    line-height: 1.7;
    margin-bottom: 20px;
    font-size: 15px;
}

.info-modal-body p:last-child {
    margin-bottom: 0;
}

.info-modal-body strong {
    color: #2d3748;
}

.info-legend {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-top: 20px;
    padding: 20px;
    background: #f7fafc;
    border-radius: 12px;
}

.info-legend-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.info-legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-top: 4px;
    flex-shrink: 0;
}

.info-legend-text {
    font-size: 13px;
    color: #4a5568;
}

.info-legend-text strong {
    display: block;
    color: #2d3748;
    margin-bottom: 2px;
}

.info-tip {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
    background: linear-gradient(135deg, #e6fffa 0%, #ebf8ff 100%);
    border-radius: 10px;
    margin-top: 20px;
    border-left: 4px solid #38b2ac;
}

.info-tip-icon {
    font-size: 20px;
}

.info-tip-text {
    font-size: 14px;
    color: #234e52;
    line-height: 1.6;
}
